Skip to content

Commit 7aaa484

Browse files
authored
Minor followup for feedback from incremental cache implementation (#13360)
Followup to #13347 Discussed with @phryneas in person. Instead of conditionally passing in the symbol by having caches opt-in, we pass it unconditionally. Caches that want to take advantage of behavior using that symbol can come talk to us on how to implement against the incremental behavior. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Improvements** * Improved incremental, deferred, and streamed cache diff handling. * Updated cache diff results to provide more consistent data-state information. * Simplified incremental data processing across cache implementations. * **Bug Fixes** * Corrected partial-data and missing-field behavior during streaming and incremental reads. * Preserved compatibility for standard cache diff queries that do not use incremental options. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 0a27476 commit 7aaa484

8 files changed

Lines changed: 189 additions & 187 deletions

File tree

.api-reports/api-report-cache.api.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import { getApolloCacheMemoryInternals } from '@apollo/client/utilities/internal
2222
import type { GetDataState } from '@apollo/client';
2323
import { getInMemoryCacheMemoryInternals } from '@apollo/client/utilities/internal';
2424
import type { GraphQLScalarType } from 'graphql';
25-
import { handleIncrementalSymbol } from '@apollo/client/utilities/internal';
25+
import type { handleIncrementalSymbol } from '@apollo/client/utilities/internal';
2626
import type { Incremental } from '@apollo/client/incremental';
2727
import type { InlineFragmentNode } from 'graphql';
2828
import type { IsAny } from '@apollo/client/utilities/internal';
@@ -95,6 +95,10 @@ export abstract class ApolloCache {
9595
// (undocumented)
9696
readonly assumeImmutableResults: boolean;
9797
batch<U>(options: Cache_2.BatchOptions<this, U>): U;
98+
abstract diff<TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: Cache_2.DiffOptions<TData, TVariables> & {
99+
[handleIncrementalSymbol]: DiffIncrementalInfo | undefined;
100+
}): Cache_2.InternalDiffResultWithDataState<TData> | Cache_2.DiffResult<TData>;
101+
// (undocumented)
98102
abstract diff<TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: Cache_2.DiffOptions<TData, TVariables>): Cache_2.DiffResult<TData>;
99103
// (undocumented)
100104
abstract evict(options: Cache_2.EvictOptions): boolean;
@@ -410,7 +414,6 @@ export interface DiffIncrementalInfo {
410414
// @public (undocumented)
411415
export type DiffQueryAgainstStoreOptions = ReadQueryOptions & {
412416
returnPartialData?: boolean;
413-
[handleIncrementalSymbol]?: true | DiffIncrementalInfo;
414417
};
415418

416419
// @public (undocumented)
@@ -630,8 +633,6 @@ export namespace InMemoryCache {
630633

631634
// @public (undocumented)
632635
export class InMemoryCache extends ApolloCache {
633-
// (undocumented)
634-
readonly [handleIncrementalSymbol] = true;
635636
constructor(...args: {} extends InMemoryCache.ScalarsOption ? [
636637
config?: InMemoryCacheConfig
637638
] : [config: InMemoryCacheConfig]);
@@ -646,7 +647,7 @@ export class InMemoryCache extends ApolloCache {
646647
protected config: InMemoryCacheConfig;
647648
// (undocumented)
648649
diff<TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: Cache_2.DiffOptions<TData, TVariables> & {
649-
[handleIncrementalSymbol]: true | DiffIncrementalInfo;
650+
[handleIncrementalSymbol]: DiffIncrementalInfo | undefined;
650651
}): Cache_2.InternalDiffResultWithDataState<TData>;
651652
// (undocumented)
652653
diff<TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: Cache_2.DiffOptions<TData, TVariables>): Cache_2.DiffResult<TData>;
@@ -1153,11 +1154,11 @@ interface WriteContext extends ReadMergeModifyContext {
11531154

11541155
// Warnings were encountered during analysis:
11551156
//
1156-
// src/cache/inmemory/inMemoryCache.ts:461:7 - (ae-incompatible-release-tags) The symbol "[handleIncrementalSymbol]" is marked as @public, but its signature references "DiffIncrementalInfo" which is marked as @internal
1157+
// src/cache/core/cache.ts:204:7 - (ae-incompatible-release-tags) The symbol "[handleIncrementalSymbol]" is marked as @public, but its signature references "DiffIncrementalInfo" which is marked as @internal
1158+
// src/cache/inmemory/inMemoryCache.ts:456:7 - (ae-incompatible-release-tags) The symbol "[handleIncrementalSymbol]" is marked as @public, but its signature references "DiffIncrementalInfo" which is marked as @internal
11571159
// src/cache/inmemory/policies.ts:176:3 - (ae-forgotten-export) The symbol "KeySpecifier" needs to be exported by the entry point index.d.ts
11581160
// src/cache/inmemory/policies.ts:179:3 - (ae-forgotten-export) The symbol "ScalarNames" needs to be exported by the entry point index.d.ts
1159-
// src/cache/inmemory/types.ts:145:3 - (ae-incompatible-release-tags) The symbol "[handleIncrementalSymbol]" is marked as @public, but its signature references "DiffIncrementalInfo" which is marked as @internal
1160-
// src/cache/inmemory/types.ts:149:3 - (ae-forgotten-export) The symbol "KeyFieldsFunction" needs to be exported by the entry point index.d.ts
1161+
// src/cache/inmemory/types.ts:147:3 - (ae-forgotten-export) The symbol "KeyFieldsFunction" needs to be exported by the entry point index.d.ts
11611162

11621163
// (No @packageDocumentation comment for this package)
11631164

.api-reports/api-report.api.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ export abstract class ApolloCache {
8787
// (undocumented)
8888
readonly assumeImmutableResults: boolean;
8989
batch<U>(options: Cache_2.BatchOptions<this, U>): U;
90+
abstract diff<TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: Cache_2.DiffOptions<TData, TVariables> & {
91+
[handleIncrementalSymbol]: DiffIncrementalInfo | undefined;
92+
}): Cache_2.InternalDiffResultWithDataState<TData> | Cache_2.DiffResult<TData>;
93+
// (undocumented)
9094
abstract diff<TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: Cache_2.DiffOptions<TData, TVariables>): Cache_2.DiffResult<TData>;
9195
// (undocumented)
9296
abstract evict(options: Cache_2.EvictOptions): boolean;
@@ -1158,7 +1162,6 @@ interface DiffIncrementalInfo {
11581162
// @public (undocumented)
11591163
export type DiffQueryAgainstStoreOptions = ReadQueryOptions & {
11601164
returnPartialData?: boolean;
1161-
[handleIncrementalSymbol]?: true | DiffIncrementalInfo;
11621165
};
11631166

11641167
export { disableExperimentalFragmentVariables }
@@ -1660,8 +1663,6 @@ export namespace InMemoryCache {
16601663

16611664
// @public (undocumented)
16621665
export class InMemoryCache extends ApolloCache {
1663-
// (undocumented)
1664-
readonly [handleIncrementalSymbol] = true;
16651666
constructor(...args: {} extends InMemoryCache.ScalarsOption ? [
16661667
config?: InMemoryCacheConfig
16671668
] : [config: InMemoryCacheConfig]);
@@ -1676,7 +1677,7 @@ export class InMemoryCache extends ApolloCache {
16761677
protected config: InMemoryCacheConfig;
16771678
// (undocumented)
16781679
diff<TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: Cache_2.DiffOptions<TData, TVariables> & {
1679-
[handleIncrementalSymbol]: true | DiffIncrementalInfo;
1680+
[handleIncrementalSymbol]: DiffIncrementalInfo | undefined;
16801681
}): Cache_2.InternalDiffResultWithDataState<TData>;
16811682
// (undocumented)
16821683
diff<TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: Cache_2.DiffOptions<TData, TVariables>): Cache_2.DiffResult<TData>;
@@ -3250,14 +3251,14 @@ interface WriteContext extends ReadMergeModifyContext {
32503251

32513252
// Warnings were encountered during analysis:
32523253
//
3253-
// src/cache/core/cache.ts:127:11 - (ae-forgotten-export) The symbol "MissingTree" needs to be exported by the entry point index.d.ts
3254+
// src/cache/core/cache.ts:129:11 - (ae-forgotten-export) The symbol "MissingTree" needs to be exported by the entry point index.d.ts
3255+
// src/cache/core/cache.ts:204:7 - (ae-forgotten-export) The symbol "DiffIncrementalInfo" needs to be exported by the entry point index.d.ts
32543256
// src/cache/inmemory/policies.ts:104:3 - (ae-forgotten-export) The symbol "FragmentMap" needs to be exported by the entry point index.d.ts
32553257
// src/cache/inmemory/policies.ts:176:3 - (ae-forgotten-export) The symbol "KeySpecifier" needs to be exported by the entry point index.d.ts
32563258
// src/cache/inmemory/policies.ts:176:3 - (ae-forgotten-export) The symbol "KeyArgsFunction" needs to be exported by the entry point index.d.ts
32573259
// src/cache/inmemory/policies.ts:179:3 - (ae-forgotten-export) The symbol "ScalarNames" needs to be exported by the entry point index.d.ts
3258-
// src/cache/inmemory/types.ts:145:3 - (ae-forgotten-export) The symbol "DiffIncrementalInfo" needs to be exported by the entry point index.d.ts
3259-
// src/cache/inmemory/types.ts:149:3 - (ae-forgotten-export) The symbol "KeyFieldsFunction" needs to be exported by the entry point index.d.ts
3260-
// src/cache/inmemory/types.ts:164:3 - (ae-forgotten-export) The symbol "FragmentRegistryAPI" needs to be exported by the entry point index.d.ts
3260+
// src/cache/inmemory/types.ts:147:3 - (ae-forgotten-export) The symbol "KeyFieldsFunction" needs to be exported by the entry point index.d.ts
3261+
// src/cache/inmemory/types.ts:162:3 - (ae-forgotten-export) The symbol "FragmentRegistryAPI" needs to be exported by the entry point index.d.ts
32613262
// src/core/ApolloClient.ts:201:5 - (ae-forgotten-export) The symbol "IgnoreModifier" needs to be exported by the entry point index.d.ts
32623263
// src/core/ApolloClient.ts:635:5 - (ae-forgotten-export) The symbol "NextFetchPolicyContext" needs to be exported by the entry point index.d.ts
32633264
// src/core/ObservableQuery.ts:375:5 - (ae-forgotten-export) The symbol "QueryManager" needs to be exported by the entry point index.d.ts

src/cache/core/cache.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import type { Reference, StoreObject } from "@apollo/client/utilities";
2929
import { cacheSizes, canonicalStringify } from "@apollo/client/utilities";
3030
import { __DEV__ } from "@apollo/client/utilities/environment";
3131
import type {
32+
handleIncrementalSymbol,
3233
IsAny,
3334
NoInfer,
3435
Prettify,
@@ -45,6 +46,7 @@ import {
4546
import { invariant } from "@apollo/client/utilities/invariant";
4647

4748
import { defaultCacheSizes } from "../../utilities/caching/sizes.js";
49+
import type { DiffIncrementalInfo } from "../inmemory/types.js";
4850

4951
import type { Scalar } from "./Scalar.js";
5052
import type { Cache } from "./types/Cache.js";
@@ -194,6 +196,15 @@ export abstract class ApolloCache {
194196
* returned if it contains at least one field that can be fulfilled from the
195197
* cache.
196198
*/
199+
public abstract diff<
200+
TData = unknown,
201+
TVariables extends OperationVariables = OperationVariables,
202+
>(
203+
query: Cache.DiffOptions<TData, TVariables> & {
204+
[handleIncrementalSymbol]: DiffIncrementalInfo | undefined;
205+
}
206+
): Cache.InternalDiffResultWithDataState<TData> | Cache.DiffResult<TData>;
207+
197208
public abstract diff<
198209
TData = unknown,
199210
TVariables extends OperationVariables = OperationVariables,

0 commit comments

Comments
 (0)