Module: GraphQL::Batch

Defined in:
lib/graphql/batch.rb,
lib/graphql/batch/setup.rb,
lib/graphql/batch/loader.rb,
lib/graphql/batch/version.rb,
lib/graphql/batch/executor.rb,
lib/graphql/batch/setup_multiplex.rb,
lib/graphql/batch/mutation_field_extension.rb

Defined Under Namespace

Classes: Executor, Loader, MutationFieldExtension, NoExecutorError, Setup, SetupMultiplex

Constant Summary collapse

BrokenPromiseError =
::Promise::BrokenError
VERSION =
"0.4.1"

Class Method Summary collapse

Class Method Details

.batch(executor_class: GraphQL::Batch::Executor) ⇒ Object



9
10
11
12
13
14
15
16
# 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) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/graphql/batch.rb', line 18

def self.use(schema_defn, executor_class: GraphQL::Batch::Executor)
  schema = schema_defn.target
  if GraphQL::VERSION >= "1.6.0"
    instrumentation = GraphQL::Batch::SetupMultiplex.new(schema, executor_class: executor_class)
    schema_defn.instrument(:multiplex, instrumentation)
    if schema.mutation
      if Gem::Version.new(GraphQL::VERSION) >= Gem::Version.new('1.9.0.pre3') &&
          schema.mutation.[:type_class]
        require_relative "batch/mutation_field_extension"
        schema.mutation.fields.each do |name, f|
          field = f.[:type_class]
          field.extension(GraphQL::Batch::MutationFieldExtension)
        end
      else
        schema_defn.instrument(:field, instrumentation)
      end
    end
  else
    instrumentation = GraphQL::Batch::Setup.new(schema, executor_class: executor_class)
    schema_defn.instrument(:query, instrumentation)
    schema_defn.instrument(:field, instrumentation)
  end
  schema_defn.lazy_resolve(::Promise, :sync)
end