Skip to content

Instantly share code, notes, and snippets.

@rohan-varma
Created September 3, 2016 11:45
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 rohan-varma/1f897987fa4d965513cd8a2e5024b4e4 to your computer and use it in GitHub Desktop.
Save rohan-varma/1f897987fa4d965513cd8a2e5024b4e4 to your computer and use it in GitHub Desktop.
const Query = new GraphQLObjectType({
name: 'Query',
//our server can return pokemon and moves.
fields: {
pokemon: {
type: pokemonType, //the type we defined earlier
args: {
id: {type: GraphQLString} //an id can be passed in to the query to select the pokemon needed.
},
resolve: (_,args) => data[args.id], //uses the id as a key to fulfill the request. Note that if there's no id passed in,
//null will be returned. In practice, you may wish to throw an exception or handle this error in some manner.
},
move: {
type: moveType,
args: {
id: {type: GraphQLString}
},
resolve: (_,args) => moves[args.id],
},
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment