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

Avoid full reapplication of cache-and-network and network-only fetch policies after successful fetchMore #9504

Merged
merged 21 commits into from
Mar 29, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
8f7a3ed
Adjust fetchMore tests to use TypedDocumentNode and subscribeAndCount.
benjamn Mar 9, 2022
c274f68
Avoid momentarily creating nonexistent QueryInfo in QueryManager#remo…
benjamn Oct 12, 2021
a6ba39c
Avoid full reobservation after `fetchMore`.
benjamn Aug 17, 2021
7e3dd93
Avoid full reobservation for complete cache results.
benjamn Oct 12, 2021
6177575
Tests of `fetchMore` interacting with network fetch policies.
benjamn Oct 12, 2021
6dccb8d
Extract reus{able,ed} private reobserveCacheFirst method.
benjamn Mar 8, 2022
a1d4a82
Bump bundlesize limit to 29.2kB (now 29.14kB).
benjamn Mar 10, 2022
53a246b
A TODO to investigate.
benjamn Mar 9, 2022
e320eb5
Call reobserveCacheFirst only if cache.watch update not already broad…
benjamn Mar 9, 2022
c5b522d
Hoist cache.batch block to include updateQuery usage as well.
benjamn Mar 9, 2022
3f7bce4
Improve fetchMore type inference.
benjamn Mar 9, 2022
857583c
Use cache.updateQuery instead of observableQuery.updateQuery.
benjamn Mar 9, 2022
1b3406a
Remove nagging updateQuery deprecation warning.
benjamn Mar 9, 2022
f7dd5f4
Remove unnecessary finally block from ObservableQuery#fetchMore.
benjamn Mar 10, 2022
33e85c7
Use reobserveCacheFirst in !diff.complete case, too.
benjamn Mar 10, 2022
359ed59
Remove cache.batch wrapping, since we no longer need onWatchUpdated.
benjamn Mar 10, 2022
521ec2d
More implementation comments in QueryInfo cache.watch listener.
benjamn Mar 10, 2022
0548f29
Mention PR #9504 in CHANGELOG.md.
benjamn Mar 11, 2022
cfc8cad
Note that fetchMore updateQuery deprecation warning has been removed.
benjamn Mar 11, 2022
e5ed91a
Bring back cache.batch to ensure delivery of unchanged results.
benjamn Mar 11, 2022
5036dc5
Use private non-method function for reobserveCacheFirst.
benjamn Mar 29, 2022
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
Prev Previous commit
Next Next commit
Avoid full reobservation for complete cache results.
  • Loading branch information
benjamn committed Mar 29, 2022
commit 7e3dd9324695e8b2494813a788489341ebd724e8
5 changes: 1 addition & 4 deletions src/__tests__/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3374,12 +3374,9 @@ describe('@connection', () => {
} else if (handleCount === 4) {
expect(result.data).toEqual({ count: "secondary" });
expect(nextFetchPolicyCallCount).toBe(3);
client.cache.evict({ fieldName: "count" });
} else if (handleCount === 5) {
expect(result.data).toEqual({ count: 1 });
expect(nextFetchPolicyCallCount).toBe(3);
client.cache.evict({ fieldName: "count" });
} else if (handleCount === 6) {
expect(result.data).toEqual({ count: 2 });
expect(nextFetchPolicyCallCount).toBe(4);
expect(obs.options.fetchPolicy).toBe("cache-first");
setTimeout(resolve, 50);
Expand Down
15 changes: 14 additions & 1 deletion src/core/QueryInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,21 @@ export class QueryInfo {
// full reobservation, since oq.reobserve might make a network
// request, and we don't want to trigger network requests for
// optimistic updates.
if (this.getDiff().fromOptimisticTransaction) {
const diff = this.getDiff();
if (diff.fromOptimisticTransaction) {
oq["observe"]();
} else if (diff.complete) {
const { fetchPolicy, nextFetchPolicy } = oq.options;
oq.reobserve({
fetchPolicy: "cache-first",
nextFetchPolicy(...args) {
this.nextFetchPolicy = nextFetchPolicy;
if (typeof nextFetchPolicy === "function") {
return nextFetchPolicy.apply(this, args);
}
return fetchPolicy!;
},
});
} else {
oq.reobserve();
}
Expand Down