import "reflect-metadata" ; import { promises as fs } from "fs" ; import { buildSchema } from "type-graphql" ; import { graphql , GraphQLSchema } from "graphql" ; import generateArtifactsDirPath from "../helpers/artifacts-dir" ; import { generateCodeFromSchema } from "../helpers/generate-code" ; describe ( "errors" , ( ) => { let outputDirPath ; let graphQLSchema ; describe ( "getPrismaFromContext" , ( ) => { beforeAll ( async ( ) => { outputDirPath = generateArtifactsDirPath ( "functional-crud" ) ; await fs . mkdir ( outputDirPath , { recursive : true } ) ; const prismaSchema = `
        model User {
          intIdField          Int     @id @default(autoincrement())
          uniqueStringField   String  @unique
          optionalStringField String?
          dateField           DateTime
        }
      ` ; await generateCodeFromSchema ( prismaSchema , { outputDirPath } ) ; const { UserCrudResolver } = require ( outputDirPath + "/resolvers/crud/User/UserCrudResolver.ts" ) ; graphQLSchema = await buildSchema ( { resolvers : [ UserCrudResolver ] , validate : false , } ) ; } ) ; it ( "should throw error when prisma not provided in context" , async ( ) => { const document = `
        query {
          user(where: { uniqueStringField: "uniqueValue" }) {
            intIdField
            dateField
          }
        }
      ` ; const { errors } = await graphql ( graphQLSchema , document , null , { } ) ; expect ( errors ) . toMatchInlineSnapshot ( `
        Array [
          [GraphQLError: Unable to find Prisma Client in GraphQL context. Please provide it under the \`context.prisma\` key.],
        ]
      ` ) ; } ) ; } ) ; } ) ;