Skip to content

Latest commit

History

History
40 lines (34 loc) 路 1.45 KB

2021-07-04.md

File metadata and controls

40 lines (34 loc) 路 1.45 KB
publish_date
2021-07-04
  • Learning lots from

    • prisma 2 schema auto completion rocks! but it auto completes with PascalCase watch out for that!

    • placing the prisma instance into the ApolloServer context is a good idea! it means that when we create our mutations and resolvers we have access to prisma via context e.g prisma.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) => {},
             },
           };