diff --git a/.changeset/hungry-pens-rule.md b/.changeset/hungry-pens-rule.md new file mode 100644 index 00000000000..3255aacaf38 --- /dev/null +++ b/.changeset/hungry-pens-rule.md @@ -0,0 +1,5 @@ +--- +"@apollo/client": patch +--- + +Use a WeakCache as backend for `executeSelectionSet`, `executeSubSelectedArray` and `maybeBroadcastWatch`. diff --git a/src/cache/inmemory/inMemoryCache.ts b/src/cache/inmemory/inMemoryCache.ts index 7be5b921ab5..9c435f64c18 100644 --- a/src/cache/inmemory/inMemoryCache.ts +++ b/src/cache/inmemory/inMemoryCache.ts @@ -34,6 +34,7 @@ import { Policies } from "./policies.js"; import { hasOwn, normalizeConfig, shouldCanonizeResults } from "./helpers.js"; import type { OperationVariables } from "../../core/index.js"; import { getInMemoryCacheMemoryInternals } from "../../utilities/caching/getMemoryInternals.js"; +import { WeakCache } from "@wry/caches"; type BroadcastOptions = Pick< Cache.BatchOptions, @@ -131,6 +132,7 @@ export class InMemoryCache extends ApolloCache { return this.broadcastWatch(c, options); }, { + cache: WeakCache, max: this.config.resultCacheMaxSize || cacheSizes["inMemoryCache.maybeBroadcastWatch"] || diff --git a/src/cache/inmemory/readFromStore.ts b/src/cache/inmemory/readFromStore.ts index d89876d85c9..e00836bb10d 100644 --- a/src/cache/inmemory/readFromStore.ts +++ b/src/cache/inmemory/readFromStore.ts @@ -4,6 +4,7 @@ import type { DocumentNode, FieldNode, SelectionSetNode } from "graphql"; import { Kind } from "graphql"; import type { OptimisticWrapperFunction } from "optimism"; import { wrap } from "optimism"; +import { WeakCache } from "@wry/caches"; import type { Reference, @@ -195,6 +196,7 @@ export class StoreReader { return this.execSelectionSetImpl(options); }, { + cache: WeakCache, max: this.config.resultCacheMaxSize || cacheSizes["inMemoryCache.executeSelectionSet"] || @@ -224,6 +226,7 @@ export class StoreReader { return this.execSubSelectedArrayImpl(options); }, { + cache: WeakCache, max: this.config.resultCacheMaxSize || cacheSizes["inMemoryCache.executeSubSelectedArray"] ||