From f794aebfa933f837b4b369d5aedcef627e6156fc Mon Sep 17 00:00:00 2001 From: "Kalle (Sendou)" <38327916+Sendouc@users.noreply.github.com> Date: Wed, 14 Oct 2020 00:04:40 +0300 Subject: [PATCH] get user by either discord id or custom url --- graphql/context.ts | 2 +- graphql/schema/user.ts | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/graphql/context.ts b/graphql/context.ts index cfdad5599..51f9b1761 100644 --- a/graphql/context.ts +++ b/graphql/context.ts @@ -1,6 +1,6 @@ import { PrismaClient } from "@prisma/client"; -const prisma = new PrismaClient(); +const prisma = new PrismaClient({log: ["query"]}); export interface Context { prisma: PrismaClient; diff --git a/graphql/schema/user.ts b/graphql/schema/user.ts index 99524c710..b34f3f800 100644 --- a/graphql/schema/user.ts +++ b/graphql/schema/user.ts @@ -18,10 +18,20 @@ export const Query = queryType({ args: { identifier: stringArg({required: true}) }, - resolve: (_root, {identifier}, ctx) => ctx.prisma.user.findOne({ + resolve: (_root, {identifier}, ctx) => ctx.prisma.user.findFirst({ where: { - discordId: identifier - } + // this is ok because the values are mutually exclusive: customUrlPath can't contain only numbers etc. + OR: [ + { + discordId: identifier + }, + { + profile: { + customUrlPath: identifier.toLowerCase() + } + }, + ] + }, }) }) }