Skip to content

Commit

Permalink
Reapply #2639 (with fix for #2680) (#2687)
Browse files Browse the repository at this point in the history
This commit reapplies #2639 with an additional fix related to
reproducing and resolving #2680.

The bug existed in the SelectionSet.contains logic in the final
check to provide a ContainsResult. Here the lengths of the
compared selection sets are used to determine subset or
strictly equal. In the case that the __typename field was
ignored up above, the comparison becomes invalid unless we
offset the comparison by 1 to account for the non-existent field.
  • Loading branch information
trevor-scheer authored Jul 19, 2023
1 parent 43e965c commit b9052fd
Show file tree
Hide file tree
Showing 6 changed files with 969 additions and 77 deletions.
12 changes: 12 additions & 0 deletions .changeset/wild-buses-poke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
"@apollo/query-planner": patch
"@apollo/federation-internals": patch
"@apollo/gateway": patch
---

Reapply #2639:

Try reusing named fragments in subgraph fetches even if those fragment only apply partially to the subgraph. Before this change, only named fragments that were applying entirely to a subgraph were tried, leading to less reuse that expected. Concretely, this change can sometimes allow the generation of smaller subgraph fetches.

Additionally, resolve a bug which surfaced in the fragment optimization logic which could result in invalid/incorrect optimizations / fragment reuse.

19 changes: 13 additions & 6 deletions gateway-js/src/__tests__/buildQueryPlan.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -744,18 +744,21 @@ describe('buildQueryPlan', () => {

it(`should not get confused by a fragment spread multiple times`, () => {
const operationString = `#graphql
fragment Price on Product {
fragment PriceAndCountry on Product {
price
details {
country
}
}
query {
topProducts {
__typename
... on Book {
...Price
...PriceAndCountry
}
... on Furniture {
...Price
...PriceAndCountry
}
}
}
Expand All @@ -770,16 +773,20 @@ describe('buildQueryPlan', () => {
topProducts {
__typename
... on Book {
...Price
...PriceAndCountry
}
... on Furniture {
...Price
...PriceAndCountry
}
}
}
fragment Price on Product {
fragment PriceAndCountry on Product {
price
details {
__typename
country
}
}
},
}
Expand Down
Loading

0 comments on commit b9052fd

Please sign in to comment.