-
Notifications
You must be signed in to change notification settings - Fork 342
/
server.ts
31 lines (26 loc) · 884 Bytes
/
server.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
import { ApolloServer } from 'apollo-server-micro';
import { getBuiltMesh } from './.mesh';
const isProd = process.env.NODE_ENV === 'production';
let apolloServer: ApolloServer;
export default async function createApolloServer() {
if (apolloServer) return apolloServer;
const { schema, cache, getEnveloped } = await getBuiltMesh();
apolloServer = new ApolloServer({
schema,
introspection: !isProd,
cache,
executor: async requestContext => {
const { schema, execute, contextFactory } = getEnveloped({
request: requestContext.request.http,
});
return execute({
schema: schema,
document: requestContext.document,
contextValue: await contextFactory(),
variableValues: requestContext.request.variables,
operationName: requestContext.operationName,
});
},
});
return apolloServer;
}