-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
27 lines (19 loc) · 834 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
const Koa = require('koa');
const koaBody = require('koa-body');
const { graphqlKoa, graphiqlKoa } = require('apollo-server-koa');
const Router = require('koa-router');
const mongoose = require('mongoose');
const products = require('./modules/products/route');
mongoose.connect(process.env.MONGO_URL || 'mongodb://localhost/products');
const app = new Koa();
const router = Router();
const myGraphQLSchema = require('./schema');
app.use(koaBody());
app.use(products.routes());
app.use(router.routes());
// koaBody is needed just for POST.
router.post('/graphql', graphqlKoa({ schema: myGraphQLSchema }));
router.get('/graphql', graphqlKoa({ schema: myGraphQLSchema }));
router.post('/graphiql', graphiqlKoa({ endpointURL: '/graphql' }));
router.get('/graphiql', graphiqlKoa({ endpointURL: '/graphql' }));
module.exports = app;