Skip to content

Instantly share code, notes, and snippets.

@lgs
Forked from websoftwares/graphql.js
Created December 27, 2017 11:31
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 lgs/8c91325db2177180848827ec68545d7e to your computer and use it in GitHub Desktop.
Save lgs/8c91325db2177180848827ec68545d7e to your computer and use it in GitHub Desktop.
Getting GraphQL on webtask.io running
'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