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.

(See hooks in the source)

  • inflection: The inflection object provides methods to derive names and will be part of the Build object, hook on the 'inflection' event to customize this object.
  • build: The build object represents the current schema build and is passed to all hooks, hook the 'build' event to extend this object.
  • init: The init event is triggered after build (which should not generate any GraphQL objects) and can be used to build common object 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 add query, mutation, subscription root operations or similar options.
  • GraphQLObjectType*: When creating a GraphQLObjectType via newWithHooks, we'll execute the following hooks:

    • GraphQLObjectType to add any root-level attributes, e.g. a description.
    • GraphQLObjectType:interfaces to add additional interfaces to this object type.
    • GraphQLObjectType:fields (deferred) to add additional fields to this object type. It is ran asynchronously (by passing fields as a thunk to GraphQLObjectType) and gets a reference to the final GraphQL Type as Self in the context.
    • GraphQLObjectType:fields:field: to manipulate any root-level attributes on an individual field, e.g. add a description.
    • GraphQLObjectType:fields:field:args to add arguments of an individual field.
  • GraphQLInputObjectType*: When creating a GraphQLInputObjectType via newWithHooks, we'll execute the following hooks:

    • GraphQLInputObjectType to 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 passing fields as a thunk to GraphQLInputObjectType) and gets a reference to the final GraphQL Type as Self in the context.
    • GraphQLInputObjectType:fields:field: to customize an individual field from above.
  • GraphQLEnumType*: When creating a GraphQLEnumType via newWithHooks, we'll execute the following hooks:

    • GraphQLEnumType add any root-level attributes, e.g. add a description.
    • GraphQLEnumType:values add values.
    • GraphQLEnumType:values:value customize 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.

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 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: