What pattern to follow when exposing Prisma API mutations via graphql-yoga server?



I have a set-up based on the advanced Node boilerplate: a graphql-yoga server and a Prisma server. Our client is a React app using Apollo.

What pattern would be recommended when exposing Prisma API mutations via the graphql-yoga server?

As an example, imagine a schema with a type Employee, a type Team, and a one to many relationship between them. In most cases, the mutation I’d like to make from the front-end is broadly similar to the existing Prisma API for createEmployee. However, in lots of the example code it seems common not to expose the wrapper fields such as data or connect when specifying the mutation schema for your graphql-yoga server. I might therefore expose a createEmployee mutation such as:

createEmployee(name: String!, teamIds: [ID!])

In my resolver function, I’d then need to map the variables from this mutation to something I can send to Prisma via the bindings:

prisma.mutation.createEmployee({ data: { name: args.name, teams: { connect: args.teamIds.map(id => ({ id }))

It’s quite frustrating to replicate this mapping for every resolver. It also means there’s two different APIs to follow - the API we expose to the front-end, and then the Prisma API.

Alternatively, I could expose the Prisma API’s schema to the front-end. However, it’s quite verbose compared to the previous simple API, and would mean rewriting all our client-side mutations.

What pattern would be recommended here?


I’ve got the exact same problem
Have you found a solution for this @Lewis_Blackwood?


Hey @carstenbaumhoegger,

I didn’t find a great solution to this. Eventually, I ended up exposing an API broadly similar to the old Graphcool Framework API from my yoga app. My yoga app then has lots of handwritten resolvers that essentially map that Framework API to the new Prisma API. I add authorization steps in my resolvers too prior to reading from/writing to the Prisma API.

I wrote a comment on one of the Github issues describing this problem here. My comment has some links to other relevant issues too, so might be worth checking out those.

Let me know if you have any more questions!