This version of graphql-js introduces a breaking change to the method signature of the resolve() method.
Previously, resolve() had this method signature:
type GraphQLResolveInfo = {
fieldName: string,
fieldASTs: Array<Field>,
returnType: GraphQLOutputType,
parentType: GraphQLCompositeType,
schema: GraphQLSchema,
fragments: { [fragmentName: string]: FragmentDefinition },
rootValue: mixed,
operation: OperationDefinition,
variableValues: { [variableName: string]: mixed },
};
resolve(
source: mixed,
args: {[argName: string]: mixed},
info: GraphQLResolveInfo
): mixedTypically, when you wanted to thread request or other context-specific information down to the resolve functions, you might have included it in rootValue when calling graphql():
// Pre 0.6.0
graphql(req => {
return {
rootValue: {viewer: req.userID},
schema,
};
});Now there exists a bonafide context property that you can set for exactly this purpose:
// New in 0.6.0
graphql(req => {
return {
context: {viewer: req.userID}, // NEW
schema,
};
});graphql-js 0.6.0 will make this context prop available to each one of your resolve() methods as the third argument:
resolve(
source: mixed,
args: {[argName: string]: mixed},
context: mixed, // NEW
info: GraphQLResolveInfo // MOVED
): mixedNote that the info argument has moved to the fourth position. Anyone previously making use of the info argument will have to update the method signatures of their resolve() methods.
@steveluscher: Just noticed this excellent gist and thought it might be useful to know that this change actually happened with v0.5.0 already.
The main change from v0.5.0 to v0.6.0 was the addition of experimental schema directives, but that requires no code changes.