$chiubaca / notes / fleeting / 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) => {},
             },
           };
Edit on GitHub ✏️

Hey I'm Alex Chiu 👋. These are my notes for literally anything.

I'm using the Zettelkasten method to organise my thoughts here.

My more polished writings are published to my main blog at chiubaca.com

Follow me on: Github / X (Twitter) / Mastodon / LinkedIn