-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
ObservableQuery.getCurrentResult: skip the cache #10631
Changes from 2 commits
52c433b
b37bed2
0a67647
8227e66
2f0175a
0e2d94a
66e8c83
088dc51
0206d72
b976e79
96933af
71f9d89
28910a3
aff4d65
b360183
6cf89bc
ee8dda5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,7 @@ import { | |
FetchMoreQueryOptions, | ||
SubscribeToMoreOptions, | ||
NextFetchPolicyContext, | ||
WatchQueryFetchPolicy, | ||
} from './watchQueryOptions'; | ||
import { QueryInfo } from './QueryInfo'; | ||
import { MissingFieldError } from '../cache'; | ||
|
@@ -86,6 +87,7 @@ export class ObservableQuery< | |
private observers = new Set<Observer<ApolloQueryResult<TData>>>(); | ||
private subscriptions = new Set<ObservableSubscription>(); | ||
|
||
private waitForOwnResult: boolean; | ||
private last?: Last<TData, TVariables>; | ||
|
||
private queryInfo: QueryInfo; | ||
|
@@ -152,6 +154,7 @@ export class ObservableQuery< | |
this.queryManager = queryManager; | ||
|
||
// active state | ||
this.waitForOwnResult = skipCacheDataFor(options.fetchPolicy); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This has to be initialized in the constructor, as |
||
this.isTornDown = false; | ||
|
||
const { | ||
|
@@ -240,9 +243,8 @@ export class ObservableQuery< | |
if ( | ||
// These fetch policies should never deliver data from the cache, unless | ||
// redelivering a previously delivered result. | ||
fetchPolicy === 'network-only' || | ||
fetchPolicy === 'no-cache' || | ||
fetchPolicy === 'standby' || | ||
skipCacheDataFor(fetchPolicy) || | ||
this.waitForOwnResult || | ||
// If this.options.query has @client(always: true) fields, we cannot | ||
// trust diff.result, since it was read from the cache without running | ||
// local resolvers (and it's too late to run resolvers now, since we must | ||
|
@@ -834,13 +836,22 @@ Did you mean to call refetch(variables) instead of refetch({ variables })?`); | |
} | ||
} | ||
|
||
this.waitForOwnResult &&= skipCacheDataFor(options.fetchPolicy) | ||
const finishWaitingForOwnResult = () => { | ||
if (this.concast === concast) { | ||
this.waitForOwnResult = false | ||
} | ||
} | ||
phryneas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
const variables = options.variables && { ...options.variables }; | ||
const concast = this.fetch(options, newNetworkStatus); | ||
const observer: Observer<ApolloQueryResult<TData>> = { | ||
next: result => { | ||
finishWaitingForOwnResult(); | ||
this.reportResult(result, variables); | ||
}, | ||
error: error => { | ||
finishWaitingForOwnResult(); | ||
this.reportError(error, variables); | ||
}, | ||
}; | ||
|
@@ -984,3 +995,7 @@ export function logMissingFieldErrors( | |
}`, missing); | ||
} | ||
} | ||
|
||
function skipCacheDataFor(fetchPolicy?: WatchQueryFetchPolicy) { | ||
phryneas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return fetchPolicy === "network-only" || fetchPolicy === "no-cache" || fetchPolicy === "standby"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Might be worth a comment that when |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -421,7 +421,7 @@ describe('[queries] loading', () => { | |
]); | ||
}, { interval: 1 }); | ||
await waitFor(() => { | ||
expect(count).toBe(6); | ||
expect(count).toBe(5); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This now rerenders one less time. I checked it - render 5 and 6 had identical |
||
}, { interval: 1 }); | ||
}); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had to add this with some commit - the Jest VSCode plugin cannot display it when two projects run the same test twice, so I just set it to exclude the React17 tests. Also adds
--runInBand
for the extension, which makes tests less flaky in general.