Skip to content

Commit

Permalink
Make QueryInfo#getDiff return stub result for no-cache policy.
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamn committed Mar 9, 2021
1 parent de6aae0 commit 1d79890
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
5 changes: 5 additions & 0 deletions src/core/QueryInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,11 @@ export class QueryInfo {

this.updateWatch(this.variables = variables);

const oq = this.observableQuery;
if (oq && oq.options.fetchPolicy === "no-cache") {
return { complete: false };
}

return this.diff = this.cache.diff({
query: this.document!,
variables,
Expand Down
11 changes: 7 additions & 4 deletions src/core/QueryManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1035,7 +1035,7 @@ export class QueryManager<TStore> {
diff: Cache.DiffResult<TData>,
networkStatus = queryInfo.networkStatus || NetworkStatus.loading,
) => {
const data = diff.result as TData;
const data = diff.result;

if (process.env.NODE_ENV !== 'production' &&
isNonEmptyArray(diff.missing) &&
Expand All @@ -1046,21 +1046,21 @@ export class QueryManager<TStore> {
}`, diff.missing);
}

const fromData = (data: TData) => Observable.of({
const fromData = (data: TData | undefined) => Observable.of({
data,
loading: isNetworkRequestInFlight(networkStatus),
networkStatus,
...(diff.complete ? null : { partial: true }),
} as ApolloQueryResult<TData>);

if (this.transform(query).hasForcedResolvers) {
if (data && this.transform(query).hasForcedResolvers) {
return this.localState.runResolvers({
document: query,
remoteResult: { data },
context,
variables,
onlyRunForcedResolvers: true,
}).then(resolved => fromData(resolved.data!));
}).then(resolved => fromData(resolved.data || void 0));
}

return fromData(data);
Expand Down Expand Up @@ -1135,6 +1135,9 @@ export class QueryManager<TStore> {
case "no-cache":
if (shouldNotify) {
return [
// Note that queryInfo.getDiff() for no-cache queries does not call
// cache.diff, but instead returns a { complete: false } stub result
// when there is no queryInfo.diff already defined.
resultsFromCache(queryInfo.getDiff()),
resultsFromLink(false),
];
Expand Down

0 comments on commit 1d79890

Please sign in to comment.