Skip to content

Commit

Permalink
Remove fetchBlockingPromise parameter from reobserve, too.
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamn committed Apr 28, 2022
1 parent da79d21 commit 1ef463c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 42 deletions.
5 changes: 1 addition & 4 deletions src/core/ObservableQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,6 @@ Did you mean to call refetch(variables) instead of refetch({ variables })?`);
private fetch(
options: WatchQueryOptions<TVariables, TData>,
newNetworkStatus?: NetworkStatus,
fetchBlockingPromise?: Promise<boolean>,
): Concast<ApolloQueryResult<TData>> {
// TODO Make sure we update the networkStatus (and infer fetchVariables)
// before actually committing to the fetch.
Expand All @@ -674,7 +673,6 @@ Did you mean to call refetch(variables) instead of refetch({ variables })?`);
this.queryId,
options,
newNetworkStatus,
fetchBlockingPromise,
);
}

Expand Down Expand Up @@ -756,7 +754,6 @@ Did you mean to call refetch(variables) instead of refetch({ variables })?`);
public reobserve(
newOptions?: Partial<WatchQueryOptions<TVariables, TData>>,
newNetworkStatus?: NetworkStatus,
fetchBlockingPromise?: Promise<boolean>,
): Promise<ApolloQueryResult<TData>> {
this.isTornDown = false;

Expand Down Expand Up @@ -803,7 +800,7 @@ Did you mean to call refetch(variables) instead of refetch({ variables })?`);
}

const variables = options.variables && { ...options.variables };
const concast = this.fetch(options, newNetworkStatus, fetchBlockingPromise);
const concast = this.fetch(options, newNetworkStatus);
const observer: Observer<ApolloQueryResult<TData>> = {
next: result => {
this.reportResult(result, variables);
Expand Down
48 changes: 10 additions & 38 deletions src/core/QueryManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1093,7 +1093,6 @@ export class QueryManager<TStore> {
// NetworkStatus.loading, but also possibly fetchMore, poll, refetch,
// or setVariables.
networkStatus = NetworkStatus.loading,
fetchBlockingPromise?: Promise<boolean>,
): Concast<ApolloQueryResult<TData>> {
const query = this.transform(options.query).document;
const variables = this.getVariables(query, options.variables) as TVars;
Expand Down Expand Up @@ -1127,7 +1126,6 @@ export class QueryManager<TStore> {
queryInfo,
normalized,
networkStatus,
fetchBlockingPromise,
);
};

Expand Down Expand Up @@ -1340,7 +1338,6 @@ export class QueryManager<TStore> {
// NetworkStatus.loading, but also possibly fetchMore, poll, refetch,
// or setVariables.
networkStatus: NetworkStatus,
fetchBlockingPromise?: Promise<boolean>,
): ConcastSourcesIterable<ApolloQueryResult<TData>> {
const oldNetworkStatus = queryInfo.networkStatus;

Expand Down Expand Up @@ -1393,41 +1390,16 @@ export class QueryManager<TStore> {
) ? CacheWriteBehavior.OVERWRITE
: CacheWriteBehavior.MERGE;

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>>(),
error => {
const apolloError = isApolloError(error)
? error
: new ApolloError({ clientErrors: [error] });

if (errorPolicy !== "ignore") {
queryInfo.markError(apolloError);
}

return Observable.of<ApolloQueryResult<TData>>({
loading: false,
networkStatus: NetworkStatus.error,
error: apolloError,
data: readCache().result,
});
},
) : get();
}
const resultsFromLink = () => this.getResultsFromLink<TData, TVars>(
queryInfo,
cacheWriteBehavior,
{
variables,
context,
fetchPolicy,
errorPolicy,
},
);

const shouldNotify =
notifyOnNetworkStatusChange &&
Expand Down

0 comments on commit 1ef463c

Please sign in to comment.