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

Fix issue where a merge function that returns an incomplete result would not allow the client to refetch from network #11839

Merged
merged 14 commits into from
May 14, 2024
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
5 changes: 5 additions & 0 deletions .changeset/itchy-dodos-approve.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@apollo/client": patch
---

Fix a regression in [3.9.5](https://github.com/apollographql/apollo-client/releases/tag/v3.9.5) where a merge function that returned an incomplete result would not allow the client to refetch in order to fulfill the query.
4 changes: 2 additions & 2 deletions .size-limits.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"dist/apollo-client.min.cjs": 39579,
"import { ApolloClient, InMemoryCache, HttpLink } from \"dist/index.js\" (production)": 32825
"dist/apollo-client.min.cjs": 39573,
"import { ApolloClient, InMemoryCache, HttpLink } from \"dist/index.js\" (production)": 32821
}
20 changes: 7 additions & 13 deletions src/core/QueryInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,22 +211,16 @@ export class QueryInfo {
setDiff(diff: Cache.DiffResult<any> | null) {
const oldDiff = this.lastDiff && this.lastDiff.diff;

// If we do not tolerate partial results, skip this update to prevent it
// from being reported. This prevents a situtuation where a query that
// errors and another succeeds with overlapping data does not report the
// partial data result to the errored query.
// If we are trying to deliver an incomplete cache result, we avoid
// reporting it if the query has errored, otherwise we let the broadcast try
// and repair the partial result by refetching the query. This check avoids
// a situation where a query that errors and another succeeds with
// overlapping data does not report the partial data result to the errored
// query.
//
// See https://github.com/apollographql/apollo-client/issues/11400 for more
// information on this issue.
if (
diff &&
!diff.complete &&
!this.observableQuery?.options.returnPartialData &&
// In the case of a cache eviction, the diff will become partial so we
// schedule a notification to send a network request (this.oqListener) to
// go and fetch the missing data.
!(oldDiff && oldDiff.complete)
) {
if (diff && !diff.complete && this.observableQuery?.getLastError()) {
Copy link
Member

@phryneas phryneas May 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't an update be okay in an error-but returnPartialData: true case?
Staying closer to the previous logic (although I'll admit I'm a bit hazy on some of it)

    if (
      diff &&
      !diff.complete &&
+    this.observableQuery?.getLastError() &&
      !this.observableQuery?.options.returnPartialData &&
      // In the case of a cache eviction, the diff will become partial so we
      // schedule a notification to send a network request (this.oqListener) to
      // go and fetch the missing data.
      !(oldDiff && oldDiff.complete)
    ) {

return;
}

Expand Down
Loading