Skip to content

Instantly share code, notes, and snippets.

@kkworden kkworden/index.js

Last active Dec 10, 2018
Embed
What would you like to do?
Execute GraphQL Query Inside of Endpoint
'use strict';
const express = require('express');
const bodyParser = require('body-parser');
const graphql = require('graphql');
const app = express();
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.get('/', function(req, res) {
res.send('We\'re in business');
});
app.post('/api', function(req, res) {
const schema = graphql.buildSchema(`
type Query {
hello: String
}
`);
const root = {
hello: () => {
return 'Hello world!';
},
};
graphql.graphql(schema, req.body.query, root).then((response) => {
res.send(response);
});
});
app.listen(8080, (app) => {
console.log('App is listening');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.