Class: GraphQL::Query::ParallelExecution

Inherits:
BaseExecution show all
Defined in:
lib/graphql/query/parallel_execution.rb

Overview

Utilize Celluloid::Future to run field resolution in parallel.

Defined Under Namespace

Classes: ExecutionPool, ExecutionWorker, FieldResolution, FragmentSpreadResolution, FutureFieldResolution, InlineFragmentResolution, OperationResolution, SelectionResolution

Instance Method Summary collapse

Methods inherited from BaseExecution

#execute, #field_resolution, #fragment_spread_resolution, #inline_fragment_resolution, #operation_resolution, #selection_resolution

Constructor Details

#initializeParallelExecution



5
6
7
8
9
# File 'lib/graphql/query/parallel_execution.rb', line 5

def initialize
  # Why isn't `require "celluloid/current"` enough here?
  Celluloid.boot unless Celluloid.running?
  @has_futures = false
end

Instance Method Details

#async(block) ⇒ Object



16
17
18
19
# File 'lib/graphql/query/parallel_execution.rb', line 16

def async(block)
  @has_futures ||= true
  pool.future.resolve(block)
end

#has_futures?Boolean



21
22
23
# File 'lib/graphql/query/parallel_execution.rb', line 21

def has_futures?
  @has_futures
end

#poolObject



11
12
13
14
# File 'lib/graphql/query/parallel_execution.rb', line 11

def pool
  @pool ||= ExecutionPool.run!
  @pool[:execution_worker_pool]
end