diff --git a/docs/executor.md b/docs/executor.md index db059930..d0950a80 100644 --- a/docs/executor.md +++ b/docs/executor.md @@ -20,8 +20,11 @@ request = GraphQL::Stitching::Request.new( context: { ... }, ) -plan = request.plan +# Via Request: result = request.execute + +# Via Executor: +result = GraphQL::Stitching::Executor.new(request).perform ``` ### Raw results @@ -29,8 +32,9 @@ result = request.execute By default, execution results are always returned with document shaping (stitching additions removed, missing fields added, null bubbling applied). You may access the raw execution result by calling the `perform` method with a `raw: true` argument: ```ruby -# get the raw result without shaping +# get the raw result without shaping using either form: raw_result = request.execute(raw: true) +raw_result = GraphQL::Stitching::Executor.new(request).perform(raw: true) ``` The raw result will contain many irregularities from the stitching process, however may be insightful when debugging inconsistencies in results: diff --git a/docs/planner.md b/docs/planner.md index 55e115a3..8f2b6ec9 100644 --- a/docs/planner.md +++ b/docs/planner.md @@ -19,7 +19,11 @@ request = GraphQL::Stitching::Request.new( operation_name: "MyQuery", ).prepare! +# Via Request: plan = request.plan + +# Via Planner: +plan = GraphQL::Stitching::Planner.new(request).perform ``` ### Caching diff --git a/lib/graphql/stitching/client.rb b/lib/graphql/stitching/client.rb index 998860b0..d48180c0 100644 --- a/lib/graphql/stitching/client.rb +++ b/lib/graphql/stitching/client.rb @@ -41,7 +41,11 @@ def execute(query:, variables: nil, operation_name: nil, context: nil, validate: end request.prepare! - request.plan = fetch_plan(request) { request.plan } + request.plan do + fetch_plan(request) do + GraphQL::Stitching::Planner.new(request).perform + end + end request.execute rescue GraphQL::ParseError, GraphQL::ExecutionError => e error_result([e]) diff --git a/lib/graphql/stitching/request.rb b/lib/graphql/stitching/request.rb index 4737d25f..2c0ab7dc 100644 --- a/lib/graphql/stitching/request.rb +++ b/lib/graphql/stitching/request.rb @@ -103,11 +103,12 @@ def prepare! end def plan - @plan ||= GraphQL::Stitching::Planner.new(self).perform + @plan ||= begin + plan = yield if block_given? + plan || GraphQL::Stitching::Planner.new(self).perform + end end - attr_writer :plan - def execute(raw: false) GraphQL::Stitching::Executor.new(self).perform(raw:) end diff --git a/test/graphql/stitching/executor/boundary_source_test.rb b/test/graphql/stitching/executor/boundary_source_test.rb index 3f26df64..b4f86e97 100644 --- a/test/graphql/stitching/executor/boundary_source_test.rb +++ b/test/graphql/stitching/executor/boundary_source_test.rb @@ -158,7 +158,7 @@ def with_mock_source } mock = GraphQL::Stitching::Request.new({}, "{}") - mock.plan = GraphQL::Stitching::Plan.new(ops: []) + mock.plan { GraphQL::Stitching::Plan.new(ops: []) } mock = GraphQL::Stitching::Executor.new(mock) mock.instance_variable_set(:@data, data)