Skip to content

Instantly share code, notes, and snippets.

@jvadillo
Created July 12, 2017 11:48
Show Gist options
  • Save jvadillo/6ba1a54de6962b32a5dbb3050b5c7c9e to your computer and use it in GitHub Desktop.
Save jvadillo/6ba1a54de6962b32a5dbb3050b5c7c9e to your computer and use it in GitHub Desktop.
GraphQL Hello World example
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