Skip to content

Commit

Permalink
Improve fragment reuse code (#2497)
Browse files Browse the repository at this point in the history
The existing code was only able to reuse named fragments in a small
subset of cases (essentially when the fragment was matched by a full
sub-selection). This patch makes the code much more able to reuse
fragments by allowing to match sub-selections, handle intersecting
fragments, etc...
  • Loading branch information
Sylvain Lebresne committed Mar 30, 2023
1 parent 450b957 commit 01fe3f8
Show file tree
Hide file tree
Showing 6 changed files with 858 additions and 151 deletions.
11 changes: 11 additions & 0 deletions .changeset/rich-kings-obey.md
@@ -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
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
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

0 comments on commit 01fe3f8

Please sign in to comment.