Class: GraphQL::Stitching::Executor
- Inherits:
-
Object
- Object
- GraphQL::Stitching::Executor
- Defined in:
- lib/graphql/stitching/executor.rb,
lib/graphql/stitching/executor/shaper.rb,
lib/graphql/stitching/executor/root_source.rb,
lib/graphql/stitching/executor/type_resolver_source.rb
Overview
Executor handles executing upon a planned request. All planned steps are initiated, their results merged, and loaded keys are collected for batching subsequent steps. Final execution results are then shaped to match the request selection.
Defined Under Namespace
Classes: RootSource, Shaper, TypeResolverSource
Instance Attribute Summary collapse
-
#data ⇒ Hash
readonly
An aggregate data payload to return.
-
#errors ⇒ Array<Hash>
readonly
Aggregate GraphQL errors to return.
-
#query_count ⇒ Integer
Tally of queries performed while executing.
-
#request ⇒ Request
readonly
The stitching request to execute.
Instance Method Summary collapse
-
#initialize(request, data: {}, errors: [], after: Planner::ROOT_INDEX, nonblocking: false) ⇒ Executor
constructor
Builds a new executor.
- #perform(raw: false) ⇒ Object
Constructor Details
#initialize(request, data: {}, errors: [], after: Planner::ROOT_INDEX, nonblocking: false) ⇒ Executor
Builds a new executor.
30 31 32 33 34 35 36 37 38 |
# File 'lib/graphql/stitching/executor.rb', line 30 def initialize(request, data: {}, errors: [], after: Planner::ROOT_INDEX, nonblocking: false) @request = request @data = data @errors = errors @after = after @query_count = 0 @exec_cycles = 0 @dataloader = GraphQL::Dataloader.new(nonblocking: nonblocking) end |
Instance Attribute Details
#data ⇒ Hash (readonly)
Returns an aggregate data payload to return.
19 20 21 |
# File 'lib/graphql/stitching/executor.rb', line 19 def data @data end |
#errors ⇒ Array<Hash> (readonly)
Returns aggregate GraphQL errors to return.
22 23 24 |
# File 'lib/graphql/stitching/executor.rb', line 22 def errors @errors end |
#query_count ⇒ Integer
Returns tally of queries performed while executing.
25 26 27 |
# File 'lib/graphql/stitching/executor.rb', line 25 def query_count @query_count end |
#request ⇒ Request (readonly)
Returns the stitching request to execute.
16 17 18 |
# File 'lib/graphql/stitching/executor.rb', line 16 def request @request end |
Instance Method Details
#perform(raw: false) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/graphql/stitching/executor.rb', line 40 def perform(raw: false) exec!([@after]) result = {} if @data && @data.length > 0 result["data"] = raw ? @data : Shaper.new(@request).perform!(@data) end if @errors.length > 0 result["errors"] = @errors end GraphQL::Query::Result.new(query: @request, values: result) end |