-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.koa.js
42 lines (33 loc) · 975 Bytes
/
server.koa.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
import koa from 'koa';
import koaRouter from 'koa-router';
import koaBody from 'koa-bodyparser';
import { apolloKoa, graphiqlKoa } from 'apollo-server';
import { makeExecutableSchema, addMockFunctionsToSchema } from 'graphql-tools';
import Schema from './data/schema';
import Mocks from './data/mocks';
import Resolvers from './data/resolvers';
const PORT = 8080;
const app = new koa();
const router = new koaRouter();
const executableSchema = makeExecutableSchema({
typeDefs: Schema,
resolvers: Resolvers,
});
/*addMockFunctionsToSchema({
schema: executableSchema,
mocks: Mocks,
preserveResolvers: false,
});*/
app.use(koaBody());
router.get('/graphiql', graphiqlKoa({
endpointURL: '/graphql',
}));
router.post('/graphql', apolloKoa({
schema: executableSchema,
context: {},
}));
app.use(router.routes());
app.use(router.allowedMethods());
app.listen(PORT, () => console.log(
`GraphQL Server is now running on http://localhost:${PORT}/graphql`
));