1 | import { ApolloServer } from 'apollo-server-express';
|
2 | import cookieParser from 'cookie-parser';
|
3 | import express from 'express';
|
4 | import hopsConfig from 'hops-config';
|
5 | import schema from 'hops-graphql/schema';
|
6 |
|
7 | const apolloAppPromise = Promise.resolve(
|
8 | typeof schema === 'function' ? schema() : schema
|
9 | ).then(resolvedSchema => {
|
10 | const app = express();
|
11 | app.use(cookieParser());
|
12 |
|
13 | const server = new ApolloServer({
|
14 | schema: resolvedSchema,
|
15 | playground: {
|
16 | settings: {
|
17 | 'request.credentials': 'same-origin',
|
18 | },
|
19 | },
|
20 | context: context => ({ ...context, config: hopsConfig }),
|
21 | });
|
22 |
|
23 | server.applyMiddleware({
|
24 | app,
|
25 | path: hopsConfig.graphqlMockServerPath,
|
26 | cors: {
|
27 | credentials: true,
|
28 | origin: true,
|
29 | methods: 'GET,HEAD,PUT,PATCH,POST,DELETE',
|
30 | allowedHeaders: 'content-type',
|
31 | },
|
32 | });
|
33 |
|
34 | return app;
|
35 | });
|
36 |
|
37 | export default (req, res, next) => {
|
38 | apolloAppPromise.then(app => app.handle(req, res, next), next);
|
39 | };
|