How to pass GraphQLResolveInfo to Prisma client?

prisma

#1

The Prisma binding docs recommend using Prisma Client over the bindings:

Note : Unless you explicitly want to use schema delegation we recommend to use Prisma client to build a GraphQL server see tutorial.

However, I haven’t been able to find a way to pass the GraphQLResolveInfo from frontend requests to the Prisma Client.

Is this possible?

For example, I generate the Typescript client and my server looks like

import { prisma } from 'backend/generated/prisma-client';
const server = new ApolloServer({
    schema,
    context: async ctx => ({
        ...ctx,
        db: prisma,
    }),
});

Then on the frontend let’s say I want to get a user’s account page and the team they’re on so I have a component like

import React from 'react';
import gql from 'graphql-tag';
import { Query } from 'react-apollo';

const MeQuery = gql`
    query MeQuery {
        me {
            id
            name
            team {
                id
                name
            }
        }
    }
`;

export default Account = () => (
    <Query query={MeQuery}>
        {({ data }) => (
            <div>{data}</div>
        )}
    </Query>
);

With Prisma binding, I’m able to access that frontend query via the info parameter in my resolver which correctly let’s the request know to return the team relation.

// Using Prisma Binding as ctx.db
const Query = {
    async me(parent, args, ctx, info) {
        return ctx.db.query.user(
            {
                where: { email: ctx.userEmail },
            },
            info
        );
    },
};

But with Prisma Client, I haven’t been able to figure out how to return that team relation based on the request from the frontend?

I know Prisma Client has the $fragment API

const Query = {
    // Using Prisma Client as ctx.db
    async me(parent, args, ctx, info) {
        const fragment = `
        fragment UserWithTeam on User {
            id
            name
            team {
                id
                name
            }
        }
        `;
        return ctx.db.user({ email: ctx.userEmail }).$fragment(fragment);
    },
};

But I’m then importing/exporting fragments between the frontend+backend and the fragment syntax doesn’t seem to play well with React Apollo on the frontend.

I’d also personally prefer to have the frontend dictate the return data from these resolvers and have the queries live in the components using them vs. having to redefine fragments for each request.

Is this possible with Prisma Client or should I just continue with Prisma Binding?

Thanks!