diff --git a/.api-reports/api-report-core.md b/.api-reports/api-report-core.md index 935e04317d7..119bc538d4e 100644 --- a/.api-reports/api-report-core.md +++ b/.api-reports/api-report-core.md @@ -601,6 +601,8 @@ export class DocumentTransform { // (undocumented) static identity(): DocumentTransform; // (undocumented) + resetCache(): void; + // (undocumented) static split(predicate: (document: DocumentNode) => boolean, left: DocumentTransform, right?: DocumentTransform): DocumentTransform; // (undocumented) transformDocument(document: DocumentNode): DocumentNode; diff --git a/.api-reports/api-report-react.md b/.api-reports/api-report-react.md index ceee7f54aac..d7a73cbefd3 100644 --- a/.api-reports/api-report-react.md +++ b/.api-reports/api-report-react.md @@ -728,6 +728,8 @@ class DocumentTransform { // (undocumented) static identity(): DocumentTransform; // (undocumented) + resetCache(): void; + // (undocumented) static split(predicate: (document: DocumentNode) => boolean, left: DocumentTransform, right?: DocumentTransform): DocumentTransform; // (undocumented) transformDocument(document: DocumentNode): DocumentNode; @@ -2221,7 +2223,7 @@ interface WatchQueryOptions boolean, left: DocumentTransform, right?: DocumentTransform): DocumentTransform; // (undocumented) transformDocument(document: DocumentNode): DocumentNode; @@ -1753,7 +1755,7 @@ interface WatchQueryOptions boolean, left: DocumentTransform, right?: DocumentTransform): DocumentTransform; // (undocumented) transformDocument(document: DocumentNode): DocumentNode; @@ -1649,7 +1651,7 @@ interface WatchQueryOptions boolean, left: DocumentTransform, right?: DocumentTransform): DocumentTransform; // (undocumented) transformDocument(document: DocumentNode): DocumentNode; @@ -1694,7 +1696,7 @@ export function withSubscription boolean, left: DocumentTransform, right?: DocumentTransform): DocumentTransform; // (undocumented) transformDocument(document: DocumentNode): DocumentNode; @@ -2115,7 +2117,7 @@ interface WatchQueryOptions boolean, left: DocumentTransform, right?: DocumentTransform): DocumentTransform; // (undocumented) transformDocument(document: DocumentNode): DocumentNode; @@ -1635,7 +1637,7 @@ interface WatchQueryOptions boolean, left: DocumentTransform, right?: DocumentTransform): DocumentTransform; // (undocumented) transformDocument(document: DocumentNode): DocumentNode; @@ -1698,7 +1700,7 @@ export function withWarningSpy(it: (...args: TArgs // src/core/types.ts:178:3 - (ae-forgotten-export) The symbol "MutationQueryReducer" needs to be exported by the entry point index.d.ts // src/core/types.ts:205:5 - (ae-forgotten-export) The symbol "Resolver" needs to be exported by the entry point index.d.ts // src/core/watchQueryOptions.ts:191:3 - (ae-forgotten-export) The symbol "UpdateQueryFn" needs to be exported by the entry point index.d.ts -// src/utilities/graphql/DocumentTransform.ts:122:7 - (ae-forgotten-export) The symbol "DocumentTransformCacheKey" needs to be exported by the entry point index.d.ts +// src/utilities/graphql/DocumentTransform.ts:130:7 - (ae-forgotten-export) The symbol "DocumentTransformCacheKey" needs to be exported by the entry point index.d.ts // (No @packageDocumentation comment for this package) diff --git a/.api-reports/api-report-testing_core.md b/.api-reports/api-report-testing_core.md index c4ee5f52cf0..db8ba43820e 100644 --- a/.api-reports/api-report-testing_core.md +++ b/.api-reports/api-report-testing_core.md @@ -581,6 +581,8 @@ class DocumentTransform { // (undocumented) static identity(): DocumentTransform; // (undocumented) + resetCache(): void; + // (undocumented) static split(predicate: (document: DocumentNode) => boolean, left: DocumentTransform, right?: DocumentTransform): DocumentTransform; // (undocumented) transformDocument(document: DocumentNode): DocumentNode; @@ -1654,7 +1656,7 @@ export function withWarningSpy(it: (...args: TArgs // src/core/types.ts:178:3 - (ae-forgotten-export) The symbol "MutationQueryReducer" needs to be exported by the entry point index.d.ts // src/core/types.ts:205:5 - (ae-forgotten-export) The symbol "Resolver" needs to be exported by the entry point index.d.ts // src/core/watchQueryOptions.ts:191:3 - (ae-forgotten-export) The symbol "UpdateQueryFn" needs to be exported by the entry point index.d.ts -// src/utilities/graphql/DocumentTransform.ts:122:7 - (ae-forgotten-export) The symbol "DocumentTransformCacheKey" needs to be exported by the entry point index.d.ts +// src/utilities/graphql/DocumentTransform.ts:130:7 - (ae-forgotten-export) The symbol "DocumentTransformCacheKey" needs to be exported by the entry point index.d.ts // (No @packageDocumentation comment for this package) diff --git a/.api-reports/api-report-utilities.md b/.api-reports/api-report-utilities.md index 4661d99d1f3..db99ac83b43 100644 --- a/.api-reports/api-report-utilities.md +++ b/.api-reports/api-report-utilities.md @@ -759,6 +759,8 @@ export class DocumentTransform { // (undocumented) static identity(): DocumentTransform; // (undocumented) + resetCache(): void; + // (undocumented) static split(predicate: (document: DocumentNode) => boolean, left: DocumentTransform, right?: DocumentTransform): DocumentTransform; // (undocumented) transformDocument(document: DocumentNode): DocumentNode; diff --git a/.api-reports/api-report.md b/.api-reports/api-report.md index a9d2cce7e79..174182d1f2c 100644 --- a/.api-reports/api-report.md +++ b/.api-reports/api-report.md @@ -751,6 +751,8 @@ export class DocumentTransform { // (undocumented) static identity(): DocumentTransform; // (undocumented) + resetCache(): void; + // (undocumented) static split(predicate: (document: DocumentNode) => boolean, left: DocumentTransform, right?: DocumentTransform): DocumentTransform; // (undocumented) transformDocument(document: DocumentNode): DocumentNode; diff --git a/.changeset/hot-ducks-burn.md b/.changeset/hot-ducks-burn.md new file mode 100644 index 00000000000..c0f8ac1836c --- /dev/null +++ b/.changeset/hot-ducks-burn.md @@ -0,0 +1,5 @@ +--- +"@apollo/client": patch +--- + +Add a `resetCache` method to `DocumentTransform` and hook `InMemoryCache.addTypenameTransform` up to `InMemoryCache.gc` diff --git a/.size-limit.cjs b/.size-limit.cjs index bd4497ec3a5..a15bd6aa160 100644 --- a/.size-limit.cjs +++ b/.size-limit.cjs @@ -1,7 +1,7 @@ const checks = [ { path: "dist/apollo-client.min.cjs", - limit: "38101", + limit: "38124", }, { path: "dist/main.cjs", @@ -10,7 +10,7 @@ const checks = [ { path: "dist/index.js", import: "{ ApolloClient, InMemoryCache, HttpLink }", - limit: "32132", + limit: "32162", }, ...[ "ApolloProvider", diff --git a/src/cache/inmemory/inMemoryCache.ts b/src/cache/inmemory/inMemoryCache.ts index 3fe7ab56fdf..1297b6eeb19 100644 --- a/src/cache/inmemory/inMemoryCache.ts +++ b/src/cache/inmemory/inMemoryCache.ts @@ -295,6 +295,7 @@ export class InMemoryCache extends ApolloCache { }) { canonicalStringify.reset(); print.reset(); + this.addTypenameTransform.resetCache(); const ids = this.optimisticData.gc(); if (options && !this.txCount) { if (options.resetResultCache) { diff --git a/src/utilities/graphql/DocumentTransform.ts b/src/utilities/graphql/DocumentTransform.ts index 0a614df4190..d88bcf7615b 100644 --- a/src/utilities/graphql/DocumentTransform.ts +++ b/src/utilities/graphql/DocumentTransform.ts @@ -80,6 +80,14 @@ export class DocumentTransform { } } + /** + * Resets the internal cache of this transform, if it has one. + */ + resetCache() { + this.stableCacheKeys = + this.stableCacheKeys && new Trie(canUseWeakMap, (key) => ({ key })); + } + transformDocument(document: DocumentNode) { // If a user passes an already transformed result back to this function, // immediately return it.