Class: GraphQL::Stitching::Executor::RootSource
- Inherits:
-
Dataloader::Source
- Object
- Dataloader::Source
- GraphQL::Stitching::Executor::RootSource
- Defined in:
- lib/graphql/stitching/executor.rb
Instance Method Summary collapse
- #build_query(op) ⇒ Object
- #fetch(ops) ⇒ Object
-
#initialize(executor, location) ⇒ RootSource
constructor
A new instance of RootSource.
Constructor Details
#initialize(executor, location) ⇒ RootSource
Returns a new instance of RootSource.
10 11 12 13 |
# File 'lib/graphql/stitching/executor.rb', line 10 def initialize(executor, location) @executor = executor @location = location end |
Instance Method Details
#build_query(op) ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/graphql/stitching/executor.rb', line 32 def build_query(op) if op["variables"].any? variable_defs = op["variables"].map { |k, v| "$#{k}:#{v}" }.join(",") "#{op["operation_type"]}(#{variable_defs})#{op["selections"]}" else "#{op["operation_type"]}#{op["selections"]}" end end |
#fetch(ops) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/graphql/stitching/executor.rb', line 15 def fetch(ops) op = ops.first # There should only ever be one per location at a time query_document = build_query(op) query_variables = @executor.request.variables.slice(*op["variables"].keys) result = @executor.supergraph.execute_at_location(op["location"], query_document, query_variables, @executor.request.context) @executor.query_count += 1 @executor.data.merge!(result["data"]) if result["data"] if result["errors"]&.any? result["errors"].each { _1.delete("locations") } @executor.errors.concat(result["errors"]) end ops.map { op["key"] } end |