Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarify types of EntityStore.makeCacheKey #11371

Merged
merged 4 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .api-reports/api-report-cache.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@apollo/client": patch
---

Clarify types of `EntityStore.makeCacheKey`.
22 changes: 22 additions & 0 deletions src/cache/inmemory/entityStore.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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