SchemaBuilder instance

The SchemaBuilder instance returned by getBuilder has a number of methods on it that may be of interest:

Consumer methods

Use these methods when you wish to consume a GraphQL schema


Returns a promise which resolves after the first schema has been generated and passed to the listener callback. Any further schemas that are generated will be passed to the listener callback immediately.


The reverse of watchSchema, this returns a promise that will be resolved when a schema is successfully unwatched. After it resolves no further calls will be made to listener.


This synchronous function returns a (possibly cached) up-to-date GraphQLSchema, you can think of it as:

class SchemaBuilder {
  // ...
  buildSchema() {
    const build = this.createBuild();
    return build.newWithHooks(GraphQLSchema, {}, { isSchema: true });


This synchronous function returns a fresh Build object which you can use to build other objects (such as the GraphQLSchema created above). Be aware the the build will store created objects, so it is not safe to use the same build object to create a GraphQL object with the same name multiple times - each time should use a fresh build object.

Plugin methods

Use these methods from plugins.

hook(hookName, hookFunction)

Example: this hook will log the name of each GraphQLObjectType that is built:

function GraphQLObjectTypeLogNamePlugin(builder) {
  builder.hook("GraphQLObjectType", spec => {
      "A new GraphQLObjectType is being constructed with name: ",

See Hooks for details

registerWatcher(watcher, unwatcher)

Registers two functions: one to be called if/when schema watching begins (see watchSchema above), and another to be called if/when schema watching ends (to clean up). Each function is passed one argument: the function to call when a change occurs.

TODO: document further (ref:

  triggerRebuild => {
    eventEmitter.on("change", triggerRebuild);
  triggerRebuild => {
    eventEmitter.removeListener("change", triggerRebuild);