Last active
October 12, 2017 21:13
-
-
Save BransonGitomeh/50e400065886131ae315c70b3d88fbe2 to your computer and use it in GitHub Desktop.
Express router, graphql, GCP cloud function
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
import express from 'express'; | |
import graphqlHTTP from 'express-graphql'; | |
import { buildSchema } from 'graphql'; | |
const router = express.Router(); | |
const schema = buildSchema(` | |
type Query { | |
hello: String | |
}`); | |
const rootValue = { hello: () => 'Hello world students!' }; | |
router.get( | |
'/', | |
graphqlHTTP({ | |
schema, | |
rootValue, | |
graphiql: true, | |
}), | |
); | |
router.post( | |
'/', | |
graphqlHTTP(() => { | |
const startTime = Date.now(); | |
return { | |
schema, | |
rootValue, | |
graphiql: false, | |
extensions() { | |
return { runTime: `${Date.now() - startTime} ms` }; | |
}, | |
}; | |
}), | |
); | |
const test = router; | |
export { test }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
test locally with
Put this beside the build folder where your output is.