Created
January 18, 2017 15:52
-
-
Save zgababa/df7ba66489ed30e1bb9db59ed2927297 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment