class GraphQL::Batch::Executor

Constants

THREAD_KEY

Attributes

loading[R]

Set to true when performing a batch query, otherwise, it is false.

Can be used to detect unbatched queries in an ActiveSupport::Notifications.subscribe block.

Public Class Methods

current() click to toggle source
# File lib/graphql/batch/executor.rb, line 7
def current
  Thread.current[THREAD_KEY]
end
current=(executor) click to toggle source
# File lib/graphql/batch/executor.rb, line 11
def current=(executor)
  Thread.current[THREAD_KEY] = executor
end
end_batch() click to toggle source
# File lib/graphql/batch/executor.rb, line 20
def end_batch
  executor = current
  unless executor
    raise NoExecutorError, 'Cannot end a batch without an Executor.'
  end
  return unless executor.decrement_level < 1
  self.current = nil
end
new() click to toggle source
# File lib/graphql/batch/executor.rb, line 35
def initialize
  @loaders = {}
  @loading = false
  @nesting_level = 0
end
start_batch(executor_class) click to toggle source
# File lib/graphql/batch/executor.rb, line 15
def start_batch(executor_class)
  executor = Thread.current[THREAD_KEY] ||= executor_class.new
  executor.increment_level
end

Public Instance Methods

loader(key) { || ... } click to toggle source
# File lib/graphql/batch/executor.rb, line 41
def loader(key)
  @loaders[key] ||= yield.tap do |loader|
    loader.executor = self
    loader.loader_key = key
  end