-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi.ts
82 lines (76 loc) · 1.99 KB
/
api.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import * as path from 'path';
import { ApolloServer } from 'apollo-server-express';
import express from 'express'
import { nexusPrisma } from 'nexus-plugin-prisma';
import { DateTimeResolver } from 'graphql-scalars';
import { asNexusMethod, makeSchema, fieldAuthorizePlugin, connectionPluginCore } from 'nexus';
import { db } from './context';
import * as HTTP from 'http'
import * as types from './graphql';
import cors from 'cors';
import { loggingPlugin } from './loggingPlugin'
export const schema = makeSchema({
types: [
asNexusMethod(DateTimeResolver, 'date'),
types,
],
sourceTypes: {
modules: [{ module: '.prisma/client', alias: 'PrismaClient' }],
},
contextType: {
module: require.resolve('./context'),
export: 'Context',
alias: 'ContextModule'
},
shouldExitAfterGenerateArtifacts: Boolean(
process.env.NEXUS_SHOULD_EXIT_AFTER_REFLECTION,
),
shouldGenerateArtifacts: Boolean(
process.env.NEXUS_SHOULD_GENERATE_ARTIFACTS,
),
plugins: [nexusPrisma({
prismaClient: (ctx) => ctx.db,
experimentalCRUD: true,
scalars: {
DateTime: DateTimeResolver,
},
shouldGenerateArtifacts: Boolean(
process.env.NEXUS_SHOULD_GENERATE_ARTIFACTS,
)
}),
fieldAuthorizePlugin()],
outputs: {
typegen: path.join(
__dirname,
'node_modules/@types/nexus-typegen/index.d.ts',
),
schema: path.join(__dirname, './api.graphql'),
},
});
const apollo = new ApolloServer({
context: (ctx) => {
return {
db,
req: ctx.req,
res: ctx.res,
}
},
schema,
// plugins: [
// loggingPlugin, <--- Enable for GraphQL query logs
// ],
})
const app = express()
app.use(cors({
credentials: true,
origin: process.env.ALLOWED_ORIGINS ? process.env.ALLOWED_ORIGINS.split(' ') : '',
}))
const http = HTTP.createServer(app)
apollo.applyMiddleware({
app,
cors: false,
})
const PORT = process.env.PORT || 4000;
http.listen(PORT, () => {
console.log(`🚀 GraphQL service ready at http://localhost:4000/graphql`)
})