import execa from 'execa' ; import * as FS from 'fs-jetpack' ; import * as nexusBuilder from 'nexus/dist/builder' ; import * as Path from 'path' ; import { getImportPathRelativeToOutput } from '../src/utils' ; import * as types from './__app/main' ; import { createNexusPrismaInternal , mockConsoleLog } from './__utils' ; it ( 'integrates together' , async ( ) => { const fs = FS . cwd ( Path . join ( __dirname , '__app' ) ) ; fs . remove ( 'generated' ) ; fs . remove ( '../node_modules/@generated' ) ; execa . sync ( 'prisma' , [ 'generate' ] , { cwd : fs . cwd ( ) , } ) ; const nexusPrismaTypegenPath = fs . path ( `generated/nexus-plugin-prisma-typegen.d.ts` ) ; const typegenFacadePath = require . resolve ( '../src/typegen/static' ) ; const nexusPrisma = createNexusPrismaInternal ( { shouldGenerateArtifacts : true , outputs : { typegen : nexusPrismaTypegenPath , } , experimentalCRUD : true , /**
         * Import nexus-prisma from the local typegen.d.ts file, as nexus-prisma is not installed
         */ nexusPrismaImportId : getImportPathRelativeToOutput ( Path . dirname ( nexusPrismaTypegenPath ) , typegenFacadePath ) , } ) ; process . env . NODE_ENV = 'development' ; await mockConsoleLog ( async ( ) => { await nexusBuilder . generateSchema ( { types , plugins : [ nexusPrisma ] , shouldGenerateArtifacts : true , outputs : { typegen : fs . path ( `generated/nexus-typegen.d.ts` ) , schema : fs . path ( `generated/schema.graphql` ) , } , } ) ; } ) ; const graphqlSchema = fs . read ( 'generated/schema.graphql' ) ; const nexusPrismaTypeGen = fs . read ( 'generated/nexus-plugin-prisma-typegen.d.ts' ) ; expect ( removeNexusHeader ( graphqlSchema ) ) . toMatchSnapshot ( 'graphql schema' ) ; expect ( nexusPrismaTypeGen ) . toMatchSnapshot ( 'nexus prisma typegen' ) ; expect ( require ( '@prisma/client' ) . dmmf ) . toMatchSnapshot ( 'prisma client dmmf' ) ; expect ( fs . cwd ( ) ) . toTypeCheck ( ) ; } ) ; function removeNexusHeader ( schema ) { if ( ! schema ) { return schema ; } return schema . split ( '\n' ) . filter ( ( line ) => line . startsWith ( '###' ) === false ) . join ( '\n' ) ; }