diff --git a/src/cache/core/cache.ts b/src/cache/core/cache.ts index b87f9da95eb..bdc6dfaf9db 100644 --- a/src/cache/core/cache.ts +++ b/src/cache/core/cache.ts @@ -117,7 +117,7 @@ export abstract class ApolloCache implements DataProxy { return []; } - public modify(options: Cache.ModifyOptions): boolean { + public modify(options: Cache.ModifyOptions): boolean { return false; } diff --git a/src/cache/core/types/Cache.ts b/src/cache/core/types/Cache.ts index 79704962b25..85c6f70aabb 100644 --- a/src/cache/core/types/Cache.ts +++ b/src/cache/core/types/Cache.ts @@ -57,9 +57,11 @@ export namespace Cache { discardWatches?: boolean; } - export interface ModifyOptions { + export interface ModifyOptions { id?: string; - fields: Modifiers> | Modifier; + fields: Entity extends Record + ? Modifiers | Modifier + : Modifier; optimistic?: boolean; broadcast?: boolean; } diff --git a/src/cache/inmemory/__tests__/cache.ts b/src/cache/inmemory/__tests__/cache.ts index 985989dc466..1ce6bba07d0 100644 --- a/src/cache/inmemory/__tests__/cache.ts +++ b/src/cache/inmemory/__tests__/cache.ts @@ -4069,7 +4069,7 @@ describe('TypedDocumentNode', () => { ): ExpectedType extends ActualType ? void : never => void 0 as any; - cache.modify({ + cache.modify({ id: cache.identify(ffplBook), fields: { isbn: (value) => { @@ -4090,7 +4090,7 @@ describe('TypedDocumentNode', () => { return DELETE; }, - } satisfies Modifiers, + }, }); }); }); diff --git a/src/cache/inmemory/inMemoryCache.ts b/src/cache/inmemory/inMemoryCache.ts index 9dd57fab005..f2efc756730 100644 --- a/src/cache/inmemory/inMemoryCache.ts +++ b/src/cache/inmemory/inMemoryCache.ts @@ -204,7 +204,7 @@ export class InMemoryCache extends ApolloCache { } } - public modify(options: Cache.ModifyOptions): boolean { + public modify(options: Cache.ModifyOptions): boolean { if (hasOwn.call(options, "id") && !options.id) { // To my knowledge, TypeScript does not currently provide a way to // enforce that an optional property?:type must *not* be undefined diff --git a/src/cache/inmemory/types.ts b/src/cache/inmemory/types.ts index 57437436e63..8605e0e842f 100644 --- a/src/cache/inmemory/types.ts +++ b/src/cache/inmemory/types.ts @@ -49,7 +49,8 @@ export interface NormalizedCache { merge(olderId: string, newerObject: StoreObject): void; merge(olderObject: StoreObject, newerId: string): void; - modify(dataId: string, fields: Modifiers> | Modifier): boolean; + modify>(dataId: string, fields: Modifiers): boolean; + modify(dataId: string, modifier: Modifier): boolean; delete(dataId: string, fieldName?: string): boolean; clear(): void;