-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.js
31 lines (25 loc) · 835 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
const bodyParser = require('body-parser');
const cors = require('cors');
const express = require('express');
const graphqlExpress = require('graphql-server-express').graphqlExpress;
const graphiqlExpress = require('graphql-server-express').graphiqlExpress;
const schema = require('./Schema').schema;
const GraphQLServer = express().use('*', cors());
// basic health route, ping /health to determine server health
GraphQLServer.get('/health', (req, res) => {
res.sendStatus(200);
});
// graphiql explorer
// ping /graphiql for an in-browser GUI explorer
GraphQLServer.use('/graphiql', graphiqlExpress({
endpointURL: '/graphql',
}));
// graphql endpoint
GraphQLServer.use(
'/',
bodyParser.json(),
graphqlExpress({ schema })
);
GraphQLServer.listen(3000, () => {
console.log(`GraphQL Server listening on port 3000`);
});