Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reapply #2639 (with fix for #2680) #2687

Merged
merged 2 commits into from
Jul 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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