class BatchLoader::GraphQL

Public Class Methods

instrument(type, field) click to toggle source
# File lib/batch_loader/graphql.rb, line 19
def self.instrument(type, field)
  old_resolve_proc = field.resolve_proc
  new_resolve_proc = ->(object, arguments, context) do
    result = old_resolve_proc.call(object, arguments, context)
    result.respond_to?(:__sync) ? BatchLoader::GraphQL::Wrapper.new(result) : result
  end

  field.redefine { resolve(new_resolve_proc) }
end
use(schema_definition) click to toggle source
# File lib/batch_loader/graphql.rb, line 14
def self.use(schema_definition)
  schema_definition.lazy_resolve(BatchLoader::GraphQL::Wrapper, :sync)
  schema_definition.instrument(:field, self)
end