Skip to content

Instantly share code, notes, and snippets.

@zgababa
Created January 18, 2017 15:52
Show Gist options
  • Save zgababa/df7ba66489ed30e1bb9db59ed2927297 to your computer and use it in GitHub Desktop.
Save zgababa/df7ba66489ed30e1bb9db59ed2927297 to your computer and use it in GitHub Desktop.
'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