Skip to content

Instantly share code, notes, and snippets.

@flesch
Created January 28, 2017 15:56
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 flesch/8a76a26c092e15a4cfab1dc621f86428 to your computer and use it in GitHub Desktop.
Save flesch/8a76a26c092e15a4cfab1dc621f86428 to your computer and use it in GitHub Desktop.
'use strict';
const { graphql, GraphQLSchema, GraphQLObjectType, GraphQLString } = require('graphql');
const Query = new GraphQLObjectType({
name: 'Query',
description: 'The root type defines how GraphQL operations begin. It is the entry point to constructing GraphQL queries.',
fields: () => ({
hello: {
type: GraphQLString,
args: {
name: { type:GraphQLString }
},
resolve: (root, args, context) => args.name
}
})
});
const Mutation = new GraphQLObjectType({
name: 'Mutation',
description: 'The mutation type defines how GraphQL operations change data.',
fields: () => ({
hello: {
type: GraphQLString,
args: {
name: { type:GraphQLString }
},
resolve:(root, args, context) => args.name
}
})
});
const schema = new GraphQLSchema({ query:Query, mutation:Mutation });
const query = `
query {
hello(name: "world")
}
`;
graphql(schema, query).then(result => console.log('query:', JSON.stringify(result, null, 2)));
const mutation = `
mutation {
hello(name: "world")
}
`;
graphql(schema, mutation).then(result => console.log('mutation:', JSON.stringify(result, null, 2)));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment