Created
January 18, 2017 15:07
-
-
Save zgababa/153367eef3506dcdf19e0c3f903124d1 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 rootSchema = require('./schema/rootSchema'); | |
const app = express(); | |
const PORT = 3001; | |
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