-
-
Save lgs/8c91325db2177180848827ec68545d7e 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