Module: GraphQL::Execution::Instrumentation

Defined in:
lib/graphql/execution/instrumentation.rb

Class Method Summary collapse

Class Method Details

.apply_instrumenters(multiplex) ⇒ Object

This function implements the instrumentation policy:

  • Instrumenters are a stack; the first before_query will have the last after_query
  • If a before_ hook returned without an error, its corresponding after_ hook will run.
  • If the before_ hook did not run, the after_ hook will not be called.

When errors are raised from after_ hooks:

  • Subsequent after_ hooks are called
  • The first raised error is captured; later errors are ignored
  • If an error was capture, it's re-raised after all hooks are finished

Partial runs of instrumentation are possible:

  • If a before_multiplex hook raises an error, no before_query hooks will run
  • If a before_query hook raises an error, subsequent before_query hooks will not run (on any query)

19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/graphql/execution/instrumentation.rb', line 19

def self.apply_instrumenters(multiplex)
  schema = multiplex.schema
  queries = multiplex.queries
  query_instrumenters = schema.instrumenters[:query]
  multiplex_instrumenters = schema.instrumenters[:multiplex]

  # First, run multiplex instrumentation, then query instrumentation for each query
  call_hooks(multiplex_instrumenters, multiplex, :before_multiplex, :after_multiplex) do
    each_query_call_hooks(query_instrumenters, queries) do
      # Let them be executed
      yield
    end
  end
end