Merging subtrees in cache
See original GitHub issueI’ve got two queries with overlapping subtrees (shown below). In the editorsQuery
, the id
of the currentVersion
might be different than in the documentQuery
, because someone might have updated the document in the time between the first and the second query. If that happens, Apollo seems to return an empty object wherever the documentQuery
is used. If I inspect the cache in the Apollo devtools, the second query overwrites the currentVersion
completely, leaving out the downloadUrl
because it’s not included in the editorsQuery
. Is there a way to instead merge the two results? The queries used in this example are of course fictional, but we have many of these types of queries in our application.
query documentQuery {
document {
id
currentVersion {
id
downloadUrl
}
}
}
query editorsQuery {
document {
id
currentVersion {
id
editors {
id
name
}
}
}
}
I’ve made a reproduction of this issue on CodeSandbox:
Front-end: https://codesandbox.io/s/k0wm12zpqr API: https://codesandbox.io/s/k282yz01p7
Make sure to open the CodeSandbox for the API because the server may have shut down in the meantime. You might have to refresh the front-end until the API is back up 😃
Issue Analytics
- State:
- Created 5 years ago
- Reactions:2
- Comments:10 (4 by maintainers)
Top GitHub Comments
I am having issues where other queries are overwriting previous queries and nullifying data that should just be merged. Not sure how to resolve it.
A lot of the Apollo Client internals have changed since v3 was launched. We recommend trying a more modern version of
@apollo/client
. Let us know if you’re still encountering this issue. Thanks!