Class: GraphQL::Execution::Multiplex

Inherits:
Object
  • Object
show all
Includes:
Tracing::Traceable
Defined in:
lib/graphql/execution/multiplex.rb

Overview

Execute multiple queries under the same multiplex "umbrella". They can share a batching context and reduce redundant database hits.

The flow is:

  • Multiplex instrumentation setup
  • Query instrumentation setup
  • Analyze the multiplex + each query
  • Begin each query
  • Resolve lazy values, breadth-first across all queries
  • Finish each query (eg, get errors)
  • Query instrumentation teardown
  • Multiplex instrumentation teardown

If one query raises an application error, all queries will be in undefined states.

Validation errors and GraphQL::ExecutionErrors are handled in isolation: one of these errors in one query will not affect the other queries.

See Schema.multiplex for the public API

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Tracing::Traceable

#trace

Constructor Details

#initialize(schema:, queries:, context:, max_complexity:) ⇒ Multiplex

Returns a new instance of Multiplex.



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/graphql/execution/multiplex.rb', line 31

def initialize(schema:, queries:, context:, max_complexity:)
  @schema = schema
  @queries = queries
  @queries.each { |q| q.multiplex = self }
  @context = context
  @dataloader = @context[:dataloader] ||= @schema.dataloader_class.new
  @tracers = schema.tracers + (context[:tracers] || EmptyObjects::EMPTY_ARRAY)
  @max_complexity = max_complexity
  @current_trace = context[:trace] ||= schema.new_trace(multiplex: self)
  @logger = nil
end

Instance Attribute Details

#context ⇒ Object (readonly)

Returns the value of attribute context.



29
30
31
# File 'lib/graphql/execution/multiplex.rb', line 29

def context
  @context
end

#current_trace ⇒ Object (readonly)

Returns the value of attribute current_trace.



29
30
31
# File 'lib/graphql/execution/multiplex.rb', line 29

def current_trace
  @current_trace
end

#dataloader ⇒ Object (readonly)

Returns the value of attribute dataloader.



29
30
31
# File 'lib/graphql/execution/multiplex.rb', line 29

def dataloader
  @dataloader
end

#max_complexity ⇒ Object (readonly)

Returns the value of attribute max_complexity.



29
30
31
# File 'lib/graphql/execution/multiplex.rb', line 29

def max_complexity
  @max_complexity
end

#queries ⇒ Object (readonly)

Returns the value of attribute queries.



29
30
31
# File 'lib/graphql/execution/multiplex.rb', line 29

def queries
  @queries
end

#schema ⇒ Object (readonly)

Returns the value of attribute schema.



29
30
31
# File 'lib/graphql/execution/multiplex.rb', line 29

def schema
  @schema
end

Instance Method Details

#logger ⇒ Object



43
44
45
# File 'lib/graphql/execution/multiplex.rb', line 43

def logger
  @logger ||= @schema.logger_for(context)
end