Skip to content

Commit

Permalink
Reapply #2639 (with fix for #2680) (#2684)
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 committed Jul 19, 2023
1 parent 43e965c commit 3766312
Show file tree
Hide file tree
Showing 7 changed files with 970 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.

1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
branches:
- main
- next
- version-2.4

concurrency: ${{ github.workflow }}-${{ github.ref }}

Expand Down
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

0 comments on commit 3766312

Please sign in to comment.