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_document(op, operation_name = nil) ⇒ Object
Builds root source documents “query MyOperation_1($var:VarType) { rootSelections … }”.
- #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_document(op, operation_name = nil) ⇒ Object
Builds root source documents “query MyOperation_1($var:VarType) { rootSelections … }”
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/graphql/stitching/executor.rb', line 34 def build_document(op, operation_name = nil) doc = String.new doc << op["operation_type"] if operation_name doc << " " << operation_name << "_" << op["key"].to_s end if op["variables"].any? variable_defs = op["variables"].map { |k, v| "$#{k}:#{v}" }.join(",") doc << "(" << variable_defs << ")" end doc << op["selections"] doc 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_document(op, @executor.request.operation_name) 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 |