Last active
December 27, 2017 11:31
-
-
Save websoftwares/98da45dab653eab528a3fba0b722c4ad to your computer and use it in GitHub Desktop.
Getting GraphQL on webtask.io running
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 latest' | |
const express = require('express') | |
const graphqlHTTP = require('express-graphql') | |
const { buildSchema } = require('graphql') | |
const app = express() | |
const webtask = require('webtask-tools') | |
const bodyParser = require('body-parser') | |
const schema = buildSchema(` | |
type Query { | |
hello: String | |
} | |
`) | |
const root = { hello: () => 'Hello world!' } | |
app.use(bodyParser.urlencoded({ extended: true })) | |
app.use(bodyParser.json()) | |
app.post('/', graphqlHTTP({ | |
schema: schema, | |
rootValue: root, | |
graphiql: false | |
})) | |
app.get('/', graphqlHTTP({ | |
schema: schema, | |
rootValue: root, | |
graphiql: true | |
})) | |
module.exports = webtask.fromExpress(app) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment