-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathindex.js
More file actions
33 lines (25 loc) · 749 Bytes
/
index.js
File metadata and controls
33 lines (25 loc) · 749 Bytes
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
'use strict';
const express = require('express');
const graphql = require('graphql').graphql;
const graphqlHTTP = require('express-graphql');
const rootSchema = require('./schema/rootSchema');
const app = express();
const PORT = 3001;
app.use('/graphiql', graphqlHTTP({
schema : rootSchema,
pretty : true,
graphiql : true
}));
app.get('/graphql', (req, res) => {
const graphqlQuery = req.query.graphqlQuery;
if (!graphqlQuery) {
return res.status(500).send('You must provide a query');
}
return graphql(rootSchema, graphqlQuery)
.then(response => response.data)
.then((data) => res.json(data))
.catch((err) => console.error(err));
});
app.listen(PORT, () => {
console.log('Server running on port', PORT);
});