module GraphQL::Batch

Constants

BrokenPromiseError
VERSION

Public Class Methods

batch(executor_class: GraphQL::Batch::Executor) { || ... } click to toggle source
# File lib/graphql/batch.rb, line 9
def self.batch(executor_class: GraphQL::Batch::Executor)
  begin
    GraphQL::Batch::Executor.start_batch(executor_class)
    ::Promise.sync(yield)
  ensure
    GraphQL::Batch::Executor.end_batch
  end
end
use(schema_defn, executor_class: GraphQL::Batch::Executor) click to toggle source
# File lib/graphql/batch.rb, line 18
def self.use(schema_defn, executor_class: GraphQL::Batch::Executor)
  instrumentation = GraphQL::Batch::SetupMultiplex.new(schema_defn, executor_class: executor_class)
  schema_defn.instrument(:multiplex, instrumentation)

  if schema_defn.mutation
    require_relative "batch/mutation_field_extension"

    schema_defn.mutation.fields.each do |name, field|
      field.extension(GraphQL::Batch::MutationFieldExtension)
    end
  end

  schema_defn.lazy_resolve(::Promise, :sync)
end

Public Instance Methods

around_promise_callbacks() { || ... } click to toggle source
# File lib/graphql/batch/executor.rb, line 76
def around_promise_callbacks
  # We need to set #loading to false so that any queries that happen in the promise
  # callback aren't interpreted as being performed in GraphQL::Batch::Loader#perform
  was_loading = @loading
  @loading = false
  yield
ensure
  @loading = was_loading
end
clear() click to toggle source
# File lib/graphql/batch/executor.rb, line 64
def clear
  @loaders.clear
end
decrement_level() click to toggle source
# File lib/graphql/batch/executor.rb, line 72
def decrement_level
  @nesting_level -= 1
end
increment_level() click to toggle source
# File lib/graphql/batch/executor.rb, line 68
def increment_level
  @nesting_level += 1
end
resolve(loader) click to toggle source
# File lib/graphql/batch/executor.rb, line 48
def resolve(loader)
  was_loading = @loading
  @loading = true
  loader.resolve
ensure
  @loading = was_loading
end
tick() click to toggle source
# File lib/graphql/batch/executor.rb, line 56
def tick
  resolve(@loaders.shift.last)
end
wait_all() click to toggle source
# File lib/graphql/batch/executor.rb, line 60
def wait_all
  tick until @loaders.empty?
end