Skip to content

Commit 887a5b1

Browse files
committed
Pass in real returnPartialData via symbol
1 parent c61b0ed commit 887a5b1

4 files changed

Lines changed: 33 additions & 22 deletions

File tree

src/cache/core/cache.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ export abstract class ApolloCache {
201201
TVariables extends OperationVariables = OperationVariables,
202202
>(
203203
query: Cache.DiffOptions<TData, TVariables> & {
204-
[handleIncrementalSymbol]: true | DiffIncrementalInfo;
204+
[handleIncrementalSymbol]: DiffIncrementalInfo;
205205
}
206206
): Cache.InternalDiffResultWithDataState<TData> | Cache.DiffResult<TData>;
207207

src/cache/inmemory/readFromStore.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ export class StoreReader {
302302
*/
303303
public diffQueryAgainstStore<T>(
304304
options: DiffQueryAgainstStoreOptions & {
305-
[handleIncrementalSymbol]: true | DiffIncrementalInfo;
305+
[handleIncrementalSymbol]: DiffIncrementalInfo;
306306
}
307307
): Cache.InternalDiffResultWithDataState<T>;
308308

@@ -315,11 +315,13 @@ export class StoreReader {
315315
query,
316316
rootId = "ROOT_QUERY",
317317
variables,
318-
returnPartialData = true,
319318
[handleIncrementalSymbol]: handleIncremental,
319+
...options
320320
}: DiffQueryAgainstStoreOptions): Cache.DiffResult<T> & {
321321
dataState?: "empty" | "partial" | "streaming" | "complete";
322322
} {
323+
const returnPartialData =
324+
handleIncremental?.returnPartialData ?? options.returnPartialData ?? true;
323325
const policies = this.config.cache.policies;
324326

325327
variables = {

src/cache/inmemory/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,13 +136,14 @@ export type ReadQueryOptions = {
136136

137137
/** @internal */
138138
export interface DiffIncrementalInfo {
139+
returnPartialData: boolean | undefined;
139140
streamInfo?: StreamInfoTrie;
140141
deferInfo?: DeferInfoTrie;
141142
}
142143

143144
export type DiffQueryAgainstStoreOptions = ReadQueryOptions & {
144145
returnPartialData?: boolean;
145-
[handleIncrementalSymbol]?: true | DiffIncrementalInfo;
146+
[handleIncrementalSymbol]?: DiffIncrementalInfo;
146147
};
147148

148149
export type ApolloReducerConfig = {

src/core/QueryInfo.ts

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import type {
77
Cache,
88
DiffIncrementalInfo,
99
IgnoreModifier,
10-
InMemoryCache,
1110
} from "@apollo/client/cache";
1211
import type { Incremental } from "@apollo/client/incremental";
1312
import type { ApolloLink } from "@apollo/client/link";
@@ -390,12 +389,12 @@ export class QueryInfo<
390389
networkStatus !== NetworkStatus.refetch;
391390

392391
const { dataState, result: diffResult } = this.getDiff(
393-
{
394-
...diffOptions,
392+
diffOptions,
393+
this.getIncrementalInfo(result, {
395394
// Never deliver partial data for network-only requests
396395
returnPartialData: returnPartialData && !isNetworkOnly,
397-
},
398-
this.getIncrementalInfo(result, { isNetworkOnly })
396+
isNetworkOnly,
397+
})
399398
);
400399

401400
if (
@@ -416,11 +415,17 @@ export class QueryInfo<
416415

417416
private getIncrementalInfo(
418417
result: MarkQueryResult<any, ExtensionsWithStreamInfo>,
419-
{ isNetworkOnly }: { isNetworkOnly: boolean }
418+
{
419+
isNetworkOnly,
420+
returnPartialData,
421+
}: { isNetworkOnly: boolean; returnPartialData: boolean | undefined }
420422
) {
421423
const pending = this.incremental?.pending ?? [];
422424
const streamInfo = result.extensions?.[streamInfoSymbol]?.deref();
423-
const incrementalInfo: DiffIncrementalInfo = { streamInfo };
425+
const incrementalInfo: DiffIncrementalInfo = {
426+
streamInfo,
427+
returnPartialData,
428+
};
424429

425430
// We don't want to deliver stream items or complete defer boundaries
426431
// for a network-only request if they haven't yet streamed from the
@@ -446,19 +451,22 @@ export class QueryInfo<
446451
options: Cache.DiffOptions<TData>,
447452
incrementalInfo?: DiffIncrementalInfo
448453
): Cache.InternalDiffResultWithDataState<TData> {
449-
if ((this.cache as any)[handleIncrementalSymbol]) {
450-
return (this.cache as unknown as InMemoryCache).diff({
451-
...options,
452-
[handleIncrementalSymbol]: incrementalInfo || true,
453-
});
454+
const diff = this.cache.diff({
455+
...options,
456+
// returnPartialData is overridden for backwards compatibility with caches
457+
// that don't handle incremental results. Without this, in-flight
458+
// incremental cache data would come back null when returnPartialData is
459+
// false due to the partial result.
460+
returnPartialData: true,
461+
[handleIncrementalSymbol]: incrementalInfo || {
462+
returnPartialData: options.returnPartialData,
463+
},
464+
});
465+
466+
if ("dataState" in diff) {
467+
return diff;
454468
}
455469

456-
// returnPartialData is overridden for backwards compatibility with caches
457-
// that don't handle incremental results. Without this, in-flight
458-
// incremental cache data would come back null when returnPartialData is
459-
// false due to the partial result.
460-
const diff = this.cache.diff({ ...options, returnPartialData: true });
461-
462470
return {
463471
...diff,
464472
dataState:

0 commit comments

Comments
 (0)