-
-
prisma 2 schema auto completion rocks! but it auto completes with
PascalCase
watch out for that! -
placing the
prisma
instance into theApolloServer
context
is a good idea! it means that when we create our mutations and resolvers we have access to prisma via context e.gprisma.context
. -
The real magic is when when combine the prisma autogenerated types with
GraphQL Code Generator
- We can tell the codegen also use a custom interface which defines the
context
. -
- overwrite: true
schema: ”http://localhost:4000”
generates:
src/generated/graphql.ts:
plugins: - “typescript” - “typescript-resolvers”
config:
contextType: ../context#Context
useIndexSignature: true
- When then use the Resolvers types in our code like so, we have full prisma auto completion on the
context
argument. -
import { Resolvers } from "./generated/graphql"; export const resolvers: Resolvers = { Query: { AllPosts: async (_, args, context) => { }, }, Mutation: { AddPost: async (_, args, context) => {}, LikePost: async (_, args, context) => {}, }, };
- We can tell the codegen also use a custom interface which defines the
-