Created
July 12, 2017 11:48
-
-
Save jvadillo/6ba1a54de6962b32a5dbb3050b5c7c9e to your computer and use it in GitHub Desktop.
GraphQL Hello World example
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
var { graphql, buildSchema } = require('graphql'); | |
// Construct a schema, using GraphQL schema language | |
var schema = buildSchema(` | |
type Query { | |
hello: String | |
} | |
`); | |
// The root provides a resolver function for each API endpoint | |
var root = { | |
hello: () => { | |
return 'Hello world!'; | |
}, | |
}; | |
// Run the GraphQL query '{ hello }' and print out the response | |
graphql(schema, '{ hello }', root).then((response) => { | |
console.log(response); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment