Created
January 28, 2017 15:56
-
-
Save flesch/8a76a26c092e15a4cfab1dc621f86428 to your computer and use it in GitHub Desktop.
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
'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