Fetch a record and its relations with Prisma Client


Let’s say I have this:

type User {
    id: ID! @id
    email: String! @unique
    customer: Customer

I want to retrieve the customer. I’ve seen two ways to do it in the docs but none of theme are satisfying.

Solution 1

let customer = await prisma.user({ email: args.email }).customer()

Now, how can I access to the user record itself?

Solution 2

let user: User = await prisma.user({ email: args.email }).$fragment(`
        fragment EnsureCustomer on User {
            customer {

While I can use user.customer to access the data, this makes my IDE cry as the customer property doesn’t exist in User (I’m using typeScript).

Any thought on that ?


Create a User.js resolver and do something like

User: { costumer: (root) => prisma.user({email:root.email}).costumer() }


Thanks but this part of my code is not related to GraphQL so creating a resolver won’t help.