Skip to content

Instantly share code, notes, and snippets.

@kkworden
Last active December 10, 2018 19:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kkworden/f36d1a04d8fdafa0eb7f32169604774b to your computer and use it in GitHub Desktop.
Save kkworden/f36d1a04d8fdafa0eb7f32169604774b to your computer and use it in GitHub Desktop.
Basic Express and GraphQL Setup
'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());
// Construct a schema, using GraphQL schema language
const schema = graphql.buildSchema(`
type Query {
hello: String
}
`);
// The root provides a resolver function for each API endpoint
const root = {
hello: () => {
return 'Hello world!';
},
};
// Run the GraphQL query '{ hello }' and print out the response
graphql.graphql(schema, '{ hello }', root).then((response) => {
console.log(JSON.stringify(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