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 extra useQuery result frames #9599

Merged
merged 24 commits into from
Apr 18, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
5a3f033
Added useQuery frame tests to show that there is an unneeded frame.
FritsvanCampen Mar 10, 2022
3d7fa34
Strengthen frame tests with expected NetworkStatus values.
benjamn Mar 22, 2022
7f98827
TODOs
benjamn Mar 21, 2022
6540b23
Call this.observable.setOptions when options change in useOptions.
benjamn Mar 22, 2022
a90922c
Fix lifecycle test extraneous results.
benjamn Mar 22, 2022
95a1749
Fix faulty skip tests.
benjamn Mar 22, 2022
9b03177
Improve mutation test timing robustness.
benjamn Apr 7, 2022
7e723db
Support WatchQueryOptions.fetchBlockingPromise.
benjamn Apr 14, 2022
7b80c93
Use fetchBlockingPromise when calling setOptions.
benjamn Apr 14, 2022
db0bd4b
Fix skip tests previously suffering from extraneous results.
benjamn Apr 14, 2022
85ae61f
Correct the frame test.
benjamn Apr 13, 2022
655fe74
Make the corrected frame test pass.
benjamn Apr 14, 2022
2101a72
Make other tests pass.
benjamn Apr 14, 2022
e94b545
Remove UNNEEDED_FRAME from useQuery tests.
benjamn Apr 14, 2022
d0265d4
Remove non-essential code (no tests fail).
benjamn Apr 14, 2022
a506feb
Use fetchBlockingPromise for initial useQuery request as well.
benjamn Apr 14, 2022
d047ab1
Decompose and reuse useUnblockFetchEffect helper function.
benjamn Apr 14, 2022
6033827
Silently discard blocked fetches after five seconds without useEffect.
benjamn Apr 14, 2022
7331572
Call this.observable.reobserve directly, instead of setOptions.
benjamn Apr 14, 2022
4ba569e
Bump bundlesize limit to 29.4kB (now 29.35kB).
benjamn Apr 14, 2022
b992e37
Reduce RenderPromises clutter in useQuery implementation.
benjamn Apr 15, 2022
c402dd4
Handle fetchBlockingPromise rejections more gracefully.
benjamn Apr 18, 2022
241f6ee
Basic tests of using options.fetchBlockingPromise directly.
benjamn Apr 18, 2022
58cab4e
Test fetchBlockingPromise prevents duplicate requests in <StrictMode>.
benjamn Apr 18, 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
27 changes: 20 additions & 7 deletions src/core/QueryManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1333,6 +1333,7 @@ export class QueryManager<TStore> {
returnPartialData,
context,
notifyOnNetworkStatusChange,
fetchBlockingPromise,
}: WatchQueryOptions<TVars, TData>,
// The initial networkStatus for this fetch, most often
// NetworkStatus.loading, but also possibly fetchMore, poll, refetch,
Expand Down Expand Up @@ -1390,13 +1391,25 @@ export class QueryManager<TStore> {
) ? CacheWriteBehavior.OVERWRITE
: CacheWriteBehavior.MERGE;

const resultsFromLink = () =>
this.getResultsFromLink<TData, TVars>(queryInfo, cacheWriteBehavior, {
variables,
context,
fetchPolicy,
errorPolicy,
});
const resultsFromLink = () => {
const get = () => this.getResultsFromLink<TData, TVars>(
queryInfo,
cacheWriteBehavior,
{
variables,
context,
fetchPolicy,
errorPolicy,
},
);

// If we have a fetchBlockingPromise, wait for it to be resolved before
// allowing any network requests, and only proceed if fetchBlockingPromise
// resolves to true. If it resolves to false, the request is discarded.
return fetchBlockingPromise ? fetchBlockingPromise.then(
ok => ok ? get() : Observable.of<ApolloQueryResult<TData>>()
brainkim marked this conversation as resolved.
Show resolved Hide resolved
) : get();
brainkim marked this conversation as resolved.
Show resolved Hide resolved
}

const shouldNotify =
notifyOnNetworkStatusChange &&
Expand Down
8 changes: 8 additions & 0 deletions src/core/watchQueryOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,14 @@ export interface WatchQueryOptions<TVariables = OperationVariables, TData = any>
* behavior, for backwards compatibility with Apollo Client 3.x.
*/
refetchWritePolicy?: RefetchWritePolicy;

/**
* If provided, stalls any network activity for this request until the Promise
* has resolved. If the Promise resolves to true, the network request will
* proceed. If the Promise resolves to false, the network request will be
* silently discarded.
*/
fetchBlockingPromise?: Promise<boolean>;
brainkim marked this conversation as resolved.
Show resolved Hide resolved
}

export interface NextFetchPolicyContext<TData, TVariables> {
Expand Down