Last active
December 10, 2018 19:29
-
-
Save kkworden/f36d1a04d8fdafa0eb7f32169604774b to your computer and use it in GitHub Desktop.
Basic Express and GraphQL Setup
This file contains hidden or 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 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