Skip to content

Commit

Permalink
cleanup plan method.
Browse files Browse the repository at this point in the history
  • Loading branch information
gmac committed Dec 26, 2023
1 parent 243c33b commit 51f41d3
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 7 deletions.
8 changes: 6 additions & 2 deletions docs/executor.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,21 @@ 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

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:
Expand Down
4 changes: 4 additions & 0 deletions docs/planner.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion lib/graphql/stitching/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
7 changes: 4 additions & 3 deletions lib/graphql/stitching/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/graphql/stitching/executor/boundary_source_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 51f41d3

Please sign in to comment.