-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.ts
51 lines (43 loc) · 1.45 KB
/
app.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
const { ApolloServer } = require('apollo-server-lambda');
import { PrismaClient } from "@prisma/client";
import { Context } from "./graphql"
import { asNexusMethod, makeSchema } from "nexus";
import { nexusSchemaPrisma } from 'nexus-plugin-prisma/schema';
import * as path from 'path';
import { account } from "./graphql/schema/account/type";
import { GraphQLBigInt } from "./graphql/type";
import Query from './graphql/query';
const schema = makeSchema({
types: [Query, account, asNexusMethod(GraphQLBigInt, 'BigInt')],
plugins: [
nexusSchemaPrisma({
experimentalCRUD: true,
paginationStrategy: 'prisma',
prismaClient: (ctx: Context) => ctx.db,
outputs: {
typegen: path.join(`${process.env.NODE_ENV === "development" ? __dirname : ""}` + '/tmp/generated/typegen-nexus-plugin-prisma.d.ts'),
},
})
],
outputs: {
schema: path.join(`${process.env.NODE_ENV === "development" ? __dirname : ""}` + '/tmp/generated/schema.graphql'),
typegen: path.join(`${process.env.NODE_ENV === "development" ? __dirname : ""}` + '/tmp/generated/nexus.ts')
}
});
const server = new ApolloServer({
schema: schema,
context: async ({ req }): Promise<Context> => ({
db: new PrismaClient()
}),
playground: process.env.NODE_ENV === "production"
? false
: {
endpoint: `/${process.env.NODE_ENV}/graphql`,
}
});
exports.graphqlHandler = server.createHandler({
cors: {
origin: '*',
credentials: true,
},
});