import * as path from 'path' ; import { ApolloServer } from 'apollo-server-lambda' ; import { applyMiddleware } from 'graphql-middleware' ; import { makePrismaSchema } from 'nexus-prisma' ; import { GraphQLSchema } from 'graphql' ; import datamodelInfo from './generated/nexus-prisma' ; import { permissions } from './permissions' ; import * as allTypes from './resolvers' ; import { Prisma , prisma } from './generated/prisma-client' ; import { Ctx } from './types' ; const prismaInstance = ( ) : Prisma => new Prisma ( { endpoint : process . env . PRISMA_ENDPOINT , debug : process . env . NODE_ENV !== 'production' , secret : process . env . PRISMA_SECRET , } ) ; const schema = applyMiddleware ( makePrismaSchema ( { types : allTypes , prisma : { datamodelInfo , client : prisma , } , outputs : { schema : path . resolve ( './src/generated/schema.graphql' ) , typegen : path . resolve ( './src/generated/nexus.ts' ) , } , nonNullDefaults : { input : false , output : false , } , typegenAutoConfig : { sources : [ { source : path . resolve ( './src/types.ts' ) , alias : 'types' , } , ] , contextType : 'types.Ctx' , } , } ) , permissions ) ; const server = new ApolloServer ( { schema , context : ( req ) : Ctx => ( { ... req , prisma : prismaInstance ( ) , } ) , } ) ; exports . handler = server . createHandler ( ) ;