Stefan N
12/03/2020, 12:57 PMRyan
12/03/2020, 1:10 PMschema.graphql
created by Nexus, and also will autogenerate queries for you based on the schema and queries that you provide.
The types that Prisma generate can be used in the backend to map to your database schema. This is helpful sometimes in your resolver or in your external business logic.
Finally the types that nexus-plugin-prisma
generates is used specifically for the resolvers and to help specify what type must be returned and used including arguments.
So basically on the frontend, GraphQL Codegen is your friend and will help you write all the necessary queries and the rest can be used in the backend as mentioned above ๐Stefan N
12/03/2020, 1:37 PM@prisma/client
there as well, which of course is a pitfall better not to fall into. When working with db queries and results it's also clear. I guess where I'm struggling the most is with the resolvers, where I'm not quite certain how to best leverage both the nexus.ts
as well as the nexus-plugin-prisma
types. Some additional docs around FieldResolver, NexusGenRootTypes and NexusGenFieldTypes, etc. could help.Ryan
12/03/2020, 1:45 PMargs
and the return type of the resolver.
For e.g.
t.nullable.field('publish', {
type: 'Post',
args: { id: intArg() },
async resolve(_parent, { id }, ctx) {
const newPost = await ctx.prisma.post.update({
where: { id },
data: { published: true },
})
ctx.pubsub.publish('latestPost', newPost)
return newPost
},
})
In this resolver, you are using the TypeScript type Post
in the field where type: 'Post'
.
All the inputObjectType
and objectType
that you create are generated as TS types and are available to use directly in the resolver.
Some additional docs around FieldResolver, NexusGenRootTypes and NexusGenFieldTypes, etc. could help.Yes this needs to be explained more in the docs as that is not mentioned clearly there ๐