-
Notifications
You must be signed in to change notification settings - Fork 5
/
app.js
32 lines (26 loc) · 838 Bytes
/
app.js
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
import koa from 'koa';
import cors from 'kcors';
import logger from 'koa-logger';
import koaRouter from 'koa-router';
import koaBody from 'koa-bodyparser';
import { graphqlKoa, graphiqlKoa } from 'apollo-server-koa';
import schema from './schema';
/* eslint new-cap: ["error", { "newIsCap": false }] */
const app = new koa();
const router = new koaRouter();
// koaBody is needed just for POST.
router.post('/graphql', koaBody(), graphqlKoa({ schema }));
router.get('/graphql', graphqlKoa({ schema }));
// GraphiQL tool
router.get('/graphiql', graphiqlKoa({ endpointURL: '/graphql' }));
if (process.env.NODE_ENV === 'development') {
const corsOptions = {
credentials: true,
origin: '*',
};
app.use(cors(corsOptions));
}
app.use(logger());
app.use(router.routes());
app.use(router.allowedMethods());
export default app;