-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
46 lines (39 loc) · 1.02 KB
/
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
37
38
39
40
41
42
43
44
45
46
import Koa from 'koa';
import Router from 'koa-router';
import graphqlHttp from 'koa-graphql';
import convert from 'koa-convert';
import { koaPlayground } from 'graphql-playground-middleware';
import mongoose from 'mongoose';
import { graphql } from 'graphql';
import graphqlSchema from './src/data/schema';
mongoose.connect(''); // Your database endpoint goes here. Example: mongodb://user:password@ds999999.mlab.com:99999/myApp
const PORT = process.env.PORT || 5000;
const schema = graphqlSchema();
const app = new Koa();
const router = new Router();
router.all(
'/playground',
koaPlayground({
endpoint: '/graphql',
}),
);
router.all(
'/graphql',
convert(
graphqlHttp(async (req, ctx) => {
return {
graphiql: true,
schema,
rootValue: {
request: ctx.req,
},
context: {},
};
}),
),
);
// app.use(router.routes()).use(router.allowedMethods());
app.use(router.routes());
app.listen(PORT, () => {
console.info('Server running on port %s', PORT);
});