class GraphQL::Batch::Setup

Public Class Methods

end_batching() click to toggle source
# File lib/graphql/batch/setup.rb, line 8
def end_batching
  GraphQL::Batch::Executor.end_batch
end
instrument_field(schema, type, field) click to toggle source
# File lib/graphql/batch/setup.rb, line 12
def instrument_field(schema, type, field)
  return field unless type == schema.mutation
  old_resolve_proc = field.resolve_proc
  field.redefine do
    resolve ->(obj, args, ctx) {
      GraphQL::Batch::Executor.current.clear
      begin
        ::Promise.sync(old_resolve_proc.call(obj, args, ctx))
      ensure
        GraphQL::Batch::Executor.current.clear
      end
    }
  end
end
new(schema, executor_class:) click to toggle source
# File lib/graphql/batch/setup.rb, line 28
def initialize(schema, executor_class:)
  @schema = schema
  @executor_class = executor_class
end
start_batching(executor_class) click to toggle source
# File lib/graphql/batch/setup.rb, line 4
def start_batching(executor_class)
  GraphQL::Batch::Executor.start_batch(executor_class)
end

Public Instance Methods

after_query(query) click to toggle source
# File lib/graphql/batch/setup.rb, line 37
def after_query(query)
  Setup.end_batching
end
before_query(query) click to toggle source
# File lib/graphql/batch/setup.rb, line 33
def before_query(query)
  Setup.start_batching(@executor_class)
end
instrument(type, field) click to toggle source
# File lib/graphql/batch/setup.rb, line 41
def instrument(type, field)
  Setup.instrument_field(@schema, type, field)
end