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

Improve fragment reuse #2497

Merged
merged 1 commit into from
Mar 30, 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
11 changes: 11 additions & 0 deletions .changeset/rich-kings-obey.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
"@apollo/query-planner": patch
"@apollo/federation-internals": patch
"@apollo/gateway": patch
---

Improves reuse of named fragments in subgraph fetches. When a question has named fragments, the code tries to reuse
those fragment in subgraph fetches is those can apply (so when the fragment is fully queried in a single subgraph fetch).
However, the existing was only able to reuse those fragment in a small subset of cases. This change makes it much more
likely that _if_ a fragment can be reused, it will be.

4 changes: 2 additions & 2 deletions gateway-js/src/__tests__/integration/requires.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,13 +218,13 @@ it('collapses nested requires with user-defined fragments', async () => {
{
user {
__typename
id
preferences {
favorites {
animal
color
animal
}
}
id
}
}
},
Expand Down
29 changes: 13 additions & 16 deletions gateway-js/src/__tests__/integration/value-types.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,33 +98,30 @@ describe('value types', () => {
reviews {
metadata {
__typename
... on KeyValue {
key
value
}
... on Error {
code
message
}
...Metadata
}
}
}
... on Furniture {
reviews {
metadata {
__typename
... on KeyValue {
key
value
}
... on Error {
code
message
}
...Metadata
}
}
}
}

fragment Metadata on MetadataOrError {
... on KeyValue {
key
value
}
... on Error {
code
message
}
}
},
},
Flatten(path: "topProducts.@") {
Expand Down
Loading