Skip to content

Instantly share code, notes, and snippets.

@bencooling
Created January 14, 2017 04:42
Show Gist options
  • Save bencooling/fb6f27e89b792f49ba57ebed088513e1 to your computer and use it in GitHub Desktop.
Save bencooling/fb6f27e89b792f49ba57ebed088513e1 to your computer and use it in GitHub Desktop.
javascript: graphql
const { graphql, buildSchema } = require('graphql');
const schema = buildSchema(`
type Query {
hello: String,
}
`);
const query = '{ hello }';
const resolver = { hello: () => 'Hello world!' }
graphql(schema, query, resolver).then(console.log);
const {
graphql,
GraphQLSchema,
GraphQLObjectType,
GraphQLString
} = require('graphql');
const schema = new GraphQLSchema({
query: new GraphQLObjectType({
name: 'RootQueryType',
fields: {
hello: {
type: GraphQLString,
resolve() {
return 'world';
}
}
}
})
});
var query = '{ hello }';
graphql(schema, query).then(console.log);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment