-
Notifications
You must be signed in to change notification settings - Fork 242
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix incorrect removal of dependencies between groups in some rare `@r…
…equires` (#2726) Fulfilling some `@requires` can necessitate querying group(s) (subgraphs) that are not the direct parent of the group with the `@requires`. To generate plan that are as optimal as possible, the code needs to figure out the proper parent of those new groups, that is what is the "earliest" group those new groups truly depend on. This is done by starting to look at the parent of the `@requires` group, see if the new groups genuinely depend on anything that parent fetches, and if not, iterate the same logic on the grand-parent (until we either find a parent the new groups depend on, or we reach the beginning of the plan. But the code that checked if the new groups truly depend on a given parent was incomplete: it was sometimes responding that there were no dependency when that was not true. The result is that for some specific configuration of a `@requires`, we could end up with a plan whereby some group/fetch A depended on the results of another group/fetch B, but A was performed in parallel of B instead of after it. Which ultimately resulted in not getting the proper data for the required fields, leading to incorrect executions (the exact detail of how this would show up depends a bit on the exact service implementation, but typically the resolver of the field on which there is a `@requires` would get `null` for its requirements, which might lead that resolver to throw an error as this is unexpected). Fixes #2683 Co-authored-by: Chris Lenfest <clenfest@apollographql.com>
- Loading branch information
Showing
3 changed files
with
390 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
--- | ||
"@apollo/query-planner": major | ||
"@apollo/gateway": major | ||
--- | ||
|
||
Fix some potentially incorrect query plans with `@requires` when some dependencies are involved. | ||
|
||
In some rare case of `@requires`, an over-eager optimisation was incorrectly considering that | ||
a dependency between 2 subgraph fetches was unnecessary, leading to doing 2 subgraphs queries | ||
in parallel when those should be done sequentially (because the 2nd query rely on results | ||
from the 1st one). This effectively resulted in the required fields not being provided (the | ||
consequence of which depends a bit on the resolver detail, but if the resolver expected | ||
the required fields to be populated (as they should), then this could typically result | ||
in a message of the form `GraphQLError: Cannot read properties of null`). | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.