Skip to content

Commit

Permalink
Clarify types of EntityStore.makeCacheKey (#11371)
Browse files Browse the repository at this point in the history
  • Loading branch information
phryneas committed Nov 20, 2023
1 parent ac4e382 commit ebd8fe2
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .api-reports/api-report-cache.md
Expand Up @@ -355,6 +355,12 @@ export abstract class EntityStore implements NormalizedCache {
// (undocumented)
protected lookup(dataId: string, dependOnExistence?: boolean): StoreObject | undefined;
// (undocumented)
makeCacheKey(document: DocumentNode, callback: Cache_2.WatchCallback<any>, details: string): object;
// (undocumented)
makeCacheKey(selectionSet: SelectionSetNode, parent: string | StoreObject, varString: string | undefined, canonizeResults: boolean): object;
// (undocumented)
makeCacheKey(field: FieldNode, array: readonly any[], varString: string | undefined): object;
// (undocumented)
makeCacheKey(...args: any[]): object;
// (undocumented)
merge(older: string | StoreObject, newer: StoreObject | string): void;
Expand Down
6 changes: 6 additions & 0 deletions .api-reports/api-report-core.md
Expand Up @@ -670,6 +670,12 @@ abstract class EntityStore implements NormalizedCache {
// (undocumented)
protected lookup(dataId: string, dependOnExistence?: boolean): StoreObject | undefined;
// (undocumented)
makeCacheKey(document: DocumentNode, callback: Cache_2.WatchCallback<any>, details: string): object;
// (undocumented)
makeCacheKey(selectionSet: SelectionSetNode, parent: string | StoreObject, varString: string | undefined, canonizeResults: boolean): object;
// (undocumented)
makeCacheKey(field: FieldNode, array: readonly any[], varString: string | undefined): object;
// (undocumented)
makeCacheKey(...args: any[]): object;
// (undocumented)
merge(older: string | StoreObject, newer: StoreObject | string): void;
Expand Down
6 changes: 6 additions & 0 deletions .api-reports/api-report-utilities.md
Expand Up @@ -827,6 +827,12 @@ abstract class EntityStore implements NormalizedCache {
// (undocumented)
protected lookup(dataId: string, dependOnExistence?: boolean): StoreObject | undefined;
// (undocumented)
makeCacheKey(document: DocumentNode, callback: Cache_2.WatchCallback<any>, details: string): object;
// (undocumented)
makeCacheKey(selectionSet: SelectionSetNode, parent: string | StoreObject, varString: string | undefined, canonizeResults: boolean): object;
// (undocumented)
makeCacheKey(field: FieldNode, array: readonly any[], varString: string | undefined): object;
// (undocumented)
makeCacheKey(...args: any[]): object;
// (undocumented)
merge(older: string | StoreObject, newer: StoreObject | string): void;
Expand Down
6 changes: 6 additions & 0 deletions .api-reports/api-report.md
Expand Up @@ -831,6 +831,12 @@ abstract class EntityStore implements NormalizedCache {
// (undocumented)
protected lookup(dataId: string, dependOnExistence?: boolean): StoreObject | undefined;
// (undocumented)
makeCacheKey(document: DocumentNode, callback: Cache_2.WatchCallback<any>, details: string): object;
// (undocumented)
makeCacheKey(selectionSet: SelectionSetNode, parent: string | StoreObject, varString: string | undefined, canonizeResults: boolean): object;
// (undocumented)
makeCacheKey(field: FieldNode, array: readonly any[], varString: string | undefined): object;
// (undocumented)
makeCacheKey(...args: any[]): object;
// (undocumented)
merge(older: string | StoreObject, newer: StoreObject | string): void;
Expand Down
5 changes: 5 additions & 0 deletions .changeset/thick-mice-collect.md
@@ -0,0 +1,5 @@
---
"@apollo/client": patch
---

Clarify types of `EntityStore.makeCacheKey`.
22 changes: 22 additions & 0 deletions src/cache/inmemory/entityStore.ts
Expand Up @@ -32,6 +32,7 @@ import type {
DeleteModifier,
ModifierDetails,
} from "../core/types/common.js";
import type { DocumentNode, FieldNode, SelectionSetNode } from "graphql";

const DELETE: DeleteModifier = Object.create(null);
const delModifier: Modifier<any> = () => DELETE;
Expand Down Expand Up @@ -522,6 +523,27 @@ export abstract class EntityStore implements NormalizedCache {
}

// Used to compute cache keys specific to this.group.
/** overload for `InMemoryCache.maybeBroadcastWatch` */
public makeCacheKey(
document: DocumentNode,
callback: Cache.WatchCallback<any>,
details: string
): object;
/** overload for `StoreReader.executeSelectionSet` */
public makeCacheKey(
selectionSet: SelectionSetNode,
parent: string /* = ( Reference.__ref ) */ | StoreObject,
varString: string | undefined,
canonizeResults: boolean
): object;
/** overload for `StoreReader.executeSubSelectedArray` */
public makeCacheKey(
field: FieldNode,
array: readonly any[],
varString: string | undefined
): object;
/** @deprecated This is only meant for internal usage,
* in your own code please use a `Trie` instance instead. */
public makeCacheKey(...args: any[]): object;
public makeCacheKey() {
return this.group.keyMaker.lookupArray(arguments);
Expand Down
4 changes: 4 additions & 0 deletions src/cache/inmemory/readFromStore.ts
Expand Up @@ -153,6 +153,10 @@ export class StoreReader {

this.canon = config.canon || new ObjectCanon();

// memoized functions in this class will be "garbage-collected"
// by recreating the whole `StoreReader` in
// `InMemoryCache.resetResultsCache`
// (triggered from `InMemoryCache.gc` with `resetResultCache: true`)
this.executeSelectionSet = wrap(
(options) => {
const { canonizeResults } = options.context;
Expand Down

0 comments on commit ebd8fe2

Please sign in to comment.