Skip to content

Commit

Permalink
Fix merge function that returns incomplete result that did not refetc…
Browse files Browse the repository at this point in the history
…h from network (#11839)
  • Loading branch information
jerelmiller authored May 14, 2024
1 parent 4c5c820 commit 6481fe1
Show file tree
Hide file tree
Showing 4 changed files with 741 additions and 15 deletions.
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()) {
return;
}

Expand Down
Loading

0 comments on commit 6481fe1

Please sign in to comment.