All Hooks
The following hooks are currently supported, but more may be added in future. Trying to add a hook for a hook name that does not exist will result in an error.
-
build: The build object represents the current schema build and is passed to all hooks, hook the 'build' event to extend this object. GraphQL types should not be constructed during this phase. -
init: The init event is triggered afterbuildand should be used to register the GraphQL type names and their specifications for types that may be useful later. The argument to this is an opaque object and should be passed through unmodified (it currently is an empty object that gets ignored). -
GraphQLSchema: This event defines the root-level schema configuration; hook it to addquery,mutation,subscriptionroot operations or similar options. -
GraphQLObjectType*: When creating a GraphQLObjectType, we'll execute the following hooks:GraphQLObjectTypeto add any root-level attributes, e.g. a description.GraphQLObjectType_interfacesto add additional interfaces to this object type.GraphQLObjectType_fields(deferred) to add additional fields to this object type. It is ran asynchronously (by passingfieldsas a thunk toGraphQLObjectType) and gets a reference to the final GraphQL Type asSelfin the context.GraphQLObjectType_fields_field: to manipulate any root-level attributes on an individual field, e.g. add a description.GraphQLObjectType_fields_field_argsto add arguments of an individual field.GraphQLObjectType_fields_field_args_argto modify a specific argument.
-
GraphQLInputObjectType*: When creating a GraphQLInputObjectType, we'll execute the following hooks:GraphQLInputObjectTypeto add any root-level attributes, e.g. a description.GraphQLInputObjectType_fields(deferred) to add additional fields to this input type. It is ran asynchronously (by passingfieldsas a thunk toGraphQLInputObjectType) and gets a reference to the final GraphQL Type asSelfin the context.GraphQLInputObjectType_fields_field: to customize an individual field from above.
-
GraphQLEnumType*: When creating a GraphQLEnumType, we'll execute the following hooks:GraphQLEnumTypeadd any root-level attributes, e.g. add a description.GraphQLEnumType_valuesadd values.GraphQLEnumType_values_valuecustomize an individual value from above.
-
finalize: This event is triggered when the schema has been constructed, hook it to modify or wrap the built schema instance.
This documentation does NOT contains all the hooks.
The "(deferred)" hooks above (and their descendents) are not called until
after the object is constructed (which means they can reference the object
itself - allowing circular references such as type Query { query: Query });
GraphQL will automatically call them when Type.getFields() is called, which
may still be within the same tick - i.e. they are not necessarily fully
asynchronous.
Input types
Depending on the hook being called the input object might be an array (as in the
case of GraphQLObjectType_interfaces) or an object (as in all other cases,
currently). More specifically, the types for each hook are:
-
inflection - a plain object with some core inflection methods, built in
makeNewBuild -
build - a
Buildobject -
init - an opaque object, please just return it verbatim
-
GraphQLSchema -
GraphQLSchemaConfig -
GraphQLObjectType -
GraphQLObjectTypeConfig -
GraphQLObjectType_interfaces - array of
GraphQLInterfaceTypeinstances -
GraphQLObjectType_fields -
GraphQLFieldConfigMap -
GraphQLObjectType_fields_field -
GraphQLFieldConfig -
GraphQLObjectType_fields_field_args -
GraphQLFieldConfigArgumentMap -
GraphQLInputObjectType -
GraphQLInputObjectTypeConfig -
GraphQLInputObjectType_fields -
GraphQLInputObjectConfigFieldMap -
GraphQLInputObjectType_fields_field -
GraphQLInputObjectFieldConfig -
GraphQLEnumType -
GraphQLEnumTypeConfig -
GraphQLEnumType_values -
GraphQLEnumValueConfigMap -
GraphQLEnumType_values_value -
GraphQLEnumValueConfig -
finalize -
GraphQLSchema