The resolve function

It's time to talk about the optional resolve function in a field configuration object:

type GraphQLFieldConfig = { 
  type: GraphQLOutputType; 
  args?: GraphQLFieldConfigArgumentMap; 
  resolve?: GraphQLFieldResolveFn; 
  deprecationReason?: string; 
  description?: ?string; 
} 

We've already seen the resolve function in our example schema, where we used it to return data for each field. This function can accept four optional arguments:

type GraphQLFieldResolveFn = ( 
  source?: any, 
  args?: {[argName: string]: any}, 
  context?: any, 
  info?: GraphQLResolveInfo 
) => any; 

First argument – source

This argument represents the field we're configuring. For example, on the EmployeeType, we can define a name field to use the source argument value to read ...

Get Learning GraphQL and Relay now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.