-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
36 lines (26 loc) · 815 Bytes
/
server.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
33
34
35
36
'use strict';
const config = require('config');
const Koa = require('koa');
const KoaRouter = require('koa-router');
const koaBody = require('koa-bodyparser');
const { graphqlKoa, graphiqlKoa } = require('apollo-server-koa');
const schema = require('./schema/executableSchema');
const app = new Koa();
const router = new KoaRouter({
prefix: config.router.prefix
});
app.use(koaBody());
router.get('/graphiql', graphiqlKoa({
endpointURL: `${config.router.prefix}/graphql`
}));
const graphqlHandler = graphqlKoa(request => ({
schema: schema,
context: request
}));
router.get('/graphql', graphqlHandler);
router.post('/graphql', graphqlHandler);
app.use(router.routes());
app.use(router.allowedMethods());
const PORT = config.port;
app.listen(PORT);
console.log(`Listening on port ${PORT}`);