From d5d8cb10c468a1f256286b354a428afd69765c15 Mon Sep 17 00:00:00 2001 From: Lenz Weber-Tronic Date: Thu, 16 Nov 2023 18:09:58 +0100 Subject: [PATCH 01/62] `print`: use `WeakCache` instead of `WeakMap` --- .changeset/polite-avocados-warn.md | 5 +++++ .size-limit.cjs | 5 +++-- package-lock.json | 12 ++++++++++++ package.json | 1 + src/utilities/graphql/print.ts | 13 +++++-------- 5 files changed, 26 insertions(+), 10 deletions(-) create mode 100644 .changeset/polite-avocados-warn.md diff --git a/.changeset/polite-avocados-warn.md b/.changeset/polite-avocados-warn.md new file mode 100644 index 00000000000..dd04015cf3d --- /dev/null +++ b/.changeset/polite-avocados-warn.md @@ -0,0 +1,5 @@ +--- +"@apollo/client": patch +--- + +`print`: use `WeakCache` instead of `WeakMap` diff --git a/.size-limit.cjs b/.size-limit.cjs index 63819405fd1..e2233d201f3 100644 --- a/.size-limit.cjs +++ b/.size-limit.cjs @@ -1,7 +1,7 @@ const checks = [ { path: "dist/apollo-client.min.cjs", - limit: "38164", + limit: "38178", }, { path: "dist/main.cjs", @@ -10,7 +10,7 @@ const checks = [ { path: "dist/index.js", import: "{ ApolloClient, InMemoryCache, HttpLink }", - limit: "32188", + limit: "32206", }, ...[ "ApolloProvider", @@ -35,6 +35,7 @@ const checks = [ "react", "react-dom", "@graphql-typed-document-node/core", + "@wry/caches", "@wry/context", "@wry/equality", "@wry/trie", diff --git a/package-lock.json b/package-lock.json index 9cf8221c770..2217dbde199 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,6 +11,7 @@ "license": "MIT", "dependencies": { "@graphql-typed-document-node/core": "^3.1.1", + "@wry/caches": "^1.0.0", "@wry/context": "^0.7.3", "@wry/equality": "^0.5.6", "@wry/trie": "^0.4.3", @@ -3294,6 +3295,17 @@ "url": "https://opencollective.com/typescript-eslint" } }, + "node_modules/@wry/caches": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/@wry/caches/-/caches-1.0.0.tgz", + "integrity": "sha512-FHRUDe2tqrXAj6A/1D39No68lFWbbnh+NCpG9J/6idhL/2Mb/AaxBTYg/sbUVImEo8a4mWeOewUlB1W7uLjByA==", + "dependencies": { + "tslib": "^2.3.0" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/@wry/context": { "version": "0.7.3", "resolved": "https://registry.npmjs.org/@wry/context/-/context-0.7.3.tgz", diff --git a/package.json b/package.json index 3a7d6f0196f..da96797c4ea 100644 --- a/package.json +++ b/package.json @@ -89,6 +89,7 @@ }, "dependencies": { "@graphql-typed-document-node/core": "^3.1.1", + "@wry/caches": "^1.0.0", "@wry/context": "^0.7.3", "@wry/equality": "^0.5.6", "@wry/trie": "^0.4.3", diff --git a/src/utilities/graphql/print.ts b/src/utilities/graphql/print.ts index d90a15611d0..572584e4ca3 100644 --- a/src/utilities/graphql/print.ts +++ b/src/utilities/graphql/print.ts @@ -1,23 +1,20 @@ import type { ASTNode } from "graphql"; import { print as origPrint } from "graphql"; -import { canUseWeakMap } from "../common/canUse.js"; +import { WeakCache } from "@wry/caches" -let printCache: undefined | WeakMap; -// further TODO: replace with `optimism` with a `WeakCache` once those are available +let printCache!: WeakCache; export const print = Object.assign( (ast: ASTNode) => { - let result; - result = printCache?.get(ast); + let result = printCache.get(ast); if (!result) { - result = origPrint(ast); - printCache?.set(ast, result); + printCache.set(ast, result = origPrint(ast)); } return result; }, { reset() { - printCache = canUseWeakMap ? new WeakMap() : undefined; + printCache = new WeakCache(/** TODO: decide on a maximum size (will do all max sizes in a combined separate PR) */); }, } ); From 29bf59da53b2846f9f713e93000c9d1d16d6b0a1 Mon Sep 17 00:00:00 2001 From: Lenz Weber-Tronic Date: Thu, 16 Nov 2023 18:11:41 +0100 Subject: [PATCH 02/62] format --- src/utilities/graphql/print.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/utilities/graphql/print.ts b/src/utilities/graphql/print.ts index 572584e4ca3..d536ff8bb77 100644 --- a/src/utilities/graphql/print.ts +++ b/src/utilities/graphql/print.ts @@ -1,6 +1,6 @@ import type { ASTNode } from "graphql"; import { print as origPrint } from "graphql"; -import { WeakCache } from "@wry/caches" +import { WeakCache } from "@wry/caches"; let printCache!: WeakCache; export const print = Object.assign( @@ -8,13 +8,16 @@ export const print = Object.assign( let result = printCache.get(ast); if (!result) { - printCache.set(ast, result = origPrint(ast)); + printCache.set(ast, (result = origPrint(ast))); } return result; }, { reset() { - printCache = new WeakCache(/** TODO: decide on a maximum size (will do all max sizes in a combined separate PR) */); + printCache = new WeakCache< + ASTNode, + string + >(/** TODO: decide on a maximum size (will do all max sizes in a combined separate PR) */); }, } ); From 9942e61166e182768fce7f0886f59677c14e3a4d Mon Sep 17 00:00:00 2001 From: Lenz Weber-Tronic Date: Fri, 17 Nov 2023 12:51:58 +0100 Subject: [PATCH 03/62] pull in memory testing tools from PR 11358 --- package.json | 3 +- src/testing/matchers/index.d.ts | 9 ++++ src/testing/matchers/index.ts | 2 + src/testing/matchers/toBeGarbageCollected.ts | 51 ++++++++++++++++++++ src/tsconfig.json | 2 +- 5 files changed, 64 insertions(+), 3 deletions(-) create mode 100644 src/testing/matchers/toBeGarbageCollected.ts diff --git a/package.json b/package.json index da96797c4ea..5f7353d178c 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ "ci:precheck": "node config/precheck.js", "format": "prettier --write .", "lint": "eslint 'src/**/*.{[jt]s,[jt]sx}'", - "test": "jest --config ./config/jest.config.js", + "test": "node --expose-gc ./node_modules/jest/bin/jest.js --config ./config/jest.config.js", "test:debug": "node --inspect-brk node_modules/.bin/jest --config ./config/jest.config.js --runInBand --testTimeout 99999 --logHeapUsage", "test:ci": "TEST_ENV=ci npm run test:coverage -- --logHeapUsage && npm run test:memory", "test:watch": "jest --config ./config/jest.config.js --watch", @@ -89,7 +89,6 @@ }, "dependencies": { "@graphql-typed-document-node/core": "^3.1.1", - "@wry/caches": "^1.0.0", "@wry/context": "^0.7.3", "@wry/equality": "^0.5.6", "@wry/trie": "^0.4.3", diff --git a/src/testing/matchers/index.d.ts b/src/testing/matchers/index.d.ts index 715f7d3dbdf..a8ea24c1023 100644 --- a/src/testing/matchers/index.d.ts +++ b/src/testing/matchers/index.d.ts @@ -9,6 +9,11 @@ import { ProfiledHook, } from "../internal/index.js"; +declare class WeakRef { + constructor(target: T); + deref(): T | undefined; +} + interface ApolloCustomMatchers { /** * Used to determine if two GraphQL query documents are equal to each other by @@ -38,6 +43,10 @@ interface ApolloCustomMatchers { | ProfiledHook ? (count: number, options?: NextRenderOptions) => Promise : { error: "matcher needs to be called on a ProfiledComponent instance" }; + + toBeGarbageCollected: T extends WeakRef + ? () => Promise + : { error: "matcher needs to be called on a WeakRef instance" }; } declare global { diff --git a/src/testing/matchers/index.ts b/src/testing/matchers/index.ts index d2ebd8ce7c2..709bfbad53b 100644 --- a/src/testing/matchers/index.ts +++ b/src/testing/matchers/index.ts @@ -2,10 +2,12 @@ import { expect } from "@jest/globals"; import { toMatchDocument } from "./toMatchDocument.js"; import { toHaveSuspenseCacheEntryUsing } from "./toHaveSuspenseCacheEntryUsing.js"; import { toRerender, toRenderExactlyTimes } from "./ProfiledComponent.js"; +import { toBeGarbageCollected } from "./toBeGarbageCollected.js"; expect.extend({ toHaveSuspenseCacheEntryUsing, toMatchDocument, toRerender, toRenderExactlyTimes, + toBeGarbageCollected, }); diff --git a/src/testing/matchers/toBeGarbageCollected.ts b/src/testing/matchers/toBeGarbageCollected.ts new file mode 100644 index 00000000000..baa9c59128b --- /dev/null +++ b/src/testing/matchers/toBeGarbageCollected.ts @@ -0,0 +1,51 @@ +import type { MatcherFunction } from "expect"; + +declare class WeakRef { + constructor(target: T); + deref(): T | undefined; +} + +export const toBeGarbageCollected: MatcherFunction<[weakRef: WeakRef]> = + async function (actual) { + const hint = this.utils.matcherHint("toBeGarbageCollected"); + + if (!(actual instanceof WeakRef)) { + throw new Error( + hint + + "\n\n" + + `Expected value to be a WeakRef, but it was a ${typeof actual}.` + ); + } + + let pass = false; + let interval: NodeJS.Timeout | undefined; + await Promise.race([ + new Promise((resolve) => setTimeout(resolve, 1000)), + new Promise((resolve) => { + setInterval(() => { + global.gc!(); + pass = actual.deref() === undefined; + if (pass) { + resolve(); + } + }, 1); + }), + ]).finally(() => clearInterval(interval)); + + return { + pass, + message: () => { + if (pass) { + return ( + hint + + "\n\n" + + "Expected value to not be cache-collected, but it was." + ); + } + + return ( + hint + "\n\n Expected value to be cache-collected, but it was not." + ); + }, + }; + }; diff --git a/src/tsconfig.json b/src/tsconfig.json index 321f038a735..40ade0f5761 100644 --- a/src/tsconfig.json +++ b/src/tsconfig.json @@ -5,7 +5,7 @@ { "compilerOptions": { "noEmit": true, - "lib": ["es2015", "esnext.asynciterable", "dom"], + "lib": ["es2015", "esnext.asynciterable", "dom", "ES2021.WeakRef"], "types": ["jest", "node", "./testing/matchers/index.d.ts"] }, "extends": "../tsconfig.json", From b933dfb00e352483c4308df6ce147c5e4da3ef5a Mon Sep 17 00:00:00 2001 From: Lenz Weber-Tronic Date: Fri, 17 Nov 2023 14:42:47 +0100 Subject: [PATCH 04/62] Persisted Query Link: improve memory management --- .../api-report-link_persisted-queries.md | 4 +- .changeset/thick-tips-cry.md | 9 + .../__tests__/persisted-queries.test.ts | 61 ++++ src/link/persisted-queries/index.ts | 285 +++++++++--------- 4 files changed, 223 insertions(+), 136 deletions(-) create mode 100644 .changeset/thick-tips-cry.md diff --git a/.api-reports/api-report-link_persisted-queries.md b/.api-reports/api-report-link_persisted-queries.md index dda0d3dd1db..84c87032e4c 100644 --- a/.api-reports/api-report-link_persisted-queries.md +++ b/.api-reports/api-report-link_persisted-queries.md @@ -57,7 +57,9 @@ interface BaseOptions { // Warning: (ae-forgotten-export) The symbol "ApolloLink" needs to be exported by the entry point index.d.ts // // @public (undocumented) -export const createPersistedQueryLink: (options: PersistedQueryLink.Options) => ApolloLink; +export const createPersistedQueryLink: (options: PersistedQueryLink.Options) => ApolloLink & { + resetCache: () => void; +}; // @public (undocumented) interface DefaultContext extends Record { diff --git a/.changeset/thick-tips-cry.md b/.changeset/thick-tips-cry.md new file mode 100644 index 00000000000..407513ec1c7 --- /dev/null +++ b/.changeset/thick-tips-cry.md @@ -0,0 +1,9 @@ +--- +"@apollo/client": patch +--- + +Persisted Query Link: improve memory management +* use LRU `WeakCache` instead of `WeakMap` to keep a limited number of hash results +* hash cache is initiated lazily, only when needed +* expose `persistedLink.resetHashCache()` method +* reset hash cache if the upstream server reports it doesn't accept persisted queries diff --git a/src/link/persisted-queries/__tests__/persisted-queries.test.ts b/src/link/persisted-queries/__tests__/persisted-queries.test.ts index ea8b56e660a..bb3b8cb8c44 100644 --- a/src/link/persisted-queries/__tests__/persisted-queries.test.ts +++ b/src/link/persisted-queries/__tests__/persisted-queries.test.ts @@ -151,6 +151,32 @@ describe("happy path", () => { }, reject); }); + it("clears the cache when calling `resetHashCache`", async () => { + fetchMock.post( + "/graphql", + () => new Promise((resolve) => resolve({ body: response })), + { repeat: 1 } + ); + + const hashRefs: WeakRef[] = []; + function hash(query: string) { + const newHash = new String(query); + hashRefs.push(new WeakRef(newHash)); + return newHash as string; + } + const persistedLink = createPersistedQuery({ sha256: hash }); + await new Promise((complete) => + execute(persistedLink.concat(createHttpLink()), { + query, + variables, + }).subscribe({ complete }) + ); + + await expect(hashRefs[0]).not.toBeGarbageCollected(); + persistedLink.resetHashCache(); + await expect(hashRefs[0]).toBeGarbageCollected(); + }); + itAsync("supports loading the hash from other method", (resolve, reject) => { fetchMock.post( "/graphql", @@ -517,6 +543,41 @@ describe("failure path", () => { }) ); + it.each([ + ["error message", giveUpResponse], + ["error code", giveUpResponseWithCode], + ] as const)( + "clears the cache when receiving NotSupported error (%s)", + async (_description, failingResponse) => { + fetchMock.post( + "/graphql", + () => new Promise((resolve) => resolve({ body: failingResponse })), + { repeat: 1 } + ); + fetchMock.post( + "/graphql", + () => new Promise((resolve) => resolve({ body: response })), + { repeat: 1 } + ); + + const hashRefs: WeakRef[] = []; + function hash(query: string) { + const newHash = new String(query); + hashRefs.push(new WeakRef(newHash)); + return newHash as string; + } + const persistedLink = createPersistedQuery({ sha256: hash }); + await new Promise((complete) => + execute(persistedLink.concat(createHttpLink()), { + query, + variables, + }).subscribe({ complete }) + ); + + await expect(hashRefs[0]).toBeGarbageCollected(); + } + ); + itAsync("works with multiple errors", (resolve, reject) => { fetchMock.post( "/graphql", diff --git a/src/link/persisted-queries/index.ts b/src/link/persisted-queries/index.ts index b2a8c97fbce..50a2aa5ca7e 100644 --- a/src/link/persisted-queries/index.ts +++ b/src/link/persisted-queries/index.ts @@ -12,6 +12,7 @@ import type { import { Observable, compact, isNonEmptyArray } from "../../utilities/index.js"; import type { NetworkError } from "../../errors/index.js"; import type { ServerError } from "../utils/index.js"; +import { WeakCache } from "@wry/caches"; export const VERSION = 1; @@ -93,7 +94,10 @@ function operationDefinesMutation(operation: Operation) { export const createPersistedQueryLink = ( options: PersistedQueryLink.Options ) => { - const hashesByQuery = new WeakMap>(); + let hashesByQuery: WeakCache> | undefined; + function resetHashCache() { + hashesByQuery = undefined; + } // Ensure a SHA-256 hash function is provided, if a custom hash // generation function is not provided. We don't supply a SHA-256 hash // function by default, to avoid forcing one as a dependency. Developers @@ -135,150 +139,161 @@ export const createPersistedQueryLink = ( // what to do with the bogus query. return getHashPromise(query); } + if (!hashesByQuery) { + hashesByQuery = + new WeakCache(/** TODO: decide on a maximum size (will do all max sizes in a combined separate PR) */); + } let hash = hashesByQuery.get(query)!; if (!hash) hashesByQuery.set(query, (hash = getHashPromise(query))); return hash; } - return new ApolloLink((operation, forward) => { - invariant( - forward, - "PersistedQueryLink cannot be the last link in the chain." - ); - - const { query } = operation; - - return new Observable((observer: Observer) => { - let subscription: ObservableSubscription; - let retried = false; - let originalFetchOptions: any; - let setFetchOptions = false; - const maybeRetry = ( - { - response, - networkError, - }: { response?: ExecutionResult; networkError?: ServerError }, - cb: () => void - ) => { - if (!retried && ((response && response.errors) || networkError)) { - retried = true; - - const graphQLErrors: GraphQLError[] = []; - - const responseErrors = response && response.errors; - if (isNonEmptyArray(responseErrors)) { - graphQLErrors.push(...responseErrors); - } - - // Network errors can return GraphQL errors on for example a 403 - let networkErrors; - if (typeof networkError?.result !== "string") { - networkErrors = - networkError && - networkError.result && - (networkError.result.errors as GraphQLError[]); - } - if (isNonEmptyArray(networkErrors)) { - graphQLErrors.push(...networkErrors); - } - - const disablePayload: ErrorResponse = { + return Object.assign( + new ApolloLink((operation, forward) => { + invariant( + forward, + "PersistedQueryLink cannot be the last link in the chain." + ); + + const { query } = operation; + + return new Observable((observer: Observer) => { + let subscription: ObservableSubscription; + let retried = false; + let originalFetchOptions: any; + let setFetchOptions = false; + const maybeRetry = ( + { response, networkError, - operation, - graphQLErrors: isNonEmptyArray(graphQLErrors) - ? graphQLErrors - : void 0, - meta: processErrors(graphQLErrors), - }; - - // if the server doesn't support persisted queries, don't try anymore - supportsPersistedQueries = !disable(disablePayload); - - // if its not found, we can try it again, otherwise just report the error - if (retry(disablePayload)) { - // need to recall the link chain - if (subscription) subscription.unsubscribe(); - // actually send the query this time - operation.setContext({ - http: { - includeQuery: true, - includeExtensions: supportsPersistedQueries, - }, - fetchOptions: { - // Since we're including the full query, which may be - // large, we should send it in the body of a POST request. - // See issue #7456. - method: "POST", - }, - }); - if (setFetchOptions) { - operation.setContext({ fetchOptions: originalFetchOptions }); + }: { response?: ExecutionResult; networkError?: ServerError }, + cb: () => void + ) => { + if (!retried && ((response && response.errors) || networkError)) { + retried = true; + + const graphQLErrors: GraphQLError[] = []; + + const responseErrors = response && response.errors; + if (isNonEmptyArray(responseErrors)) { + graphQLErrors.push(...responseErrors); } - subscription = forward(operation).subscribe(handler); - return; - } - } - cb(); - }; - const handler = { - next: (response: ExecutionResult) => { - maybeRetry({ response }, () => observer.next!(response)); - }, - error: (networkError: ServerError) => { - maybeRetry({ networkError }, () => observer.error!(networkError)); - }, - complete: observer.complete!.bind(observer), - }; - - // don't send the query the first time - operation.setContext({ - http: { - includeQuery: !supportsPersistedQueries, - includeExtensions: supportsPersistedQueries, - }, - }); + // Network errors can return GraphQL errors on for example a 403 + let networkErrors; + if (typeof networkError?.result !== "string") { + networkErrors = + networkError && + networkError.result && + (networkError.result.errors as GraphQLError[]); + } + if (isNonEmptyArray(networkErrors)) { + graphQLErrors.push(...networkErrors); + } - // If requested, set method to GET if there are no mutations. Remember the - // original fetchOptions so we can restore them if we fall back to a - // non-hashed request. - if ( - useGETForHashedQueries && - supportsPersistedQueries && - !operationDefinesMutation(operation) - ) { - operation.setContext( - ({ fetchOptions = {} }: { fetchOptions: Record }) => { - originalFetchOptions = fetchOptions; - return { - fetchOptions: { - ...fetchOptions, - method: "GET", - }, + const disablePayload: ErrorResponse = { + response, + networkError, + operation, + graphQLErrors: isNonEmptyArray(graphQLErrors) + ? graphQLErrors + : void 0, + meta: processErrors(graphQLErrors), }; + + // if the server doesn't support persisted queries, don't try anymore + supportsPersistedQueries = !disable(disablePayload); + if (!supportsPersistedQueries) { + // clear hashes from cache, we don't need them anymore + resetHashCache(); + } + + // if its not found, we can try it again, otherwise just report the error + if (retry(disablePayload)) { + // need to recall the link chain + if (subscription) subscription.unsubscribe(); + // actually send the query this time + operation.setContext({ + http: { + includeQuery: true, + includeExtensions: supportsPersistedQueries, + }, + fetchOptions: { + // Since we're including the full query, which may be + // large, we should send it in the body of a POST request. + // See issue #7456. + method: "POST", + }, + }); + if (setFetchOptions) { + operation.setContext({ fetchOptions: originalFetchOptions }); + } + subscription = forward(operation).subscribe(handler); + + return; + } } - ); - setFetchOptions = true; - } - - if (supportsPersistedQueries) { - getQueryHash(query) - .then((sha256Hash) => { - operation.extensions.persistedQuery = { - version: VERSION, - sha256Hash, - }; - subscription = forward(operation).subscribe(handler); - }) - .catch(observer.error!.bind(observer)); - } else { - subscription = forward(operation).subscribe(handler); - } - - return () => { - if (subscription) subscription.unsubscribe(); - }; - }); - }); + cb(); + }; + const handler = { + next: (response: ExecutionResult) => { + maybeRetry({ response }, () => observer.next!(response)); + }, + error: (networkError: ServerError) => { + maybeRetry({ networkError }, () => observer.error!(networkError)); + }, + complete: observer.complete!.bind(observer), + }; + + // don't send the query the first time + operation.setContext({ + http: { + includeQuery: !supportsPersistedQueries, + includeExtensions: supportsPersistedQueries, + }, + }); + + // If requested, set method to GET if there are no mutations. Remember the + // original fetchOptions so we can restore them if we fall back to a + // non-hashed request. + if ( + useGETForHashedQueries && + supportsPersistedQueries && + !operationDefinesMutation(operation) + ) { + operation.setContext( + ({ fetchOptions = {} }: { fetchOptions: Record }) => { + originalFetchOptions = fetchOptions; + return { + fetchOptions: { + ...fetchOptions, + method: "GET", + }, + }; + } + ); + setFetchOptions = true; + } + + if (supportsPersistedQueries) { + getQueryHash(query) + .then((sha256Hash) => { + operation.extensions.persistedQuery = { + version: VERSION, + sha256Hash, + }; + subscription = forward(operation).subscribe(handler); + }) + .catch(observer.error!.bind(observer)); + } else { + subscription = forward(operation).subscribe(handler); + } + + return () => { + if (subscription) subscription.unsubscribe(); + }; + }); + }), + { resetHashCache } + ); }; From a117bd0cc780d5c61878b67a589ff971b856c0bb Mon Sep 17 00:00:00 2001 From: Lenz Weber-Tronic Date: Fri, 17 Nov 2023 14:46:32 +0100 Subject: [PATCH 05/62] re-add accidentally removed dependency --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 5f7353d178c..24daea70d79 100644 --- a/package.json +++ b/package.json @@ -89,6 +89,7 @@ }, "dependencies": { "@graphql-typed-document-node/core": "^3.1.1", + "@wry/caches": "^1.0.0", "@wry/context": "^0.7.3", "@wry/equality": "^0.5.6", "@wry/trie": "^0.4.3", From 0a1b7187c0c67fa8448af454058c32aa3e28fdb0 Mon Sep 17 00:00:00 2001 From: Lenz Weber-Tronic Date: Fri, 17 Nov 2023 15:00:29 +0100 Subject: [PATCH 06/62] update api --- .api-reports/api-report-link_persisted-queries.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.api-reports/api-report-link_persisted-queries.md b/.api-reports/api-report-link_persisted-queries.md index 84c87032e4c..353d48364e6 100644 --- a/.api-reports/api-report-link_persisted-queries.md +++ b/.api-reports/api-report-link_persisted-queries.md @@ -58,7 +58,7 @@ interface BaseOptions { // // @public (undocumented) export const createPersistedQueryLink: (options: PersistedQueryLink.Options) => ApolloLink & { - resetCache: () => void; + resetHashCache: () => void; }; // @public (undocumented) From bd40e8e4f16b6ae69249d41c539eb16bfa72794c Mon Sep 17 00:00:00 2001 From: Lenz Weber-Tronic Date: Fri, 17 Nov 2023 15:48:22 +0100 Subject: [PATCH 07/62] update size limit --- .size-limits.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.size-limits.json b/.size-limits.json index f71b98fe37c..8a945778178 100644 --- a/.size-limits.json +++ b/.size-limits.json @@ -1,4 +1,4 @@ { - "dist/apollo-client.min.cjs": 37975, - "import { ApolloClient, InMemoryCache, HttpLink } from \"dist/index.js\" (production)": 32019 + "dist/apollo-client.min.cjs": 38178, + "import { ApolloClient, InMemoryCache, HttpLink } from \"dist/index.js\" (production)": 32206 } From f84da806411314c19a9fda8d76bf1e9bd46833c1 Mon Sep 17 00:00:00 2001 From: Lenz Weber-Tronic Date: Fri, 17 Nov 2023 15:56:17 +0100 Subject: [PATCH 08/62] size-limit --- .size-limits.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.size-limits.json b/.size-limits.json index 52108cf4fb9..8a945778178 100644 --- a/.size-limits.json +++ b/.size-limits.json @@ -1,4 +1,4 @@ { - "dist/apollo-client.min.cjs": 38164, - "import { ApolloClient, InMemoryCache, HttpLink } from \"dist/index.js\" (production)": 32188 + "dist/apollo-client.min.cjs": 38178, + "import { ApolloClient, InMemoryCache, HttpLink } from \"dist/index.js\" (production)": 32206 } From 6ad8e56a7b04ae5f7823d20ddaf92d3835f742b4 Mon Sep 17 00:00:00 2001 From: Lenz Weber-Tronic Date: Wed, 29 Nov 2023 14:44:47 +0100 Subject: [PATCH 09/62] fix test failure --- .../persisted-queries/__tests__/persisted-queries.test.ts | 2 +- src/link/persisted-queries/__tests__/react.test.tsx | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/link/persisted-queries/__tests__/persisted-queries.test.ts b/src/link/persisted-queries/__tests__/persisted-queries.test.ts index bb3b8cb8c44..32d75fe5136 100644 --- a/src/link/persisted-queries/__tests__/persisted-queries.test.ts +++ b/src/link/persisted-queries/__tests__/persisted-queries.test.ts @@ -66,7 +66,7 @@ const giveUpResponse = JSON.stringify({ errors: giveUpErrors }); const giveUpResponseWithCode = JSON.stringify({ errors: giveUpErrorsWithCode }); const multiResponse = JSON.stringify({ errors: multipleErrors }); -export function sha256(data: string) { +function sha256(data: string) { const hash = crypto.createHash("sha256"); hash.update(data); return hash.digest("hex"); diff --git a/src/link/persisted-queries/__tests__/react.test.tsx b/src/link/persisted-queries/__tests__/react.test.tsx index 07c3fe7375e..b05e7d98f32 100644 --- a/src/link/persisted-queries/__tests__/react.test.tsx +++ b/src/link/persisted-queries/__tests__/react.test.tsx @@ -4,6 +4,7 @@ import * as ReactDOM from "react-dom/server"; import gql from "graphql-tag"; import { print } from "graphql"; import fetchMock from "fetch-mock"; +import crypto from "crypto"; import { ApolloProvider } from "../../../react/context"; import { InMemoryCache as Cache } from "../../../cache/inmemory/inMemoryCache"; @@ -12,7 +13,12 @@ import { createHttpLink } from "../../http/createHttpLink"; import { graphql } from "../../../react/hoc/graphql"; import { getDataFromTree } from "../../../react/ssr/getDataFromTree"; import { createPersistedQueryLink as createPersistedQuery, VERSION } from ".."; -import { sha256 } from "./persisted-queries.test"; + +function sha256(data: string) { + const hash = crypto.createHash("sha256"); + hash.update(data); + return hash.digest("hex"); +} // Necessary configuration in order to mock multiple requests // to a single (/graphql) endpoint From 7cbf8dc77a2243ec17d96d35e5d4f7bbe6c7b9c5 Mon Sep 17 00:00:00 2001 From: Lenz Weber-Tronic Date: Wed, 29 Nov 2023 14:45:16 +0100 Subject: [PATCH 10/62] better cleanup of interval/timeout --- src/testing/matchers/toBeGarbageCollected.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/testing/matchers/toBeGarbageCollected.ts b/src/testing/matchers/toBeGarbageCollected.ts index baa9c59128b..4dee2956121 100644 --- a/src/testing/matchers/toBeGarbageCollected.ts +++ b/src/testing/matchers/toBeGarbageCollected.ts @@ -19,10 +19,13 @@ export const toBeGarbageCollected: MatcherFunction<[weakRef: WeakRef]> = let pass = false; let interval: NodeJS.Timeout | undefined; + let timeout: NodeJS.Timeout | undefined; await Promise.race([ - new Promise((resolve) => setTimeout(resolve, 1000)), new Promise((resolve) => { - setInterval(() => { + timeout = setTimeout(resolve, 1000); + }), + new Promise((resolve) => { + interval = setInterval(() => { global.gc!(); pass = actual.deref() === undefined; if (pass) { @@ -30,7 +33,10 @@ export const toBeGarbageCollected: MatcherFunction<[weakRef: WeakRef]> = } }, 1); }), - ]).finally(() => clearInterval(interval)); + ]); + + clearInterval(interval); + clearTimeout(timeout); return { pass, From 0521529f22e262ce42f1497a93c968678e3f6ee8 Mon Sep 17 00:00:00 2001 From: Lenz Weber-Tronic Date: Mon, 4 Dec 2023 10:34:50 +0100 Subject: [PATCH 11/62] apply formatting --- src/link/persisted-queries/index.ts | 5 ++-- src/testing/matchers/index.d.ts | 45 ++++++++++++++--------------- 2 files changed, 23 insertions(+), 27 deletions(-) diff --git a/src/link/persisted-queries/index.ts b/src/link/persisted-queries/index.ts index 50a2aa5ca7e..95c4129c802 100644 --- a/src/link/persisted-queries/index.ts +++ b/src/link/persisted-queries/index.ts @@ -195,9 +195,8 @@ export const createPersistedQueryLink = ( response, networkError, operation, - graphQLErrors: isNonEmptyArray(graphQLErrors) - ? graphQLErrors - : void 0, + graphQLErrors: + isNonEmptyArray(graphQLErrors) ? graphQLErrors : void 0, meta: processErrors(graphQLErrors), }; diff --git a/src/testing/matchers/index.d.ts b/src/testing/matchers/index.d.ts index d933163abee..6936be4804c 100644 --- a/src/testing/matchers/index.d.ts +++ b/src/testing/matchers/index.d.ts @@ -25,33 +25,30 @@ interface ApolloCustomMatchers { /** * Used to determine if the Suspense cache has a cache entry. */ - toHaveSuspenseCacheEntryUsing: T extends ApolloClient - ? ( - query: DocumentNode, - options?: { - variables?: OperationVariables; - queryKey?: string | number | any[]; - } - ) => R - : { error: "matcher needs to be called on an ApolloClient instance" }; + toHaveSuspenseCacheEntryUsing: T extends ApolloClient ? + ( + query: DocumentNode, + options?: { + variables?: OperationVariables; + queryKey?: string | number | any[]; + } + ) => R + : { error: "matcher needs to be called on an ApolloClient instance" }; - toRerender: T extends - | Profiler - | ProfiledComponent - | ProfiledHook - ? (options?: NextRenderOptions) => Promise - : { error: "matcher needs to be called on a ProfiledComponent instance" }; + toRerender: T extends ( + Profiler | ProfiledComponent | ProfiledHook + ) ? + (options?: NextRenderOptions) => Promise + : { error: "matcher needs to be called on a ProfiledComponent instance" }; - toRenderExactlyTimes: T extends - | Profiler - | ProfiledComponent - | ProfiledHook - ? (count: number, options?: NextRenderOptions) => Promise - : { error: "matcher needs to be called on a ProfiledComponent instance" }; + toRenderExactlyTimes: T extends ( + Profiler | ProfiledComponent | ProfiledHook + ) ? + (count: number, options?: NextRenderOptions) => Promise + : { error: "matcher needs to be called on a ProfiledComponent instance" }; - toBeGarbageCollected: T extends WeakRef - ? () => Promise - : { error: "matcher needs to be called on a WeakRef instance" }; + toBeGarbageCollected: T extends WeakRef ? () => Promise + : { error: "matcher needs to be called on a WeakRef instance" }; } declare global { From 188dd0ae17f406cf9d95a86550fdcee38881facd Mon Sep 17 00:00:00 2001 From: Lenz Weber-Tronic Date: Mon, 4 Dec 2023 10:35:53 +0100 Subject: [PATCH 12/62] remove unneccessary type --- src/testing/matchers/index.d.ts | 50 ++++++++++++++++----------------- 1 file changed, 24 insertions(+), 26 deletions(-) diff --git a/src/testing/matchers/index.d.ts b/src/testing/matchers/index.d.ts index 6936be4804c..65b10ba4fc8 100644 --- a/src/testing/matchers/index.d.ts +++ b/src/testing/matchers/index.d.ts @@ -10,11 +10,6 @@ import { ProfiledHook, } from "../internal/index.js"; -declare class WeakRef { - constructor(target: T); - deref(): T | undefined; -} - interface ApolloCustomMatchers { /** * Used to determine if two GraphQL query documents are equal to each other by @@ -25,30 +20,33 @@ interface ApolloCustomMatchers { /** * Used to determine if the Suspense cache has a cache entry. */ - toHaveSuspenseCacheEntryUsing: T extends ApolloClient ? - ( - query: DocumentNode, - options?: { - variables?: OperationVariables; - queryKey?: string | number | any[]; - } - ) => R - : { error: "matcher needs to be called on an ApolloClient instance" }; + toHaveSuspenseCacheEntryUsing: T extends ApolloClient + ? ( + query: DocumentNode, + options?: { + variables?: OperationVariables; + queryKey?: string | number | any[]; + } + ) => R + : { error: "matcher needs to be called on an ApolloClient instance" }; - toRerender: T extends ( - Profiler | ProfiledComponent | ProfiledHook - ) ? - (options?: NextRenderOptions) => Promise - : { error: "matcher needs to be called on a ProfiledComponent instance" }; + toRerender: T extends + | Profiler + | ProfiledComponent + | ProfiledHook + ? (options?: NextRenderOptions) => Promise + : { error: "matcher needs to be called on a ProfiledComponent instance" }; - toRenderExactlyTimes: T extends ( - Profiler | ProfiledComponent | ProfiledHook - ) ? - (count: number, options?: NextRenderOptions) => Promise - : { error: "matcher needs to be called on a ProfiledComponent instance" }; + toRenderExactlyTimes: T extends + | Profiler + | ProfiledComponent + | ProfiledHook + ? (count: number, options?: NextRenderOptions) => Promise + : { error: "matcher needs to be called on a ProfiledComponent instance" }; - toBeGarbageCollected: T extends WeakRef ? () => Promise - : { error: "matcher needs to be called on a WeakRef instance" }; + toBeGarbageCollected: T extends WeakRef + ? () => Promise + : { error: "matcher needs to be called on a WeakRef instance" }; } declare global { From 4283908f5de8971bba1b41f973a354222cb88513 Mon Sep 17 00:00:00 2001 From: Lenz Weber-Tronic Date: Mon, 4 Dec 2023 10:36:42 +0100 Subject: [PATCH 13/62] format again after updating prettier --- src/testing/matchers/index.d.ts | 45 +++++++++++++++------------------ 1 file changed, 21 insertions(+), 24 deletions(-) diff --git a/src/testing/matchers/index.d.ts b/src/testing/matchers/index.d.ts index 65b10ba4fc8..690589af128 100644 --- a/src/testing/matchers/index.d.ts +++ b/src/testing/matchers/index.d.ts @@ -20,33 +20,30 @@ interface ApolloCustomMatchers { /** * Used to determine if the Suspense cache has a cache entry. */ - toHaveSuspenseCacheEntryUsing: T extends ApolloClient - ? ( - query: DocumentNode, - options?: { - variables?: OperationVariables; - queryKey?: string | number | any[]; - } - ) => R - : { error: "matcher needs to be called on an ApolloClient instance" }; + toHaveSuspenseCacheEntryUsing: T extends ApolloClient ? + ( + query: DocumentNode, + options?: { + variables?: OperationVariables; + queryKey?: string | number | any[]; + } + ) => R + : { error: "matcher needs to be called on an ApolloClient instance" }; - toRerender: T extends - | Profiler - | ProfiledComponent - | ProfiledHook - ? (options?: NextRenderOptions) => Promise - : { error: "matcher needs to be called on a ProfiledComponent instance" }; + toRerender: T extends ( + Profiler | ProfiledComponent | ProfiledHook + ) ? + (options?: NextRenderOptions) => Promise + : { error: "matcher needs to be called on a ProfiledComponent instance" }; - toRenderExactlyTimes: T extends - | Profiler - | ProfiledComponent - | ProfiledHook - ? (count: number, options?: NextRenderOptions) => Promise - : { error: "matcher needs to be called on a ProfiledComponent instance" }; + toRenderExactlyTimes: T extends ( + Profiler | ProfiledComponent | ProfiledHook + ) ? + (count: number, options?: NextRenderOptions) => Promise + : { error: "matcher needs to be called on a ProfiledComponent instance" }; - toBeGarbageCollected: T extends WeakRef - ? () => Promise - : { error: "matcher needs to be called on a WeakRef instance" }; + toBeGarbageCollected: T extends WeakRef ? () => Promise + : { error: "matcher needs to be called on a WeakRef instance" }; } declare global { From 9d3bd6804847aa71e1003f214b42ead0828ce6ef Mon Sep 17 00:00:00 2001 From: Lenz Weber-Tronic Date: Mon, 4 Dec 2023 13:08:02 +0100 Subject: [PATCH 14/62] add central confiuguration for Apollo Client cache sizes --- src/cache/inmemory/fragmentRegistry.ts | 19 +- src/core/QueryManager.ts | 6 +- src/link/persisted-queries/index.ts | 7 +- src/react/parser/index.ts | 7 +- src/utilities/caching/caches.ts | 47 +++++ src/utilities/caching/index.ts | 2 + src/utilities/caching/sizes.ts | 193 +++++++++++++++++++++ src/utilities/common/canonicalStringify.ts | 7 +- src/utilities/graphql/DocumentTransform.ts | 3 +- src/utilities/graphql/print.ts | 9 +- src/utilities/index.ts | 6 + 11 files changed, 283 insertions(+), 23 deletions(-) create mode 100644 src/utilities/caching/caches.ts create mode 100644 src/utilities/caching/index.ts create mode 100644 src/utilities/caching/sizes.ts diff --git a/src/cache/inmemory/fragmentRegistry.ts b/src/cache/inmemory/fragmentRegistry.ts index 12cade01aea..47e434bee75 100644 --- a/src/cache/inmemory/fragmentRegistry.ts +++ b/src/cache/inmemory/fragmentRegistry.ts @@ -9,7 +9,8 @@ import { visit } from "graphql"; import { wrap } from "optimism"; import type { FragmentMap } from "../../utilities/index.js"; -import { getFragmentDefinitions } from "../../utilities/index.js"; +import { cacheSizes, getFragmentDefinitions } from "../../utilities/index.js"; +import { WeakCache } from "@wry/caches"; export interface FragmentRegistryAPI { register(...fragments: DocumentNode[]): this; @@ -68,11 +69,23 @@ class FragmentRegistry implements FragmentRegistryAPI { const proto = FragmentRegistry.prototype; this.invalidate = (this.lookup = wrap(proto.lookup.bind(this), { makeCacheKey: (arg) => arg, + max: cacheSizes.fragmentRegistryLookup, })).dirty; // This dirty function is bound to the wrapped lookup method. - this.transform = wrap(proto.transform.bind(this)); - this.findFragmentSpreads = wrap(proto.findFragmentSpreads.bind(this)); + this.transform = wrap(proto.transform.bind(this), { + cache: WeakCache, + max: cacheSizes.fragmentRegistryTransform, + }); + this.findFragmentSpreads = wrap(proto.findFragmentSpreads.bind(this), { + cache: WeakCache, + max: cacheSizes.fragmentRegistryFindFragmentSpreads, + }); } + /* + * Note: + * This method is only memoized so it can serve a a dependency to `tranform`, + * so calling `invalidate` will invalidate cache entries for `transform`. + */ public lookup(fragmentName: string): FragmentDefinitionNode | null { return this.registry[fragmentName] || null; } diff --git a/src/core/QueryManager.ts b/src/core/QueryManager.ts index 84e01b89023..8af3412db60 100644 --- a/src/core/QueryManager.ts +++ b/src/core/QueryManager.ts @@ -4,7 +4,6 @@ import type { DocumentNode } from "graphql"; // TODO(brian): A hack until this issue is resolved (https://github.com/graphql/graphql-js/issues/3356) type OperationTypeNode = any; import { equal } from "@wry/equality"; -import { WeakCache } from "@wry/caches"; import type { ApolloLink, FetchResult } from "../link/core/index.js"; import { execute } from "../link/core/index.js"; @@ -100,6 +99,7 @@ interface TransformCacheEntry { import type { DefaultOptions } from "./ApolloClient.js"; import { Trie } from "@wry/trie"; +import { CleanWeakCache, cacheSizes } from "../utilities/index.js"; export class QueryManager { public cache: ApolloCache; @@ -662,10 +662,10 @@ export class QueryManager { return this.documentTransform.transformDocument(document); } - private transformCache = new WeakCache< + private transformCache = new CleanWeakCache< DocumentNode, TransformCacheEntry - >(/** TODO: decide on a maximum size (will do all max sizes in a combined separate PR) */); + >(cacheSizes.queryManagerTransforms); public getDocumentInfo(document: DocumentNode) { const { transformCache } = this; diff --git a/src/link/persisted-queries/index.ts b/src/link/persisted-queries/index.ts index 95c4129c802..2514df5fc4b 100644 --- a/src/link/persisted-queries/index.ts +++ b/src/link/persisted-queries/index.ts @@ -12,7 +12,7 @@ import type { import { Observable, compact, isNonEmptyArray } from "../../utilities/index.js"; import type { NetworkError } from "../../errors/index.js"; import type { ServerError } from "../utils/index.js"; -import { WeakCache } from "@wry/caches"; +import { cacheSizes, CleanWeakCache } from "../../utilities/index.js"; export const VERSION = 1; @@ -94,7 +94,7 @@ function operationDefinesMutation(operation: Operation) { export const createPersistedQueryLink = ( options: PersistedQueryLink.Options ) => { - let hashesByQuery: WeakCache> | undefined; + let hashesByQuery: CleanWeakCache> | undefined; function resetHashCache() { hashesByQuery = undefined; } @@ -140,8 +140,7 @@ export const createPersistedQueryLink = ( return getHashPromise(query); } if (!hashesByQuery) { - hashesByQuery = - new WeakCache(/** TODO: decide on a maximum size (will do all max sizes in a combined separate PR) */); + hashesByQuery = new CleanWeakCache(cacheSizes.persistedQueryHashes); } let hash = hashesByQuery.get(query)!; if (!hash) hashesByQuery.set(query, (hash = getHashPromise(query))); diff --git a/src/react/parser/index.ts b/src/react/parser/index.ts index 3c5dc3abc8d..9aed9eeb05c 100644 --- a/src/react/parser/index.ts +++ b/src/react/parser/index.ts @@ -1,4 +1,3 @@ -import { WeakCache } from "@wry/caches"; import { invariant } from "../../utilities/globals/index.js"; import type { @@ -7,6 +6,7 @@ import type { VariableDefinitionNode, OperationDefinitionNode, } from "graphql"; +import { CleanWeakCache, cacheSizes } from "../../utilities/index.js"; export enum DocumentType { Query, @@ -22,7 +22,7 @@ export interface IDocumentDefinition { let cache: | undefined - | WeakCache< + | CleanWeakCache< DocumentNode, { name: string; @@ -50,8 +50,7 @@ export function operationName(type: DocumentType) { // This parser is mostly used to safety check incoming documents. export function parser(document: DocumentNode): IDocumentDefinition { if (!cache) { - cache = - new WeakCache(/** TODO: decide on a maximum size (will do all max sizes in a combined separate PR) */); + cache = new CleanWeakCache(cacheSizes.parser); } const cached = cache.get(document); if (cached) return cached; diff --git a/src/utilities/caching/caches.ts b/src/utilities/caching/caches.ts new file mode 100644 index 00000000000..808768fc959 --- /dev/null +++ b/src/utilities/caching/caches.ts @@ -0,0 +1,47 @@ +import type { CommonCache } from "@wry/caches"; +import { WeakCache, StrongCache } from "@wry/caches"; + +const scheduledCleanup = new WeakSet>(); +function schedule(cache: CommonCache) { + if (!scheduledCleanup.has(cache)) { + scheduledCleanup.add(cache); + setTimeout(() => { + cache.clean(); + scheduledCleanup.delete(cache); + }, 1000); + } +} +/** + * A version of WeakCache that will auto-schedule a cleanup of the cache when + * a new item is added. + * Throttled to once per second. + * + * @privateRemarks + * Should be used throughout the rest of the codebase instead of WeakCache, + * with the notable exception of usage in `wrap` from `optimism` - that one + * already handles cleanup and should remain a `WeakCache`. + */ + +export class CleanWeakCache extends WeakCache { + set(key: K, value: V) { + schedule(this); + return super.set(key, value); + } +} +/** + * A version of StrongCache that will auto-schedule a cleanup of the cache when + * a new item is added. + * Throttled to once per second. + * + * @privateRemarks + * Should be used throughout the rest of the codebase instead of StrongCache, + * with the notable exception of usage in `wrap` from `optimism` - that one + * already handles cleanup and should remain a `StrongCache`. + */ + +export class CleanStrongCache extends StrongCache { + set(key: K, value: V) { + schedule(this); + return super.set(key, value); + } +} diff --git a/src/utilities/caching/index.ts b/src/utilities/caching/index.ts new file mode 100644 index 00000000000..4fc49c5dbab --- /dev/null +++ b/src/utilities/caching/index.ts @@ -0,0 +1,2 @@ +export { CleanStrongCache, CleanWeakCache } from "./caches.js"; +export { cacheSizes } from "./sizes.js"; diff --git a/src/utilities/caching/sizes.ts b/src/utilities/caching/sizes.ts new file mode 100644 index 00000000000..b1501ad5622 --- /dev/null +++ b/src/utilities/caching/sizes.ts @@ -0,0 +1,193 @@ +import { global } from "../globals/index.js"; + +declare global { + interface Window { + [cacheSizeSymbol]?: Partial; + } +} + +/** + * The cache sizes used by various Apollo Client caches. + * + * Note that these caches are all derivative and if an item is cache-collected, + * it's not the end of the world - the cached item will just be recalculated. + * + * As a result, these cache sizes should not be chosen to hold every value ever + * encountered, but rather to hold a reasonable number of values that can be + * assumed to be on the screen at any given time. + * + * We assume a "base value" of 1000 here, which is already very generous. + * In most applications, it will be very unlikely that 1000 different queries + * are on screen at the same time. + */ +interface CacheSizes { + /** + * Cache size for the [`print`](../../utilities/graphql/print.ts) function. + * + * @defaultValue + * Defaults to `2000`. + * + * @remarks + * This method is called from the `QueryManager` and various `Link`s, + * always with the "serverQuery", so the server-facing part of a transformed + * DocumentNode. + */ + print: number; + /** + * Cache size for the [`parser`](../../react/parser/index.ts) function. + * + * @defaultValue + * Defaults to `1000`. + * + * @remarks + * This function is used directly in HOCs, and nowadays mainly accessed by + * calling `verifyDocumentType` from various hooks. + * It is called with a user-provided DocumentNode. + */ + parser: number; + /** + * Cache size for the `performWork` method of each [`DocumentTransform`](../../utilities/graphql/DocumentTransform.ts). + * + * @defaultValue + * Defaults to `2000`. + * + * @remarks + * This method is called from `transformDocument`, which is called from + * `QueryManager` with a user-provided DocumentNode. + * It is also called with already-transformed DocumentNodes, assuming the + * user provided additional transforms. + * + * The cache size here should be chosen with other DocumentTransforms in mind. + * For example, if there was a DocumentTransform that would take `n` DocumentNodes, + * and returned a differently-transformed DocumentNode depending if the app is + * online or offline, then we assume that the cache returns `2*n` documents. + * + * No user-provided DocumentNode will actually be "the last one", as we run the + * `defaultDocumentTransform` before *and* after the user-provided transforms. + * + * So if we assume that the user-provided transforms receive `n` documents and + * return `n` documents, the cache size should be `2*n`. + * + * If we assume that the user-provided transforms receive `n` documents and + * returns `2*n` documents, the cache size should be `3*n`. + * + * This size should also then be used in every other cache that mentions that + * it operates on a "transformed" DocumentNode. + */ + documentTransform: number; + /** + * Cache size for the `transformCache` used in the `getDocumentInfo` method of + * [`QueryManager`](../../core/QueryManager.ts). + * + * @defaultValue + * Defaults to `2000`. + * + * @remarks + * `getDocumentInfo` is called throughout the `QueryManager` with transformed + * DocumentNodes. + */ + queryManagerTransforms: number; + /** + * Cache size for the `hashesByQuery` cache in the [`PersistedQueryLink`](../../link/persisted-queries/index.ts). + * + * @defaultValue + * Defaults to `2000`. + * + * @remarks + * This cache is used to cache the hashes of persisted queries. It is working with + * transformed DocumentNodes. + */ + persistedQueryHashes: number; + /** + * Cache for the `sortingMap` used by [`canonicalStringify`](../../utilities/common/canonicalStringify.ts). + * + * @defaultValue + * Defaults to `1000`. + * + * @remarks + * This cache contains the sorted keys of objects that are stringified by + * `canonicalStringify`. + * It uses the stringified unsorted keys of objects as keys. + * The cache will not grow beyond the size of different object **shapes** + * encountered in an application, no matter how much actual data gets stringified. + */ + canonicalStringify: number; + /** + * Cache size for the `transform` method of [`FragmentRegistry`](../../cache/inmemory/fragmentRegistry.ts). + * + * @defaultValue + * Defaults to `2000`. + * + * @remarks + * This function is called as part of the `defaultDocumentTransform` which will be called with + * user-provided and already-transformed DocumentNodes. + * + */ + fragmentRegistryTransform: number; + /** + * Cache size for the `lookup` method of [`FragmentRegistry`](../../cache/inmemory/fragmentRegistry.ts). + * + * @defaultValue + * Defaults to `1000`. + * + * @remarks + * This function is called with fragment names in the form of a string. + * + * Note: + * This function is a dependency of `transform`, so having a too small cache size here + * might involuntarily invalidate values in the `transform` cache. + */ + fragmentRegistryLookup: number; + /** + * Cache size for the `findFragmentSpreads` method of [`FragmentRegistry`](../../cache/inmemory/fragmentRegistry.ts). + * + * @defaultValue + * Defaults to `4000`. + * + * @remarks + * This function is called with transformed DocumentNodes, as well as recursively + * with every fragment spread referenced within that, or a fragment referenced by a + * fragment spread. + * + * Note: + * This function is a dependency of `transform`, so having a too small cache size here + * might involuntarily invalidate values in the `transform` cache. + */ + fragmentRegistryFindFragmentSpreads: number; +} + +const cacheSizeSymbol = Symbol.for("apollo.cacheSize"); +/** + * + * The global cache size configuration for Apollo Client. + * + * @remark + * + * You can directly modify this object, but any modification will + * only have an effect on caches that are created after the modification. + * + * So for global caches, such as `parser`, `canonicalStringify` and `print`, + * you might need to call `.reset` on them, which will essentially re-create them. + * + * Alternatively, you can set `globalThis[Symbol.for("apollo.cacheSize")]` before + * you load the Apollo Client package: + * + * @example + * ```ts + * globalThis[Symbol.for("apollo.cacheSize")] = { + * parser: 100 + * } + * ``` + */ +export const cacheSizes: CacheSizes = { + parser: 1000, + canonicalStringify: 1000, + print: 2000, + documentTransform: 2000, + queryManagerTransforms: 2000, + persistedQueryHashes: 2000, + fragmentRegistryTransform: 2000, + fragmentRegistryLookup: 1000, + fragmentRegistryFindFragmentSpreads: 4000, + ...global[cacheSizeSymbol], +}; diff --git a/src/utilities/common/canonicalStringify.ts b/src/utilities/common/canonicalStringify.ts index 021f23430e2..239ec8496aa 100644 --- a/src/utilities/common/canonicalStringify.ts +++ b/src/utilities/common/canonicalStringify.ts @@ -1,3 +1,5 @@ +import { CleanStrongCache } from "../../utilities/index.js"; + /** * Like JSON.stringify, but with object keys always sorted in the same order. * @@ -24,14 +26,15 @@ export const canonicalStringify = Object.assign( // Clearing the sortingMap will reclaim all cached memory, without // affecting the logical results of canonicalStringify, but potentially // sacrificing performance until the cache is refilled. - sortingMap.clear(); + sortingMap = new CleanStrongCache(); }, } ); // Values are JSON-serialized arrays of object keys (in any order), and values // are sorted arrays of the same keys. -const sortingMap = new Map(); +let sortingMap!: CleanStrongCache; +canonicalStringify.reset(); // The JSON.stringify function takes an optional second argument called a // replacer function. This function is called for each key-value pair in the diff --git a/src/utilities/graphql/DocumentTransform.ts b/src/utilities/graphql/DocumentTransform.ts index 7a5ce40fe4c..c32df389ddc 100644 --- a/src/utilities/graphql/DocumentTransform.ts +++ b/src/utilities/graphql/DocumentTransform.ts @@ -5,6 +5,7 @@ import { invariant } from "../globals/index.js"; import type { DocumentNode } from "graphql"; import { WeakCache } from "@wry/caches"; import { wrap } from "optimism"; +import { cacheSizes } from "../../utilities/index.js"; export type DocumentTransformCacheKey = ReadonlyArray; @@ -96,7 +97,7 @@ export class DocumentTransform { return stableCacheKeys.lookupArray(cacheKeys); } }, - max: 1000 /** TODO: decide on a maximum size (will do all max sizes in a combined separate PR) */, + max: cacheSizes.documentTransform, cache: WeakCache, } ); diff --git a/src/utilities/graphql/print.ts b/src/utilities/graphql/print.ts index 3ba1134c968..f8474aa00ec 100644 --- a/src/utilities/graphql/print.ts +++ b/src/utilities/graphql/print.ts @@ -1,8 +1,8 @@ import type { ASTNode } from "graphql"; import { print as origPrint } from "graphql"; -import { WeakCache } from "@wry/caches"; +import { CleanWeakCache, cacheSizes } from "../../utilities/index.js"; -let printCache!: WeakCache; +let printCache!: CleanWeakCache; export const print = Object.assign( (ast: ASTNode) => { let result = printCache.get(ast); @@ -15,10 +15,7 @@ export const print = Object.assign( }, { reset() { - printCache = new WeakCache< - ASTNode, - string - >(/** TODO: decide on a maximum size (will do all max sizes in a combined separate PR) */); + printCache = new CleanWeakCache(cacheSizes.print); }, } ); diff --git a/src/utilities/index.ts b/src/utilities/index.ts index 35c1ec45cad..541bd5693a9 100644 --- a/src/utilities/index.ts +++ b/src/utilities/index.ts @@ -131,3 +131,9 @@ export * from "./types/IsStrictlyAny.js"; export type { DeepOmit } from "./types/DeepOmit.js"; export type { DeepPartial } from "./types/DeepPartial.js"; export type { OnlyRequiredProperties } from "./types/OnlyRequiredProperties.js"; + +export { + CleanStrongCache, + CleanWeakCache, + cacheSizes, +} from "./caching/index.js"; From 825e0124f7d881ca45c17e58d24187faa5264ae5 Mon Sep 17 00:00:00 2001 From: Lenz Weber-Tronic Date: Mon, 4 Dec 2023 13:18:34 +0100 Subject: [PATCH 15/62] resolve import cycle --- src/utilities/caching/caches.ts | 6 ++++++ src/utilities/common/canonicalStringify.ts | 6 ++++-- src/utilities/graphql/print.ts | 2 +- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/utilities/caching/caches.ts b/src/utilities/caching/caches.ts index 808768fc959..648d92178ce 100644 --- a/src/utilities/caching/caches.ts +++ b/src/utilities/caching/caches.ts @@ -23,6 +23,9 @@ function schedule(cache: CommonCache) { */ export class CleanWeakCache extends WeakCache { + constructor(max: number, dispose?: (value: V) => void) { + super(max, dispose); + } set(key: K, value: V) { schedule(this); return super.set(key, value); @@ -40,6 +43,9 @@ export class CleanWeakCache extends WeakCache { */ export class CleanStrongCache extends StrongCache { + constructor(max: number, dispose?: (value: V) => void) { + super(max, dispose); + } set(key: K, value: V) { schedule(this); return super.set(key, value); diff --git a/src/utilities/common/canonicalStringify.ts b/src/utilities/common/canonicalStringify.ts index 239ec8496aa..8a550cdd400 100644 --- a/src/utilities/common/canonicalStringify.ts +++ b/src/utilities/common/canonicalStringify.ts @@ -1,4 +1,4 @@ -import { CleanStrongCache } from "../../utilities/index.js"; +import { CleanStrongCache, cacheSizes } from "../../utilities/caching/index.js"; /** * Like JSON.stringify, but with object keys always sorted in the same order. @@ -26,7 +26,9 @@ export const canonicalStringify = Object.assign( // Clearing the sortingMap will reclaim all cached memory, without // affecting the logical results of canonicalStringify, but potentially // sacrificing performance until the cache is refilled. - sortingMap = new CleanStrongCache(); + sortingMap = new CleanStrongCache( + cacheSizes.canonicalStringify + ); }, } ); diff --git a/src/utilities/graphql/print.ts b/src/utilities/graphql/print.ts index f8474aa00ec..4615f906271 100644 --- a/src/utilities/graphql/print.ts +++ b/src/utilities/graphql/print.ts @@ -1,6 +1,6 @@ import type { ASTNode } from "graphql"; import { print as origPrint } from "graphql"; -import { CleanWeakCache, cacheSizes } from "../../utilities/index.js"; +import { CleanWeakCache, cacheSizes } from "../caching/index.js"; let printCache!: CleanWeakCache; export const print = Object.assign( From 3762c5e968dec9fffc27e1ee322980dec7066db7 Mon Sep 17 00:00:00 2001 From: Lenz Weber-Tronic Date: Mon, 4 Dec 2023 15:17:00 +0100 Subject: [PATCH 16/62] add exports --- src/__tests__/__snapshots__/exports.ts.snap | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/__tests__/__snapshots__/exports.ts.snap b/src/__tests__/__snapshots__/exports.ts.snap index 70229c88a17..e98583155b8 100644 --- a/src/__tests__/__snapshots__/exports.ts.snap +++ b/src/__tests__/__snapshots__/exports.ts.snap @@ -383,6 +383,8 @@ Array [ exports[`exports of public entry points @apollo/client/utilities 1`] = ` Array [ + "CleanStrongCache", + "CleanWeakCache", "Concast", "DEV", "DeepMerger", @@ -392,6 +394,7 @@ Array [ "argumentsObjectFromField", "asyncMap", "buildQueryFromSelectionSet", + "cacheSizes", "canUseAsyncIteratorSymbol", "canUseDOM", "canUseLayoutEffect", From 554240c31f44e9f8b891bc359b81262aacf80853 Mon Sep 17 00:00:00 2001 From: Lenz Weber-Tronic Date: Mon, 4 Dec 2023 15:17:13 +0100 Subject: [PATCH 17/62] reduce cache collection throttle timeout --- src/utilities/caching/caches.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/utilities/caching/caches.ts b/src/utilities/caching/caches.ts index 648d92178ce..bbdd7a5baea 100644 --- a/src/utilities/caching/caches.ts +++ b/src/utilities/caching/caches.ts @@ -8,13 +8,13 @@ function schedule(cache: CommonCache) { setTimeout(() => { cache.clean(); scheduledCleanup.delete(cache); - }, 1000); + }, 100); } } /** * A version of WeakCache that will auto-schedule a cleanup of the cache when * a new item is added. - * Throttled to once per second. + * Throttled to once per 100ms. * * @privateRemarks * Should be used throughout the rest of the codebase instead of WeakCache, @@ -34,7 +34,7 @@ export class CleanWeakCache extends WeakCache { /** * A version of StrongCache that will auto-schedule a cleanup of the cache when * a new item is added. - * Throttled to once per second. + * Throttled to once per 100ms. * * @privateRemarks * Should be used throughout the rest of the codebase instead of StrongCache, From af8b16f156d5a17c74148af8d72627360dc8b6a0 Mon Sep 17 00:00:00 2001 From: Lenz Weber-Tronic Date: Mon, 4 Dec 2023 15:18:06 +0100 Subject: [PATCH 18/62] typo in comment --- src/cache/inmemory/fragmentRegistry.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cache/inmemory/fragmentRegistry.ts b/src/cache/inmemory/fragmentRegistry.ts index 47e434bee75..2dc6d0fef93 100644 --- a/src/cache/inmemory/fragmentRegistry.ts +++ b/src/cache/inmemory/fragmentRegistry.ts @@ -83,7 +83,7 @@ class FragmentRegistry implements FragmentRegistryAPI { /* * Note: - * This method is only memoized so it can serve a a dependency to `tranform`, + * This method is only memoized so it can serve as a dependency to `tranform`, * so calling `invalidate` will invalidate cache entries for `transform`. */ public lookup(fragmentName: string): FragmentDefinitionNode | null { From 6ce26135c4f27f18ad7ada8c93789b6dca4e4d47 Mon Sep 17 00:00:00 2001 From: Lenz Weber-Tronic Date: Mon, 4 Dec 2023 16:51:53 +0100 Subject: [PATCH 19/62] experimental `ApolloClient.getCacheStatus` helper --- src/core/ApolloClient.ts | 15 +++ src/link/core/ApolloLink.ts | 15 ++- src/link/persisted-queries/index.ts | 11 ++- src/react/parser/index.ts | 5 + src/utilities/caching/getCacheStatus.ts | 101 +++++++++++++++++++++ src/utilities/caching/sizes.ts | 2 +- src/utilities/common/canonicalStringify.ts | 5 + src/utilities/graphql/DocumentTransform.ts | 46 ++++++---- src/utilities/graphql/print.ts | 6 +- 9 files changed, 182 insertions(+), 24 deletions(-) create mode 100644 src/utilities/caching/getCacheStatus.ts diff --git a/src/core/ApolloClient.ts b/src/core/ApolloClient.ts index 050245e9d8b..81b25b6e5ec 100644 --- a/src/core/ApolloClient.ts +++ b/src/core/ApolloClient.ts @@ -122,6 +122,8 @@ export interface ApolloClientOptions { // @apollo/client/core. Since we need to preserve that API anyway, the easiest // solution is to reexport mergeOptions where it was previously declared (here). import { mergeOptions } from "../utilities/index.js"; +import type { GetCacheStatus } from "../utilities/caching/getCacheStatus.js"; +import { getCacheStatus } from "../utilities/caching/getCacheStatus.js"; export { mergeOptions }; /** @@ -746,4 +748,17 @@ export class ApolloClient implements DataProxy { public get defaultContext() { return this.queryManager.defaultContext; } + + /** + * @experimental + * @internal + * This is not a stable API - it is used in development builds to expose + * information to the DevTools. + * Use at your own risk! + */ + public getCacheStatus?: GetCacheStatus; +} + +if (__DEV__) { + ApolloClient.prototype.getCacheStatus = getCacheStatus; } diff --git a/src/link/core/ApolloLink.ts b/src/link/core/ApolloLink.ts index ca9d2cfcd72..a544b45f8cb 100644 --- a/src/link/core/ApolloLink.ts +++ b/src/link/core/ApolloLink.ts @@ -45,19 +45,21 @@ export class ApolloLink { const leftLink = toLink(left); const rightLink = toLink(right || new ApolloLink(passthrough)); + let ret: ApolloLink; if (isTerminating(leftLink) && isTerminating(rightLink)) { - return new ApolloLink((operation) => { + ret = new ApolloLink((operation) => { return test(operation) ? leftLink.request(operation) || Observable.of() : rightLink.request(operation) || Observable.of(); }); } else { - return new ApolloLink((operation, forward) => { + ret = new ApolloLink((operation, forward) => { return test(operation) ? leftLink.request(operation, forward) || Observable.of() : rightLink.request(operation, forward) || Observable.of(); }); } + return Object.assign(ret, { left: leftLink, right: rightLink }); } public static execute( @@ -88,8 +90,9 @@ export class ApolloLink { } const nextLink = toLink(second); + let ret: ApolloLink; if (isTerminating(nextLink)) { - return new ApolloLink( + ret = new ApolloLink( (operation) => firstLink.request( operation, @@ -97,7 +100,7 @@ export class ApolloLink { ) || Observable.of() ); } else { - return new ApolloLink((operation, forward) => { + ret = new ApolloLink((operation, forward) => { return ( firstLink.request(operation, (op) => { return nextLink.request(op, forward) || Observable.of(); @@ -105,6 +108,7 @@ export class ApolloLink { ); }); } + return Object.assign(ret, { left: firstLink, right: nextLink }); } constructor(request?: RequestHandler) { @@ -154,4 +158,7 @@ export class ApolloLink { this.onError = fn; return this; } + + readonly left?: ApolloLink; + readonly right?: ApolloLink; } diff --git a/src/link/persisted-queries/index.ts b/src/link/persisted-queries/index.ts index 2514df5fc4b..f6985d3afec 100644 --- a/src/link/persisted-queries/index.ts +++ b/src/link/persisted-queries/index.ts @@ -292,6 +292,15 @@ export const createPersistedQueryLink = ( }; }); }), - { resetHashCache } + { + resetHashCache, + }, + __DEV__ ? + { + get cacheSize() { + return hashesByQuery?.size ?? 0; + }, + } + : {} ); }; diff --git a/src/react/parser/index.ts b/src/react/parser/index.ts index 9aed9eeb05c..5bb0ab28a8e 100644 --- a/src/react/parser/index.ts +++ b/src/react/parser/index.ts @@ -7,6 +7,7 @@ import type { OperationDefinitionNode, } from "graphql"; import { CleanWeakCache, cacheSizes } from "../../utilities/index.js"; +import { registerGlobalCache } from "../../utilities/caching/getCacheStatus.js"; export enum DocumentType { Query, @@ -147,6 +148,10 @@ parser.resetCache = () => { cache = undefined; }; +if (__DEV__) { + registerGlobalCache("parser", () => (cache ? cache.size : 0)); +} + export function verifyDocumentType(document: DocumentNode, type: DocumentType) { const operation = parser(document); const requiredOperationName = operationName(type); diff --git a/src/utilities/caching/getCacheStatus.ts b/src/utilities/caching/getCacheStatus.ts new file mode 100644 index 00000000000..3eabda5754a --- /dev/null +++ b/src/utilities/caching/getCacheStatus.ts @@ -0,0 +1,101 @@ +import type { OptimisticWrapperFunction } from "optimism"; +import type { + InMemoryCache, + DocumentTransform, + ApolloLink, +} from "../../core/index.js"; +import type { ApolloClient } from "../../core/index.js"; +import type { CacheSizes } from "./sizes.js"; +import { cacheSizes } from "./sizes.js"; + +export type CacheStatus = { + limits: CacheSizes; + sizes: { + [K in keyof CacheSizes]?: number | number[]; + } & { + links?: number[]; + }; +}; + +const globalCaches: { + print?: () => number; + parser?: () => number; + canonicalStringify?: () => number; +} = {}; + +export function registerGlobalCache( + name: keyof typeof globalCaches, + getSize: () => number +) { + globalCaches[name] = getSize; +} + +export type GetCacheStatus = (this: ApolloClient) => CacheStatus; + +/** + * For internal purposes only - please call `ApolloClient.getCacheStatus` instead + * @internal + */ +export const getCacheStatus: GetCacheStatus = function () { + if (!__DEV__) throw new Error("only supported in development mode"); + const documentTransforms: Array = []; + if ("addTypenameTransform" in this.cache) { + documentTransforms.push( + ...transformInfo( + (this.cache as any as InMemoryCache)["addTypenameTransform"] + ) + ); + } + documentTransforms.push( + ...transformInfo(this["queryManager"].documentTransform) + ); + + const fragments = (this.cache as InMemoryCache)["config"].fragments as + | undefined + | { + findFragmentSpreads?: Function; + transform?: Function; + lookup?: Function; + }; + + return { + limits: cacheSizes, + sizes: { + print: globalCaches.print?.(), + parser: globalCaches.parser?.(), + canonicalStringify: globalCaches.canonicalStringify?.(), + documentTransform: documentTransforms, + links: linkInfo(this.link), + queryManagerTransforms: this["queryManager"]["transformCache"].size, + fragmentRegistryFindFragmentSpreads: getWrapperInformation( + fragments?.findFragmentSpreads + ), + fragmentRegistryLookup: getWrapperInformation(fragments?.lookup), + fragmentRegistryTransform: getWrapperInformation(fragments?.transform), + }, + }; +}; + +function isWrapper(f?: Function): f is OptimisticWrapperFunction { + return !!f && "dirtyKey" in f; +} + +function getWrapperInformation(f?: Function) { + return isWrapper(f) ? f.size : undefined; +} + +function transformInfo(transform?: DocumentTransform): number[] { + return [ + getWrapperInformation(transform?.["performWork"]), + ...transformInfo(transform?.["left"]), + ...transformInfo(transform?.["right"]), + ].filter(Boolean as any as (x: any) => x is number); +} + +function linkInfo(link?: ApolloLink & { cacheSize?: number }): number[] { + return [ + link?.cacheSize, + ...linkInfo(link?.left), + ...linkInfo(link?.right), + ].filter(Boolean as any as (x: any) => x is number); +} diff --git a/src/utilities/caching/sizes.ts b/src/utilities/caching/sizes.ts index b1501ad5622..2e7e00fbc1c 100644 --- a/src/utilities/caching/sizes.ts +++ b/src/utilities/caching/sizes.ts @@ -20,7 +20,7 @@ declare global { * In most applications, it will be very unlikely that 1000 different queries * are on screen at the same time. */ -interface CacheSizes { +export interface CacheSizes { /** * Cache size for the [`print`](../../utilities/graphql/print.ts) function. * diff --git a/src/utilities/common/canonicalStringify.ts b/src/utilities/common/canonicalStringify.ts index 8a550cdd400..4e02504e356 100644 --- a/src/utilities/common/canonicalStringify.ts +++ b/src/utilities/common/canonicalStringify.ts @@ -1,4 +1,5 @@ import { CleanStrongCache, cacheSizes } from "../../utilities/caching/index.js"; +import { registerGlobalCache } from "../caching/getCacheStatus.js"; /** * Like JSON.stringify, but with object keys always sorted in the same order. @@ -33,6 +34,10 @@ export const canonicalStringify = Object.assign( } ); +if (__DEV__) { + registerGlobalCache("canonicalStringify", () => sortingMap.size); +} + // Values are JSON-serialized arrays of object keys (in any order), and values // are sorted arrays of the same keys. let sortingMap!: CleanStrongCache; diff --git a/src/utilities/graphql/DocumentTransform.ts b/src/utilities/graphql/DocumentTransform.ts index c32df389ddc..1e239145a9d 100644 --- a/src/utilities/graphql/DocumentTransform.ts +++ b/src/utilities/graphql/DocumentTransform.ts @@ -52,14 +52,17 @@ export class DocumentTransform { left: DocumentTransform, right: DocumentTransform = DocumentTransform.identity() ) { - return new DocumentTransform( - (document) => { - const documentTransform = predicate(document) ? left : right; - - return documentTransform.transformDocument(document); - }, - // Reasonably assume both `left` and `right` transforms handle their own caching - { cache: false } + return Object.assign( + new DocumentTransform( + (document) => { + const documentTransform = predicate(document) ? left : right; + + return documentTransform.transformDocument(document); + }, + // Reasonably assume both `left` and `right` transforms handle their own caching + { cache: false } + ), + { left, right } ); } @@ -123,15 +126,24 @@ export class DocumentTransform { return transformedDocument; } - concat(otherTransform: DocumentTransform) { - return new DocumentTransform( - (document) => { - return otherTransform.transformDocument( - this.transformDocument(document) - ); - }, - // Reasonably assume both transforms handle their own caching - { cache: false } + concat(otherTransform: DocumentTransform): DocumentTransform { + return Object.assign( + new DocumentTransform( + (document) => { + return otherTransform.transformDocument( + this.transformDocument(document) + ); + }, + // Reasonably assume both transforms handle their own caching + { cache: false } + ), + { + left: this, + right: otherTransform, + } ); } + + readonly left?: DocumentTransform; + readonly right?: DocumentTransform; } diff --git a/src/utilities/graphql/print.ts b/src/utilities/graphql/print.ts index 4615f906271..28d5f4f9575 100644 --- a/src/utilities/graphql/print.ts +++ b/src/utilities/graphql/print.ts @@ -1,6 +1,7 @@ import type { ASTNode } from "graphql"; import { print as origPrint } from "graphql"; import { CleanWeakCache, cacheSizes } from "../caching/index.js"; +import { registerGlobalCache } from "../caching/getCacheStatus.js"; let printCache!: CleanWeakCache; export const print = Object.assign( @@ -19,5 +20,8 @@ export const print = Object.assign( }, } ); - print.reset(); + +if (__DEV__) { + registerGlobalCache("print", () => (printCache ? printCache.size : 0)); +} From 147a491af4f076c3f7992e105d73277b79a348df Mon Sep 17 00:00:00 2001 From: Lenz Weber-Tronic Date: Mon, 4 Dec 2023 17:17:34 +0100 Subject: [PATCH 20/62] update size-limits --- .size-limits.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.size-limits.json b/.size-limits.json index f9e9c6f50a8..ce52d08e3dc 100644 --- a/.size-limits.json +++ b/.size-limits.json @@ -1,4 +1,4 @@ { - "dist/apollo-client.min.cjs": 38546, - "import { ApolloClient, InMemoryCache, HttpLink } from \"dist/index.js\" (production)": 32318 + "dist/apollo-client.min.cjs": 38843, + "import { ApolloClient, InMemoryCache, HttpLink } from \"dist/index.js\" (production)": 32627 } From 324e4c918fc2563d7a411e1595f3dc792def3437 Mon Sep 17 00:00:00 2001 From: Lenz Weber-Tronic Date: Mon, 4 Dec 2023 17:21:21 +0100 Subject: [PATCH 21/62] fix circular import --- src/utilities/graphql/DocumentTransform.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utilities/graphql/DocumentTransform.ts b/src/utilities/graphql/DocumentTransform.ts index c32df389ddc..c6b4d6f1db8 100644 --- a/src/utilities/graphql/DocumentTransform.ts +++ b/src/utilities/graphql/DocumentTransform.ts @@ -5,7 +5,7 @@ import { invariant } from "../globals/index.js"; import type { DocumentNode } from "graphql"; import { WeakCache } from "@wry/caches"; import { wrap } from "optimism"; -import { cacheSizes } from "../../utilities/index.js"; +import { cacheSizes } from "../caching/index.js"; export type DocumentTransformCacheKey = ReadonlyArray; From 2e65620841e23fffb747cb74b1d894ea44d8eaf3 Mon Sep 17 00:00:00 2001 From: Lenz Weber-Tronic Date: Mon, 4 Dec 2023 17:21:53 +0100 Subject: [PATCH 22/62] size-limits --- .size-limits.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.size-limits.json b/.size-limits.json index f9e9c6f50a8..5081d8f0202 100644 --- a/.size-limits.json +++ b/.size-limits.json @@ -1,4 +1,4 @@ { - "dist/apollo-client.min.cjs": 38546, - "import { ApolloClient, InMemoryCache, HttpLink } from \"dist/index.js\" (production)": 32318 + "dist/apollo-client.min.cjs": 38804, + "import { ApolloClient, InMemoryCache, HttpLink } from \"dist/index.js\" (production)": 32573 } From 717dc2dc835eb0ec684cbe9cddafb58a3966cf13 Mon Sep 17 00:00:00 2001 From: Lenz Weber-Tronic Date: Mon, 4 Dec 2023 17:25:22 +0100 Subject: [PATCH 23/62] update type to remove `WeakKey` --- src/utilities/caching/caches.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utilities/caching/caches.ts b/src/utilities/caching/caches.ts index bbdd7a5baea..7c06c4ea60a 100644 --- a/src/utilities/caching/caches.ts +++ b/src/utilities/caching/caches.ts @@ -22,7 +22,7 @@ function schedule(cache: CommonCache) { * already handles cleanup and should remain a `WeakCache`. */ -export class CleanWeakCache extends WeakCache { +export class CleanWeakCache extends WeakCache { constructor(max: number, dispose?: (value: V) => void) { super(max, dispose); } From b2d33d09319f44054205fc605973c5673c646549 Mon Sep 17 00:00:00 2001 From: Lenz Weber-Tronic Date: Mon, 4 Dec 2023 17:25:29 +0100 Subject: [PATCH 24/62] api-extractor --- .api-reports/api-report-utilities.md | 34 ++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/.api-reports/api-report-utilities.md b/.api-reports/api-report-utilities.md index 2c4231f2096..841f022cfac 100644 --- a/.api-reports/api-report-utilities.md +++ b/.api-reports/api-report-utilities.md @@ -22,12 +22,14 @@ import type { Observer } from 'zen-observable-ts'; import type { OperationDefinitionNode } from 'graphql'; import type { SelectionNode } from 'graphql'; import type { SelectionSetNode } from 'graphql'; +import { StrongCache } from '@wry/caches'; import type { Subscriber } from 'zen-observable-ts'; import { Trie } from '@wry/trie'; import { TypedDocumentNode } from '@graphql-typed-document-node/core'; import type { ValueNode } from 'graphql'; import type { VariableDefinitionNode } from 'graphql'; import type { VariableNode } from 'graphql'; +import { WeakCache } from '@wry/caches'; // @public (undocumented) export const addTypenameToDocument: ((doc: TNode) => TNode) & { @@ -444,6 +446,24 @@ class CacheGroup { resetCaching(): void; } +// @public +interface CacheSizes { + canonicalStringify: number; + documentTransform: number; + fragmentRegistryFindFragmentSpreads: number; + fragmentRegistryLookup: number; + fragmentRegistryTransform: number; + parser: number; + persistedQueryHashes: number; + print: number; + queryManagerTransforms: number; +} + +// Warning: (ae-forgotten-export) The symbol "CacheSizes" needs to be exported by the entry point index.d.ts +// +// @public +export const cacheSizes: CacheSizes; + // @public (undocumented) const enum CacheWriteBehavior { // (undocumented) @@ -483,6 +503,20 @@ export const canUseWeakSet: boolean; // @public (undocumented) export function checkDocument(doc: DocumentNode): DocumentNode; +// @public +export class CleanStrongCache extends StrongCache { + constructor(max: number, dispose?: (value: V) => void); + // (undocumented) + set(key: K, value: V): V; +} + +// @public +export class CleanWeakCache extends WeakCache { + constructor(max: number, dispose?: (value: V) => void); + // (undocumented) + set(key: K, value: V): V; +} + // @public export function cloneDeep(value: T): T; From 15db6d0712b049642be37999feeeab5406c64045 Mon Sep 17 00:00:00 2001 From: Lenz Weber-Tronic Date: Mon, 4 Dec 2023 18:33:17 +0100 Subject: [PATCH 25/62] work around ES5 class compat --- src/utilities/caching/caches.ts | 55 ++++++++++++++++++++++----------- 1 file changed, 37 insertions(+), 18 deletions(-) diff --git a/src/utilities/caching/caches.ts b/src/utilities/caching/caches.ts index 7c06c4ea60a..d290413eb02 100644 --- a/src/utilities/caching/caches.ts +++ b/src/utilities/caching/caches.ts @@ -21,16 +21,26 @@ function schedule(cache: CommonCache) { * with the notable exception of usage in `wrap` from `optimism` - that one * already handles cleanup and should remain a `WeakCache`. */ - -export class CleanWeakCache extends WeakCache { - constructor(max: number, dispose?: (value: V) => void) { - super(max, dispose); - } - set(key: K, value: V) { +export const CleanWeakCache = function CleanWeakCache( + max?: number | undefined, + dispose?: ((value: any, key: any) => void) | undefined +) { + /* + Some builds of `WeakCache` are function prototypes, some are classes. + This library still builds with an ES5 target, so we can't extend the + real classes. + Instead, we have to use this workaround until we switch to a newer build + target. + */ + const cache = new WeakCache(max, dispose); + cache.set = function (key: any, value: any) { schedule(this); - return super.set(key, value); - } -} + return WeakCache.prototype.set.call(this, key, value); + }; + return cache; +} as any as typeof WeakCache; +export type CleanWeakCache = WeakCache; + /** * A version of StrongCache that will auto-schedule a cleanup of the cache when * a new item is added. @@ -41,13 +51,22 @@ export class CleanWeakCache extends WeakCache { * with the notable exception of usage in `wrap` from `optimism` - that one * already handles cleanup and should remain a `StrongCache`. */ - -export class CleanStrongCache extends StrongCache { - constructor(max: number, dispose?: (value: V) => void) { - super(max, dispose); - } - set(key: K, value: V) { +export const CleanStrongCache = function CleanStrongCache( + max?: number | undefined, + dispose?: ((value: any, key: any) => void) | undefined +) { + /* + Some builds of `StrongCache` are function prototypes, some are classes. + This library still builds with an ES5 target, so we can't extend the + real classes. + Instead, we have to use this workaround until we switch to a newer build + target. + */ + const cache = new StrongCache(max, dispose); + cache.set = function (key: any, value: any) { schedule(this); - return super.set(key, value); - } -} + return StrongCache.prototype.set.call(this, key, value); + }; + return cache; +} as any as typeof StrongCache; +export type CleanStrongCache = StrongCache; From fc605d702fe54d3e379b960c9b4868eddff3cf02 Mon Sep 17 00:00:00 2001 From: Lenz Weber-Tronic Date: Mon, 4 Dec 2023 18:38:26 +0100 Subject: [PATCH 26/62] update api-report --- .api-reports/api-report-utilities.md | 18 ++++++++---------- .size-limits.json | 4 ++-- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/.api-reports/api-report-utilities.md b/.api-reports/api-report-utilities.md index 841f022cfac..e89e7161bad 100644 --- a/.api-reports/api-report-utilities.md +++ b/.api-reports/api-report-utilities.md @@ -504,18 +504,16 @@ export const canUseWeakSet: boolean; export function checkDocument(doc: DocumentNode): DocumentNode; // @public -export class CleanStrongCache extends StrongCache { - constructor(max: number, dispose?: (value: V) => void); - // (undocumented) - set(key: K, value: V): V; -} +export const CleanStrongCache: typeof StrongCache; + +// @public (undocumented) +export type CleanStrongCache = StrongCache; // @public -export class CleanWeakCache extends WeakCache { - constructor(max: number, dispose?: (value: V) => void); - // (undocumented) - set(key: K, value: V): V; -} +export const CleanWeakCache: typeof WeakCache; + +// @public (undocumented) +export type CleanWeakCache = WeakCache; // @public export function cloneDeep(value: T): T; diff --git a/.size-limits.json b/.size-limits.json index 5081d8f0202..57fa36ea646 100644 --- a/.size-limits.json +++ b/.size-limits.json @@ -1,4 +1,4 @@ { - "dist/apollo-client.min.cjs": 38804, - "import { ApolloClient, InMemoryCache, HttpLink } from \"dist/index.js\" (production)": 32573 + "dist/apollo-client.min.cjs": 38800, + "import { ApolloClient, InMemoryCache, HttpLink } from \"dist/index.js\" (production)": 32562 } From c503b2dde501e6c318c2f8ddc69353a222acbf83 Mon Sep 17 00:00:00 2001 From: Lenz Weber-Tronic Date: Mon, 4 Dec 2023 18:43:43 +0100 Subject: [PATCH 27/62] fix typo in comment --- src/utilities/caching/sizes.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utilities/caching/sizes.ts b/src/utilities/caching/sizes.ts index b1501ad5622..b9ac738fc69 100644 --- a/src/utilities/caching/sizes.ts +++ b/src/utilities/caching/sizes.ts @@ -161,7 +161,7 @@ const cacheSizeSymbol = Symbol.for("apollo.cacheSize"); * * The global cache size configuration for Apollo Client. * - * @remark + * @remarks * * You can directly modify this object, but any modification will * only have an effect on caches that are created after the modification. From 71318ffe8096e4ba3faa2911c676ff587b5fe50c Mon Sep 17 00:00:00 2001 From: Lenz Weber-Tronic Date: Mon, 4 Dec 2023 19:03:22 +0100 Subject: [PATCH 28/62] chores --- .api-reports/api-report-core.md | 46 ++++++++++++++++++- .api-reports/api-report-link_batch-http.md | 4 ++ .api-reports/api-report-link_batch.md | 4 ++ .api-reports/api-report-link_context.md | 4 ++ .api-reports/api-report-link_core.md | 4 ++ .api-reports/api-report-link_error.md | 4 ++ .api-reports/api-report-link_http.md | 4 ++ .../api-report-link_persisted-queries.md | 10 +++- .../api-report-link_remove-typename.md | 4 ++ .api-reports/api-report-link_retry.md | 4 ++ .api-reports/api-report-link_schema.md | 4 ++ .api-reports/api-report-link_subscriptions.md | 4 ++ .api-reports/api-report-link_ws.md | 4 ++ .api-reports/api-report-react.md | 46 ++++++++++++++++++- .api-reports/api-report-react_components.md | 46 ++++++++++++++++++- .api-reports/api-report-react_context.md | 46 ++++++++++++++++++- .api-reports/api-report-react_hoc.md | 46 ++++++++++++++++++- .api-reports/api-report-react_hooks.md | 46 ++++++++++++++++++- .api-reports/api-report-react_ssr.md | 46 ++++++++++++++++++- .api-reports/api-report-testing.md | 46 ++++++++++++++++++- .api-reports/api-report-testing_core.md | 46 ++++++++++++++++++- .api-reports/api-report-utilities.md | 34 +++++++++++++- .api-reports/api-report.md | 46 ++++++++++++++++++- .size-limits.json | 4 +- 24 files changed, 537 insertions(+), 15 deletions(-) diff --git a/.api-reports/api-report-core.md b/.api-reports/api-report-core.md index 8129823a675..238a140efa8 100644 --- a/.api-reports/api-report-core.md +++ b/.api-reports/api-report-core.md @@ -104,6 +104,10 @@ export class ApolloClient implements DataProxy { disableNetworkFetches: boolean; get documentTransform(): DocumentTransform; extract(optimistic?: boolean): TCacheShape; + // Warning: (ae-forgotten-export) The symbol "GetCacheStatus" needs to be exported by the entry point index.d.ts + // + // @internal + getCacheStatus?: GetCacheStatus; getObservableQueries(include?: RefetchQueriesInclude): Map>; getResolvers(): Resolvers; // (undocumented) @@ -222,10 +226,14 @@ export class ApolloLink { // (undocumented) static from(links: (ApolloLink | RequestHandler)[]): ApolloLink; // (undocumented) + readonly left?: ApolloLink; + // (undocumented) protected onError(error: any, observer?: Observer): false | void; // (undocumented) request(operation: Operation, forward?: NextLink): Observable | null; // (undocumented) + readonly right?: ApolloLink; + // (undocumented) setOnError(fn: ApolloLink["onError"]): this; // (undocumented) static split(test: (op: Operation) => boolean, left: ApolloLink | RequestHandler, right?: ApolloLink | RequestHandler): ApolloLink; @@ -384,6 +392,29 @@ class CacheGroup { resetCaching(): void; } +// @public +interface CacheSizes { + canonicalStringify: number; + documentTransform: number; + fragmentRegistryFindFragmentSpreads: number; + fragmentRegistryLookup: number; + fragmentRegistryTransform: number; + parser: number; + persistedQueryHashes: number; + print: number; + queryManagerTransforms: number; +} + +// @public (undocumented) +type CacheStatus = { + limits: CacheSizes; + sizes: { + [K in keyof CacheSizes]?: number | number[]; + } & { + links?: number[]; + }; +}; + // @public (undocumented) const enum CacheWriteBehavior { // (undocumented) @@ -559,9 +590,16 @@ export class DocumentTransform { concat(otherTransform: DocumentTransform): DocumentTransform; // (undocumented) static identity(): DocumentTransform; + // (undocumented) + readonly left?: DocumentTransform; resetCache(): void; // (undocumented) - static split(predicate: (document: DocumentNode) => boolean, left: DocumentTransform, right?: DocumentTransform): DocumentTransform; + readonly right?: DocumentTransform; + // (undocumented) + static split(predicate: (document: DocumentNode) => boolean, left: DocumentTransform, right?: DocumentTransform): DocumentTransform & { + left: DocumentTransform; + right: DocumentTransform; + }; // (undocumented) transformDocument(document: DocumentNode): DocumentNode; } @@ -860,6 +898,11 @@ export function fromError(errorValue: any): Observable; // @public (undocumented) export function fromPromise(promise: Promise): Observable; +// Warning: (ae-forgotten-export) The symbol "CacheStatus" needs to be exported by the entry point index.d.ts +// +// @public (undocumented) +type GetCacheStatus = (this: ApolloClient) => CacheStatus; + export { gql } // @public (undocumented) @@ -2117,6 +2160,7 @@ interface WriteContext extends ReadMergeModifyContext { // src/core/QueryManager.ts:395:7 - (ae-forgotten-export) The symbol "UpdateQueries" needs to be exported by the entry point index.d.ts // src/core/watchQueryOptions.ts:253:2 - (ae-forgotten-export) The symbol "UpdateQueryFn" needs to be exported by the entry point index.d.ts // src/link/http/selectHttpOptionsAndBody.ts:128:32 - (ae-forgotten-export) The symbol "HttpQueryOptions" needs to be exported by the entry point index.d.ts +// src/utilities/caching/getCacheStatus.ts:12:3 - (ae-forgotten-export) The symbol "CacheSizes" needs to be exported by the entry point index.d.ts // (No @packageDocumentation comment for this package) diff --git a/.api-reports/api-report-link_batch-http.md b/.api-reports/api-report-link_batch-http.md index 4ea94f13b7b..d4cb14316a0 100644 --- a/.api-reports/api-report-link_batch-http.md +++ b/.api-reports/api-report-link_batch-http.md @@ -30,12 +30,16 @@ class ApolloLink { // (undocumented) static from(links: (ApolloLink | RequestHandler)[]): ApolloLink; // (undocumented) + readonly left?: ApolloLink; + // (undocumented) protected onError(error: any, observer?: Observer): false | void; // Warning: (ae-forgotten-export) The symbol "NextLink" needs to be exported by the entry point index.d.ts // // (undocumented) request(operation: Operation, forward?: NextLink): Observable | null; // (undocumented) + readonly right?: ApolloLink; + // (undocumented) setOnError(fn: ApolloLink["onError"]): this; // Warning: (ae-forgotten-export) The symbol "Operation" needs to be exported by the entry point index.d.ts // diff --git a/.api-reports/api-report-link_batch.md b/.api-reports/api-report-link_batch.md index 7562ad80181..6de08659fe2 100644 --- a/.api-reports/api-report-link_batch.md +++ b/.api-reports/api-report-link_batch.md @@ -29,12 +29,16 @@ class ApolloLink { // (undocumented) static from(links: (ApolloLink | RequestHandler)[]): ApolloLink; // (undocumented) + readonly left?: ApolloLink; + // (undocumented) protected onError(error: any, observer?: Observer): false | void; // Warning: (ae-forgotten-export) The symbol "NextLink" needs to be exported by the entry point index.d.ts // // (undocumented) request(operation: Operation, forward?: NextLink): Observable | null; // (undocumented) + readonly right?: ApolloLink; + // (undocumented) setOnError(fn: ApolloLink["onError"]): this; // Warning: (ae-forgotten-export) The symbol "Operation" needs to be exported by the entry point index.d.ts // diff --git a/.api-reports/api-report-link_context.md b/.api-reports/api-report-link_context.md index bd2790f5381..329edd2d086 100644 --- a/.api-reports/api-report-link_context.md +++ b/.api-reports/api-report-link_context.md @@ -29,12 +29,16 @@ class ApolloLink { // (undocumented) static from(links: (ApolloLink | RequestHandler)[]): ApolloLink; // (undocumented) + readonly left?: ApolloLink; + // (undocumented) protected onError(error: any, observer?: Observer): false | void; // Warning: (ae-forgotten-export) The symbol "NextLink" needs to be exported by the entry point index.d.ts // // (undocumented) request(operation: Operation, forward?: NextLink): Observable | null; // (undocumented) + readonly right?: ApolloLink; + // (undocumented) setOnError(fn: ApolloLink["onError"]): this; // Warning: (ae-forgotten-export) The symbol "Operation" needs to be exported by the entry point index.d.ts // diff --git a/.api-reports/api-report-link_core.md b/.api-reports/api-report-link_core.md index e711dfe7fc1..8c06830fb86 100644 --- a/.api-reports/api-report-link_core.md +++ b/.api-reports/api-report-link_core.md @@ -24,10 +24,14 @@ export class ApolloLink { // (undocumented) static from(links: (ApolloLink | RequestHandler)[]): ApolloLink; // (undocumented) + readonly left?: ApolloLink; + // (undocumented) protected onError(error: any, observer?: Observer): false | void; // (undocumented) request(operation: Operation, forward?: NextLink): Observable | null; // (undocumented) + readonly right?: ApolloLink; + // (undocumented) setOnError(fn: ApolloLink["onError"]): this; // (undocumented) static split(test: (op: Operation) => boolean, left: ApolloLink | RequestHandler, right?: ApolloLink | RequestHandler): ApolloLink; diff --git a/.api-reports/api-report-link_error.md b/.api-reports/api-report-link_error.md index febf5b6be00..2216b2190a1 100644 --- a/.api-reports/api-report-link_error.md +++ b/.api-reports/api-report-link_error.md @@ -29,12 +29,16 @@ class ApolloLink { // (undocumented) static from(links: (ApolloLink | RequestHandler)[]): ApolloLink; // (undocumented) + readonly left?: ApolloLink; + // (undocumented) protected onError(error: any, observer?: Observer): false | void; // Warning: (ae-forgotten-export) The symbol "NextLink" needs to be exported by the entry point index.d.ts // // (undocumented) request(operation: Operation, forward?: NextLink): Observable | null; // (undocumented) + readonly right?: ApolloLink; + // (undocumented) setOnError(fn: ApolloLink["onError"]): this; // Warning: (ae-forgotten-export) The symbol "Operation" needs to be exported by the entry point index.d.ts // diff --git a/.api-reports/api-report-link_http.md b/.api-reports/api-report-link_http.md index 3849a3649df..c13f0fa0a87 100644 --- a/.api-reports/api-report-link_http.md +++ b/.api-reports/api-report-link_http.md @@ -31,12 +31,16 @@ class ApolloLink { // (undocumented) static from(links: (ApolloLink | RequestHandler)[]): ApolloLink; // (undocumented) + readonly left?: ApolloLink; + // (undocumented) protected onError(error: any, observer?: Observer): false | void; // Warning: (ae-forgotten-export) The symbol "NextLink" needs to be exported by the entry point index.d.ts // // (undocumented) request(operation: Operation, forward?: NextLink): Observable | null; // (undocumented) + readonly right?: ApolloLink; + // (undocumented) setOnError(fn: ApolloLink["onError"]): this; // Warning: (ae-forgotten-export) The symbol "Operation" needs to be exported by the entry point index.d.ts // diff --git a/.api-reports/api-report-link_persisted-queries.md b/.api-reports/api-report-link_persisted-queries.md index 353d48364e6..f7ea3b4768a 100644 --- a/.api-reports/api-report-link_persisted-queries.md +++ b/.api-reports/api-report-link_persisted-queries.md @@ -29,12 +29,16 @@ class ApolloLink { // (undocumented) static from(links: (ApolloLink | RequestHandler)[]): ApolloLink; // (undocumented) + readonly left?: ApolloLink; + // (undocumented) protected onError(error: any, observer?: Observer): false | void; // Warning: (ae-forgotten-export) The symbol "NextLink" needs to be exported by the entry point index.d.ts // // (undocumented) request(operation: Operation, forward?: NextLink): Observable | null; // (undocumented) + readonly right?: ApolloLink; + // (undocumented) setOnError(fn: ApolloLink["onError"]): this; // Warning: (ae-forgotten-export) The symbol "Operation" needs to be exported by the entry point index.d.ts // @@ -59,7 +63,11 @@ interface BaseOptions { // @public (undocumented) export const createPersistedQueryLink: (options: PersistedQueryLink.Options) => ApolloLink & { resetHashCache: () => void; -}; +} & ({ + readonly cacheSize: number; +} | { + readonly cacheSize?: undefined; +}); // @public (undocumented) interface DefaultContext extends Record { diff --git a/.api-reports/api-report-link_remove-typename.md b/.api-reports/api-report-link_remove-typename.md index ddec205b0ac..2fa733a42df 100644 --- a/.api-reports/api-report-link_remove-typename.md +++ b/.api-reports/api-report-link_remove-typename.md @@ -29,12 +29,16 @@ class ApolloLink { // (undocumented) static from(links: (ApolloLink | RequestHandler)[]): ApolloLink; // (undocumented) + readonly left?: ApolloLink; + // (undocumented) protected onError(error: any, observer?: Observer): false | void; // Warning: (ae-forgotten-export) The symbol "NextLink" needs to be exported by the entry point index.d.ts // // (undocumented) request(operation: Operation, forward?: NextLink): Observable | null; // (undocumented) + readonly right?: ApolloLink; + // (undocumented) setOnError(fn: ApolloLink["onError"]): this; // Warning: (ae-forgotten-export) The symbol "Operation" needs to be exported by the entry point index.d.ts // diff --git a/.api-reports/api-report-link_retry.md b/.api-reports/api-report-link_retry.md index 1c3d0f2557d..f4371cdc539 100644 --- a/.api-reports/api-report-link_retry.md +++ b/.api-reports/api-report-link_retry.md @@ -29,12 +29,16 @@ class ApolloLink { // (undocumented) static from(links: (ApolloLink | RequestHandler)[]): ApolloLink; // (undocumented) + readonly left?: ApolloLink; + // (undocumented) protected onError(error: any, observer?: Observer): false | void; // Warning: (ae-forgotten-export) The symbol "NextLink" needs to be exported by the entry point index.d.ts // // (undocumented) request(operation: Operation, forward?: NextLink): Observable | null; // (undocumented) + readonly right?: ApolloLink; + // (undocumented) setOnError(fn: ApolloLink["onError"]): this; // Warning: (ae-forgotten-export) The symbol "Operation" needs to be exported by the entry point index.d.ts // diff --git a/.api-reports/api-report-link_schema.md b/.api-reports/api-report-link_schema.md index 31712ec362d..8e23b7757ac 100644 --- a/.api-reports/api-report-link_schema.md +++ b/.api-reports/api-report-link_schema.md @@ -30,12 +30,16 @@ class ApolloLink { // (undocumented) static from(links: (ApolloLink | RequestHandler)[]): ApolloLink; // (undocumented) + readonly left?: ApolloLink; + // (undocumented) protected onError(error: any, observer?: Observer): false | void; // Warning: (ae-forgotten-export) The symbol "NextLink" needs to be exported by the entry point index.d.ts // // (undocumented) request(operation: Operation, forward?: NextLink): Observable | null; // (undocumented) + readonly right?: ApolloLink; + // (undocumented) setOnError(fn: ApolloLink["onError"]): this; // Warning: (ae-forgotten-export) The symbol "Operation" needs to be exported by the entry point index.d.ts // diff --git a/.api-reports/api-report-link_subscriptions.md b/.api-reports/api-report-link_subscriptions.md index 5b5e1585f6e..962d9f09795 100644 --- a/.api-reports/api-report-link_subscriptions.md +++ b/.api-reports/api-report-link_subscriptions.md @@ -30,12 +30,16 @@ class ApolloLink { // (undocumented) static from(links: (ApolloLink | RequestHandler)[]): ApolloLink; // (undocumented) + readonly left?: ApolloLink; + // (undocumented) protected onError(error: any, observer?: Observer): false | void; // Warning: (ae-forgotten-export) The symbol "NextLink" needs to be exported by the entry point index.d.ts // // (undocumented) request(operation: Operation, forward?: NextLink): Observable | null; // (undocumented) + readonly right?: ApolloLink; + // (undocumented) setOnError(fn: ApolloLink["onError"]): this; // Warning: (ae-forgotten-export) The symbol "Operation" needs to be exported by the entry point index.d.ts // diff --git a/.api-reports/api-report-link_ws.md b/.api-reports/api-report-link_ws.md index 4ee65142d54..f16ccd6d700 100644 --- a/.api-reports/api-report-link_ws.md +++ b/.api-reports/api-report-link_ws.md @@ -31,12 +31,16 @@ class ApolloLink { // (undocumented) static from(links: (ApolloLink | RequestHandler)[]): ApolloLink; // (undocumented) + readonly left?: ApolloLink; + // (undocumented) protected onError(error: any, observer?: Observer): false | void; // Warning: (ae-forgotten-export) The symbol "NextLink" needs to be exported by the entry point index.d.ts // // (undocumented) request(operation: Operation, forward?: NextLink): Observable | null; // (undocumented) + readonly right?: ApolloLink; + // (undocumented) setOnError(fn: ApolloLink["onError"]): this; // Warning: (ae-forgotten-export) The symbol "Operation" needs to be exported by the entry point index.d.ts // diff --git a/.api-reports/api-report-react.md b/.api-reports/api-report-react.md index 268f955f1bf..f972a412a77 100644 --- a/.api-reports/api-report-react.md +++ b/.api-reports/api-report-react.md @@ -115,6 +115,10 @@ class ApolloClient implements DataProxy { // Warning: (ae-forgotten-export) The symbol "DocumentTransform" needs to be exported by the entry point index.d.ts get documentTransform(): DocumentTransform; extract(optimistic?: boolean): TCacheShape; + // Warning: (ae-forgotten-export) The symbol "GetCacheStatus" needs to be exported by the entry point index.d.ts + // + // @internal + getCacheStatus?: GetCacheStatus; // Warning: (ae-forgotten-export) The symbol "RefetchQueriesInclude" needs to be exported by the entry point index.d.ts getObservableQueries(include?: RefetchQueriesInclude): Map>; getResolvers(): Resolvers; @@ -282,12 +286,16 @@ class ApolloLink { // (undocumented) static from(links: (ApolloLink | RequestHandler)[]): ApolloLink; // (undocumented) + readonly left?: ApolloLink; + // (undocumented) protected onError(error: any, observer?: Observer): false | void; // Warning: (ae-forgotten-export) The symbol "NextLink" needs to be exported by the entry point index.d.ts // // (undocumented) request(operation: Operation, forward?: NextLink): Observable | null; // (undocumented) + readonly right?: ApolloLink; + // (undocumented) setOnError(fn: ApolloLink["onError"]): this; // Warning: (ae-forgotten-export) The symbol "Operation" needs to be exported by the entry point index.d.ts // @@ -494,6 +502,29 @@ namespace Cache_2 { import Fragment = DataProxy.Fragment; } +// @public +interface CacheSizes { + canonicalStringify: number; + documentTransform: number; + fragmentRegistryFindFragmentSpreads: number; + fragmentRegistryLookup: number; + fragmentRegistryTransform: number; + parser: number; + persistedQueryHashes: number; + print: number; + queryManagerTransforms: number; +} + +// @public (undocumented) +type CacheStatus = { + limits: CacheSizes; + sizes: { + [K in keyof CacheSizes]?: number | number[]; + } & { + links?: number[]; + }; +}; + // @public (undocumented) const enum CacheWriteBehavior { // (undocumented) @@ -678,9 +709,16 @@ class DocumentTransform { concat(otherTransform: DocumentTransform): DocumentTransform; // (undocumented) static identity(): DocumentTransform; + // (undocumented) + readonly left?: DocumentTransform; resetCache(): void; // (undocumented) - static split(predicate: (document: DocumentNode) => boolean, left: DocumentTransform, right?: DocumentTransform): DocumentTransform; + readonly right?: DocumentTransform; + // (undocumented) + static split(predicate: (document: DocumentNode) => boolean, left: DocumentTransform, right?: DocumentTransform): DocumentTransform & { + left: DocumentTransform; + right: DocumentTransform; + }; // (undocumented) transformDocument(document: DocumentNode): DocumentNode; } @@ -818,6 +856,11 @@ interface FulfilledPromise extends Promise { // @public (undocumented) export function getApolloContext(): ReactTypes.Context; +// Warning: (ae-forgotten-export) The symbol "CacheStatus" needs to be exported by the entry point index.d.ts +// +// @public (undocumented) +type GetCacheStatus = (this: ApolloClient) => CacheStatus; + // @public (undocumented) type GraphQLErrors = ReadonlyArray; @@ -2260,6 +2303,7 @@ interface WatchQueryOptions implements DataProxy { // Warning: (ae-forgotten-export) The symbol "DocumentTransform" needs to be exported by the entry point index.d.ts get documentTransform(): DocumentTransform; extract(optimistic?: boolean): TCacheShape; + // Warning: (ae-forgotten-export) The symbol "GetCacheStatus" needs to be exported by the entry point index.d.ts + // + // @internal + getCacheStatus?: GetCacheStatus; // Warning: (ae-forgotten-export) The symbol "RefetchQueriesInclude" needs to be exported by the entry point index.d.ts getObservableQueries(include?: RefetchQueriesInclude): Map>; getResolvers(): Resolvers; @@ -260,12 +264,16 @@ class ApolloLink { // (undocumented) static from(links: (ApolloLink | RequestHandler)[]): ApolloLink; // (undocumented) + readonly left?: ApolloLink; + // (undocumented) protected onError(error: any, observer?: Observer): false | void; // Warning: (ae-forgotten-export) The symbol "NextLink" needs to be exported by the entry point index.d.ts // // (undocumented) request(operation: Operation, forward?: NextLink): Observable | null; // (undocumented) + readonly right?: ApolloLink; + // (undocumented) setOnError(fn: ApolloLink["onError"]): this; // Warning: (ae-forgotten-export) The symbol "Operation" needs to be exported by the entry point index.d.ts // @@ -447,6 +455,29 @@ namespace Cache_2 { import Fragment = DataProxy.Fragment; } +// @public +interface CacheSizes { + canonicalStringify: number; + documentTransform: number; + fragmentRegistryFindFragmentSpreads: number; + fragmentRegistryLookup: number; + fragmentRegistryTransform: number; + parser: number; + persistedQueryHashes: number; + print: number; + queryManagerTransforms: number; +} + +// @public (undocumented) +type CacheStatus = { + limits: CacheSizes; + sizes: { + [K in keyof CacheSizes]?: number | number[]; + } & { + links?: number[]; + }; +}; + // @public (undocumented) const enum CacheWriteBehavior { // (undocumented) @@ -592,9 +623,16 @@ class DocumentTransform { concat(otherTransform: DocumentTransform): DocumentTransform; // (undocumented) static identity(): DocumentTransform; + // (undocumented) + readonly left?: DocumentTransform; resetCache(): void; // (undocumented) - static split(predicate: (document: DocumentNode) => boolean, left: DocumentTransform, right?: DocumentTransform): DocumentTransform; + readonly right?: DocumentTransform; + // (undocumented) + static split(predicate: (document: DocumentNode) => boolean, left: DocumentTransform, right?: DocumentTransform): DocumentTransform & { + left: DocumentTransform; + right: DocumentTransform; + }; // (undocumented) transformDocument(document: DocumentNode): DocumentNode; } @@ -697,6 +735,11 @@ interface FragmentMap { // @public (undocumented) type FragmentMatcher = (rootValue: any, typeCondition: string, context: any) => boolean; +// Warning: (ae-forgotten-export) The symbol "CacheStatus" needs to be exported by the entry point index.d.ts +// +// @public (undocumented) +type GetCacheStatus = (this: ApolloClient) => CacheStatus; + // @public (undocumented) type GraphQLErrors = ReadonlyArray; @@ -1686,6 +1729,7 @@ interface WatchQueryOptions implements DataProxy { // Warning: (ae-forgotten-export) The symbol "DocumentTransform" needs to be exported by the entry point index.d.ts get documentTransform(): DocumentTransform; extract(optimistic?: boolean): TCacheShape; + // Warning: (ae-forgotten-export) The symbol "GetCacheStatus" needs to be exported by the entry point index.d.ts + // + // @internal + getCacheStatus?: GetCacheStatus; // Warning: (ae-forgotten-export) The symbol "RefetchQueriesInclude" needs to be exported by the entry point index.d.ts getObservableQueries(include?: RefetchQueriesInclude): Map>; getResolvers(): Resolvers; @@ -280,12 +284,16 @@ class ApolloLink { // (undocumented) static from(links: (ApolloLink | RequestHandler)[]): ApolloLink; // (undocumented) + readonly left?: ApolloLink; + // (undocumented) protected onError(error: any, observer?: Observer): false | void; // Warning: (ae-forgotten-export) The symbol "NextLink" needs to be exported by the entry point index.d.ts // // (undocumented) request(operation: Operation, forward?: NextLink): Observable | null; // (undocumented) + readonly right?: ApolloLink; + // (undocumented) setOnError(fn: ApolloLink["onError"]): this; // Warning: (ae-forgotten-export) The symbol "Operation" needs to be exported by the entry point index.d.ts // @@ -430,6 +438,29 @@ namespace Cache_2 { import Fragment = DataProxy.Fragment; } +// @public +interface CacheSizes { + canonicalStringify: number; + documentTransform: number; + fragmentRegistryFindFragmentSpreads: number; + fragmentRegistryLookup: number; + fragmentRegistryTransform: number; + parser: number; + persistedQueryHashes: number; + print: number; + queryManagerTransforms: number; +} + +// @public (undocumented) +type CacheStatus = { + limits: CacheSizes; + sizes: { + [K in keyof CacheSizes]?: number | number[]; + } & { + links?: number[]; + }; +}; + // @public (undocumented) const enum CacheWriteBehavior { // (undocumented) @@ -575,9 +606,16 @@ class DocumentTransform { concat(otherTransform: DocumentTransform): DocumentTransform; // (undocumented) static identity(): DocumentTransform; + // (undocumented) + readonly left?: DocumentTransform; resetCache(): void; // (undocumented) - static split(predicate: (document: DocumentNode) => boolean, left: DocumentTransform, right?: DocumentTransform): DocumentTransform; + readonly right?: DocumentTransform; + // (undocumented) + static split(predicate: (document: DocumentNode) => boolean, left: DocumentTransform, right?: DocumentTransform): DocumentTransform & { + left: DocumentTransform; + right: DocumentTransform; + }; // (undocumented) transformDocument(document: DocumentNode): DocumentNode; } @@ -683,6 +721,11 @@ type FragmentMatcher = (rootValue: any, typeCondition: string, context: any) => // @public (undocumented) export function getApolloContext(): ReactTypes.Context; +// Warning: (ae-forgotten-export) The symbol "CacheStatus" needs to be exported by the entry point index.d.ts +// +// @public (undocumented) +type GetCacheStatus = (this: ApolloClient) => CacheStatus; + // @public (undocumented) type GraphQLErrors = ReadonlyArray; @@ -1582,6 +1625,7 @@ interface WatchQueryOptions implements DataProxy { // Warning: (ae-forgotten-export) The symbol "DocumentTransform" needs to be exported by the entry point index.d.ts get documentTransform(): DocumentTransform; extract(optimistic?: boolean): TCacheShape; + // Warning: (ae-forgotten-export) The symbol "GetCacheStatus" needs to be exported by the entry point index.d.ts + // + // @internal + getCacheStatus?: GetCacheStatus; // Warning: (ae-forgotten-export) The symbol "RefetchQueriesInclude" needs to be exported by the entry point index.d.ts getObservableQueries(include?: RefetchQueriesInclude): Map>; getResolvers(): Resolvers; @@ -259,12 +263,16 @@ class ApolloLink { // (undocumented) static from(links: (ApolloLink | RequestHandler)[]): ApolloLink; // (undocumented) + readonly left?: ApolloLink; + // (undocumented) protected onError(error: any, observer?: Observer): false | void; // Warning: (ae-forgotten-export) The symbol "NextLink" needs to be exported by the entry point index.d.ts // // (undocumented) request(operation: Operation, forward?: NextLink): Observable | null; // (undocumented) + readonly right?: ApolloLink; + // (undocumented) setOnError(fn: ApolloLink["onError"]): this; // Warning: (ae-forgotten-export) The symbol "Operation" needs to be exported by the entry point index.d.ts // @@ -414,6 +422,29 @@ namespace Cache_2 { import Fragment = DataProxy.Fragment; } +// @public +interface CacheSizes { + canonicalStringify: number; + documentTransform: number; + fragmentRegistryFindFragmentSpreads: number; + fragmentRegistryLookup: number; + fragmentRegistryTransform: number; + parser: number; + persistedQueryHashes: number; + print: number; + queryManagerTransforms: number; +} + +// @public (undocumented) +type CacheStatus = { + limits: CacheSizes; + sizes: { + [K in keyof CacheSizes]?: number | number[]; + } & { + links?: number[]; + }; +}; + // @public (undocumented) const enum CacheWriteBehavior { // (undocumented) @@ -577,9 +608,16 @@ class DocumentTransform { concat(otherTransform: DocumentTransform): DocumentTransform; // (undocumented) static identity(): DocumentTransform; + // (undocumented) + readonly left?: DocumentTransform; resetCache(): void; // (undocumented) - static split(predicate: (document: DocumentNode) => boolean, left: DocumentTransform, right?: DocumentTransform): DocumentTransform; + readonly right?: DocumentTransform; + // (undocumented) + static split(predicate: (document: DocumentNode) => boolean, left: DocumentTransform, right?: DocumentTransform): DocumentTransform & { + left: DocumentTransform; + right: DocumentTransform; + }; // (undocumented) transformDocument(document: DocumentNode): DocumentNode; } @@ -691,6 +729,11 @@ interface FragmentMap { // @public (undocumented) type FragmentMatcher = (rootValue: any, typeCondition: string, context: any) => boolean; +// Warning: (ae-forgotten-export) The symbol "CacheStatus" needs to be exported by the entry point index.d.ts +// +// @public (undocumented) +type GetCacheStatus = (this: ApolloClient) => CacheStatus; + // @public (undocumented) export function graphql> & Partial>>(document: DocumentNode, operationOptions?: OperationOption): (WrappedComponent: ReactTypes.ComponentType) => ReactTypes.ComponentClass; @@ -1627,6 +1670,7 @@ export function withSubscription implements DataProxy { // Warning: (ae-forgotten-export) The symbol "DocumentTransform" needs to be exported by the entry point index.d.ts get documentTransform(): DocumentTransform; extract(optimistic?: boolean): TCacheShape; + // Warning: (ae-forgotten-export) The symbol "GetCacheStatus" needs to be exported by the entry point index.d.ts + // + // @internal + getCacheStatus?: GetCacheStatus; // Warning: (ae-forgotten-export) The symbol "RefetchQueriesInclude" needs to be exported by the entry point index.d.ts getObservableQueries(include?: RefetchQueriesInclude): Map>; getResolvers(): Resolvers; @@ -258,12 +262,16 @@ class ApolloLink { // (undocumented) static from(links: (ApolloLink | RequestHandler)[]): ApolloLink; // (undocumented) + readonly left?: ApolloLink; + // (undocumented) protected onError(error: any, observer?: Observer): false | void; // Warning: (ae-forgotten-export) The symbol "NextLink" needs to be exported by the entry point index.d.ts // // (undocumented) request(operation: Operation, forward?: NextLink): Observable | null; // (undocumented) + readonly right?: ApolloLink; + // (undocumented) setOnError(fn: ApolloLink["onError"]): this; // Warning: (ae-forgotten-export) The symbol "Operation" needs to be exported by the entry point index.d.ts // @@ -470,6 +478,29 @@ namespace Cache_2 { import Fragment = DataProxy.Fragment; } +// @public +interface CacheSizes { + canonicalStringify: number; + documentTransform: number; + fragmentRegistryFindFragmentSpreads: number; + fragmentRegistryLookup: number; + fragmentRegistryTransform: number; + parser: number; + persistedQueryHashes: number; + print: number; + queryManagerTransforms: number; +} + +// @public (undocumented) +type CacheStatus = { + limits: CacheSizes; + sizes: { + [K in keyof CacheSizes]?: number | number[]; + } & { + links?: number[]; + }; +}; + // @public (undocumented) const enum CacheWriteBehavior { // (undocumented) @@ -649,9 +680,16 @@ class DocumentTransform { concat(otherTransform: DocumentTransform): DocumentTransform; // (undocumented) static identity(): DocumentTransform; + // (undocumented) + readonly left?: DocumentTransform; resetCache(): void; // (undocumented) - static split(predicate: (document: DocumentNode) => boolean, left: DocumentTransform, right?: DocumentTransform): DocumentTransform; + readonly right?: DocumentTransform; + // (undocumented) + static split(predicate: (document: DocumentNode) => boolean, left: DocumentTransform, right?: DocumentTransform): DocumentTransform & { + left: DocumentTransform; + right: DocumentTransform; + }; // (undocumented) transformDocument(document: DocumentNode): DocumentNode; } @@ -775,6 +813,11 @@ interface FulfilledPromise extends Promise { value: TValue; } +// Warning: (ae-forgotten-export) The symbol "CacheStatus" needs to be exported by the entry point index.d.ts +// +// @public (undocumented) +type GetCacheStatus = (this: ApolloClient) => CacheStatus; + // @public (undocumented) type GraphQLErrors = ReadonlyArray; @@ -2151,6 +2194,7 @@ interface WatchQueryOptions implements DataProxy { // Warning: (ae-forgotten-export) The symbol "DocumentTransform" needs to be exported by the entry point index.d.ts get documentTransform(): DocumentTransform; extract(optimistic?: boolean): TCacheShape; + // Warning: (ae-forgotten-export) The symbol "GetCacheStatus" needs to be exported by the entry point index.d.ts + // + // @internal + getCacheStatus?: GetCacheStatus; // Warning: (ae-forgotten-export) The symbol "RefetchQueriesInclude" needs to be exported by the entry point index.d.ts getObservableQueries(include?: RefetchQueriesInclude): Map>; getResolvers(): Resolvers; @@ -259,12 +263,16 @@ class ApolloLink { // (undocumented) static from(links: (ApolloLink | RequestHandler)[]): ApolloLink; // (undocumented) + readonly left?: ApolloLink; + // (undocumented) protected onError(error: any, observer?: Observer): false | void; // Warning: (ae-forgotten-export) The symbol "NextLink" needs to be exported by the entry point index.d.ts // // (undocumented) request(operation: Operation, forward?: NextLink): Observable | null; // (undocumented) + readonly right?: ApolloLink; + // (undocumented) setOnError(fn: ApolloLink["onError"]): this; // Warning: (ae-forgotten-export) The symbol "Operation" needs to be exported by the entry point index.d.ts // @@ -400,6 +408,29 @@ namespace Cache_2 { import Fragment = DataProxy.Fragment; } +// @public +interface CacheSizes { + canonicalStringify: number; + documentTransform: number; + fragmentRegistryFindFragmentSpreads: number; + fragmentRegistryLookup: number; + fragmentRegistryTransform: number; + parser: number; + persistedQueryHashes: number; + print: number; + queryManagerTransforms: number; +} + +// @public (undocumented) +type CacheStatus = { + limits: CacheSizes; + sizes: { + [K in keyof CacheSizes]?: number | number[]; + } & { + links?: number[]; + }; +}; + // @public (undocumented) const enum CacheWriteBehavior { // (undocumented) @@ -545,9 +576,16 @@ class DocumentTransform { concat(otherTransform: DocumentTransform): DocumentTransform; // (undocumented) static identity(): DocumentTransform; + // (undocumented) + readonly left?: DocumentTransform; resetCache(): void; // (undocumented) - static split(predicate: (document: DocumentNode) => boolean, left: DocumentTransform, right?: DocumentTransform): DocumentTransform; + readonly right?: DocumentTransform; + // (undocumented) + static split(predicate: (document: DocumentNode) => boolean, left: DocumentTransform, right?: DocumentTransform): DocumentTransform & { + left: DocumentTransform; + right: DocumentTransform; + }; // (undocumented) transformDocument(document: DocumentNode): DocumentNode; } @@ -650,6 +688,11 @@ interface FragmentMap { // @public (undocumented) type FragmentMatcher = (rootValue: any, typeCondition: string, context: any) => boolean; +// Warning: (ae-forgotten-export) The symbol "CacheStatus" needs to be exported by the entry point index.d.ts +// +// @public (undocumented) +type GetCacheStatus = (this: ApolloClient) => CacheStatus; + // @public (undocumented) export function getDataFromTree(tree: ReactTypes.ReactNode, context?: { [key: string]: any; @@ -1568,6 +1611,7 @@ interface WatchQueryOptions implements DataProxy { // Warning: (ae-forgotten-export) The symbol "DocumentTransform" needs to be exported by the entry point index.d.ts get documentTransform(): DocumentTransform; extract(optimistic?: boolean): TCacheShape; + // Warning: (ae-forgotten-export) The symbol "GetCacheStatus" needs to be exported by the entry point index.d.ts + // + // @internal + getCacheStatus?: GetCacheStatus; // Warning: (ae-forgotten-export) The symbol "RefetchQueriesInclude" needs to be exported by the entry point index.d.ts getObservableQueries(include?: RefetchQueriesInclude): Map>; getResolvers(): Resolvers; @@ -259,12 +263,16 @@ class ApolloLink { // (undocumented) static from(links: (ApolloLink | RequestHandler)[]): ApolloLink; // (undocumented) + readonly left?: ApolloLink; + // (undocumented) protected onError(error: any, observer?: Observer): false | void; // Warning: (ae-forgotten-export) The symbol "NextLink" needs to be exported by the entry point index.d.ts // // (undocumented) request(operation: Operation, forward?: NextLink): Observable | null; // (undocumented) + readonly right?: ApolloLink; + // (undocumented) setOnError(fn: ApolloLink["onError"]): this; // Warning: (ae-forgotten-export) The symbol "Operation" needs to be exported by the entry point index.d.ts // @@ -388,6 +396,29 @@ namespace Cache_2 { import Fragment = DataProxy.Fragment; } +// @public +interface CacheSizes { + canonicalStringify: number; + documentTransform: number; + fragmentRegistryFindFragmentSpreads: number; + fragmentRegistryLookup: number; + fragmentRegistryTransform: number; + parser: number; + persistedQueryHashes: number; + print: number; + queryManagerTransforms: number; +} + +// @public (undocumented) +type CacheStatus = { + limits: CacheSizes; + sizes: { + [K in keyof CacheSizes]?: number | number[]; + } & { + links?: number[]; + }; +}; + // @public (undocumented) const enum CacheWriteBehavior { // (undocumented) @@ -539,9 +570,16 @@ class DocumentTransform { concat(otherTransform: DocumentTransform): DocumentTransform; // (undocumented) static identity(): DocumentTransform; + // (undocumented) + readonly left?: DocumentTransform; resetCache(): void; // (undocumented) - static split(predicate: (document: DocumentNode) => boolean, left: DocumentTransform, right?: DocumentTransform): DocumentTransform; + readonly right?: DocumentTransform; + // (undocumented) + static split(predicate: (document: DocumentNode) => boolean, left: DocumentTransform, right?: DocumentTransform): DocumentTransform & { + left: DocumentTransform; + right: DocumentTransform; + }; // (undocumented) transformDocument(document: DocumentNode): DocumentNode; } @@ -644,6 +682,11 @@ interface FragmentMap { // @public (undocumented) type FragmentMatcher = (rootValue: any, typeCondition: string, context: any) => boolean; +// Warning: (ae-forgotten-export) The symbol "CacheStatus" needs to be exported by the entry point index.d.ts +// +// @public (undocumented) +type GetCacheStatus = (this: ApolloClient) => CacheStatus; + // @public (undocumented) type GraphQLErrors = ReadonlyArray; @@ -1630,6 +1673,7 @@ export function withWarningSpy(it: (...args: TArgs // src/core/types.ts:174:3 - (ae-forgotten-export) The symbol "MutationQueryReducer" needs to be exported by the entry point index.d.ts // src/core/types.ts:201:5 - (ae-forgotten-export) The symbol "Resolver" needs to be exported by the entry point index.d.ts // src/core/watchQueryOptions.ts:253:2 - (ae-forgotten-export) The symbol "UpdateQueryFn" needs to be exported by the entry point index.d.ts +// src/utilities/caching/getCacheStatus.ts:12:3 - (ae-forgotten-export) The symbol "CacheSizes" 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 a306aeb99fb..56d2da2cbf9 100644 --- a/.api-reports/api-report-testing_core.md +++ b/.api-reports/api-report-testing_core.md @@ -113,6 +113,10 @@ class ApolloClient implements DataProxy { // Warning: (ae-forgotten-export) The symbol "DocumentTransform" needs to be exported by the entry point index.d.ts get documentTransform(): DocumentTransform; extract(optimistic?: boolean): TCacheShape; + // Warning: (ae-forgotten-export) The symbol "GetCacheStatus" needs to be exported by the entry point index.d.ts + // + // @internal + getCacheStatus?: GetCacheStatus; // Warning: (ae-forgotten-export) The symbol "RefetchQueriesInclude" needs to be exported by the entry point index.d.ts getObservableQueries(include?: RefetchQueriesInclude): Map>; getResolvers(): Resolvers; @@ -258,12 +262,16 @@ class ApolloLink { // (undocumented) static from(links: (ApolloLink | RequestHandler)[]): ApolloLink; // (undocumented) + readonly left?: ApolloLink; + // (undocumented) protected onError(error: any, observer?: Observer): false | void; // Warning: (ae-forgotten-export) The symbol "NextLink" needs to be exported by the entry point index.d.ts // // (undocumented) request(operation: Operation, forward?: NextLink): Observable | null; // (undocumented) + readonly right?: ApolloLink; + // (undocumented) setOnError(fn: ApolloLink["onError"]): this; // Warning: (ae-forgotten-export) The symbol "Operation" needs to be exported by the entry point index.d.ts // @@ -387,6 +395,29 @@ namespace Cache_2 { import Fragment = DataProxy.Fragment; } +// @public +interface CacheSizes { + canonicalStringify: number; + documentTransform: number; + fragmentRegistryFindFragmentSpreads: number; + fragmentRegistryLookup: number; + fragmentRegistryTransform: number; + parser: number; + persistedQueryHashes: number; + print: number; + queryManagerTransforms: number; +} + +// @public (undocumented) +type CacheStatus = { + limits: CacheSizes; + sizes: { + [K in keyof CacheSizes]?: number | number[]; + } & { + links?: number[]; + }; +}; + // @public (undocumented) const enum CacheWriteBehavior { // (undocumented) @@ -538,9 +569,16 @@ class DocumentTransform { concat(otherTransform: DocumentTransform): DocumentTransform; // (undocumented) static identity(): DocumentTransform; + // (undocumented) + readonly left?: DocumentTransform; resetCache(): void; // (undocumented) - static split(predicate: (document: DocumentNode) => boolean, left: DocumentTransform, right?: DocumentTransform): DocumentTransform; + readonly right?: DocumentTransform; + // (undocumented) + static split(predicate: (document: DocumentNode) => boolean, left: DocumentTransform, right?: DocumentTransform): DocumentTransform & { + left: DocumentTransform; + right: DocumentTransform; + }; // (undocumented) transformDocument(document: DocumentNode): DocumentNode; } @@ -643,6 +681,11 @@ interface FragmentMap { // @public (undocumented) type FragmentMatcher = (rootValue: any, typeCondition: string, context: any) => boolean; +// Warning: (ae-forgotten-export) The symbol "CacheStatus" needs to be exported by the entry point index.d.ts +// +// @public (undocumented) +type GetCacheStatus = (this: ApolloClient) => CacheStatus; + // @public (undocumented) type GraphQLErrors = ReadonlyArray; @@ -1587,6 +1630,7 @@ export function withWarningSpy(it: (...args: TArgs // src/core/types.ts:174:3 - (ae-forgotten-export) The symbol "MutationQueryReducer" needs to be exported by the entry point index.d.ts // src/core/types.ts:201:5 - (ae-forgotten-export) The symbol "Resolver" needs to be exported by the entry point index.d.ts // src/core/watchQueryOptions.ts:253:2 - (ae-forgotten-export) The symbol "UpdateQueryFn" needs to be exported by the entry point index.d.ts +// src/utilities/caching/getCacheStatus.ts:12:3 - (ae-forgotten-export) The symbol "CacheSizes" 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 e89e7161bad..5cfcb5afada 100644 --- a/.api-reports/api-report-utilities.md +++ b/.api-reports/api-report-utilities.md @@ -126,6 +126,10 @@ class ApolloClient implements DataProxy { disableNetworkFetches: boolean; get documentTransform(): DocumentTransform; extract(optimistic?: boolean): TCacheShape; + // Warning: (ae-forgotten-export) The symbol "GetCacheStatus" needs to be exported by the entry point index.d.ts + // + // @internal + getCacheStatus?: GetCacheStatus; // Warning: (ae-forgotten-export) The symbol "RefetchQueriesInclude" needs to be exported by the entry point index.d.ts getObservableQueries(include?: RefetchQueriesInclude): Map>; getResolvers(): Resolvers; @@ -271,12 +275,16 @@ class ApolloLink { // (undocumented) static from(links: (ApolloLink | RequestHandler)[]): ApolloLink; // (undocumented) + readonly left?: ApolloLink; + // (undocumented) protected onError(error: any, observer?: Observer): false | void; // Warning: (ae-forgotten-export) The symbol "NextLink" needs to be exported by the entry point index.d.ts // // (undocumented) request(operation: Operation, forward?: NextLink): Observable | null; // (undocumented) + readonly right?: ApolloLink; + // (undocumented) setOnError(fn: ApolloLink["onError"]): this; // Warning: (ae-forgotten-export) The symbol "Operation" needs to be exported by the entry point index.d.ts // @@ -464,6 +472,16 @@ interface CacheSizes { // @public export const cacheSizes: CacheSizes; +// @public (undocumented) +type CacheStatus = { + limits: CacheSizes; + sizes: { + [K in keyof CacheSizes]?: number | number[]; + } & { + links?: number[]; + }; +}; + // @public (undocumented) const enum CacheWriteBehavior { // (undocumented) @@ -748,9 +766,16 @@ export class DocumentTransform { concat(otherTransform: DocumentTransform): DocumentTransform; // (undocumented) static identity(): DocumentTransform; + // (undocumented) + readonly left?: DocumentTransform; resetCache(): void; // (undocumented) - static split(predicate: (document: DocumentNode) => boolean, left: DocumentTransform, right?: DocumentTransform): DocumentTransform; + readonly right?: DocumentTransform; + // (undocumented) + static split(predicate: (document: DocumentNode) => boolean, left: DocumentTransform, right?: DocumentTransform): DocumentTransform & { + left: DocumentTransform; + right: DocumentTransform; + }; // (undocumented) transformDocument(document: DocumentNode): DocumentNode; } @@ -1033,6 +1058,12 @@ interface FulfilledPromise extends Promise { value: TValue; } +// Warning: (ae-forgotten-export) The symbol "ApolloClient" needs to be exported by the entry point index.d.ts +// Warning: (ae-forgotten-export) The symbol "CacheStatus" needs to be exported by the entry point index.d.ts +// +// @public (undocumented) +type GetCacheStatus = (this: ApolloClient) => CacheStatus; + // @public (undocumented) export function getDefaultValues(definition: OperationDefinitionNode | undefined): Record; @@ -2491,7 +2522,6 @@ interface WriteContext extends ReadMergeModifyContext { // src/cache/inmemory/policies.ts:163:3 - (ae-forgotten-export) The symbol "FieldMergeFunction" needs to be exported by the entry point index.d.ts // src/cache/inmemory/types.ts:132:3 - (ae-forgotten-export) The symbol "KeyFieldsFunction" needs to be exported by the entry point index.d.ts // src/cache/inmemory/writeToStore.ts:65:7 - (ae-forgotten-export) The symbol "MergeTree" needs to be exported by the entry point index.d.ts -// src/core/LocalState.ts:71:3 - (ae-forgotten-export) The symbol "ApolloClient" needs to be exported by the entry point index.d.ts // src/core/ObservableQuery.ts:113:5 - (ae-forgotten-export) The symbol "QueryManager" needs to be exported by the entry point index.d.ts // src/core/ObservableQuery.ts:114:5 - (ae-forgotten-export) The symbol "QueryInfo" needs to be exported by the entry point index.d.ts // src/core/QueryManager.ts:120:5 - (ae-forgotten-export) The symbol "MutationStoreValue" needs to be exported by the entry point index.d.ts diff --git a/.api-reports/api-report.md b/.api-reports/api-report.md index 081d7af9dc9..e4b164b3867 100644 --- a/.api-reports/api-report.md +++ b/.api-reports/api-report.md @@ -106,6 +106,10 @@ export class ApolloClient implements DataProxy { disableNetworkFetches: boolean; get documentTransform(): DocumentTransform; extract(optimistic?: boolean): TCacheShape; + // Warning: (ae-forgotten-export) The symbol "GetCacheStatus" needs to be exported by the entry point index.d.ts + // + // @internal + getCacheStatus?: GetCacheStatus; getObservableQueries(include?: RefetchQueriesInclude): Map>; getResolvers(): Resolvers; // (undocumented) @@ -245,10 +249,14 @@ export class ApolloLink { // (undocumented) static from(links: (ApolloLink | RequestHandler)[]): ApolloLink; // (undocumented) + readonly left?: ApolloLink; + // (undocumented) protected onError(error: any, observer?: Observer): false | void; // (undocumented) request(operation: Operation, forward?: NextLink): Observable | null; // (undocumented) + readonly right?: ApolloLink; + // (undocumented) setOnError(fn: ApolloLink["onError"]): this; // (undocumented) static split(test: (op: Operation) => boolean, left: ApolloLink | RequestHandler, right?: ApolloLink | RequestHandler): ApolloLink; @@ -486,6 +494,29 @@ class CacheGroup { resetCaching(): void; } +// @public +interface CacheSizes { + canonicalStringify: number; + documentTransform: number; + fragmentRegistryFindFragmentSpreads: number; + fragmentRegistryLookup: number; + fragmentRegistryTransform: number; + parser: number; + persistedQueryHashes: number; + print: number; + queryManagerTransforms: number; +} + +// @public (undocumented) +type CacheStatus = { + limits: CacheSizes; + sizes: { + [K in keyof CacheSizes]?: number | number[]; + } & { + links?: number[]; + }; +}; + // @public (undocumented) const enum CacheWriteBehavior { // (undocumented) @@ -702,9 +733,16 @@ export class DocumentTransform { concat(otherTransform: DocumentTransform): DocumentTransform; // (undocumented) static identity(): DocumentTransform; + // (undocumented) + readonly left?: DocumentTransform; resetCache(): void; // (undocumented) - static split(predicate: (document: DocumentNode) => boolean, left: DocumentTransform, right?: DocumentTransform): DocumentTransform; + readonly right?: DocumentTransform; + // (undocumented) + static split(predicate: (document: DocumentNode) => boolean, left: DocumentTransform, right?: DocumentTransform): DocumentTransform & { + left: DocumentTransform; + right: DocumentTransform; + }; // (undocumented) transformDocument(document: DocumentNode): DocumentNode; } @@ -1036,6 +1074,11 @@ interface FulfilledPromise extends Promise { // @public (undocumented) export function getApolloContext(): ReactTypes.Context; +// Warning: (ae-forgotten-export) The symbol "CacheStatus" needs to be exported by the entry point index.d.ts +// +// @public (undocumented) +type GetCacheStatus = (this: ApolloClient) => CacheStatus; + export { gql } // @public (undocumented) @@ -2904,6 +2947,7 @@ interface WriteContext extends ReadMergeModifyContext { // src/react/hooks/useBackgroundQuery.ts:30:3 - (ae-forgotten-export) The symbol "FetchMoreFunction" needs to be exported by the entry point index.d.ts // src/react/hooks/useBackgroundQuery.ts:31:3 - (ae-forgotten-export) The symbol "RefetchFunction" needs to be exported by the entry point index.d.ts // src/react/hooks/useLoadableQuery.ts:50:5 - (ae-forgotten-export) The symbol "ResetFunction" needs to be exported by the entry point index.d.ts +// src/utilities/caching/getCacheStatus.ts:12:3 - (ae-forgotten-export) The symbol "CacheSizes" needs to be exported by the entry point index.d.ts // (No @packageDocumentation comment for this package) diff --git a/.size-limits.json b/.size-limits.json index ce52d08e3dc..a1aecbd49af 100644 --- a/.size-limits.json +++ b/.size-limits.json @@ -1,4 +1,4 @@ { - "dist/apollo-client.min.cjs": 38843, - "import { ApolloClient, InMemoryCache, HttpLink } from \"dist/index.js\" (production)": 32627 + "dist/apollo-client.min.cjs": 38839, + "import { ApolloClient, InMemoryCache, HttpLink } from \"dist/index.js\" (production)": 32621 } From 96b8d26fe42bbebdf418164939f585022d806764 Mon Sep 17 00:00:00 2001 From: Lenz Weber-Tronic Date: Mon, 4 Dec 2023 19:03:59 +0100 Subject: [PATCH 29/62] changeset --- .changeset/wet-forks-rhyme.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/wet-forks-rhyme.md diff --git a/.changeset/wet-forks-rhyme.md b/.changeset/wet-forks-rhyme.md new file mode 100644 index 00000000000..ec3cab55b77 --- /dev/null +++ b/.changeset/wet-forks-rhyme.md @@ -0,0 +1,5 @@ +--- +"@apollo/client": patch +--- + +Adds an experimental ApolloClient.getCacheStatus helper From 6e60676f0116a3c5b41df86bc86975004c98bea1 Mon Sep 17 00:00:00 2001 From: Lenz Weber-Tronic Date: Tue, 5 Dec 2023 12:46:39 +0100 Subject: [PATCH 30/62] stop recursion --- src/utilities/caching/getCacheStatus.ts | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/utilities/caching/getCacheStatus.ts b/src/utilities/caching/getCacheStatus.ts index 3eabda5754a..3c5a36b64fe 100644 --- a/src/utilities/caching/getCacheStatus.ts +++ b/src/utilities/caching/getCacheStatus.ts @@ -85,17 +85,21 @@ function getWrapperInformation(f?: Function) { } function transformInfo(transform?: DocumentTransform): number[] { - return [ - getWrapperInformation(transform?.["performWork"]), - ...transformInfo(transform?.["left"]), - ...transformInfo(transform?.["right"]), - ].filter(Boolean as any as (x: any) => x is number); + return !transform ? + [] + : [ + getWrapperInformation(transform?.["performWork"]), + ...transformInfo(transform?.["left"]), + ...transformInfo(transform?.["right"]), + ].filter(Boolean as any as (x: any) => x is number); } function linkInfo(link?: ApolloLink & { cacheSize?: number }): number[] { - return [ - link?.cacheSize, - ...linkInfo(link?.left), - ...linkInfo(link?.right), - ].filter(Boolean as any as (x: any) => x is number); + return !link ? + [] + : [ + link?.cacheSize, + ...linkInfo(link?.left), + ...linkInfo(link?.right), + ].filter(Boolean as any as (x: any) => x is number); } From 4d9928bce2150a574a849c1c426f6d9775f990b4 Mon Sep 17 00:00:00 2001 From: Lenz Weber-Tronic Date: Tue, 5 Dec 2023 14:17:51 +0100 Subject: [PATCH 31/62] add some internal annotations and optional readonly cacheSize property --- src/link/core/ApolloLink.ts | 14 ++++++++++++++ src/utilities/caching/getCacheStatus.ts | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/link/core/ApolloLink.ts b/src/link/core/ApolloLink.ts index a544b45f8cb..bbc62f75087 100644 --- a/src/link/core/ApolloLink.ts +++ b/src/link/core/ApolloLink.ts @@ -159,6 +159,20 @@ export class ApolloLink { return this; } + /** + * @internal + * Used to iterate through all links for caches that are concatenations of `split` links. + */ readonly left?: ApolloLink; + /** + * @internal + * Used to iterate through all links for caches that are concatenations of `split` links. + */ readonly right?: ApolloLink; + + /** + * @internal + * Can be provided by a link that has an internal cache to report it's cache size. + */ + readonly cacheSize?: number; } diff --git a/src/utilities/caching/getCacheStatus.ts b/src/utilities/caching/getCacheStatus.ts index 3c5a36b64fe..d4f37eea537 100644 --- a/src/utilities/caching/getCacheStatus.ts +++ b/src/utilities/caching/getCacheStatus.ts @@ -94,7 +94,7 @@ function transformInfo(transform?: DocumentTransform): number[] { ].filter(Boolean as any as (x: any) => x is number); } -function linkInfo(link?: ApolloLink & { cacheSize?: number }): number[] { +function linkInfo(link?: ApolloLink): number[] { return !link ? [] : [ From 7d7b7e6e5821218da2a758635c2969154f464bf2 Mon Sep 17 00:00:00 2001 From: Lenz Weber-Tronic Date: Tue, 5 Dec 2023 15:02:36 +0100 Subject: [PATCH 32/62] slight remodel, add more caches --- src/cache/inmemory/inMemoryCache.ts | 14 +++++ src/core/ApolloClient.ts | 7 +-- src/utilities/caching/getCacheStatus.ts | 73 ++++++++++++++++--------- 3 files changed, 64 insertions(+), 30 deletions(-) diff --git a/src/cache/inmemory/inMemoryCache.ts b/src/cache/inmemory/inMemoryCache.ts index f00fed8767e..a716481c1cd 100644 --- a/src/cache/inmemory/inMemoryCache.ts +++ b/src/cache/inmemory/inMemoryCache.ts @@ -27,6 +27,7 @@ import { makeVar, forgetCache, recallCache } from "./reactiveVars.js"; import { Policies } from "./policies.js"; import { hasOwn, normalizeConfig, shouldCanonizeResults } from "./helpers.js"; import type { OperationVariables } from "../../core/index.js"; +import { getInMemoryCacheStatus } from "../../utilities/caching/getCacheStatus.js"; type BroadcastOptions = Pick< Cache.BatchOptions, @@ -576,4 +577,17 @@ export class InMemoryCache extends ApolloCache { c.callback((c.lastDiff = diff), lastDiff); } } + + /** + * @experimental + * @internal + * This is not a stable API - it is used in development builds to expose + * information to the DevTools. + * Use at your own risk! + */ + public getCacheStatus?: typeof getInMemoryCacheStatus; +} + +if (__DEV__) { + InMemoryCache.prototype.getCacheStatus = getInMemoryCacheStatus; } diff --git a/src/core/ApolloClient.ts b/src/core/ApolloClient.ts index 81b25b6e5ec..6e7c58763bd 100644 --- a/src/core/ApolloClient.ts +++ b/src/core/ApolloClient.ts @@ -122,8 +122,7 @@ export interface ApolloClientOptions { // @apollo/client/core. Since we need to preserve that API anyway, the easiest // solution is to reexport mergeOptions where it was previously declared (here). import { mergeOptions } from "../utilities/index.js"; -import type { GetCacheStatus } from "../utilities/caching/getCacheStatus.js"; -import { getCacheStatus } from "../utilities/caching/getCacheStatus.js"; +import { getApolloClientCacheStatus } from "../utilities/caching/getCacheStatus.js"; export { mergeOptions }; /** @@ -756,9 +755,9 @@ export class ApolloClient implements DataProxy { * information to the DevTools. * Use at your own risk! */ - public getCacheStatus?: GetCacheStatus; + public getCacheStatus?: typeof getApolloClientCacheStatus; } if (__DEV__) { - ApolloClient.prototype.getCacheStatus = getCacheStatus; + ApolloClient.prototype.getCacheStatus = getApolloClientCacheStatus; } diff --git a/src/utilities/caching/getCacheStatus.ts b/src/utilities/caching/getCacheStatus.ts index d4f37eea537..069982f0280 100644 --- a/src/utilities/caching/getCacheStatus.ts +++ b/src/utilities/caching/getCacheStatus.ts @@ -30,27 +30,45 @@ export function registerGlobalCache( globalCaches[name] = getSize; } -export type GetCacheStatus = (this: ApolloClient) => CacheStatus; +/** + * For internal purposes only - please call `ApolloClient.getCacheStatus` instead + * @internal + */ +export const getApolloClientCacheStatus = + __DEV__ ? _getApolloClientCacheStatus : undefined; /** * For internal purposes only - please call `ApolloClient.getCacheStatus` instead * @internal */ -export const getCacheStatus: GetCacheStatus = function () { +export const getInMemoryCacheStatus = + __DEV__ ? _getInMemoryCacheStatus : undefined; + +function _getApolloClientCacheStatus(this: ApolloClient) { if (!__DEV__) throw new Error("only supported in development mode"); - const documentTransforms: Array = []; - if ("addTypenameTransform" in this.cache) { - documentTransforms.push( - ...transformInfo( - (this.cache as any as InMemoryCache)["addTypenameTransform"] - ) - ); - } - documentTransforms.push( - ...transformInfo(this["queryManager"].documentTransform) - ); - const fragments = (this.cache as InMemoryCache)["config"].fragments as + return { + limits: cacheSizes, + sizes: { + global: { + print: globalCaches.print?.(), + parser: globalCaches.parser?.(), + canonicalStringify: globalCaches.canonicalStringify?.(), + }, + links: linkInfo(this.link), + queryManager: { + Transforms: this["queryManager"]["transformCache"].size, + documentTransforms: transformInfo( + this["queryManager"].documentTransform + ), + }, + cache: (this.cache as InMemoryCache).getCacheStatus?.(), + }, + }; +} + +function _getInMemoryCacheStatus(this: InMemoryCache) { + const fragments = this.config.fragments as | undefined | { findFragmentSpreads?: Function; @@ -59,22 +77,25 @@ export const getCacheStatus: GetCacheStatus = function () { }; return { - limits: cacheSizes, - sizes: { - print: globalCaches.print?.(), - parser: globalCaches.parser?.(), - canonicalStringify: globalCaches.canonicalStringify?.(), - documentTransform: documentTransforms, - links: linkInfo(this.link), - queryManagerTransforms: this["queryManager"]["transformCache"].size, - fragmentRegistryFindFragmentSpreads: getWrapperInformation( + addTypenameTransform: transformInfo(this["addTypenameTransform"]), + storeReader: { + executeSelectionSet: getWrapperInformation( + this["storeReader"]["executeSelectionSet"] + ), + executeSubSelectedArray: getWrapperInformation( + this["storeReader"]["executeSubSelectedArray"] + ), + }, + maybeBroadcastWatch: getWrapperInformation(this["maybeBroadcastWatch"]), + fragmentRegistry: { + findFragmentSpreads: getWrapperInformation( fragments?.findFragmentSpreads ), - fragmentRegistryLookup: getWrapperInformation(fragments?.lookup), - fragmentRegistryTransform: getWrapperInformation(fragments?.transform), + lookup: getWrapperInformation(fragments?.lookup), + transform: getWrapperInformation(fragments?.transform), }, }; -}; +} function isWrapper(f?: Function): f is OptimisticWrapperFunction { return !!f && "dirtyKey" in f; From 0ce3f55f4b00bc1ad4f42df112886e11dfb5cab8 Mon Sep 17 00:00:00 2001 From: Lenz Weber-Tronic Date: Tue, 5 Dec 2023 15:19:38 +0100 Subject: [PATCH 33/62] chores --- .api-reports/api-report-cache.md | 24 ++++++ .api-reports/api-report-core.md | 80 +++++++++++++++---- .api-reports/api-report-link_batch-http.md | 6 +- .api-reports/api-report-link_batch.md | 6 +- .api-reports/api-report-link_context.md | 6 +- .api-reports/api-report-link_core.md | 6 +- .api-reports/api-report-link_error.md | 6 +- .api-reports/api-report-link_http.md | 6 +- .../api-report-link_persisted-queries.md | 6 +- .../api-report-link_remove-typename.md | 6 +- .api-reports/api-report-link_retry.md | 6 +- .api-reports/api-report-link_schema.md | 6 +- .api-reports/api-report-link_subscriptions.md | 6 +- .api-reports/api-report-link_ws.md | 6 +- .api-reports/api-report-react.md | 60 +++++++++----- .api-reports/api-report-react_components.md | 56 +++++++++---- .api-reports/api-report-react_context.md | 60 +++++++++----- .api-reports/api-report-react_hoc.md | 56 +++++++++---- .api-reports/api-report-react_hooks.md | 56 +++++++++---- .api-reports/api-report-react_ssr.md | 56 +++++++++---- .api-reports/api-report-testing.md | 56 +++++++++---- .api-reports/api-report-testing_core.md | 56 +++++++++---- .api-reports/api-report-utilities.md | 79 ++++++++++++++---- .api-reports/api-report.md | 80 +++++++++++++++---- .size-limits.json | 2 +- 25 files changed, 578 insertions(+), 215 deletions(-) diff --git a/.api-reports/api-report-cache.md b/.api-reports/api-report-cache.md index 50588f8f4c0..81a4302f96b 100644 --- a/.api-reports/api-report-cache.md +++ b/.api-reports/api-report-cache.md @@ -474,6 +474,26 @@ export interface FragmentRegistryAPI { transform(document: D): D; } +// Warning: (ae-forgotten-export) The symbol "_getInMemoryCacheStatus" needs to be exported by the entry point index.d.ts +// +// @internal +const getInMemoryCacheStatus: typeof _getInMemoryCacheStatus | undefined; + +// @public (undocumented) +function _getInMemoryCacheStatus(this: InMemoryCache): { + addTypenameTransform: number[]; + storeReader: { + executeSelectionSet: number | undefined; + executeSubSelectedArray: number | undefined; + }; + maybeBroadcastWatch: number | undefined; + fragmentRegistry: { + findFragmentSpreads: number | undefined; + lookup: number | undefined; + transform: number | undefined; + }; +}; + // @public (undocumented) export type IdGetter = (value: IdGetterObj) => string | undefined; @@ -513,6 +533,10 @@ export class InMemoryCache extends ApolloCache { resetResultCache?: boolean; resetResultIdentities?: boolean; }): string[]; + // Warning: (ae-forgotten-export) The symbol "getInMemoryCacheStatus" needs to be exported by the entry point index.d.ts + // + // @internal + getCacheStatus?: typeof getInMemoryCacheStatus; // (undocumented) identify(object: StoreObject | Reference): string | undefined; // (undocumented) diff --git a/.api-reports/api-report-core.md b/.api-reports/api-report-core.md index 238a140efa8..f0a8ec80070 100644 --- a/.api-reports/api-report-core.md +++ b/.api-reports/api-report-core.md @@ -104,10 +104,10 @@ export class ApolloClient implements DataProxy { disableNetworkFetches: boolean; get documentTransform(): DocumentTransform; extract(optimistic?: boolean): TCacheShape; - // Warning: (ae-forgotten-export) The symbol "GetCacheStatus" needs to be exported by the entry point index.d.ts + // Warning: (ae-forgotten-export) The symbol "getApolloClientCacheStatus" needs to be exported by the entry point index.d.ts // // @internal - getCacheStatus?: GetCacheStatus; + getCacheStatus?: typeof getApolloClientCacheStatus; getObservableQueries(include?: RefetchQueriesInclude): Map>; getResolvers(): Resolvers; // (undocumented) @@ -215,6 +215,8 @@ interface ApolloErrorOptions { // @public (undocumented) export class ApolloLink { constructor(request?: RequestHandler); + // @internal + readonly cacheSize?: number; // (undocumented) static concat(first: ApolloLink | RequestHandler, second: ApolloLink | RequestHandler): ApolloLink; // (undocumented) @@ -225,13 +227,13 @@ export class ApolloLink { static execute(link: ApolloLink, operation: GraphQLRequest): Observable; // (undocumented) static from(links: (ApolloLink | RequestHandler)[]): ApolloLink; - // (undocumented) + // @internal readonly left?: ApolloLink; // (undocumented) protected onError(error: any, observer?: Observer): false | void; // (undocumented) request(operation: Operation, forward?: NextLink): Observable | null; - // (undocumented) + // @internal readonly right?: ApolloLink; // (undocumented) setOnError(fn: ApolloLink["onError"]): this; @@ -405,16 +407,6 @@ interface CacheSizes { queryManagerTransforms: number; } -// @public (undocumented) -type CacheStatus = { - limits: CacheSizes; - sizes: { - [K in keyof CacheSizes]?: number | number[]; - } & { - links?: number[]; - }; -}; - // @public (undocumented) const enum CacheWriteBehavior { // (undocumented) @@ -898,10 +890,60 @@ export function fromError(errorValue: any): Observable; // @public (undocumented) export function fromPromise(promise: Promise): Observable; -// Warning: (ae-forgotten-export) The symbol "CacheStatus" needs to be exported by the entry point index.d.ts +// Warning: (ae-forgotten-export) The symbol "_getApolloClientCacheStatus" needs to be exported by the entry point index.d.ts // +// @internal +const getApolloClientCacheStatus: typeof _getApolloClientCacheStatus | undefined; + // @public (undocumented) -type GetCacheStatus = (this: ApolloClient) => CacheStatus; +function _getApolloClientCacheStatus(this: ApolloClient): { + limits: CacheSizes; + sizes: { + global: { + print: number | undefined; + parser: number | undefined; + canonicalStringify: number | undefined; + }; + links: number[]; + queryManager: { + Transforms: number; + documentTransforms: number[]; + }; + cache: { + addTypenameTransform: number[]; + storeReader: { + executeSelectionSet: number | undefined; + executeSubSelectedArray: number | undefined; + }; + maybeBroadcastWatch: number | undefined; + fragmentRegistry: { + findFragmentSpreads: number | undefined; + lookup: number | undefined; + transform: number | undefined; + }; + } | undefined; + }; +}; + +// Warning: (ae-forgotten-export) The symbol "_getInMemoryCacheStatus" needs to be exported by the entry point index.d.ts +// +// @internal +const getInMemoryCacheStatus: typeof _getInMemoryCacheStatus | undefined; + +// @public (undocumented) +function _getInMemoryCacheStatus(this: InMemoryCache): { + addTypenameTransform: number[]; + storeReader: { + executeSelectionSet: number | undefined; + executeSubSelectedArray: number | undefined; + }; + maybeBroadcastWatch: number | undefined; + fragmentRegistry: { + findFragmentSpreads: number | undefined; + lookup: number | undefined; + transform: number | undefined; + }; +}; export { gql } @@ -1016,6 +1058,10 @@ export class InMemoryCache extends ApolloCache { resetResultCache?: boolean; resetResultIdentities?: boolean; }): string[]; + // Warning: (ae-forgotten-export) The symbol "getInMemoryCacheStatus" needs to be exported by the entry point index.d.ts + // + // @internal + getCacheStatus?: typeof getInMemoryCacheStatus; // (undocumented) identify(object: StoreObject | Reference): string | undefined; // (undocumented) @@ -2160,7 +2206,7 @@ interface WriteContext extends ReadMergeModifyContext { // src/core/QueryManager.ts:395:7 - (ae-forgotten-export) The symbol "UpdateQueries" needs to be exported by the entry point index.d.ts // src/core/watchQueryOptions.ts:253:2 - (ae-forgotten-export) The symbol "UpdateQueryFn" needs to be exported by the entry point index.d.ts // src/link/http/selectHttpOptionsAndBody.ts:128:32 - (ae-forgotten-export) The symbol "HttpQueryOptions" needs to be exported by the entry point index.d.ts -// src/utilities/caching/getCacheStatus.ts:12:3 - (ae-forgotten-export) The symbol "CacheSizes" needs to be exported by the entry point index.d.ts +// src/utilities/caching/getCacheStatus.ts:47:61 - (ae-forgotten-export) The symbol "CacheSizes" needs to be exported by the entry point index.d.ts // (No @packageDocumentation comment for this package) diff --git a/.api-reports/api-report-link_batch-http.md b/.api-reports/api-report-link_batch-http.md index d4cb14316a0..6b309b17a1c 100644 --- a/.api-reports/api-report-link_batch-http.md +++ b/.api-reports/api-report-link_batch-http.md @@ -14,6 +14,8 @@ import type { Observer } from 'zen-observable-ts'; // @public (undocumented) class ApolloLink { constructor(request?: RequestHandler); + // @internal + readonly cacheSize?: number; // (undocumented) static concat(first: ApolloLink | RequestHandler, second: ApolloLink | RequestHandler): ApolloLink; // (undocumented) @@ -29,7 +31,7 @@ class ApolloLink { // // (undocumented) static from(links: (ApolloLink | RequestHandler)[]): ApolloLink; - // (undocumented) + // @internal readonly left?: ApolloLink; // (undocumented) protected onError(error: any, observer?: Observer): false | void; @@ -37,7 +39,7 @@ class ApolloLink { // // (undocumented) request(operation: Operation, forward?: NextLink): Observable | null; - // (undocumented) + // @internal readonly right?: ApolloLink; // (undocumented) setOnError(fn: ApolloLink["onError"]): this; diff --git a/.api-reports/api-report-link_batch.md b/.api-reports/api-report-link_batch.md index 6de08659fe2..bf5b34b6217 100644 --- a/.api-reports/api-report-link_batch.md +++ b/.api-reports/api-report-link_batch.md @@ -13,6 +13,8 @@ import type { Observer } from 'zen-observable-ts'; // @public (undocumented) class ApolloLink { constructor(request?: RequestHandler); + // @internal + readonly cacheSize?: number; // (undocumented) static concat(first: ApolloLink | RequestHandler, second: ApolloLink | RequestHandler): ApolloLink; // (undocumented) @@ -28,7 +30,7 @@ class ApolloLink { // // (undocumented) static from(links: (ApolloLink | RequestHandler)[]): ApolloLink; - // (undocumented) + // @internal readonly left?: ApolloLink; // (undocumented) protected onError(error: any, observer?: Observer): false | void; @@ -36,7 +38,7 @@ class ApolloLink { // // (undocumented) request(operation: Operation, forward?: NextLink): Observable | null; - // (undocumented) + // @internal readonly right?: ApolloLink; // (undocumented) setOnError(fn: ApolloLink["onError"]): this; diff --git a/.api-reports/api-report-link_context.md b/.api-reports/api-report-link_context.md index 329edd2d086..da1be1cd478 100644 --- a/.api-reports/api-report-link_context.md +++ b/.api-reports/api-report-link_context.md @@ -13,6 +13,8 @@ import type { Observer } from 'zen-observable-ts'; // @public (undocumented) class ApolloLink { constructor(request?: RequestHandler); + // @internal + readonly cacheSize?: number; // (undocumented) static concat(first: ApolloLink | RequestHandler, second: ApolloLink | RequestHandler): ApolloLink; // (undocumented) @@ -28,7 +30,7 @@ class ApolloLink { // // (undocumented) static from(links: (ApolloLink | RequestHandler)[]): ApolloLink; - // (undocumented) + // @internal readonly left?: ApolloLink; // (undocumented) protected onError(error: any, observer?: Observer): false | void; @@ -36,7 +38,7 @@ class ApolloLink { // // (undocumented) request(operation: Operation, forward?: NextLink): Observable | null; - // (undocumented) + // @internal readonly right?: ApolloLink; // (undocumented) setOnError(fn: ApolloLink["onError"]): this; diff --git a/.api-reports/api-report-link_core.md b/.api-reports/api-report-link_core.md index 8c06830fb86..da49593b51c 100644 --- a/.api-reports/api-report-link_core.md +++ b/.api-reports/api-report-link_core.md @@ -13,6 +13,8 @@ import type { Observer } from 'zen-observable-ts'; // @public (undocumented) export class ApolloLink { constructor(request?: RequestHandler); + // @internal + readonly cacheSize?: number; // (undocumented) static concat(first: ApolloLink | RequestHandler, second: ApolloLink | RequestHandler): ApolloLink; // (undocumented) @@ -23,13 +25,13 @@ export class ApolloLink { static execute(link: ApolloLink, operation: GraphQLRequest): Observable; // (undocumented) static from(links: (ApolloLink | RequestHandler)[]): ApolloLink; - // (undocumented) + // @internal readonly left?: ApolloLink; // (undocumented) protected onError(error: any, observer?: Observer): false | void; // (undocumented) request(operation: Operation, forward?: NextLink): Observable | null; - // (undocumented) + // @internal readonly right?: ApolloLink; // (undocumented) setOnError(fn: ApolloLink["onError"]): this; diff --git a/.api-reports/api-report-link_error.md b/.api-reports/api-report-link_error.md index 2216b2190a1..186caf6958e 100644 --- a/.api-reports/api-report-link_error.md +++ b/.api-reports/api-report-link_error.md @@ -13,6 +13,8 @@ import type { Observer } from 'zen-observable-ts'; // @public (undocumented) class ApolloLink { constructor(request?: RequestHandler); + // @internal + readonly cacheSize?: number; // (undocumented) static concat(first: ApolloLink | RequestHandler, second: ApolloLink | RequestHandler): ApolloLink; // (undocumented) @@ -28,7 +30,7 @@ class ApolloLink { // // (undocumented) static from(links: (ApolloLink | RequestHandler)[]): ApolloLink; - // (undocumented) + // @internal readonly left?: ApolloLink; // (undocumented) protected onError(error: any, observer?: Observer): false | void; @@ -36,7 +38,7 @@ class ApolloLink { // // (undocumented) request(operation: Operation, forward?: NextLink): Observable | null; - // (undocumented) + // @internal readonly right?: ApolloLink; // (undocumented) setOnError(fn: ApolloLink["onError"]): this; diff --git a/.api-reports/api-report-link_http.md b/.api-reports/api-report-link_http.md index c13f0fa0a87..a40384874a6 100644 --- a/.api-reports/api-report-link_http.md +++ b/.api-reports/api-report-link_http.md @@ -15,6 +15,8 @@ import type { Observer } from 'zen-observable-ts'; // @public (undocumented) class ApolloLink { constructor(request?: RequestHandler); + // @internal + readonly cacheSize?: number; // (undocumented) static concat(first: ApolloLink | RequestHandler, second: ApolloLink | RequestHandler): ApolloLink; // (undocumented) @@ -30,7 +32,7 @@ class ApolloLink { // // (undocumented) static from(links: (ApolloLink | RequestHandler)[]): ApolloLink; - // (undocumented) + // @internal readonly left?: ApolloLink; // (undocumented) protected onError(error: any, observer?: Observer): false | void; @@ -38,7 +40,7 @@ class ApolloLink { // // (undocumented) request(operation: Operation, forward?: NextLink): Observable | null; - // (undocumented) + // @internal readonly right?: ApolloLink; // (undocumented) setOnError(fn: ApolloLink["onError"]): this; diff --git a/.api-reports/api-report-link_persisted-queries.md b/.api-reports/api-report-link_persisted-queries.md index f7ea3b4768a..db59134f2fe 100644 --- a/.api-reports/api-report-link_persisted-queries.md +++ b/.api-reports/api-report-link_persisted-queries.md @@ -13,6 +13,8 @@ import type { Observer } from 'zen-observable-ts'; // @public (undocumented) class ApolloLink { constructor(request?: RequestHandler); + // @internal + readonly cacheSize?: number; // (undocumented) static concat(first: ApolloLink | RequestHandler, second: ApolloLink | RequestHandler): ApolloLink; // (undocumented) @@ -28,7 +30,7 @@ class ApolloLink { // // (undocumented) static from(links: (ApolloLink | RequestHandler)[]): ApolloLink; - // (undocumented) + // @internal readonly left?: ApolloLink; // (undocumented) protected onError(error: any, observer?: Observer): false | void; @@ -36,7 +38,7 @@ class ApolloLink { // // (undocumented) request(operation: Operation, forward?: NextLink): Observable | null; - // (undocumented) + // @internal readonly right?: ApolloLink; // (undocumented) setOnError(fn: ApolloLink["onError"]): this; diff --git a/.api-reports/api-report-link_remove-typename.md b/.api-reports/api-report-link_remove-typename.md index 2fa733a42df..3f6c576133c 100644 --- a/.api-reports/api-report-link_remove-typename.md +++ b/.api-reports/api-report-link_remove-typename.md @@ -13,6 +13,8 @@ import type { Observer } from 'zen-observable-ts'; // @public (undocumented) class ApolloLink { constructor(request?: RequestHandler); + // @internal + readonly cacheSize?: number; // (undocumented) static concat(first: ApolloLink | RequestHandler, second: ApolloLink | RequestHandler): ApolloLink; // (undocumented) @@ -28,7 +30,7 @@ class ApolloLink { // // (undocumented) static from(links: (ApolloLink | RequestHandler)[]): ApolloLink; - // (undocumented) + // @internal readonly left?: ApolloLink; // (undocumented) protected onError(error: any, observer?: Observer): false | void; @@ -36,7 +38,7 @@ class ApolloLink { // // (undocumented) request(operation: Operation, forward?: NextLink): Observable | null; - // (undocumented) + // @internal readonly right?: ApolloLink; // (undocumented) setOnError(fn: ApolloLink["onError"]): this; diff --git a/.api-reports/api-report-link_retry.md b/.api-reports/api-report-link_retry.md index f4371cdc539..bc0689c5c47 100644 --- a/.api-reports/api-report-link_retry.md +++ b/.api-reports/api-report-link_retry.md @@ -13,6 +13,8 @@ import type { Observer } from 'zen-observable-ts'; // @public (undocumented) class ApolloLink { constructor(request?: RequestHandler); + // @internal + readonly cacheSize?: number; // (undocumented) static concat(first: ApolloLink | RequestHandler, second: ApolloLink | RequestHandler): ApolloLink; // (undocumented) @@ -28,7 +30,7 @@ class ApolloLink { // // (undocumented) static from(links: (ApolloLink | RequestHandler)[]): ApolloLink; - // (undocumented) + // @internal readonly left?: ApolloLink; // (undocumented) protected onError(error: any, observer?: Observer): false | void; @@ -36,7 +38,7 @@ class ApolloLink { // // (undocumented) request(operation: Operation, forward?: NextLink): Observable | null; - // (undocumented) + // @internal readonly right?: ApolloLink; // (undocumented) setOnError(fn: ApolloLink["onError"]): this; diff --git a/.api-reports/api-report-link_schema.md b/.api-reports/api-report-link_schema.md index 8e23b7757ac..ef56668ec7d 100644 --- a/.api-reports/api-report-link_schema.md +++ b/.api-reports/api-report-link_schema.md @@ -14,6 +14,8 @@ import type { Observer } from 'zen-observable-ts'; // @public (undocumented) class ApolloLink { constructor(request?: RequestHandler); + // @internal + readonly cacheSize?: number; // (undocumented) static concat(first: ApolloLink | RequestHandler, second: ApolloLink | RequestHandler): ApolloLink; // (undocumented) @@ -29,7 +31,7 @@ class ApolloLink { // // (undocumented) static from(links: (ApolloLink | RequestHandler)[]): ApolloLink; - // (undocumented) + // @internal readonly left?: ApolloLink; // (undocumented) protected onError(error: any, observer?: Observer): false | void; @@ -37,7 +39,7 @@ class ApolloLink { // // (undocumented) request(operation: Operation, forward?: NextLink): Observable | null; - // (undocumented) + // @internal readonly right?: ApolloLink; // (undocumented) setOnError(fn: ApolloLink["onError"]): this; diff --git a/.api-reports/api-report-link_subscriptions.md b/.api-reports/api-report-link_subscriptions.md index 962d9f09795..359060696d1 100644 --- a/.api-reports/api-report-link_subscriptions.md +++ b/.api-reports/api-report-link_subscriptions.md @@ -14,6 +14,8 @@ import type { Observer } from 'zen-observable-ts'; // @public (undocumented) class ApolloLink { constructor(request?: RequestHandler); + // @internal + readonly cacheSize?: number; // (undocumented) static concat(first: ApolloLink | RequestHandler, second: ApolloLink | RequestHandler): ApolloLink; // (undocumented) @@ -29,7 +31,7 @@ class ApolloLink { // // (undocumented) static from(links: (ApolloLink | RequestHandler)[]): ApolloLink; - // (undocumented) + // @internal readonly left?: ApolloLink; // (undocumented) protected onError(error: any, observer?: Observer): false | void; @@ -37,7 +39,7 @@ class ApolloLink { // // (undocumented) request(operation: Operation, forward?: NextLink): Observable | null; - // (undocumented) + // @internal readonly right?: ApolloLink; // (undocumented) setOnError(fn: ApolloLink["onError"]): this; diff --git a/.api-reports/api-report-link_ws.md b/.api-reports/api-report-link_ws.md index f16ccd6d700..79ae349e6f8 100644 --- a/.api-reports/api-report-link_ws.md +++ b/.api-reports/api-report-link_ws.md @@ -15,6 +15,8 @@ import { SubscriptionClient } from 'subscriptions-transport-ws'; // @public (undocumented) class ApolloLink { constructor(request?: RequestHandler); + // @internal + readonly cacheSize?: number; // (undocumented) static concat(first: ApolloLink | RequestHandler, second: ApolloLink | RequestHandler): ApolloLink; // (undocumented) @@ -30,7 +32,7 @@ class ApolloLink { // // (undocumented) static from(links: (ApolloLink | RequestHandler)[]): ApolloLink; - // (undocumented) + // @internal readonly left?: ApolloLink; // (undocumented) protected onError(error: any, observer?: Observer): false | void; @@ -38,7 +40,7 @@ class ApolloLink { // // (undocumented) request(operation: Operation, forward?: NextLink): Observable | null; - // (undocumented) + // @internal readonly right?: ApolloLink; // (undocumented) setOnError(fn: ApolloLink["onError"]): this; diff --git a/.api-reports/api-report-react.md b/.api-reports/api-report-react.md index f972a412a77..92e738c156c 100644 --- a/.api-reports/api-report-react.md +++ b/.api-reports/api-report-react.md @@ -115,10 +115,10 @@ class ApolloClient implements DataProxy { // Warning: (ae-forgotten-export) The symbol "DocumentTransform" needs to be exported by the entry point index.d.ts get documentTransform(): DocumentTransform; extract(optimistic?: boolean): TCacheShape; - // Warning: (ae-forgotten-export) The symbol "GetCacheStatus" needs to be exported by the entry point index.d.ts + // Warning: (ae-forgotten-export) The symbol "getApolloClientCacheStatus" needs to be exported by the entry point index.d.ts // // @internal - getCacheStatus?: GetCacheStatus; + getCacheStatus?: typeof getApolloClientCacheStatus; // Warning: (ae-forgotten-export) The symbol "RefetchQueriesInclude" needs to be exported by the entry point index.d.ts getObservableQueries(include?: RefetchQueriesInclude): Map>; getResolvers(): Resolvers; @@ -273,6 +273,8 @@ interface ApolloErrorOptions { // @public (undocumented) class ApolloLink { constructor(request?: RequestHandler); + // @internal + readonly cacheSize?: number; // (undocumented) static concat(first: ApolloLink | RequestHandler, second: ApolloLink | RequestHandler): ApolloLink; // (undocumented) @@ -285,7 +287,7 @@ class ApolloLink { // // (undocumented) static from(links: (ApolloLink | RequestHandler)[]): ApolloLink; - // (undocumented) + // @internal readonly left?: ApolloLink; // (undocumented) protected onError(error: any, observer?: Observer): false | void; @@ -293,7 +295,7 @@ class ApolloLink { // // (undocumented) request(operation: Operation, forward?: NextLink): Observable | null; - // (undocumented) + // @internal readonly right?: ApolloLink; // (undocumented) setOnError(fn: ApolloLink["onError"]): this; @@ -515,16 +517,6 @@ interface CacheSizes { queryManagerTransforms: number; } -// @public (undocumented) -type CacheStatus = { - limits: CacheSizes; - sizes: { - [K in keyof CacheSizes]?: number | number[]; - } & { - links?: number[]; - }; -}; - // @public (undocumented) const enum CacheWriteBehavior { // (undocumented) @@ -853,13 +845,43 @@ interface FulfilledPromise extends Promise { value: TValue; } +// Warning: (ae-forgotten-export) The symbol "_getApolloClientCacheStatus" needs to be exported by the entry point index.d.ts +// +// @internal +const getApolloClientCacheStatus: typeof _getApolloClientCacheStatus | undefined; + // @public (undocumented) -export function getApolloContext(): ReactTypes.Context; +function _getApolloClientCacheStatus(this: ApolloClient): { + limits: CacheSizes; + sizes: { + global: { + print: number | undefined; + parser: number | undefined; + canonicalStringify: number | undefined; + }; + links: number[]; + queryManager: { + Transforms: number; + documentTransforms: number[]; + }; + cache: { + addTypenameTransform: number[]; + storeReader: { + executeSelectionSet: number | undefined; + executeSubSelectedArray: number | undefined; + }; + maybeBroadcastWatch: number | undefined; + fragmentRegistry: { + findFragmentSpreads: number | undefined; + lookup: number | undefined; + transform: number | undefined; + }; + } | undefined; + }; +}; -// Warning: (ae-forgotten-export) The symbol "CacheStatus" needs to be exported by the entry point index.d.ts -// // @public (undocumented) -type GetCacheStatus = (this: ApolloClient) => CacheStatus; +export function getApolloContext(): ReactTypes.Context; // @public (undocumented) type GraphQLErrors = ReadonlyArray; @@ -2303,7 +2325,7 @@ interface WatchQueryOptions implements DataProxy { // Warning: (ae-forgotten-export) The symbol "DocumentTransform" needs to be exported by the entry point index.d.ts get documentTransform(): DocumentTransform; extract(optimistic?: boolean): TCacheShape; - // Warning: (ae-forgotten-export) The symbol "GetCacheStatus" needs to be exported by the entry point index.d.ts + // Warning: (ae-forgotten-export) The symbol "getApolloClientCacheStatus" needs to be exported by the entry point index.d.ts // // @internal - getCacheStatus?: GetCacheStatus; + getCacheStatus?: typeof getApolloClientCacheStatus; // Warning: (ae-forgotten-export) The symbol "RefetchQueriesInclude" needs to be exported by the entry point index.d.ts getObservableQueries(include?: RefetchQueriesInclude): Map>; getResolvers(): Resolvers; @@ -251,6 +251,8 @@ interface ApolloErrorOptions { // @public (undocumented) class ApolloLink { constructor(request?: RequestHandler); + // @internal + readonly cacheSize?: number; // (undocumented) static concat(first: ApolloLink | RequestHandler, second: ApolloLink | RequestHandler): ApolloLink; // (undocumented) @@ -263,7 +265,7 @@ class ApolloLink { // // (undocumented) static from(links: (ApolloLink | RequestHandler)[]): ApolloLink; - // (undocumented) + // @internal readonly left?: ApolloLink; // (undocumented) protected onError(error: any, observer?: Observer): false | void; @@ -271,7 +273,7 @@ class ApolloLink { // // (undocumented) request(operation: Operation, forward?: NextLink): Observable | null; - // (undocumented) + // @internal readonly right?: ApolloLink; // (undocumented) setOnError(fn: ApolloLink["onError"]): this; @@ -468,16 +470,6 @@ interface CacheSizes { queryManagerTransforms: number; } -// @public (undocumented) -type CacheStatus = { - limits: CacheSizes; - sizes: { - [K in keyof CacheSizes]?: number | number[]; - } & { - links?: number[]; - }; -}; - // @public (undocumented) const enum CacheWriteBehavior { // (undocumented) @@ -735,10 +727,40 @@ interface FragmentMap { // @public (undocumented) type FragmentMatcher = (rootValue: any, typeCondition: string, context: any) => boolean; -// Warning: (ae-forgotten-export) The symbol "CacheStatus" needs to be exported by the entry point index.d.ts +// Warning: (ae-forgotten-export) The symbol "_getApolloClientCacheStatus" needs to be exported by the entry point index.d.ts // +// @internal +const getApolloClientCacheStatus: typeof _getApolloClientCacheStatus | undefined; + // @public (undocumented) -type GetCacheStatus = (this: ApolloClient) => CacheStatus; +function _getApolloClientCacheStatus(this: ApolloClient): { + limits: CacheSizes; + sizes: { + global: { + print: number | undefined; + parser: number | undefined; + canonicalStringify: number | undefined; + }; + links: number[]; + queryManager: { + Transforms: number; + documentTransforms: number[]; + }; + cache: { + addTypenameTransform: number[]; + storeReader: { + executeSelectionSet: number | undefined; + executeSubSelectedArray: number | undefined; + }; + maybeBroadcastWatch: number | undefined; + fragmentRegistry: { + findFragmentSpreads: number | undefined; + lookup: number | undefined; + transform: number | undefined; + }; + } | undefined; + }; +}; // @public (undocumented) type GraphQLErrors = ReadonlyArray; @@ -1729,7 +1751,7 @@ interface WatchQueryOptions implements DataProxy { // Warning: (ae-forgotten-export) The symbol "DocumentTransform" needs to be exported by the entry point index.d.ts get documentTransform(): DocumentTransform; extract(optimistic?: boolean): TCacheShape; - // Warning: (ae-forgotten-export) The symbol "GetCacheStatus" needs to be exported by the entry point index.d.ts + // Warning: (ae-forgotten-export) The symbol "getApolloClientCacheStatus" needs to be exported by the entry point index.d.ts // // @internal - getCacheStatus?: GetCacheStatus; + getCacheStatus?: typeof getApolloClientCacheStatus; // Warning: (ae-forgotten-export) The symbol "RefetchQueriesInclude" needs to be exported by the entry point index.d.ts getObservableQueries(include?: RefetchQueriesInclude): Map>; getResolvers(): Resolvers; @@ -271,6 +271,8 @@ interface ApolloErrorOptions { // @public (undocumented) class ApolloLink { constructor(request?: RequestHandler); + // @internal + readonly cacheSize?: number; // (undocumented) static concat(first: ApolloLink | RequestHandler, second: ApolloLink | RequestHandler): ApolloLink; // (undocumented) @@ -283,7 +285,7 @@ class ApolloLink { // // (undocumented) static from(links: (ApolloLink | RequestHandler)[]): ApolloLink; - // (undocumented) + // @internal readonly left?: ApolloLink; // (undocumented) protected onError(error: any, observer?: Observer): false | void; @@ -291,7 +293,7 @@ class ApolloLink { // // (undocumented) request(operation: Operation, forward?: NextLink): Observable | null; - // (undocumented) + // @internal readonly right?: ApolloLink; // (undocumented) setOnError(fn: ApolloLink["onError"]): this; @@ -451,16 +453,6 @@ interface CacheSizes { queryManagerTransforms: number; } -// @public (undocumented) -type CacheStatus = { - limits: CacheSizes; - sizes: { - [K in keyof CacheSizes]?: number | number[]; - } & { - links?: number[]; - }; -}; - // @public (undocumented) const enum CacheWriteBehavior { // (undocumented) @@ -718,13 +710,43 @@ interface FragmentMap { // @public (undocumented) type FragmentMatcher = (rootValue: any, typeCondition: string, context: any) => boolean; +// Warning: (ae-forgotten-export) The symbol "_getApolloClientCacheStatus" needs to be exported by the entry point index.d.ts +// +// @internal +const getApolloClientCacheStatus: typeof _getApolloClientCacheStatus | undefined; + // @public (undocumented) -export function getApolloContext(): ReactTypes.Context; +function _getApolloClientCacheStatus(this: ApolloClient): { + limits: CacheSizes; + sizes: { + global: { + print: number | undefined; + parser: number | undefined; + canonicalStringify: number | undefined; + }; + links: number[]; + queryManager: { + Transforms: number; + documentTransforms: number[]; + }; + cache: { + addTypenameTransform: number[]; + storeReader: { + executeSelectionSet: number | undefined; + executeSubSelectedArray: number | undefined; + }; + maybeBroadcastWatch: number | undefined; + fragmentRegistry: { + findFragmentSpreads: number | undefined; + lookup: number | undefined; + transform: number | undefined; + }; + } | undefined; + }; +}; -// Warning: (ae-forgotten-export) The symbol "CacheStatus" needs to be exported by the entry point index.d.ts -// // @public (undocumented) -type GetCacheStatus = (this: ApolloClient) => CacheStatus; +export function getApolloContext(): ReactTypes.Context; // @public (undocumented) type GraphQLErrors = ReadonlyArray; @@ -1625,7 +1647,7 @@ interface WatchQueryOptions implements DataProxy { // Warning: (ae-forgotten-export) The symbol "DocumentTransform" needs to be exported by the entry point index.d.ts get documentTransform(): DocumentTransform; extract(optimistic?: boolean): TCacheShape; - // Warning: (ae-forgotten-export) The symbol "GetCacheStatus" needs to be exported by the entry point index.d.ts + // Warning: (ae-forgotten-export) The symbol "getApolloClientCacheStatus" needs to be exported by the entry point index.d.ts // // @internal - getCacheStatus?: GetCacheStatus; + getCacheStatus?: typeof getApolloClientCacheStatus; // Warning: (ae-forgotten-export) The symbol "RefetchQueriesInclude" needs to be exported by the entry point index.d.ts getObservableQueries(include?: RefetchQueriesInclude): Map>; getResolvers(): Resolvers; @@ -250,6 +250,8 @@ interface ApolloErrorOptions { // @public (undocumented) class ApolloLink { constructor(request?: RequestHandler); + // @internal + readonly cacheSize?: number; // (undocumented) static concat(first: ApolloLink | RequestHandler, second: ApolloLink | RequestHandler): ApolloLink; // (undocumented) @@ -262,7 +264,7 @@ class ApolloLink { // // (undocumented) static from(links: (ApolloLink | RequestHandler)[]): ApolloLink; - // (undocumented) + // @internal readonly left?: ApolloLink; // (undocumented) protected onError(error: any, observer?: Observer): false | void; @@ -270,7 +272,7 @@ class ApolloLink { // // (undocumented) request(operation: Operation, forward?: NextLink): Observable | null; - // (undocumented) + // @internal readonly right?: ApolloLink; // (undocumented) setOnError(fn: ApolloLink["onError"]): this; @@ -435,16 +437,6 @@ interface CacheSizes { queryManagerTransforms: number; } -// @public (undocumented) -type CacheStatus = { - limits: CacheSizes; - sizes: { - [K in keyof CacheSizes]?: number | number[]; - } & { - links?: number[]; - }; -}; - // @public (undocumented) const enum CacheWriteBehavior { // (undocumented) @@ -729,10 +721,40 @@ interface FragmentMap { // @public (undocumented) type FragmentMatcher = (rootValue: any, typeCondition: string, context: any) => boolean; -// Warning: (ae-forgotten-export) The symbol "CacheStatus" needs to be exported by the entry point index.d.ts +// Warning: (ae-forgotten-export) The symbol "_getApolloClientCacheStatus" needs to be exported by the entry point index.d.ts // +// @internal +const getApolloClientCacheStatus: typeof _getApolloClientCacheStatus | undefined; + // @public (undocumented) -type GetCacheStatus = (this: ApolloClient) => CacheStatus; +function _getApolloClientCacheStatus(this: ApolloClient): { + limits: CacheSizes; + sizes: { + global: { + print: number | undefined; + parser: number | undefined; + canonicalStringify: number | undefined; + }; + links: number[]; + queryManager: { + Transforms: number; + documentTransforms: number[]; + }; + cache: { + addTypenameTransform: number[]; + storeReader: { + executeSelectionSet: number | undefined; + executeSubSelectedArray: number | undefined; + }; + maybeBroadcastWatch: number | undefined; + fragmentRegistry: { + findFragmentSpreads: number | undefined; + lookup: number | undefined; + transform: number | undefined; + }; + } | undefined; + }; +}; // @public (undocumented) export function graphql> & Partial>>(document: DocumentNode, operationOptions?: OperationOption): (WrappedComponent: ReactTypes.ComponentType) => ReactTypes.ComponentClass; @@ -1670,7 +1692,7 @@ export function withSubscription implements DataProxy { // Warning: (ae-forgotten-export) The symbol "DocumentTransform" needs to be exported by the entry point index.d.ts get documentTransform(): DocumentTransform; extract(optimistic?: boolean): TCacheShape; - // Warning: (ae-forgotten-export) The symbol "GetCacheStatus" needs to be exported by the entry point index.d.ts + // Warning: (ae-forgotten-export) The symbol "getApolloClientCacheStatus" needs to be exported by the entry point index.d.ts // // @internal - getCacheStatus?: GetCacheStatus; + getCacheStatus?: typeof getApolloClientCacheStatus; // Warning: (ae-forgotten-export) The symbol "RefetchQueriesInclude" needs to be exported by the entry point index.d.ts getObservableQueries(include?: RefetchQueriesInclude): Map>; getResolvers(): Resolvers; @@ -249,6 +249,8 @@ interface ApolloErrorOptions { // @public (undocumented) class ApolloLink { constructor(request?: RequestHandler); + // @internal + readonly cacheSize?: number; // (undocumented) static concat(first: ApolloLink | RequestHandler, second: ApolloLink | RequestHandler): ApolloLink; // (undocumented) @@ -261,7 +263,7 @@ class ApolloLink { // // (undocumented) static from(links: (ApolloLink | RequestHandler)[]): ApolloLink; - // (undocumented) + // @internal readonly left?: ApolloLink; // (undocumented) protected onError(error: any, observer?: Observer): false | void; @@ -269,7 +271,7 @@ class ApolloLink { // // (undocumented) request(operation: Operation, forward?: NextLink): Observable | null; - // (undocumented) + // @internal readonly right?: ApolloLink; // (undocumented) setOnError(fn: ApolloLink["onError"]): this; @@ -491,16 +493,6 @@ interface CacheSizes { queryManagerTransforms: number; } -// @public (undocumented) -type CacheStatus = { - limits: CacheSizes; - sizes: { - [K in keyof CacheSizes]?: number | number[]; - } & { - links?: number[]; - }; -}; - // @public (undocumented) const enum CacheWriteBehavior { // (undocumented) @@ -813,10 +805,40 @@ interface FulfilledPromise extends Promise { value: TValue; } -// Warning: (ae-forgotten-export) The symbol "CacheStatus" needs to be exported by the entry point index.d.ts +// Warning: (ae-forgotten-export) The symbol "_getApolloClientCacheStatus" needs to be exported by the entry point index.d.ts // +// @internal +const getApolloClientCacheStatus: typeof _getApolloClientCacheStatus | undefined; + // @public (undocumented) -type GetCacheStatus = (this: ApolloClient) => CacheStatus; +function _getApolloClientCacheStatus(this: ApolloClient): { + limits: CacheSizes; + sizes: { + global: { + print: number | undefined; + parser: number | undefined; + canonicalStringify: number | undefined; + }; + links: number[]; + queryManager: { + Transforms: number; + documentTransforms: number[]; + }; + cache: { + addTypenameTransform: number[]; + storeReader: { + executeSelectionSet: number | undefined; + executeSubSelectedArray: number | undefined; + }; + maybeBroadcastWatch: number | undefined; + fragmentRegistry: { + findFragmentSpreads: number | undefined; + lookup: number | undefined; + transform: number | undefined; + }; + } | undefined; + }; +}; // @public (undocumented) type GraphQLErrors = ReadonlyArray; @@ -2194,7 +2216,7 @@ interface WatchQueryOptions implements DataProxy { // Warning: (ae-forgotten-export) The symbol "DocumentTransform" needs to be exported by the entry point index.d.ts get documentTransform(): DocumentTransform; extract(optimistic?: boolean): TCacheShape; - // Warning: (ae-forgotten-export) The symbol "GetCacheStatus" needs to be exported by the entry point index.d.ts + // Warning: (ae-forgotten-export) The symbol "getApolloClientCacheStatus" needs to be exported by the entry point index.d.ts // // @internal - getCacheStatus?: GetCacheStatus; + getCacheStatus?: typeof getApolloClientCacheStatus; // Warning: (ae-forgotten-export) The symbol "RefetchQueriesInclude" needs to be exported by the entry point index.d.ts getObservableQueries(include?: RefetchQueriesInclude): Map>; getResolvers(): Resolvers; @@ -250,6 +250,8 @@ interface ApolloErrorOptions { // @public (undocumented) class ApolloLink { constructor(request?: RequestHandler); + // @internal + readonly cacheSize?: number; // (undocumented) static concat(first: ApolloLink | RequestHandler, second: ApolloLink | RequestHandler): ApolloLink; // (undocumented) @@ -262,7 +264,7 @@ class ApolloLink { // // (undocumented) static from(links: (ApolloLink | RequestHandler)[]): ApolloLink; - // (undocumented) + // @internal readonly left?: ApolloLink; // (undocumented) protected onError(error: any, observer?: Observer): false | void; @@ -270,7 +272,7 @@ class ApolloLink { // // (undocumented) request(operation: Operation, forward?: NextLink): Observable | null; - // (undocumented) + // @internal readonly right?: ApolloLink; // (undocumented) setOnError(fn: ApolloLink["onError"]): this; @@ -421,16 +423,6 @@ interface CacheSizes { queryManagerTransforms: number; } -// @public (undocumented) -type CacheStatus = { - limits: CacheSizes; - sizes: { - [K in keyof CacheSizes]?: number | number[]; - } & { - links?: number[]; - }; -}; - // @public (undocumented) const enum CacheWriteBehavior { // (undocumented) @@ -688,10 +680,40 @@ interface FragmentMap { // @public (undocumented) type FragmentMatcher = (rootValue: any, typeCondition: string, context: any) => boolean; -// Warning: (ae-forgotten-export) The symbol "CacheStatus" needs to be exported by the entry point index.d.ts +// Warning: (ae-forgotten-export) The symbol "_getApolloClientCacheStatus" needs to be exported by the entry point index.d.ts // +// @internal +const getApolloClientCacheStatus: typeof _getApolloClientCacheStatus | undefined; + // @public (undocumented) -type GetCacheStatus = (this: ApolloClient) => CacheStatus; +function _getApolloClientCacheStatus(this: ApolloClient): { + limits: CacheSizes; + sizes: { + global: { + print: number | undefined; + parser: number | undefined; + canonicalStringify: number | undefined; + }; + links: number[]; + queryManager: { + Transforms: number; + documentTransforms: number[]; + }; + cache: { + addTypenameTransform: number[]; + storeReader: { + executeSelectionSet: number | undefined; + executeSubSelectedArray: number | undefined; + }; + maybeBroadcastWatch: number | undefined; + fragmentRegistry: { + findFragmentSpreads: number | undefined; + lookup: number | undefined; + transform: number | undefined; + }; + } | undefined; + }; +}; // @public (undocumented) export function getDataFromTree(tree: ReactTypes.ReactNode, context?: { @@ -1611,7 +1633,7 @@ interface WatchQueryOptions implements DataProxy { // Warning: (ae-forgotten-export) The symbol "DocumentTransform" needs to be exported by the entry point index.d.ts get documentTransform(): DocumentTransform; extract(optimistic?: boolean): TCacheShape; - // Warning: (ae-forgotten-export) The symbol "GetCacheStatus" needs to be exported by the entry point index.d.ts + // Warning: (ae-forgotten-export) The symbol "getApolloClientCacheStatus" needs to be exported by the entry point index.d.ts // // @internal - getCacheStatus?: GetCacheStatus; + getCacheStatus?: typeof getApolloClientCacheStatus; // Warning: (ae-forgotten-export) The symbol "RefetchQueriesInclude" needs to be exported by the entry point index.d.ts getObservableQueries(include?: RefetchQueriesInclude): Map>; getResolvers(): Resolvers; @@ -250,6 +250,8 @@ interface ApolloErrorOptions { // @public (undocumented) class ApolloLink { constructor(request?: RequestHandler); + // @internal + readonly cacheSize?: number; // (undocumented) static concat(first: ApolloLink | RequestHandler, second: ApolloLink | RequestHandler): ApolloLink; // (undocumented) @@ -262,7 +264,7 @@ class ApolloLink { // // (undocumented) static from(links: (ApolloLink | RequestHandler)[]): ApolloLink; - // (undocumented) + // @internal readonly left?: ApolloLink; // (undocumented) protected onError(error: any, observer?: Observer): false | void; @@ -270,7 +272,7 @@ class ApolloLink { // // (undocumented) request(operation: Operation, forward?: NextLink): Observable | null; - // (undocumented) + // @internal readonly right?: ApolloLink; // (undocumented) setOnError(fn: ApolloLink["onError"]): this; @@ -409,16 +411,6 @@ interface CacheSizes { queryManagerTransforms: number; } -// @public (undocumented) -type CacheStatus = { - limits: CacheSizes; - sizes: { - [K in keyof CacheSizes]?: number | number[]; - } & { - links?: number[]; - }; -}; - // @public (undocumented) const enum CacheWriteBehavior { // (undocumented) @@ -682,10 +674,40 @@ interface FragmentMap { // @public (undocumented) type FragmentMatcher = (rootValue: any, typeCondition: string, context: any) => boolean; -// Warning: (ae-forgotten-export) The symbol "CacheStatus" needs to be exported by the entry point index.d.ts +// Warning: (ae-forgotten-export) The symbol "_getApolloClientCacheStatus" needs to be exported by the entry point index.d.ts // +// @internal +const getApolloClientCacheStatus: typeof _getApolloClientCacheStatus | undefined; + // @public (undocumented) -type GetCacheStatus = (this: ApolloClient) => CacheStatus; +function _getApolloClientCacheStatus(this: ApolloClient): { + limits: CacheSizes; + sizes: { + global: { + print: number | undefined; + parser: number | undefined; + canonicalStringify: number | undefined; + }; + links: number[]; + queryManager: { + Transforms: number; + documentTransforms: number[]; + }; + cache: { + addTypenameTransform: number[]; + storeReader: { + executeSelectionSet: number | undefined; + executeSubSelectedArray: number | undefined; + }; + maybeBroadcastWatch: number | undefined; + fragmentRegistry: { + findFragmentSpreads: number | undefined; + lookup: number | undefined; + transform: number | undefined; + }; + } | undefined; + }; +}; // @public (undocumented) type GraphQLErrors = ReadonlyArray; @@ -1673,7 +1695,7 @@ export function withWarningSpy(it: (...args: TArgs // src/core/types.ts:174:3 - (ae-forgotten-export) The symbol "MutationQueryReducer" needs to be exported by the entry point index.d.ts // src/core/types.ts:201:5 - (ae-forgotten-export) The symbol "Resolver" needs to be exported by the entry point index.d.ts // src/core/watchQueryOptions.ts:253:2 - (ae-forgotten-export) The symbol "UpdateQueryFn" needs to be exported by the entry point index.d.ts -// src/utilities/caching/getCacheStatus.ts:12:3 - (ae-forgotten-export) The symbol "CacheSizes" needs to be exported by the entry point index.d.ts +// src/utilities/caching/getCacheStatus.ts:47:61 - (ae-forgotten-export) The symbol "CacheSizes" 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 56d2da2cbf9..b4b478df0ce 100644 --- a/.api-reports/api-report-testing_core.md +++ b/.api-reports/api-report-testing_core.md @@ -113,10 +113,10 @@ class ApolloClient implements DataProxy { // Warning: (ae-forgotten-export) The symbol "DocumentTransform" needs to be exported by the entry point index.d.ts get documentTransform(): DocumentTransform; extract(optimistic?: boolean): TCacheShape; - // Warning: (ae-forgotten-export) The symbol "GetCacheStatus" needs to be exported by the entry point index.d.ts + // Warning: (ae-forgotten-export) The symbol "getApolloClientCacheStatus" needs to be exported by the entry point index.d.ts // // @internal - getCacheStatus?: GetCacheStatus; + getCacheStatus?: typeof getApolloClientCacheStatus; // Warning: (ae-forgotten-export) The symbol "RefetchQueriesInclude" needs to be exported by the entry point index.d.ts getObservableQueries(include?: RefetchQueriesInclude): Map>; getResolvers(): Resolvers; @@ -249,6 +249,8 @@ interface ApolloErrorOptions { // @public (undocumented) class ApolloLink { constructor(request?: RequestHandler); + // @internal + readonly cacheSize?: number; // (undocumented) static concat(first: ApolloLink | RequestHandler, second: ApolloLink | RequestHandler): ApolloLink; // (undocumented) @@ -261,7 +263,7 @@ class ApolloLink { // // (undocumented) static from(links: (ApolloLink | RequestHandler)[]): ApolloLink; - // (undocumented) + // @internal readonly left?: ApolloLink; // (undocumented) protected onError(error: any, observer?: Observer): false | void; @@ -269,7 +271,7 @@ class ApolloLink { // // (undocumented) request(operation: Operation, forward?: NextLink): Observable | null; - // (undocumented) + // @internal readonly right?: ApolloLink; // (undocumented) setOnError(fn: ApolloLink["onError"]): this; @@ -408,16 +410,6 @@ interface CacheSizes { queryManagerTransforms: number; } -// @public (undocumented) -type CacheStatus = { - limits: CacheSizes; - sizes: { - [K in keyof CacheSizes]?: number | number[]; - } & { - links?: number[]; - }; -}; - // @public (undocumented) const enum CacheWriteBehavior { // (undocumented) @@ -681,10 +673,40 @@ interface FragmentMap { // @public (undocumented) type FragmentMatcher = (rootValue: any, typeCondition: string, context: any) => boolean; -// Warning: (ae-forgotten-export) The symbol "CacheStatus" needs to be exported by the entry point index.d.ts +// Warning: (ae-forgotten-export) The symbol "_getApolloClientCacheStatus" needs to be exported by the entry point index.d.ts // +// @internal +const getApolloClientCacheStatus: typeof _getApolloClientCacheStatus | undefined; + // @public (undocumented) -type GetCacheStatus = (this: ApolloClient) => CacheStatus; +function _getApolloClientCacheStatus(this: ApolloClient): { + limits: CacheSizes; + sizes: { + global: { + print: number | undefined; + parser: number | undefined; + canonicalStringify: number | undefined; + }; + links: number[]; + queryManager: { + Transforms: number; + documentTransforms: number[]; + }; + cache: { + addTypenameTransform: number[]; + storeReader: { + executeSelectionSet: number | undefined; + executeSubSelectedArray: number | undefined; + }; + maybeBroadcastWatch: number | undefined; + fragmentRegistry: { + findFragmentSpreads: number | undefined; + lookup: number | undefined; + transform: number | undefined; + }; + } | undefined; + }; +}; // @public (undocumented) type GraphQLErrors = ReadonlyArray; @@ -1630,7 +1652,7 @@ export function withWarningSpy(it: (...args: TArgs // src/core/types.ts:174:3 - (ae-forgotten-export) The symbol "MutationQueryReducer" needs to be exported by the entry point index.d.ts // src/core/types.ts:201:5 - (ae-forgotten-export) The symbol "Resolver" needs to be exported by the entry point index.d.ts // src/core/watchQueryOptions.ts:253:2 - (ae-forgotten-export) The symbol "UpdateQueryFn" needs to be exported by the entry point index.d.ts -// src/utilities/caching/getCacheStatus.ts:12:3 - (ae-forgotten-export) The symbol "CacheSizes" needs to be exported by the entry point index.d.ts +// src/utilities/caching/getCacheStatus.ts:47:61 - (ae-forgotten-export) The symbol "CacheSizes" 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 5cfcb5afada..1d7e98caa59 100644 --- a/.api-reports/api-report-utilities.md +++ b/.api-reports/api-report-utilities.md @@ -126,10 +126,10 @@ class ApolloClient implements DataProxy { disableNetworkFetches: boolean; get documentTransform(): DocumentTransform; extract(optimistic?: boolean): TCacheShape; - // Warning: (ae-forgotten-export) The symbol "GetCacheStatus" needs to be exported by the entry point index.d.ts + // Warning: (ae-forgotten-export) The symbol "getApolloClientCacheStatus" needs to be exported by the entry point index.d.ts // // @internal - getCacheStatus?: GetCacheStatus; + getCacheStatus?: typeof getApolloClientCacheStatus; // Warning: (ae-forgotten-export) The symbol "RefetchQueriesInclude" needs to be exported by the entry point index.d.ts getObservableQueries(include?: RefetchQueriesInclude): Map>; getResolvers(): Resolvers; @@ -262,6 +262,8 @@ interface ApolloErrorOptions { // @public (undocumented) class ApolloLink { constructor(request?: RequestHandler); + // @internal + readonly cacheSize?: number; // (undocumented) static concat(first: ApolloLink | RequestHandler, second: ApolloLink | RequestHandler): ApolloLink; // (undocumented) @@ -274,7 +276,7 @@ class ApolloLink { // // (undocumented) static from(links: (ApolloLink | RequestHandler)[]): ApolloLink; - // (undocumented) + // @internal readonly left?: ApolloLink; // (undocumented) protected onError(error: any, observer?: Observer): false | void; @@ -282,7 +284,7 @@ class ApolloLink { // // (undocumented) request(operation: Operation, forward?: NextLink): Observable | null; - // (undocumented) + // @internal readonly right?: ApolloLink; // (undocumented) setOnError(fn: ApolloLink["onError"]): this; @@ -472,16 +474,6 @@ interface CacheSizes { // @public export const cacheSizes: CacheSizes; -// @public (undocumented) -type CacheStatus = { - limits: CacheSizes; - sizes: { - [K in keyof CacheSizes]?: number | number[]; - } & { - links?: number[]; - }; -}; - // @public (undocumented) const enum CacheWriteBehavior { // (undocumented) @@ -1058,11 +1050,42 @@ interface FulfilledPromise extends Promise { value: TValue; } +// Warning: (ae-forgotten-export) The symbol "_getApolloClientCacheStatus" needs to be exported by the entry point index.d.ts +// +// @internal +const getApolloClientCacheStatus: typeof _getApolloClientCacheStatus | undefined; + // Warning: (ae-forgotten-export) The symbol "ApolloClient" needs to be exported by the entry point index.d.ts -// Warning: (ae-forgotten-export) The symbol "CacheStatus" needs to be exported by the entry point index.d.ts // // @public (undocumented) -type GetCacheStatus = (this: ApolloClient) => CacheStatus; +function _getApolloClientCacheStatus(this: ApolloClient): { + limits: CacheSizes; + sizes: { + global: { + print: number | undefined; + parser: number | undefined; + canonicalStringify: number | undefined; + }; + links: number[]; + queryManager: { + Transforms: number; + documentTransforms: number[]; + }; + cache: { + addTypenameTransform: number[]; + storeReader: { + executeSelectionSet: number | undefined; + executeSubSelectedArray: number | undefined; + }; + maybeBroadcastWatch: number | undefined; + fragmentRegistry: { + findFragmentSpreads: number | undefined; + lookup: number | undefined; + transform: number | undefined; + }; + } | undefined; + }; +}; // @public (undocumented) export function getDefaultValues(definition: OperationDefinitionNode | undefined): Record; @@ -1094,6 +1117,26 @@ export function getGraphQLErrorsFromResult(result: FetchResult): GraphQLEr // @public (undocumented) export function getInclusionDirectives(directives: ReadonlyArray): InclusionDirectives; +// Warning: (ae-forgotten-export) The symbol "_getInMemoryCacheStatus" needs to be exported by the entry point index.d.ts +// +// @internal +const getInMemoryCacheStatus: typeof _getInMemoryCacheStatus | undefined; + +// @public (undocumented) +function _getInMemoryCacheStatus(this: InMemoryCache): { + addTypenameTransform: number[]; + storeReader: { + executeSelectionSet: number | undefined; + executeSubSelectedArray: number | undefined; + }; + maybeBroadcastWatch: number | undefined; + fragmentRegistry: { + findFragmentSpreads: number | undefined; + lookup: number | undefined; + transform: number | undefined; + }; +}; + // @public export function getMainDefinition(queryDoc: DocumentNode): OperationDefinitionNode | FragmentDefinitionNode; @@ -1215,6 +1258,10 @@ class InMemoryCache extends ApolloCache { resetResultCache?: boolean; resetResultIdentities?: boolean; }): string[]; + // Warning: (ae-forgotten-export) The symbol "getInMemoryCacheStatus" needs to be exported by the entry point index.d.ts + // + // @internal + getCacheStatus?: typeof getInMemoryCacheStatus; // (undocumented) identify(object: StoreObject | Reference): string | undefined; // Warning: (ae-forgotten-export) The symbol "makeVar" needs to be exported by the entry point index.d.ts diff --git a/.api-reports/api-report.md b/.api-reports/api-report.md index e4b164b3867..44a802c5df4 100644 --- a/.api-reports/api-report.md +++ b/.api-reports/api-report.md @@ -106,10 +106,10 @@ export class ApolloClient implements DataProxy { disableNetworkFetches: boolean; get documentTransform(): DocumentTransform; extract(optimistic?: boolean): TCacheShape; - // Warning: (ae-forgotten-export) The symbol "GetCacheStatus" needs to be exported by the entry point index.d.ts + // Warning: (ae-forgotten-export) The symbol "getApolloClientCacheStatus" needs to be exported by the entry point index.d.ts // // @internal - getCacheStatus?: GetCacheStatus; + getCacheStatus?: typeof getApolloClientCacheStatus; getObservableQueries(include?: RefetchQueriesInclude): Map>; getResolvers(): Resolvers; // (undocumented) @@ -238,6 +238,8 @@ interface ApolloErrorOptions { // @public (undocumented) export class ApolloLink { constructor(request?: RequestHandler); + // @internal + readonly cacheSize?: number; // (undocumented) static concat(first: ApolloLink | RequestHandler, second: ApolloLink | RequestHandler): ApolloLink; // (undocumented) @@ -248,13 +250,13 @@ export class ApolloLink { static execute(link: ApolloLink, operation: GraphQLRequest): Observable; // (undocumented) static from(links: (ApolloLink | RequestHandler)[]): ApolloLink; - // (undocumented) + // @internal readonly left?: ApolloLink; // (undocumented) protected onError(error: any, observer?: Observer): false | void; // (undocumented) request(operation: Operation, forward?: NextLink): Observable | null; - // (undocumented) + // @internal readonly right?: ApolloLink; // (undocumented) setOnError(fn: ApolloLink["onError"]): this; @@ -507,16 +509,6 @@ interface CacheSizes { queryManagerTransforms: number; } -// @public (undocumented) -type CacheStatus = { - limits: CacheSizes; - sizes: { - [K in keyof CacheSizes]?: number | number[]; - } & { - links?: number[]; - }; -}; - // @public (undocumented) const enum CacheWriteBehavior { // (undocumented) @@ -1071,13 +1063,63 @@ interface FulfilledPromise extends Promise { value: TValue; } +// Warning: (ae-forgotten-export) The symbol "_getApolloClientCacheStatus" needs to be exported by the entry point index.d.ts +// +// @internal +const getApolloClientCacheStatus: typeof _getApolloClientCacheStatus | undefined; + +// @public (undocumented) +function _getApolloClientCacheStatus(this: ApolloClient): { + limits: CacheSizes; + sizes: { + global: { + print: number | undefined; + parser: number | undefined; + canonicalStringify: number | undefined; + }; + links: number[]; + queryManager: { + Transforms: number; + documentTransforms: number[]; + }; + cache: { + addTypenameTransform: number[]; + storeReader: { + executeSelectionSet: number | undefined; + executeSubSelectedArray: number | undefined; + }; + maybeBroadcastWatch: number | undefined; + fragmentRegistry: { + findFragmentSpreads: number | undefined; + lookup: number | undefined; + transform: number | undefined; + }; + } | undefined; + }; +}; + // @public (undocumented) export function getApolloContext(): ReactTypes.Context; -// Warning: (ae-forgotten-export) The symbol "CacheStatus" needs to be exported by the entry point index.d.ts +// Warning: (ae-forgotten-export) The symbol "_getInMemoryCacheStatus" needs to be exported by the entry point index.d.ts // +// @internal +const getInMemoryCacheStatus: typeof _getInMemoryCacheStatus | undefined; + // @public (undocumented) -type GetCacheStatus = (this: ApolloClient) => CacheStatus; +function _getInMemoryCacheStatus(this: InMemoryCache): { + addTypenameTransform: number[]; + storeReader: { + executeSelectionSet: number | undefined; + executeSubSelectedArray: number | undefined; + }; + maybeBroadcastWatch: number | undefined; + fragmentRegistry: { + findFragmentSpreads: number | undefined; + lookup: number | undefined; + transform: number | undefined; + }; +}; export { gql } @@ -1202,6 +1244,10 @@ export class InMemoryCache extends ApolloCache { resetResultCache?: boolean; resetResultIdentities?: boolean; }): string[]; + // Warning: (ae-forgotten-export) The symbol "getInMemoryCacheStatus" needs to be exported by the entry point index.d.ts + // + // @internal + getCacheStatus?: typeof getInMemoryCacheStatus; // (undocumented) identify(object: StoreObject | Reference): string | undefined; // (undocumented) @@ -2947,7 +2993,7 @@ interface WriteContext extends ReadMergeModifyContext { // src/react/hooks/useBackgroundQuery.ts:30:3 - (ae-forgotten-export) The symbol "FetchMoreFunction" needs to be exported by the entry point index.d.ts // src/react/hooks/useBackgroundQuery.ts:31:3 - (ae-forgotten-export) The symbol "RefetchFunction" needs to be exported by the entry point index.d.ts // src/react/hooks/useLoadableQuery.ts:50:5 - (ae-forgotten-export) The symbol "ResetFunction" needs to be exported by the entry point index.d.ts -// src/utilities/caching/getCacheStatus.ts:12:3 - (ae-forgotten-export) The symbol "CacheSizes" needs to be exported by the entry point index.d.ts +// src/utilities/caching/getCacheStatus.ts:47:61 - (ae-forgotten-export) The symbol "CacheSizes" needs to be exported by the entry point index.d.ts // (No @packageDocumentation comment for this package) diff --git a/.size-limits.json b/.size-limits.json index a1aecbd49af..64b0e2b00f7 100644 --- a/.size-limits.json +++ b/.size-limits.json @@ -1,4 +1,4 @@ { "dist/apollo-client.min.cjs": 38839, - "import { ApolloClient, InMemoryCache, HttpLink } from \"dist/index.js\" (production)": 32621 + "import { ApolloClient, InMemoryCache, HttpLink } from \"dist/index.js\" (production)": 32620 } From 001da1a1e6cc38c0f9756d3fcaed062a8c588ebd Mon Sep 17 00:00:00 2001 From: Lenz Weber-Tronic Date: Tue, 5 Dec 2023 16:00:32 +0100 Subject: [PATCH 34/62] add more caches --- .api-reports/api-report-utilities.md | 2 ++ .size-limits.json | 4 +-- src/cache/core/cache.ts | 8 +++-- .../removeTypenameFromVariables.ts | 31 +++++++++++++------ src/utilities/caching/sizes.ts | 22 +++++++++++++ 5 files changed, 53 insertions(+), 14 deletions(-) diff --git a/.api-reports/api-report-utilities.md b/.api-reports/api-report-utilities.md index e89e7161bad..6a34fd8be99 100644 --- a/.api-reports/api-report-utilities.md +++ b/.api-reports/api-report-utilities.md @@ -450,9 +450,11 @@ class CacheGroup { interface CacheSizes { canonicalStringify: number; documentTransform: number; + fragmentQueryDocuments: number; fragmentRegistryFindFragmentSpreads: number; fragmentRegistryLookup: number; fragmentRegistryTransform: number; + getVariableDefinitions: number; parser: number; persistedQueryHashes: number; print: number; diff --git a/.size-limits.json b/.size-limits.json index 57fa36ea646..193f1919b9a 100644 --- a/.size-limits.json +++ b/.size-limits.json @@ -1,4 +1,4 @@ { - "dist/apollo-client.min.cjs": 38800, - "import { ApolloClient, InMemoryCache, HttpLink } from \"dist/index.js\" (production)": 32562 + "dist/apollo-client.min.cjs": 38819, + "import { ApolloClient, InMemoryCache, HttpLink } from \"dist/index.js\" (production)": 32590 } diff --git a/src/cache/core/cache.ts b/src/cache/core/cache.ts index 44f283a2723..af2a5b9400d 100644 --- a/src/cache/core/cache.ts +++ b/src/cache/core/cache.ts @@ -2,9 +2,10 @@ import type { DocumentNode } from "graphql"; import { wrap } from "optimism"; import type { StoreObject, Reference } from "../../utilities/index.js"; -import { getFragmentQueryDocument } from "../../utilities/index.js"; +import { cacheSizes, getFragmentQueryDocument } from "../../utilities/index.js"; import type { DataProxy } from "./types/DataProxy.js"; import type { Cache } from "./types/Cache.js"; +import { WeakCache } from "@wry/caches"; export type Transaction = (c: ApolloCache) => void; @@ -137,7 +138,10 @@ export abstract class ApolloCache implements DataProxy { // Make sure we compute the same (===) fragment query document every // time we receive the same fragment in readFragment. - private getFragmentDoc = wrap(getFragmentQueryDocument); + private getFragmentDoc = wrap(getFragmentQueryDocument, { + max: cacheSizes.fragmentQueryDocuments, + cache: WeakCache, + }); public readFragment( options: Cache.ReadFragmentOptions, diff --git a/src/link/remove-typename/removeTypenameFromVariables.ts b/src/link/remove-typename/removeTypenameFromVariables.ts index b8c173b15d2..69ca1777d01 100644 --- a/src/link/remove-typename/removeTypenameFromVariables.ts +++ b/src/link/remove-typename/removeTypenameFromVariables.ts @@ -2,8 +2,13 @@ import { wrap } from "optimism"; import type { DocumentNode, TypeNode } from "graphql"; import { Kind, visit } from "graphql"; import { ApolloLink } from "../core/index.js"; -import { stripTypename, isPlainObject } from "../../utilities/index.js"; +import { + stripTypename, + isPlainObject, + cacheSizes, +} from "../../utilities/index.js"; import type { OperationVariables } from "../../core/index.js"; +import { WeakCache } from "@wry/caches"; export const KEEP = "__KEEP"; @@ -95,17 +100,23 @@ function maybeStripTypename( return value; } -const getVariableDefinitions = wrap((document: DocumentNode) => { - const definitions: Record = {}; +const getVariableDefinitions = wrap( + (document: DocumentNode) => { + const definitions: Record = {}; - visit(document, { - VariableDefinition(node) { - definitions[node.variable.name.value] = unwrapType(node.type); - }, - }); + visit(document, { + VariableDefinition(node) { + definitions[node.variable.name.value] = unwrapType(node.type); + }, + }); - return definitions; -}); + return definitions; + }, + { + max: cacheSizes.getVariableDefinitions, + cache: WeakCache, + } +); function unwrapType(node: TypeNode): string { switch (node.kind) { diff --git a/src/utilities/caching/sizes.ts b/src/utilities/caching/sizes.ts index b9ac738fc69..706f372c921 100644 --- a/src/utilities/caching/sizes.ts +++ b/src/utilities/caching/sizes.ts @@ -154,6 +154,26 @@ interface CacheSizes { * might involuntarily invalidate values in the `transform` cache. */ fragmentRegistryFindFragmentSpreads: number; + /** + * Cache size for the `getFragmentDoc` method of [`ApolloCache`](../../cache/core/cache.ts). + * + * @defaultValue + * Defaults to `1000`. + * + * @remarks + * This function is called from `readFragment` with user-provided fragment definitions. + */ + fragmentQueryDocuments: number; + /** + * Cache size for the `getVariableDefinitions` function in [`removeTypenameFromVariables`](../../link/remove-typename/removeTypenameFromVariables.ts). + * + * @defaultValue + * Defaults to `2000`. + * + * @remarks + * This function is called in a link with transformed DocumentNodes. + */ + getVariableDefinitions: number; } const cacheSizeSymbol = Symbol.for("apollo.cacheSize"); @@ -189,5 +209,7 @@ export const cacheSizes: CacheSizes = { fragmentRegistryTransform: 2000, fragmentRegistryLookup: 1000, fragmentRegistryFindFragmentSpreads: 4000, + fragmentQueryDocuments: 1000, + getVariableDefinitions: 2000, ...global[cacheSizeSymbol], }; From 2ab6bd6b3442e9f9f46ebfbcfe0708e3280ec8d4 Mon Sep 17 00:00:00 2001 From: Lenz Weber-Tronic Date: Tue, 5 Dec 2023 16:49:19 +0100 Subject: [PATCH 35/62] add more caches --- src/cache/inmemory/inMemoryCache.ts | 3 +- src/cache/inmemory/readFromStore.ts | 6 ++-- src/cache/inmemory/types.ts | 5 +++ src/utilities/caching/sizes.ts | 48 +++++++++++++++++++++++++++++ 4 files changed, 59 insertions(+), 3 deletions(-) diff --git a/src/cache/inmemory/inMemoryCache.ts b/src/cache/inmemory/inMemoryCache.ts index f00fed8767e..5f0aca55e60 100644 --- a/src/cache/inmemory/inMemoryCache.ts +++ b/src/cache/inmemory/inMemoryCache.ts @@ -18,6 +18,7 @@ import { DocumentTransform, canonicalStringify, print, + cacheSizes, } from "../../utilities/index.js"; import type { InMemoryCacheConfig, NormalizedCacheObject } from "./types.js"; import { StoreReader } from "./readFromStore.js"; @@ -124,7 +125,7 @@ export class InMemoryCache extends ApolloCache { return this.broadcastWatch(c, options); }, { - max: this.config.resultCacheMaxSize, + max: this.config.resultCacheMaxSize ?? cacheSizes.maybeBroadcastWatch, makeCacheKey: (c: Cache.WatchOptions) => { // Return a cache key (thus enabling result caching) only if we're // currently using a data store that can track cache dependencies. diff --git a/src/cache/inmemory/readFromStore.ts b/src/cache/inmemory/readFromStore.ts index a280948b87e..ef82cee5b2a 100644 --- a/src/cache/inmemory/readFromStore.ts +++ b/src/cache/inmemory/readFromStore.ts @@ -29,6 +29,7 @@ import { canUseWeakMap, compact, canonicalStringify, + cacheSizes, } from "../../utilities/index.js"; import type { Cache } from "../core/types/Cache.js"; import type { @@ -193,7 +194,7 @@ export class StoreReader { return this.execSelectionSetImpl(options); }, { - max: this.config.resultCacheMaxSize, + max: this.config.resultCacheMaxSize ?? cacheSizes.executeSelectionSet, keyArgs: execSelectionSetKeyArgs, // Note that the parameters of makeCacheKey are determined by the // array returned by keyArgs. @@ -219,7 +220,8 @@ export class StoreReader { return this.execSubSelectedArrayImpl(options); }, { - max: this.config.resultCacheMaxSize, + max: + this.config.resultCacheMaxSize ?? cacheSizes.executeSubSelectedArray, makeCacheKey({ field, array, context }) { if (supportsResultCaching(context.store)) { return context.store.makeCacheKey(field, array, context.varString); diff --git a/src/cache/inmemory/types.ts b/src/cache/inmemory/types.ts index 5a8d66ec300..207a802feb4 100644 --- a/src/cache/inmemory/types.ts +++ b/src/cache/inmemory/types.ts @@ -137,6 +137,11 @@ export interface InMemoryCacheConfig extends ApolloReducerConfig { resultCaching?: boolean; possibleTypes?: PossibleTypesMap; typePolicies?: TypePolicies; + /** + * @deprecated + * Please use `cacheSizes` instead. + * TODO: write docs page, add link here + */ resultCacheMaxSize?: number; canonizeResults?: boolean; fragments?: FragmentRegistryAPI; diff --git a/src/utilities/caching/sizes.ts b/src/utilities/caching/sizes.ts index 706f372c921..d5b5f789251 100644 --- a/src/utilities/caching/sizes.ts +++ b/src/utilities/caching/sizes.ts @@ -174,6 +174,51 @@ interface CacheSizes { * This function is called in a link with transformed DocumentNodes. */ getVariableDefinitions: number; + /** + * Cache size for the `maybeBroadcastWatch` method on [`InMemoryCache`](../../cache/inmemory/inMemoryCache.ts). + * + * `maybeBroadcastWatch` will be set to the `resultCacheMaxSize` option and + * will fall back to this configuration value if the option is not set. + * + * @defaultValue + * Defaults to `5000`. + * + * @remarks + * This method is used for dependency tracking in the `InMemoryCache` and + * prevents from unnecessary re-renders. + * It is recommended to keep this value significantly higher than the number of + * possible subscribers you will have active at the same time in your application + * at any time. + */ + maybeBroadcastWatch: number; + /** + * Cache size for the `executeSelectionSet` method on [`StoreReader`](../../cache/inmemory/readFromStore.ts). + * + * `executeSelectionSet` will be set to the `resultCacheMaxSize` option and + * will fall back to this configuration value if the option is not set. + * + * @defaultValue + * Defaults to `10000`. + * + * @remarks + * Every object that is read from the cache will be cached here, so it is + * recommended to set this to a high value. + */ + executeSelectionSet: number; + /** + * Cache size for the `executeSubSelectedArray` method on [`StoreReader`](../../cache/inmemory/readFromStore.ts). + * + * `executeSubSelectedArray` will be set to the `resultCacheMaxSize` option and + * will fall back to this configuration value if the option is not set. + * + * @defaultValue + * Defaults to `5000`. + * + * @remarks + * Every array that is read from the cache will be cached here, so it is + * recommended to set this to a high value. + */ + executeSubSelectedArray: number; } const cacheSizeSymbol = Symbol.for("apollo.cacheSize"); @@ -211,5 +256,8 @@ export const cacheSizes: CacheSizes = { fragmentRegistryFindFragmentSpreads: 4000, fragmentQueryDocuments: 1000, getVariableDefinitions: 2000, + maybeBroadcastWatch: 5000, + executeSelectionSet: 10000, + executeSubSelectedArray: 5000, ...global[cacheSizeSymbol], }; From 74df66246309705bd4111a0c9747edd932c89fdd Mon Sep 17 00:00:00 2001 From: Lenz Weber-Tronic Date: Tue, 5 Dec 2023 16:52:02 +0100 Subject: [PATCH 36/62] chores --- .api-reports/api-report-cache.md | 2 +- .api-reports/api-report-core.md | 2 +- .api-reports/api-report-utilities.md | 5 ++++- .api-reports/api-report.md | 2 +- .size-limits.json | 4 ++-- 5 files changed, 9 insertions(+), 6 deletions(-) diff --git a/.api-reports/api-report-cache.md b/.api-reports/api-report-cache.md index 50588f8f4c0..1f2efd837fc 100644 --- a/.api-reports/api-report-cache.md +++ b/.api-reports/api-report-cache.md @@ -551,7 +551,7 @@ export interface InMemoryCacheConfig extends ApolloReducerConfig { fragments?: FragmentRegistryAPI; // (undocumented) possibleTypes?: PossibleTypesMap; - // (undocumented) + // @deprecated (undocumented) resultCacheMaxSize?: number; // (undocumented) resultCaching?: boolean; diff --git a/.api-reports/api-report-core.md b/.api-reports/api-report-core.md index 8129823a675..3980b506239 100644 --- a/.api-reports/api-report-core.md +++ b/.api-reports/api-report-core.md @@ -1013,7 +1013,7 @@ export interface InMemoryCacheConfig extends ApolloReducerConfig { fragments?: FragmentRegistryAPI; // (undocumented) possibleTypes?: PossibleTypesMap; - // (undocumented) + // @deprecated (undocumented) resultCacheMaxSize?: number; // (undocumented) resultCaching?: boolean; diff --git a/.api-reports/api-report-utilities.md b/.api-reports/api-report-utilities.md index 6a34fd8be99..4df4e7cb549 100644 --- a/.api-reports/api-report-utilities.md +++ b/.api-reports/api-report-utilities.md @@ -450,11 +450,14 @@ class CacheGroup { interface CacheSizes { canonicalStringify: number; documentTransform: number; + executeSelectionSet: number; + executeSubSelectedArray: number; fragmentQueryDocuments: number; fragmentRegistryFindFragmentSpreads: number; fragmentRegistryLookup: number; fragmentRegistryTransform: number; getVariableDefinitions: number; + maybeBroadcastWatch: number; parser: number; persistedQueryHashes: number; print: number; @@ -1232,7 +1235,7 @@ interface InMemoryCacheConfig extends ApolloReducerConfig { // // (undocumented) possibleTypes?: PossibleTypesMap; - // (undocumented) + // @deprecated (undocumented) resultCacheMaxSize?: number; // (undocumented) resultCaching?: boolean; diff --git a/.api-reports/api-report.md b/.api-reports/api-report.md index 081d7af9dc9..a2c21c1e432 100644 --- a/.api-reports/api-report.md +++ b/.api-reports/api-report.md @@ -1199,7 +1199,7 @@ export interface InMemoryCacheConfig extends ApolloReducerConfig { fragments?: FragmentRegistryAPI; // (undocumented) possibleTypes?: PossibleTypesMap; - // (undocumented) + // @deprecated (undocumented) resultCacheMaxSize?: number; // (undocumented) resultCaching?: boolean; diff --git a/.size-limits.json b/.size-limits.json index 193f1919b9a..d4e240c86ab 100644 --- a/.size-limits.json +++ b/.size-limits.json @@ -1,4 +1,4 @@ { - "dist/apollo-client.min.cjs": 38819, - "import { ApolloClient, InMemoryCache, HttpLink } from \"dist/index.js\" (production)": 32590 + "dist/apollo-client.min.cjs": 38902, + "import { ApolloClient, InMemoryCache, HttpLink } from \"dist/index.js\" (production)": 32678 } From 517b133a906af85cd9b2abe55cf0fd2385a2961e Mon Sep 17 00:00:00 2001 From: Lenz Weber-Tronic Date: Wed, 6 Dec 2023 11:44:06 +0100 Subject: [PATCH 37/62] add type export --- src/utilities/caching/index.ts | 1 + src/utilities/caching/sizes.ts | 4 ++-- src/utilities/index.ts | 1 + 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/utilities/caching/index.ts b/src/utilities/caching/index.ts index 4fc49c5dbab..d2df24b167f 100644 --- a/src/utilities/caching/index.ts +++ b/src/utilities/caching/index.ts @@ -1,2 +1,3 @@ export { CleanStrongCache, CleanWeakCache } from "./caches.js"; +export type { CacheSizes } from "./sizes.js"; export { cacheSizes } from "./sizes.js"; diff --git a/src/utilities/caching/sizes.ts b/src/utilities/caching/sizes.ts index d5b5f789251..e0a70d851a9 100644 --- a/src/utilities/caching/sizes.ts +++ b/src/utilities/caching/sizes.ts @@ -20,7 +20,7 @@ declare global { * In most applications, it will be very unlikely that 1000 different queries * are on screen at the same time. */ -interface CacheSizes { +export interface CacheSizes { /** * Cache size for the [`print`](../../utilities/graphql/print.ts) function. * @@ -241,7 +241,7 @@ const cacheSizeSymbol = Symbol.for("apollo.cacheSize"); * ```ts * globalThis[Symbol.for("apollo.cacheSize")] = { * parser: 100 - * } + * } satisfies Partial // the `satisfies` is optional if using TypeScript * ``` */ export const cacheSizes: CacheSizes = { diff --git a/src/utilities/index.ts b/src/utilities/index.ts index 541bd5693a9..4e7c4ad47bf 100644 --- a/src/utilities/index.ts +++ b/src/utilities/index.ts @@ -137,3 +137,4 @@ export { CleanWeakCache, cacheSizes, } from "./caching/index.js"; +export type { CacheSizes } from "./caching/index.js"; From 06e2e2ce23d895652d796beccd9beb3277de46bc Mon Sep 17 00:00:00 2001 From: Lenz Weber-Tronic Date: Wed, 6 Dec 2023 12:00:55 +0100 Subject: [PATCH 38/62] update test --- src/cache/inmemory/__tests__/readFromStore.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cache/inmemory/__tests__/readFromStore.ts b/src/cache/inmemory/__tests__/readFromStore.ts index 972e252215c..2051b328b03 100644 --- a/src/cache/inmemory/__tests__/readFromStore.ts +++ b/src/cache/inmemory/__tests__/readFromStore.ts @@ -17,14 +17,14 @@ import { isReference, TypedDocumentNode, } from "../../../core"; +import { cacheSizes } from "../../../utilities"; describe("resultCacheMaxSize", () => { const cache = new InMemoryCache(); - const defaultMaxSize = Math.pow(2, 16); it("uses default max size on caches if resultCacheMaxSize is not configured", () => { const reader = new StoreReader({ cache }); - expect(reader["executeSelectionSet"].options.max).toBe(defaultMaxSize); + expect(reader["executeSelectionSet"].options.max).toBe(cacheSizes.executeSelectionSet); }); it("configures max size on caches when resultCacheMaxSize is set", () => { From f380a5708f65db7fb239bf54fa3c1d331258f240 Mon Sep 17 00:00:00 2001 From: Lenz Weber-Tronic Date: Wed, 6 Dec 2023 12:11:00 +0100 Subject: [PATCH 39/62] chores --- .api-reports/api-report-utilities.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.api-reports/api-report-utilities.md b/.api-reports/api-report-utilities.md index 4df4e7cb549..a219ff86f50 100644 --- a/.api-reports/api-report-utilities.md +++ b/.api-reports/api-report-utilities.md @@ -447,7 +447,7 @@ class CacheGroup { } // @public -interface CacheSizes { +export interface CacheSizes { canonicalStringify: number; documentTransform: number; executeSelectionSet: number; @@ -464,8 +464,6 @@ interface CacheSizes { queryManagerTransforms: number; } -// Warning: (ae-forgotten-export) The symbol "CacheSizes" needs to be exported by the entry point index.d.ts -// // @public export const cacheSizes: CacheSizes; From b8a1f0c82aabc8fe82fcd1e74245762160466090 Mon Sep 17 00:00:00 2001 From: Lenz Weber-Tronic Date: Wed, 6 Dec 2023 12:12:07 +0100 Subject: [PATCH 40/62] formatting --- src/cache/inmemory/__tests__/readFromStore.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/cache/inmemory/__tests__/readFromStore.ts b/src/cache/inmemory/__tests__/readFromStore.ts index 2051b328b03..0d4602a902c 100644 --- a/src/cache/inmemory/__tests__/readFromStore.ts +++ b/src/cache/inmemory/__tests__/readFromStore.ts @@ -24,7 +24,9 @@ describe("resultCacheMaxSize", () => { it("uses default max size on caches if resultCacheMaxSize is not configured", () => { const reader = new StoreReader({ cache }); - expect(reader["executeSelectionSet"].options.max).toBe(cacheSizes.executeSelectionSet); + expect(reader["executeSelectionSet"].options.max).toBe( + cacheSizes.executeSelectionSet + ); }); it("configures max size on caches when resultCacheMaxSize is set", () => { From 28a4289308c9b3e10c0f5cd737cc7443da37376a Mon Sep 17 00:00:00 2001 From: Lenz Weber-Tronic Date: Wed, 6 Dec 2023 12:24:23 +0100 Subject: [PATCH 41/62] adjust more tests --- src/cache/inmemory/__tests__/cache.ts | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/cache/inmemory/__tests__/cache.ts b/src/cache/inmemory/__tests__/cache.ts index edaa63fb4d4..ae1056b7d80 100644 --- a/src/cache/inmemory/__tests__/cache.ts +++ b/src/cache/inmemory/__tests__/cache.ts @@ -19,6 +19,7 @@ import { StoreWriter } from "../writeToStore"; import { ObjectCanon } from "../object-canon"; import { TypePolicies } from "../policies"; import { spyOnConsole } from "../../../testing/internal"; +import { cacheSizes } from "../../../utilities"; disableFragmentWarnings(); @@ -2119,15 +2120,17 @@ describe("Cache", () => { }); describe("resultCacheMaxSize", () => { - const defaultMaxSize = Math.pow(2, 16); - it("uses default max size on caches if resultCacheMaxSize is not configured", () => { const cache = new InMemoryCache(); - expect(cache["maybeBroadcastWatch"].options.max).toBe(defaultMaxSize); + expect(cache["maybeBroadcastWatch"].options.max).toBe( + cacheSizes.maybeBroadcastWatch + ); expect(cache["storeReader"]["executeSelectionSet"].options.max).toBe( - defaultMaxSize + cacheSizes.executeSelectionSet + ); + expect(cache["getFragmentDoc"].options.max).toBe( + cacheSizes.fragmentQueryDocuments ); - expect(cache["getFragmentDoc"].options.max).toBe(defaultMaxSize); }); it("configures max size on caches when resultCacheMaxSize is set", () => { @@ -2137,7 +2140,9 @@ describe("resultCacheMaxSize", () => { expect(cache["storeReader"]["executeSelectionSet"].options.max).toBe( resultCacheMaxSize ); - expect(cache["getFragmentDoc"].options.max).toBe(defaultMaxSize); + expect(cache["getFragmentDoc"].options.max).toBe( + cacheSizes.fragmentQueryDocuments + ); }); }); From 1a392b25180062fc81614066b77a93e02c03b69d Mon Sep 17 00:00:00 2001 From: Lenz Weber-Tronic Date: Wed, 6 Dec 2023 17:15:14 +0100 Subject: [PATCH 42/62] chores --- .api-reports/api-report-core.md | 5 +++++ .api-reports/api-report-react.md | 5 +++++ .api-reports/api-report-react_components.md | 5 +++++ .api-reports/api-report-react_context.md | 5 +++++ .api-reports/api-report-react_hoc.md | 5 +++++ .api-reports/api-report-react_hooks.md | 5 +++++ .api-reports/api-report-react_ssr.md | 5 +++++ .api-reports/api-report-testing.md | 5 +++++ .api-reports/api-report-testing_core.md | 5 +++++ .api-reports/api-report.md | 5 +++++ 10 files changed, 50 insertions(+) diff --git a/.api-reports/api-report-core.md b/.api-reports/api-report-core.md index 0c68955ea64..27d24bbbe5b 100644 --- a/.api-reports/api-report-core.md +++ b/.api-reports/api-report-core.md @@ -398,9 +398,14 @@ class CacheGroup { interface CacheSizes { canonicalStringify: number; documentTransform: number; + executeSelectionSet: number; + executeSubSelectedArray: number; + fragmentQueryDocuments: number; fragmentRegistryFindFragmentSpreads: number; fragmentRegistryLookup: number; fragmentRegistryTransform: number; + getVariableDefinitions: number; + maybeBroadcastWatch: number; parser: number; persistedQueryHashes: number; print: number; diff --git a/.api-reports/api-report-react.md b/.api-reports/api-report-react.md index 92e738c156c..32cbc8ba90f 100644 --- a/.api-reports/api-report-react.md +++ b/.api-reports/api-report-react.md @@ -508,9 +508,14 @@ namespace Cache_2 { interface CacheSizes { canonicalStringify: number; documentTransform: number; + executeSelectionSet: number; + executeSubSelectedArray: number; + fragmentQueryDocuments: number; fragmentRegistryFindFragmentSpreads: number; fragmentRegistryLookup: number; fragmentRegistryTransform: number; + getVariableDefinitions: number; + maybeBroadcastWatch: number; parser: number; persistedQueryHashes: number; print: number; diff --git a/.api-reports/api-report-react_components.md b/.api-reports/api-report-react_components.md index 4499c550091..7c03262fbf4 100644 --- a/.api-reports/api-report-react_components.md +++ b/.api-reports/api-report-react_components.md @@ -461,9 +461,14 @@ namespace Cache_2 { interface CacheSizes { canonicalStringify: number; documentTransform: number; + executeSelectionSet: number; + executeSubSelectedArray: number; + fragmentQueryDocuments: number; fragmentRegistryFindFragmentSpreads: number; fragmentRegistryLookup: number; fragmentRegistryTransform: number; + getVariableDefinitions: number; + maybeBroadcastWatch: number; parser: number; persistedQueryHashes: number; print: number; diff --git a/.api-reports/api-report-react_context.md b/.api-reports/api-report-react_context.md index 309616ee3b0..659aa1ad6b5 100644 --- a/.api-reports/api-report-react_context.md +++ b/.api-reports/api-report-react_context.md @@ -444,9 +444,14 @@ namespace Cache_2 { interface CacheSizes { canonicalStringify: number; documentTransform: number; + executeSelectionSet: number; + executeSubSelectedArray: number; + fragmentQueryDocuments: number; fragmentRegistryFindFragmentSpreads: number; fragmentRegistryLookup: number; fragmentRegistryTransform: number; + getVariableDefinitions: number; + maybeBroadcastWatch: number; parser: number; persistedQueryHashes: number; print: number; diff --git a/.api-reports/api-report-react_hoc.md b/.api-reports/api-report-react_hoc.md index 5b75442eed3..7f15bc2e83a 100644 --- a/.api-reports/api-report-react_hoc.md +++ b/.api-reports/api-report-react_hoc.md @@ -428,9 +428,14 @@ namespace Cache_2 { interface CacheSizes { canonicalStringify: number; documentTransform: number; + executeSelectionSet: number; + executeSubSelectedArray: number; + fragmentQueryDocuments: number; fragmentRegistryFindFragmentSpreads: number; fragmentRegistryLookup: number; fragmentRegistryTransform: number; + getVariableDefinitions: number; + maybeBroadcastWatch: number; parser: number; persistedQueryHashes: number; print: number; diff --git a/.api-reports/api-report-react_hooks.md b/.api-reports/api-report-react_hooks.md index a18f3a7ae25..ee783d0bf74 100644 --- a/.api-reports/api-report-react_hooks.md +++ b/.api-reports/api-report-react_hooks.md @@ -484,9 +484,14 @@ namespace Cache_2 { interface CacheSizes { canonicalStringify: number; documentTransform: number; + executeSelectionSet: number; + executeSubSelectedArray: number; + fragmentQueryDocuments: number; fragmentRegistryFindFragmentSpreads: number; fragmentRegistryLookup: number; fragmentRegistryTransform: number; + getVariableDefinitions: number; + maybeBroadcastWatch: number; parser: number; persistedQueryHashes: number; print: number; diff --git a/.api-reports/api-report-react_ssr.md b/.api-reports/api-report-react_ssr.md index 7113b1fb9c3..1fcf4a506a4 100644 --- a/.api-reports/api-report-react_ssr.md +++ b/.api-reports/api-report-react_ssr.md @@ -414,9 +414,14 @@ namespace Cache_2 { interface CacheSizes { canonicalStringify: number; documentTransform: number; + executeSelectionSet: number; + executeSubSelectedArray: number; + fragmentQueryDocuments: number; fragmentRegistryFindFragmentSpreads: number; fragmentRegistryLookup: number; fragmentRegistryTransform: number; + getVariableDefinitions: number; + maybeBroadcastWatch: number; parser: number; persistedQueryHashes: number; print: number; diff --git a/.api-reports/api-report-testing.md b/.api-reports/api-report-testing.md index 4264c48e9c9..51957ef007b 100644 --- a/.api-reports/api-report-testing.md +++ b/.api-reports/api-report-testing.md @@ -402,9 +402,14 @@ namespace Cache_2 { interface CacheSizes { canonicalStringify: number; documentTransform: number; + executeSelectionSet: number; + executeSubSelectedArray: number; + fragmentQueryDocuments: number; fragmentRegistryFindFragmentSpreads: number; fragmentRegistryLookup: number; fragmentRegistryTransform: number; + getVariableDefinitions: number; + maybeBroadcastWatch: number; parser: number; persistedQueryHashes: number; print: number; diff --git a/.api-reports/api-report-testing_core.md b/.api-reports/api-report-testing_core.md index b4b478df0ce..b732c178099 100644 --- a/.api-reports/api-report-testing_core.md +++ b/.api-reports/api-report-testing_core.md @@ -401,9 +401,14 @@ namespace Cache_2 { interface CacheSizes { canonicalStringify: number; documentTransform: number; + executeSelectionSet: number; + executeSubSelectedArray: number; + fragmentQueryDocuments: number; fragmentRegistryFindFragmentSpreads: number; fragmentRegistryLookup: number; fragmentRegistryTransform: number; + getVariableDefinitions: number; + maybeBroadcastWatch: number; parser: number; persistedQueryHashes: number; print: number; diff --git a/.api-reports/api-report.md b/.api-reports/api-report.md index 876d95124fc..bea514b4a2a 100644 --- a/.api-reports/api-report.md +++ b/.api-reports/api-report.md @@ -500,9 +500,14 @@ class CacheGroup { interface CacheSizes { canonicalStringify: number; documentTransform: number; + executeSelectionSet: number; + executeSubSelectedArray: number; + fragmentQueryDocuments: number; fragmentRegistryFindFragmentSpreads: number; fragmentRegistryLookup: number; fragmentRegistryTransform: number; + getVariableDefinitions: number; + maybeBroadcastWatch: number; parser: number; persistedQueryHashes: number; print: number; From e0bef2a21199f623555d872bf173318518e668e7 Mon Sep 17 00:00:00 2001 From: Lenz Weber-Tronic Date: Tue, 12 Dec 2023 18:47:36 +0100 Subject: [PATCH 43/62] rename, add more caches --- src/cache/core/cache.ts | 14 ++ src/cache/inmemory/inMemoryCache.ts | 6 +- src/core/ApolloClient.ts | 6 +- src/link/core/ApolloLink.ts | 4 +- src/link/persisted-queries/index.ts | 4 +- .../removeTypenameFromVariables.ts | 35 ++-- .../caching/__tests__/getMemoryInternals.ts | 173 ++++++++++++++++++ src/utilities/caching/getCacheStatus.ts | 53 ++++-- 8 files changed, 261 insertions(+), 34 deletions(-) create mode 100644 src/utilities/caching/__tests__/getMemoryInternals.ts diff --git a/src/cache/core/cache.ts b/src/cache/core/cache.ts index af2a5b9400d..7a82a32b571 100644 --- a/src/cache/core/cache.ts +++ b/src/cache/core/cache.ts @@ -6,6 +6,7 @@ import { cacheSizes, getFragmentQueryDocument } from "../../utilities/index.js"; import type { DataProxy } from "./types/DataProxy.js"; import type { Cache } from "./types/Cache.js"; import { WeakCache } from "@wry/caches"; +import { getApolloCacheMemoryInternals } from "../../utilities/caching/getCacheStatus.js"; export type Transaction = (c: ApolloCache) => void; @@ -213,4 +214,17 @@ export abstract class ApolloCache implements DataProxy { }, }); } + + /** + * @experimental + * @internal + * This is not a stable API - it is used in development builds to expose + * information to the DevTools. + * Use at your own risk! + */ + public getMemoryInternals?: typeof getApolloCacheMemoryInternals; +} + +if (__DEV__) { + ApolloCache.prototype.getMemoryInternals = getApolloCacheMemoryInternals; } diff --git a/src/cache/inmemory/inMemoryCache.ts b/src/cache/inmemory/inMemoryCache.ts index dc8ad8fa395..a9f85d6be22 100644 --- a/src/cache/inmemory/inMemoryCache.ts +++ b/src/cache/inmemory/inMemoryCache.ts @@ -28,7 +28,7 @@ import { makeVar, forgetCache, recallCache } from "./reactiveVars.js"; import { Policies } from "./policies.js"; import { hasOwn, normalizeConfig, shouldCanonizeResults } from "./helpers.js"; import type { OperationVariables } from "../../core/index.js"; -import { getInMemoryCacheStatus } from "../../utilities/caching/getCacheStatus.js"; +import { getInMemoryCacheMemoryInternals } from "../../utilities/caching/getCacheStatus.js"; type BroadcastOptions = Pick< Cache.BatchOptions, @@ -586,9 +586,9 @@ export class InMemoryCache extends ApolloCache { * information to the DevTools. * Use at your own risk! */ - public getCacheStatus?: typeof getInMemoryCacheStatus; + public getMemoryInternals?: typeof getInMemoryCacheMemoryInternals; } if (__DEV__) { - InMemoryCache.prototype.getCacheStatus = getInMemoryCacheStatus; + InMemoryCache.prototype.getMemoryInternals = getInMemoryCacheMemoryInternals; } diff --git a/src/core/ApolloClient.ts b/src/core/ApolloClient.ts index 6e7c58763bd..f9c31d7d12e 100644 --- a/src/core/ApolloClient.ts +++ b/src/core/ApolloClient.ts @@ -122,7 +122,7 @@ export interface ApolloClientOptions { // @apollo/client/core. Since we need to preserve that API anyway, the easiest // solution is to reexport mergeOptions where it was previously declared (here). import { mergeOptions } from "../utilities/index.js"; -import { getApolloClientCacheStatus } from "../utilities/caching/getCacheStatus.js"; +import { getApolloClientMemoryInternals } from "../utilities/caching/getCacheStatus.js"; export { mergeOptions }; /** @@ -755,9 +755,9 @@ export class ApolloClient implements DataProxy { * information to the DevTools. * Use at your own risk! */ - public getCacheStatus?: typeof getApolloClientCacheStatus; + public getMemoryInternals?: typeof getApolloClientMemoryInternals; } if (__DEV__) { - ApolloClient.prototype.getCacheStatus = getApolloClientCacheStatus; + ApolloClient.prototype.getMemoryInternals = getApolloClientMemoryInternals; } diff --git a/src/link/core/ApolloLink.ts b/src/link/core/ApolloLink.ts index bbc62f75087..2e31d3d2702 100644 --- a/src/link/core/ApolloLink.ts +++ b/src/link/core/ApolloLink.ts @@ -172,7 +172,7 @@ export class ApolloLink { /** * @internal - * Can be provided by a link that has an internal cache to report it's cache size. + * Can be provided by a link that has an internal cache to report it's memory details. */ - readonly cacheSize?: number; + getMemoryInternals?: () => unknown; } diff --git a/src/link/persisted-queries/index.ts b/src/link/persisted-queries/index.ts index f6985d3afec..5fb55c9e8f1 100644 --- a/src/link/persisted-queries/index.ts +++ b/src/link/persisted-queries/index.ts @@ -297,8 +297,8 @@ export const createPersistedQueryLink = ( }, __DEV__ ? { - get cacheSize() { - return hashesByQuery?.size ?? 0; + getMemoryInternals() { + return { persistedQueryHashes: hashesByQuery?.size ?? 0 }; }, } : {} diff --git a/src/link/remove-typename/removeTypenameFromVariables.ts b/src/link/remove-typename/removeTypenameFromVariables.ts index 69ca1777d01..c25834b57a5 100644 --- a/src/link/remove-typename/removeTypenameFromVariables.ts +++ b/src/link/remove-typename/removeTypenameFromVariables.ts @@ -23,19 +23,28 @@ export interface RemoveTypenameFromVariablesOptions { export function removeTypenameFromVariables( options: RemoveTypenameFromVariablesOptions = Object.create(null) ) { - return new ApolloLink((operation, forward) => { - const { except } = options; - const { query, variables } = operation; - - if (variables) { - operation.variables = - except ? - maybeStripTypenameUsingConfig(query, variables, except) - : stripTypename(variables); - } - - return forward(operation); - }); + return Object.assign( + new ApolloLink((operation, forward) => { + const { except } = options; + const { query, variables } = operation; + + if (variables) { + operation.variables = + except ? + maybeStripTypenameUsingConfig(query, variables, except) + : stripTypename(variables); + } + + return forward(operation); + }), + __DEV__ ? + { + getMemoryInternals() { + return { getVariableDefinitions: getVariableDefinitions?.size ?? 0 }; + }, + } + : {} + ); } function maybeStripTypenameUsingConfig( diff --git a/src/utilities/caching/__tests__/getMemoryInternals.ts b/src/utilities/caching/__tests__/getMemoryInternals.ts new file mode 100644 index 00000000000..6179db3d8d1 --- /dev/null +++ b/src/utilities/caching/__tests__/getMemoryInternals.ts @@ -0,0 +1,173 @@ +import { createFragmentRegistry } from "../../../cache"; +import { + ApolloClient, + ApolloLink, + DocumentTransform, + InMemoryCache, + gql, +} from "../../../core"; +import { createPersistedQueryLink } from "../../../link/persisted-queries"; +import { removeTypenameFromVariables } from "../../../link/remove-typename"; +import crypto from "crypto"; +// importing react so the `parser` cache initializes +import "../../../react"; + +function sha256(data: string) { + const hash = crypto.createHash("sha256"); + hash.update(data); + return hash.digest("hex"); +} + +it("returns information about cache usage (empty caches)", () => { + const client = new ApolloClient({ + documentTransform: new DocumentTransform((x) => x, { + cache: true, + }).concat( + new DocumentTransform((x) => x, { + cache: true, + }) + ), + cache: new InMemoryCache({ + fragments: createFragmentRegistry(), + }), + link: createPersistedQueryLink({ + sha256, + }) + .concat(removeTypenameFromVariables()) + .concat(ApolloLink.empty()), + }); + expect(client.getMemoryInternals?.()).toEqual( + expect.objectContaining({ + limits: { + canonicalStringify: 1000, + documentTransform: 2000, + executeSelectionSet: 10000, + executeSubSelectedArray: 5000, + fragmentQueryDocuments: 1000, + fragmentRegistryFindFragmentSpreads: 4000, + fragmentRegistryLookup: 1000, + fragmentRegistryTransform: 2000, + getVariableDefinitions: 2000, + maybeBroadcastWatch: 5000, + parser: 1000, + persistedQueryHashes: 2000, + print: 2000, + queryManagerTransforms: 2000, + }, + sizes: { + cache: { + addTypenameTransform: [0], + fragmentQueryDocuments: 0, + fragmentRegistry: { + findFragmentSpreads: 0, + lookup: 0, + transform: 0, + }, + maybeBroadcastWatch: 0, + storeReader: { + executeSelectionSet: 0, + executeSubSelectedArray: 0, + }, + }, + global: { + canonicalStringify: 0, + parser: 0, + print: 0, + }, + links: [ + { + persistedQueryHashes: 0, + }, + { + getVariableDefinitions: 0, + }, + ], + queryManager: { + Transforms: 0, + documentTransforms: [0, 0], + }, + }, + }) + ); +}); + +it("returns information about cache usage (some query triggered)", () => { + const client = new ApolloClient({ + documentTransform: new DocumentTransform((x) => x, { + cache: true, + }).concat( + new DocumentTransform((x) => x, { + cache: true, + }) + ), + cache: new InMemoryCache({ + fragments: createFragmentRegistry(), + }), + link: createPersistedQueryLink({ + sha256, + }) + .concat(removeTypenameFromVariables()) + .concat(ApolloLink.empty()), + }); + + client.query({ + query: gql` + query { + hello + } + `, + }); + expect(client.getMemoryInternals?.()).toEqual( + expect.objectContaining({ + limits: { + canonicalStringify: 1000, + documentTransform: 2000, + executeSelectionSet: 10000, + executeSubSelectedArray: 5000, + fragmentQueryDocuments: 1000, + fragmentRegistryFindFragmentSpreads: 4000, + fragmentRegistryLookup: 1000, + fragmentRegistryTransform: 2000, + getVariableDefinitions: 2000, + maybeBroadcastWatch: 5000, + parser: 1000, + persistedQueryHashes: 2000, + print: 2000, + queryManagerTransforms: 2000, + }, + sizes: { + cache: { + addTypenameTransform: [1], + fragmentQueryDocuments: 0, + fragmentRegistry: { + findFragmentSpreads: 1, + lookup: 0, + transform: 1, + }, + maybeBroadcastWatch: 0, + storeReader: { + executeSelectionSet: 1, + executeSubSelectedArray: 0, + }, + }, + global: { + canonicalStringify: 0, + parser: 0, + print: 1, + }, + links: [ + { + persistedQueryHashes: 1, + }, + { + getVariableDefinitions: 0, + }, + ], + queryManager: { + Transforms: 1, + documentTransforms: [1, 1], + }, + }, + }) + ); +}); diff --git a/src/utilities/caching/getCacheStatus.ts b/src/utilities/caching/getCacheStatus.ts index 069982f0280..17d367acd56 100644 --- a/src/utilities/caching/getCacheStatus.ts +++ b/src/utilities/caching/getCacheStatus.ts @@ -3,6 +3,7 @@ import type { InMemoryCache, DocumentTransform, ApolloLink, + ApolloCache, } from "../../core/index.js"; import type { ApolloClient } from "../../core/index.js"; import type { CacheSizes } from "./sizes.js"; @@ -30,21 +31,42 @@ export function registerGlobalCache( globalCaches[name] = getSize; } +type RemoveThis = T extends (this: any) => infer R ? () => R : never; + +/** + * For internal purposes only - please call `ApolloClient.getCacheStatus` instead + * @internal + */ +export const getApolloClientMemoryInternals = + __DEV__ ? + (_getApolloClientMemoryInternals as RemoveThis< + typeof _getApolloClientMemoryInternals + >) + : undefined; + /** * For internal purposes only - please call `ApolloClient.getCacheStatus` instead * @internal */ -export const getApolloClientCacheStatus = - __DEV__ ? _getApolloClientCacheStatus : undefined; +export const getInMemoryCacheMemoryInternals = + __DEV__ ? + (_getInMemoryCacheMemoryInternals as RemoveThis< + typeof _getInMemoryCacheMemoryInternals + >) + : undefined; /** * For internal purposes only - please call `ApolloClient.getCacheStatus` instead * @internal */ -export const getInMemoryCacheStatus = - __DEV__ ? _getInMemoryCacheStatus : undefined; +export const getApolloCacheMemoryInternals = + __DEV__ ? + (_getApolloCacheMemoryInternals as RemoveThis< + typeof _getApolloCacheMemoryInternals + >) + : undefined; -function _getApolloClientCacheStatus(this: ApolloClient) { +function _getApolloClientMemoryInternals(this: ApolloClient) { if (!__DEV__) throw new Error("only supported in development mode"); return { @@ -62,12 +84,18 @@ function _getApolloClientCacheStatus(this: ApolloClient) { this["queryManager"].documentTransform ), }, - cache: (this.cache as InMemoryCache).getCacheStatus?.(), + cache: this.cache.getMemoryInternals?.(), }, }; } -function _getInMemoryCacheStatus(this: InMemoryCache) { +function _getApolloCacheMemoryInternals(this: ApolloCache) { + return { + fragmentQueryDocuments: getWrapperInformation(this["getFragmentDoc"]), + }; +} + +function _getInMemoryCacheMemoryInternals(this: InMemoryCache) { const fragments = this.config.fragments as | undefined | { @@ -77,6 +105,7 @@ function _getInMemoryCacheStatus(this: InMemoryCache) { }; return { + ..._getApolloCacheMemoryInternals.apply(this as any), addTypenameTransform: transformInfo(this["addTypenameTransform"]), storeReader: { executeSelectionSet: getWrapperInformation( @@ -112,15 +141,17 @@ function transformInfo(transform?: DocumentTransform): number[] { getWrapperInformation(transform?.["performWork"]), ...transformInfo(transform?.["left"]), ...transformInfo(transform?.["right"]), - ].filter(Boolean as any as (x: any) => x is number); + ].filter((x): x is number => x != null); } -function linkInfo(link?: ApolloLink): number[] { +function linkInfo(link?: ApolloLink): unknown[] { return !link ? [] : [ - link?.cacheSize, + link?.getMemoryInternals?.(), ...linkInfo(link?.left), ...linkInfo(link?.right), - ].filter(Boolean as any as (x: any) => x is number); + ].filter((x) => x != null); } + +// removeTypenameFromVariables getVariableDefinitions From 0054428388f6ad7314aaac7f9e73697ec58772b1 Mon Sep 17 00:00:00 2001 From: Lenz Weber-Tronic Date: Tue, 12 Dec 2023 18:49:11 +0100 Subject: [PATCH 44/62] rename file --- src/cache/core/cache.ts | 2 +- src/cache/inmemory/inMemoryCache.ts | 2 +- src/core/ApolloClient.ts | 2 +- src/react/parser/index.ts | 2 +- .../caching/{getCacheStatus.ts => getMemoryInternals.ts} | 6 +++--- src/utilities/common/canonicalStringify.ts | 2 +- src/utilities/graphql/print.ts | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-) rename src/utilities/caching/{getCacheStatus.ts => getMemoryInternals.ts} (93%) diff --git a/src/cache/core/cache.ts b/src/cache/core/cache.ts index 7a82a32b571..4ac1727a5e9 100644 --- a/src/cache/core/cache.ts +++ b/src/cache/core/cache.ts @@ -6,7 +6,7 @@ import { cacheSizes, getFragmentQueryDocument } from "../../utilities/index.js"; import type { DataProxy } from "./types/DataProxy.js"; import type { Cache } from "./types/Cache.js"; import { WeakCache } from "@wry/caches"; -import { getApolloCacheMemoryInternals } from "../../utilities/caching/getCacheStatus.js"; +import { getApolloCacheMemoryInternals } from "../../utilities/caching/getMemoryInternals.js"; export type Transaction = (c: ApolloCache) => void; diff --git a/src/cache/inmemory/inMemoryCache.ts b/src/cache/inmemory/inMemoryCache.ts index a9f85d6be22..fa3a4c019ac 100644 --- a/src/cache/inmemory/inMemoryCache.ts +++ b/src/cache/inmemory/inMemoryCache.ts @@ -28,7 +28,7 @@ import { makeVar, forgetCache, recallCache } from "./reactiveVars.js"; import { Policies } from "./policies.js"; import { hasOwn, normalizeConfig, shouldCanonizeResults } from "./helpers.js"; import type { OperationVariables } from "../../core/index.js"; -import { getInMemoryCacheMemoryInternals } from "../../utilities/caching/getCacheStatus.js"; +import { getInMemoryCacheMemoryInternals } from "../../utilities/caching/getMemoryInternals.js"; type BroadcastOptions = Pick< Cache.BatchOptions, diff --git a/src/core/ApolloClient.ts b/src/core/ApolloClient.ts index f9c31d7d12e..a3216fdda34 100644 --- a/src/core/ApolloClient.ts +++ b/src/core/ApolloClient.ts @@ -122,7 +122,7 @@ export interface ApolloClientOptions { // @apollo/client/core. Since we need to preserve that API anyway, the easiest // solution is to reexport mergeOptions where it was previously declared (here). import { mergeOptions } from "../utilities/index.js"; -import { getApolloClientMemoryInternals } from "../utilities/caching/getCacheStatus.js"; +import { getApolloClientMemoryInternals } from "../utilities/caching/getMemoryInternals.js"; export { mergeOptions }; /** diff --git a/src/react/parser/index.ts b/src/react/parser/index.ts index 5bb0ab28a8e..35544189300 100644 --- a/src/react/parser/index.ts +++ b/src/react/parser/index.ts @@ -7,7 +7,7 @@ import type { OperationDefinitionNode, } from "graphql"; import { CleanWeakCache, cacheSizes } from "../../utilities/index.js"; -import { registerGlobalCache } from "../../utilities/caching/getCacheStatus.js"; +import { registerGlobalCache } from "../../utilities/caching/getMemoryInternals.js"; export enum DocumentType { Query, diff --git a/src/utilities/caching/getCacheStatus.ts b/src/utilities/caching/getMemoryInternals.ts similarity index 93% rename from src/utilities/caching/getCacheStatus.ts rename to src/utilities/caching/getMemoryInternals.ts index 17d367acd56..5636e44341a 100644 --- a/src/utilities/caching/getCacheStatus.ts +++ b/src/utilities/caching/getMemoryInternals.ts @@ -34,7 +34,7 @@ export function registerGlobalCache( type RemoveThis = T extends (this: any) => infer R ? () => R : never; /** - * For internal purposes only - please call `ApolloClient.getCacheStatus` instead + * For internal purposes only - please call `ApolloClient.getMemoryInternals` instead * @internal */ export const getApolloClientMemoryInternals = @@ -45,7 +45,7 @@ export const getApolloClientMemoryInternals = : undefined; /** - * For internal purposes only - please call `ApolloClient.getCacheStatus` instead + * For internal purposes only - please call `ApolloClient.getMemoryInternals` instead * @internal */ export const getInMemoryCacheMemoryInternals = @@ -56,7 +56,7 @@ export const getInMemoryCacheMemoryInternals = : undefined; /** - * For internal purposes only - please call `ApolloClient.getCacheStatus` instead + * For internal purposes only - please call `ApolloClient.getMemoryInternals` instead * @internal */ export const getApolloCacheMemoryInternals = diff --git a/src/utilities/common/canonicalStringify.ts b/src/utilities/common/canonicalStringify.ts index 4e02504e356..c64ff5c4063 100644 --- a/src/utilities/common/canonicalStringify.ts +++ b/src/utilities/common/canonicalStringify.ts @@ -1,5 +1,5 @@ import { CleanStrongCache, cacheSizes } from "../../utilities/caching/index.js"; -import { registerGlobalCache } from "../caching/getCacheStatus.js"; +import { registerGlobalCache } from "../caching/getMemoryInternals.js"; /** * Like JSON.stringify, but with object keys always sorted in the same order. diff --git a/src/utilities/graphql/print.ts b/src/utilities/graphql/print.ts index 28d5f4f9575..beb15f34937 100644 --- a/src/utilities/graphql/print.ts +++ b/src/utilities/graphql/print.ts @@ -1,7 +1,7 @@ import type { ASTNode } from "graphql"; import { print as origPrint } from "graphql"; import { CleanWeakCache, cacheSizes } from "../caching/index.js"; -import { registerGlobalCache } from "../caching/getCacheStatus.js"; +import { registerGlobalCache } from "../caching/getMemoryInternals.js"; let printCache!: CleanWeakCache; export const print = Object.assign( From bb857847890013b78ab9bcc3b3fea40917830676 Mon Sep 17 00:00:00 2001 From: Lenz Weber-Tronic Date: Tue, 12 Dec 2023 18:52:31 +0100 Subject: [PATCH 45/62] chores --- .api-reports/api-report-cache.md | 21 ++++--- .api-reports/api-report-core.md | 54 ++++++++---------- .api-reports/api-report-link_batch-http.md | 4 +- .api-reports/api-report-link_batch.md | 4 +- .api-reports/api-report-link_context.md | 4 +- .api-reports/api-report-link_core.md | 4 +- .api-reports/api-report-link_error.md | 4 +- .api-reports/api-report-link_http.md | 4 +- .../api-report-link_persisted-queries.md | 10 ++-- .../api-report-link_remove-typename.md | 12 +++- .api-reports/api-report-link_retry.md | 4 +- .api-reports/api-report-link_schema.md | 4 +- .api-reports/api-report-link_subscriptions.md | 4 +- .api-reports/api-report-link_ws.md | 4 +- .api-reports/api-report-react.md | 40 ++++++-------- .api-reports/api-report-react_components.md | 40 ++++++-------- .api-reports/api-report-react_context.md | 40 ++++++-------- .api-reports/api-report-react_hoc.md | 40 ++++++-------- .api-reports/api-report-react_hooks.md | 40 ++++++-------- .api-reports/api-report-react_ssr.md | 40 ++++++-------- .api-reports/api-report-testing.md | 40 ++++++-------- .api-reports/api-report-testing_core.md | 40 ++++++-------- .api-reports/api-report-utilities.md | 55 ++++++++----------- .api-reports/api-report.md | 54 ++++++++---------- src/core/QueryInfo.ts | 5 +- 25 files changed, 253 insertions(+), 318 deletions(-) diff --git a/.api-reports/api-report-cache.md b/.api-reports/api-report-cache.md index d73c0bffa54..ed31a3b8028 100644 --- a/.api-reports/api-report-cache.md +++ b/.api-reports/api-report-cache.md @@ -30,6 +30,10 @@ export abstract class ApolloCache implements DataProxy { abstract extract(optimistic?: boolean): TSerialized; // (undocumented) gc(): string[]; + // Warning: (ae-forgotten-export) The symbol "getApolloCacheMemoryInternals" needs to be exported by the entry point index.d.ts + // + // @internal + getMemoryInternals?: typeof getApolloCacheMemoryInternals; // (undocumented) identify(object: StoreObject | Reference): string | undefined; // (undocumented) @@ -474,13 +478,13 @@ export interface FragmentRegistryAPI { transform(document: D): D; } -// Warning: (ae-forgotten-export) The symbol "_getInMemoryCacheStatus" needs to be exported by the entry point index.d.ts -// // @internal -const getInMemoryCacheStatus: typeof _getInMemoryCacheStatus | undefined; +const getApolloCacheMemoryInternals: (() => { + fragmentQueryDocuments: number | undefined; +}) | undefined; -// @public (undocumented) -function _getInMemoryCacheStatus(this: InMemoryCache): { +// @internal +const getInMemoryCacheMemoryInternals: (() => { addTypenameTransform: number[]; storeReader: { executeSelectionSet: number | undefined; @@ -492,7 +496,8 @@ function _getInMemoryCacheStatus(this: InMemoryCache): { lookup: number | undefined; transform: number | undefined; }; -}; + fragmentQueryDocuments: number | undefined; +}) | undefined; // @public (undocumented) export type IdGetter = (value: IdGetterObj) => string | undefined; @@ -533,10 +538,10 @@ export class InMemoryCache extends ApolloCache { resetResultCache?: boolean; resetResultIdentities?: boolean; }): string[]; - // Warning: (ae-forgotten-export) The symbol "getInMemoryCacheStatus" needs to be exported by the entry point index.d.ts + // Warning: (ae-forgotten-export) The symbol "getInMemoryCacheMemoryInternals" needs to be exported by the entry point index.d.ts // // @internal - getCacheStatus?: typeof getInMemoryCacheStatus; + getMemoryInternals?: typeof getInMemoryCacheMemoryInternals; // (undocumented) identify(object: StoreObject | Reference): string | undefined; // (undocumented) diff --git a/.api-reports/api-report-core.md b/.api-reports/api-report-core.md index 27d24bbbe5b..89b7a6ebc99 100644 --- a/.api-reports/api-report-core.md +++ b/.api-reports/api-report-core.md @@ -46,6 +46,10 @@ export abstract class ApolloCache implements DataProxy { abstract extract(optimistic?: boolean): TSerialized; // (undocumented) gc(): string[]; + // Warning: (ae-forgotten-export) The symbol "getApolloCacheMemoryInternals" needs to be exported by the entry point index.d.ts + // + // @internal + getMemoryInternals?: typeof getApolloCacheMemoryInternals; // (undocumented) identify(object: StoreObject | Reference): string | undefined; // (undocumented) @@ -104,10 +108,10 @@ export class ApolloClient implements DataProxy { disableNetworkFetches: boolean; get documentTransform(): DocumentTransform; extract(optimistic?: boolean): TCacheShape; - // Warning: (ae-forgotten-export) The symbol "getApolloClientCacheStatus" needs to be exported by the entry point index.d.ts + // Warning: (ae-forgotten-export) The symbol "getApolloClientMemoryInternals" needs to be exported by the entry point index.d.ts // // @internal - getCacheStatus?: typeof getApolloClientCacheStatus; + getMemoryInternals?: typeof getApolloClientMemoryInternals; getObservableQueries(include?: RefetchQueriesInclude): Map>; getResolvers(): Resolvers; // (undocumented) @@ -215,8 +219,6 @@ interface ApolloErrorOptions { // @public (undocumented) export class ApolloLink { constructor(request?: RequestHandler); - // @internal - readonly cacheSize?: number; // (undocumented) static concat(first: ApolloLink | RequestHandler, second: ApolloLink | RequestHandler): ApolloLink; // (undocumented) @@ -228,6 +230,8 @@ export class ApolloLink { // (undocumented) static from(links: (ApolloLink | RequestHandler)[]): ApolloLink; // @internal + getMemoryInternals?: () => unknown; + // @internal readonly left?: ApolloLink; // (undocumented) protected onError(error: any, observer?: Observer): false | void; @@ -895,13 +899,13 @@ export function fromError(errorValue: any): Observable; // @public (undocumented) export function fromPromise(promise: Promise): Observable; -// Warning: (ae-forgotten-export) The symbol "_getApolloClientCacheStatus" needs to be exported by the entry point index.d.ts -// // @internal -const getApolloClientCacheStatus: typeof _getApolloClientCacheStatus | undefined; +const getApolloCacheMemoryInternals: (() => { + fragmentQueryDocuments: number | undefined; +}) | undefined; -// @public (undocumented) -function _getApolloClientCacheStatus(this: ApolloClient): { +// @internal +const getApolloClientMemoryInternals: (() => { limits: CacheSizes; sizes: { global: { @@ -909,34 +913,19 @@ function _getApolloClientCacheStatus(this: ApolloClient): { parser: number | undefined; canonicalStringify: number | undefined; }; - links: number[]; + links: unknown[]; queryManager: { Transforms: number; documentTransforms: number[]; }; cache: { - addTypenameTransform: number[]; - storeReader: { - executeSelectionSet: number | undefined; - executeSubSelectedArray: number | undefined; - }; - maybeBroadcastWatch: number | undefined; - fragmentRegistry: { - findFragmentSpreads: number | undefined; - lookup: number | undefined; - transform: number | undefined; - }; + fragmentQueryDocuments: number | undefined; } | undefined; }; -}; +}) | undefined; -// Warning: (ae-forgotten-export) The symbol "_getInMemoryCacheStatus" needs to be exported by the entry point index.d.ts -// // @internal -const getInMemoryCacheStatus: typeof _getInMemoryCacheStatus | undefined; - -// @public (undocumented) -function _getInMemoryCacheStatus(this: InMemoryCache): { +const getInMemoryCacheMemoryInternals: (() => { addTypenameTransform: number[]; storeReader: { executeSelectionSet: number | undefined; @@ -948,7 +937,8 @@ function _getInMemoryCacheStatus(this: InMemoryCache): { lookup: number | undefined; transform: number | undefined; }; -}; + fragmentQueryDocuments: number | undefined; +}) | undefined; export { gql } @@ -1063,10 +1053,10 @@ export class InMemoryCache extends ApolloCache { resetResultCache?: boolean; resetResultIdentities?: boolean; }): string[]; - // Warning: (ae-forgotten-export) The symbol "getInMemoryCacheStatus" needs to be exported by the entry point index.d.ts + // Warning: (ae-forgotten-export) The symbol "getInMemoryCacheMemoryInternals" needs to be exported by the entry point index.d.ts // // @internal - getCacheStatus?: typeof getInMemoryCacheStatus; + getMemoryInternals?: typeof getInMemoryCacheMemoryInternals; // (undocumented) identify(object: StoreObject | Reference): string | undefined; // (undocumented) @@ -2211,7 +2201,7 @@ interface WriteContext extends ReadMergeModifyContext { // src/core/QueryManager.ts:395:7 - (ae-forgotten-export) The symbol "UpdateQueries" needs to be exported by the entry point index.d.ts // src/core/watchQueryOptions.ts:253:2 - (ae-forgotten-export) The symbol "UpdateQueryFn" needs to be exported by the entry point index.d.ts // src/link/http/selectHttpOptionsAndBody.ts:128:32 - (ae-forgotten-export) The symbol "HttpQueryOptions" needs to be exported by the entry point index.d.ts -// src/utilities/caching/getCacheStatus.ts:47:61 - (ae-forgotten-export) The symbol "CacheSizes" needs to be exported by the entry point index.d.ts +// src/utilities/caching/getMemoryInternals.ts:40:44 - (ae-forgotten-export) The symbol "CacheSizes" needs to be exported by the entry point index.d.ts // (No @packageDocumentation comment for this package) diff --git a/.api-reports/api-report-link_batch-http.md b/.api-reports/api-report-link_batch-http.md index 6b309b17a1c..569450e1771 100644 --- a/.api-reports/api-report-link_batch-http.md +++ b/.api-reports/api-report-link_batch-http.md @@ -14,8 +14,6 @@ import type { Observer } from 'zen-observable-ts'; // @public (undocumented) class ApolloLink { constructor(request?: RequestHandler); - // @internal - readonly cacheSize?: number; // (undocumented) static concat(first: ApolloLink | RequestHandler, second: ApolloLink | RequestHandler): ApolloLink; // (undocumented) @@ -32,6 +30,8 @@ class ApolloLink { // (undocumented) static from(links: (ApolloLink | RequestHandler)[]): ApolloLink; // @internal + getMemoryInternals?: () => unknown; + // @internal readonly left?: ApolloLink; // (undocumented) protected onError(error: any, observer?: Observer): false | void; diff --git a/.api-reports/api-report-link_batch.md b/.api-reports/api-report-link_batch.md index bf5b34b6217..a547973287d 100644 --- a/.api-reports/api-report-link_batch.md +++ b/.api-reports/api-report-link_batch.md @@ -13,8 +13,6 @@ import type { Observer } from 'zen-observable-ts'; // @public (undocumented) class ApolloLink { constructor(request?: RequestHandler); - // @internal - readonly cacheSize?: number; // (undocumented) static concat(first: ApolloLink | RequestHandler, second: ApolloLink | RequestHandler): ApolloLink; // (undocumented) @@ -31,6 +29,8 @@ class ApolloLink { // (undocumented) static from(links: (ApolloLink | RequestHandler)[]): ApolloLink; // @internal + getMemoryInternals?: () => unknown; + // @internal readonly left?: ApolloLink; // (undocumented) protected onError(error: any, observer?: Observer): false | void; diff --git a/.api-reports/api-report-link_context.md b/.api-reports/api-report-link_context.md index da1be1cd478..af79db73e52 100644 --- a/.api-reports/api-report-link_context.md +++ b/.api-reports/api-report-link_context.md @@ -13,8 +13,6 @@ import type { Observer } from 'zen-observable-ts'; // @public (undocumented) class ApolloLink { constructor(request?: RequestHandler); - // @internal - readonly cacheSize?: number; // (undocumented) static concat(first: ApolloLink | RequestHandler, second: ApolloLink | RequestHandler): ApolloLink; // (undocumented) @@ -31,6 +29,8 @@ class ApolloLink { // (undocumented) static from(links: (ApolloLink | RequestHandler)[]): ApolloLink; // @internal + getMemoryInternals?: () => unknown; + // @internal readonly left?: ApolloLink; // (undocumented) protected onError(error: any, observer?: Observer): false | void; diff --git a/.api-reports/api-report-link_core.md b/.api-reports/api-report-link_core.md index da49593b51c..f488d284b51 100644 --- a/.api-reports/api-report-link_core.md +++ b/.api-reports/api-report-link_core.md @@ -13,8 +13,6 @@ import type { Observer } from 'zen-observable-ts'; // @public (undocumented) export class ApolloLink { constructor(request?: RequestHandler); - // @internal - readonly cacheSize?: number; // (undocumented) static concat(first: ApolloLink | RequestHandler, second: ApolloLink | RequestHandler): ApolloLink; // (undocumented) @@ -26,6 +24,8 @@ export class ApolloLink { // (undocumented) static from(links: (ApolloLink | RequestHandler)[]): ApolloLink; // @internal + getMemoryInternals?: () => unknown; + // @internal readonly left?: ApolloLink; // (undocumented) protected onError(error: any, observer?: Observer): false | void; diff --git a/.api-reports/api-report-link_error.md b/.api-reports/api-report-link_error.md index 186caf6958e..af048d6fe6b 100644 --- a/.api-reports/api-report-link_error.md +++ b/.api-reports/api-report-link_error.md @@ -13,8 +13,6 @@ import type { Observer } from 'zen-observable-ts'; // @public (undocumented) class ApolloLink { constructor(request?: RequestHandler); - // @internal - readonly cacheSize?: number; // (undocumented) static concat(first: ApolloLink | RequestHandler, second: ApolloLink | RequestHandler): ApolloLink; // (undocumented) @@ -31,6 +29,8 @@ class ApolloLink { // (undocumented) static from(links: (ApolloLink | RequestHandler)[]): ApolloLink; // @internal + getMemoryInternals?: () => unknown; + // @internal readonly left?: ApolloLink; // (undocumented) protected onError(error: any, observer?: Observer): false | void; diff --git a/.api-reports/api-report-link_http.md b/.api-reports/api-report-link_http.md index a40384874a6..30f6fa9210c 100644 --- a/.api-reports/api-report-link_http.md +++ b/.api-reports/api-report-link_http.md @@ -15,8 +15,6 @@ import type { Observer } from 'zen-observable-ts'; // @public (undocumented) class ApolloLink { constructor(request?: RequestHandler); - // @internal - readonly cacheSize?: number; // (undocumented) static concat(first: ApolloLink | RequestHandler, second: ApolloLink | RequestHandler): ApolloLink; // (undocumented) @@ -33,6 +31,8 @@ class ApolloLink { // (undocumented) static from(links: (ApolloLink | RequestHandler)[]): ApolloLink; // @internal + getMemoryInternals?: () => unknown; + // @internal readonly left?: ApolloLink; // (undocumented) protected onError(error: any, observer?: Observer): false | void; diff --git a/.api-reports/api-report-link_persisted-queries.md b/.api-reports/api-report-link_persisted-queries.md index db59134f2fe..63c58b75323 100644 --- a/.api-reports/api-report-link_persisted-queries.md +++ b/.api-reports/api-report-link_persisted-queries.md @@ -13,8 +13,6 @@ import type { Observer } from 'zen-observable-ts'; // @public (undocumented) class ApolloLink { constructor(request?: RequestHandler); - // @internal - readonly cacheSize?: number; // (undocumented) static concat(first: ApolloLink | RequestHandler, second: ApolloLink | RequestHandler): ApolloLink; // (undocumented) @@ -31,6 +29,8 @@ class ApolloLink { // (undocumented) static from(links: (ApolloLink | RequestHandler)[]): ApolloLink; // @internal + getMemoryInternals?: () => unknown; + // @internal readonly left?: ApolloLink; // (undocumented) protected onError(error: any, observer?: Observer): false | void; @@ -66,9 +66,11 @@ interface BaseOptions { export const createPersistedQueryLink: (options: PersistedQueryLink.Options) => ApolloLink & { resetHashCache: () => void; } & ({ - readonly cacheSize: number; + getMemoryInternals(): { + persistedQueryHashes: number; + }; } | { - readonly cacheSize?: undefined; + getMemoryInternals?: undefined; }); // @public (undocumented) diff --git a/.api-reports/api-report-link_remove-typename.md b/.api-reports/api-report-link_remove-typename.md index 3f6c576133c..f9ac25babc8 100644 --- a/.api-reports/api-report-link_remove-typename.md +++ b/.api-reports/api-report-link_remove-typename.md @@ -13,8 +13,6 @@ import type { Observer } from 'zen-observable-ts'; // @public (undocumented) class ApolloLink { constructor(request?: RequestHandler); - // @internal - readonly cacheSize?: number; // (undocumented) static concat(first: ApolloLink | RequestHandler, second: ApolloLink | RequestHandler): ApolloLink; // (undocumented) @@ -31,6 +29,8 @@ class ApolloLink { // (undocumented) static from(links: (ApolloLink | RequestHandler)[]): ApolloLink; // @internal + getMemoryInternals?: () => unknown; + // @internal readonly left?: ApolloLink; // (undocumented) protected onError(error: any, observer?: Observer): false | void; @@ -166,7 +166,13 @@ type Path = ReadonlyArray; // Warning: (ae-forgotten-export) The symbol "ApolloLink" needs to be exported by the entry point index.d.ts // // @public (undocumented) -export function removeTypenameFromVariables(options?: RemoveTypenameFromVariablesOptions): ApolloLink; +export function removeTypenameFromVariables(options?: RemoveTypenameFromVariablesOptions): ApolloLink & ({ + getMemoryInternals(): { + getVariableDefinitions: number; + }; +} | { + getMemoryInternals?: undefined; +}); // @public (undocumented) export interface RemoveTypenameFromVariablesOptions { diff --git a/.api-reports/api-report-link_retry.md b/.api-reports/api-report-link_retry.md index bc0689c5c47..a4a61a6ea1d 100644 --- a/.api-reports/api-report-link_retry.md +++ b/.api-reports/api-report-link_retry.md @@ -13,8 +13,6 @@ import type { Observer } from 'zen-observable-ts'; // @public (undocumented) class ApolloLink { constructor(request?: RequestHandler); - // @internal - readonly cacheSize?: number; // (undocumented) static concat(first: ApolloLink | RequestHandler, second: ApolloLink | RequestHandler): ApolloLink; // (undocumented) @@ -31,6 +29,8 @@ class ApolloLink { // (undocumented) static from(links: (ApolloLink | RequestHandler)[]): ApolloLink; // @internal + getMemoryInternals?: () => unknown; + // @internal readonly left?: ApolloLink; // (undocumented) protected onError(error: any, observer?: Observer): false | void; diff --git a/.api-reports/api-report-link_schema.md b/.api-reports/api-report-link_schema.md index ef56668ec7d..fcbee50828b 100644 --- a/.api-reports/api-report-link_schema.md +++ b/.api-reports/api-report-link_schema.md @@ -14,8 +14,6 @@ import type { Observer } from 'zen-observable-ts'; // @public (undocumented) class ApolloLink { constructor(request?: RequestHandler); - // @internal - readonly cacheSize?: number; // (undocumented) static concat(first: ApolloLink | RequestHandler, second: ApolloLink | RequestHandler): ApolloLink; // (undocumented) @@ -32,6 +30,8 @@ class ApolloLink { // (undocumented) static from(links: (ApolloLink | RequestHandler)[]): ApolloLink; // @internal + getMemoryInternals?: () => unknown; + // @internal readonly left?: ApolloLink; // (undocumented) protected onError(error: any, observer?: Observer): false | void; diff --git a/.api-reports/api-report-link_subscriptions.md b/.api-reports/api-report-link_subscriptions.md index 359060696d1..8745a5772cb 100644 --- a/.api-reports/api-report-link_subscriptions.md +++ b/.api-reports/api-report-link_subscriptions.md @@ -14,8 +14,6 @@ import type { Observer } from 'zen-observable-ts'; // @public (undocumented) class ApolloLink { constructor(request?: RequestHandler); - // @internal - readonly cacheSize?: number; // (undocumented) static concat(first: ApolloLink | RequestHandler, second: ApolloLink | RequestHandler): ApolloLink; // (undocumented) @@ -32,6 +30,8 @@ class ApolloLink { // (undocumented) static from(links: (ApolloLink | RequestHandler)[]): ApolloLink; // @internal + getMemoryInternals?: () => unknown; + // @internal readonly left?: ApolloLink; // (undocumented) protected onError(error: any, observer?: Observer): false | void; diff --git a/.api-reports/api-report-link_ws.md b/.api-reports/api-report-link_ws.md index 79ae349e6f8..72a8165e4f0 100644 --- a/.api-reports/api-report-link_ws.md +++ b/.api-reports/api-report-link_ws.md @@ -15,8 +15,6 @@ import { SubscriptionClient } from 'subscriptions-transport-ws'; // @public (undocumented) class ApolloLink { constructor(request?: RequestHandler); - // @internal - readonly cacheSize?: number; // (undocumented) static concat(first: ApolloLink | RequestHandler, second: ApolloLink | RequestHandler): ApolloLink; // (undocumented) @@ -33,6 +31,8 @@ class ApolloLink { // (undocumented) static from(links: (ApolloLink | RequestHandler)[]): ApolloLink; // @internal + getMemoryInternals?: () => unknown; + // @internal readonly left?: ApolloLink; // (undocumented) protected onError(error: any, observer?: Observer): false | void; diff --git a/.api-reports/api-report-react.md b/.api-reports/api-report-react.md index 32cbc8ba90f..bd99988f5cb 100644 --- a/.api-reports/api-report-react.md +++ b/.api-reports/api-report-react.md @@ -41,6 +41,10 @@ abstract class ApolloCache implements DataProxy { abstract extract(optimistic?: boolean): TSerialized; // (undocumented) gc(): string[]; + // Warning: (ae-forgotten-export) The symbol "getApolloCacheMemoryInternals" needs to be exported by the entry point index.d.ts + // + // @internal + getMemoryInternals?: typeof getApolloCacheMemoryInternals; // Warning: (ae-forgotten-export) The symbol "StoreObject" needs to be exported by the entry point index.d.ts // // (undocumented) @@ -115,10 +119,10 @@ class ApolloClient implements DataProxy { // Warning: (ae-forgotten-export) The symbol "DocumentTransform" needs to be exported by the entry point index.d.ts get documentTransform(): DocumentTransform; extract(optimistic?: boolean): TCacheShape; - // Warning: (ae-forgotten-export) The symbol "getApolloClientCacheStatus" needs to be exported by the entry point index.d.ts + // Warning: (ae-forgotten-export) The symbol "getApolloClientMemoryInternals" needs to be exported by the entry point index.d.ts // // @internal - getCacheStatus?: typeof getApolloClientCacheStatus; + getMemoryInternals?: typeof getApolloClientMemoryInternals; // Warning: (ae-forgotten-export) The symbol "RefetchQueriesInclude" needs to be exported by the entry point index.d.ts getObservableQueries(include?: RefetchQueriesInclude): Map>; getResolvers(): Resolvers; @@ -273,8 +277,6 @@ interface ApolloErrorOptions { // @public (undocumented) class ApolloLink { constructor(request?: RequestHandler); - // @internal - readonly cacheSize?: number; // (undocumented) static concat(first: ApolloLink | RequestHandler, second: ApolloLink | RequestHandler): ApolloLink; // (undocumented) @@ -288,6 +290,8 @@ class ApolloLink { // (undocumented) static from(links: (ApolloLink | RequestHandler)[]): ApolloLink; // @internal + getMemoryInternals?: () => unknown; + // @internal readonly left?: ApolloLink; // (undocumented) protected onError(error: any, observer?: Observer): false | void; @@ -850,13 +854,13 @@ interface FulfilledPromise extends Promise { value: TValue; } -// Warning: (ae-forgotten-export) The symbol "_getApolloClientCacheStatus" needs to be exported by the entry point index.d.ts -// // @internal -const getApolloClientCacheStatus: typeof _getApolloClientCacheStatus | undefined; +const getApolloCacheMemoryInternals: (() => { + fragmentQueryDocuments: number | undefined; +}) | undefined; -// @public (undocumented) -function _getApolloClientCacheStatus(this: ApolloClient): { +// @internal +const getApolloClientMemoryInternals: (() => { limits: CacheSizes; sizes: { global: { @@ -864,26 +868,16 @@ function _getApolloClientCacheStatus(this: ApolloClient): { parser: number | undefined; canonicalStringify: number | undefined; }; - links: number[]; + links: unknown[]; queryManager: { Transforms: number; documentTransforms: number[]; }; cache: { - addTypenameTransform: number[]; - storeReader: { - executeSelectionSet: number | undefined; - executeSubSelectedArray: number | undefined; - }; - maybeBroadcastWatch: number | undefined; - fragmentRegistry: { - findFragmentSpreads: number | undefined; - lookup: number | undefined; - transform: number | undefined; - }; + fragmentQueryDocuments: number | undefined; } | undefined; }; -}; +}) | undefined; // @public (undocumented) export function getApolloContext(): ReactTypes.Context; @@ -2330,7 +2324,7 @@ interface WatchQueryOptions implements DataProxy { abstract extract(optimistic?: boolean): TSerialized; // (undocumented) gc(): string[]; + // Warning: (ae-forgotten-export) The symbol "getApolloCacheMemoryInternals" needs to be exported by the entry point index.d.ts + // + // @internal + getMemoryInternals?: typeof getApolloCacheMemoryInternals; // Warning: (ae-forgotten-export) The symbol "StoreObject" needs to be exported by the entry point index.d.ts // // (undocumented) @@ -115,10 +119,10 @@ class ApolloClient implements DataProxy { // Warning: (ae-forgotten-export) The symbol "DocumentTransform" needs to be exported by the entry point index.d.ts get documentTransform(): DocumentTransform; extract(optimistic?: boolean): TCacheShape; - // Warning: (ae-forgotten-export) The symbol "getApolloClientCacheStatus" needs to be exported by the entry point index.d.ts + // Warning: (ae-forgotten-export) The symbol "getApolloClientMemoryInternals" needs to be exported by the entry point index.d.ts // // @internal - getCacheStatus?: typeof getApolloClientCacheStatus; + getMemoryInternals?: typeof getApolloClientMemoryInternals; // Warning: (ae-forgotten-export) The symbol "RefetchQueriesInclude" needs to be exported by the entry point index.d.ts getObservableQueries(include?: RefetchQueriesInclude): Map>; getResolvers(): Resolvers; @@ -251,8 +255,6 @@ interface ApolloErrorOptions { // @public (undocumented) class ApolloLink { constructor(request?: RequestHandler); - // @internal - readonly cacheSize?: number; // (undocumented) static concat(first: ApolloLink | RequestHandler, second: ApolloLink | RequestHandler): ApolloLink; // (undocumented) @@ -266,6 +268,8 @@ class ApolloLink { // (undocumented) static from(links: (ApolloLink | RequestHandler)[]): ApolloLink; // @internal + getMemoryInternals?: () => unknown; + // @internal readonly left?: ApolloLink; // (undocumented) protected onError(error: any, observer?: Observer): false | void; @@ -732,13 +736,13 @@ interface FragmentMap { // @public (undocumented) type FragmentMatcher = (rootValue: any, typeCondition: string, context: any) => boolean; -// Warning: (ae-forgotten-export) The symbol "_getApolloClientCacheStatus" needs to be exported by the entry point index.d.ts -// // @internal -const getApolloClientCacheStatus: typeof _getApolloClientCacheStatus | undefined; +const getApolloCacheMemoryInternals: (() => { + fragmentQueryDocuments: number | undefined; +}) | undefined; -// @public (undocumented) -function _getApolloClientCacheStatus(this: ApolloClient): { +// @internal +const getApolloClientMemoryInternals: (() => { limits: CacheSizes; sizes: { global: { @@ -746,26 +750,16 @@ function _getApolloClientCacheStatus(this: ApolloClient): { parser: number | undefined; canonicalStringify: number | undefined; }; - links: number[]; + links: unknown[]; queryManager: { Transforms: number; documentTransforms: number[]; }; cache: { - addTypenameTransform: number[]; - storeReader: { - executeSelectionSet: number | undefined; - executeSubSelectedArray: number | undefined; - }; - maybeBroadcastWatch: number | undefined; - fragmentRegistry: { - findFragmentSpreads: number | undefined; - lookup: number | undefined; - transform: number | undefined; - }; + fragmentQueryDocuments: number | undefined; } | undefined; }; -}; +}) | undefined; // @public (undocumented) type GraphQLErrors = ReadonlyArray; @@ -1756,7 +1750,7 @@ interface WatchQueryOptions implements DataProxy { abstract extract(optimistic?: boolean): TSerialized; // (undocumented) gc(): string[]; + // Warning: (ae-forgotten-export) The symbol "getApolloCacheMemoryInternals" needs to be exported by the entry point index.d.ts + // + // @internal + getMemoryInternals?: typeof getApolloCacheMemoryInternals; // Warning: (ae-forgotten-export) The symbol "StoreObject" needs to be exported by the entry point index.d.ts // // (undocumented) @@ -114,10 +118,10 @@ class ApolloClient implements DataProxy { // Warning: (ae-forgotten-export) The symbol "DocumentTransform" needs to be exported by the entry point index.d.ts get documentTransform(): DocumentTransform; extract(optimistic?: boolean): TCacheShape; - // Warning: (ae-forgotten-export) The symbol "getApolloClientCacheStatus" needs to be exported by the entry point index.d.ts + // Warning: (ae-forgotten-export) The symbol "getApolloClientMemoryInternals" needs to be exported by the entry point index.d.ts // // @internal - getCacheStatus?: typeof getApolloClientCacheStatus; + getMemoryInternals?: typeof getApolloClientMemoryInternals; // Warning: (ae-forgotten-export) The symbol "RefetchQueriesInclude" needs to be exported by the entry point index.d.ts getObservableQueries(include?: RefetchQueriesInclude): Map>; getResolvers(): Resolvers; @@ -271,8 +275,6 @@ interface ApolloErrorOptions { // @public (undocumented) class ApolloLink { constructor(request?: RequestHandler); - // @internal - readonly cacheSize?: number; // (undocumented) static concat(first: ApolloLink | RequestHandler, second: ApolloLink | RequestHandler): ApolloLink; // (undocumented) @@ -286,6 +288,8 @@ class ApolloLink { // (undocumented) static from(links: (ApolloLink | RequestHandler)[]): ApolloLink; // @internal + getMemoryInternals?: () => unknown; + // @internal readonly left?: ApolloLink; // (undocumented) protected onError(error: any, observer?: Observer): false | void; @@ -715,13 +719,13 @@ interface FragmentMap { // @public (undocumented) type FragmentMatcher = (rootValue: any, typeCondition: string, context: any) => boolean; -// Warning: (ae-forgotten-export) The symbol "_getApolloClientCacheStatus" needs to be exported by the entry point index.d.ts -// // @internal -const getApolloClientCacheStatus: typeof _getApolloClientCacheStatus | undefined; +const getApolloCacheMemoryInternals: (() => { + fragmentQueryDocuments: number | undefined; +}) | undefined; -// @public (undocumented) -function _getApolloClientCacheStatus(this: ApolloClient): { +// @internal +const getApolloClientMemoryInternals: (() => { limits: CacheSizes; sizes: { global: { @@ -729,26 +733,16 @@ function _getApolloClientCacheStatus(this: ApolloClient): { parser: number | undefined; canonicalStringify: number | undefined; }; - links: number[]; + links: unknown[]; queryManager: { Transforms: number; documentTransforms: number[]; }; cache: { - addTypenameTransform: number[]; - storeReader: { - executeSelectionSet: number | undefined; - executeSubSelectedArray: number | undefined; - }; - maybeBroadcastWatch: number | undefined; - fragmentRegistry: { - findFragmentSpreads: number | undefined; - lookup: number | undefined; - transform: number | undefined; - }; + fragmentQueryDocuments: number | undefined; } | undefined; }; -}; +}) | undefined; // @public (undocumented) export function getApolloContext(): ReactTypes.Context; @@ -1652,7 +1646,7 @@ interface WatchQueryOptions implements DataProxy { abstract extract(optimistic?: boolean): TSerialized; // (undocumented) gc(): string[]; + // Warning: (ae-forgotten-export) The symbol "getApolloCacheMemoryInternals" needs to be exported by the entry point index.d.ts + // + // @internal + getMemoryInternals?: typeof getApolloCacheMemoryInternals; // Warning: (ae-forgotten-export) The symbol "StoreObject" needs to be exported by the entry point index.d.ts // // (undocumented) @@ -114,10 +118,10 @@ class ApolloClient implements DataProxy { // Warning: (ae-forgotten-export) The symbol "DocumentTransform" needs to be exported by the entry point index.d.ts get documentTransform(): DocumentTransform; extract(optimistic?: boolean): TCacheShape; - // Warning: (ae-forgotten-export) The symbol "getApolloClientCacheStatus" needs to be exported by the entry point index.d.ts + // Warning: (ae-forgotten-export) The symbol "getApolloClientMemoryInternals" needs to be exported by the entry point index.d.ts // // @internal - getCacheStatus?: typeof getApolloClientCacheStatus; + getMemoryInternals?: typeof getApolloClientMemoryInternals; // Warning: (ae-forgotten-export) The symbol "RefetchQueriesInclude" needs to be exported by the entry point index.d.ts getObservableQueries(include?: RefetchQueriesInclude): Map>; getResolvers(): Resolvers; @@ -250,8 +254,6 @@ interface ApolloErrorOptions { // @public (undocumented) class ApolloLink { constructor(request?: RequestHandler); - // @internal - readonly cacheSize?: number; // (undocumented) static concat(first: ApolloLink | RequestHandler, second: ApolloLink | RequestHandler): ApolloLink; // (undocumented) @@ -265,6 +267,8 @@ class ApolloLink { // (undocumented) static from(links: (ApolloLink | RequestHandler)[]): ApolloLink; // @internal + getMemoryInternals?: () => unknown; + // @internal readonly left?: ApolloLink; // (undocumented) protected onError(error: any, observer?: Observer): false | void; @@ -726,13 +730,13 @@ interface FragmentMap { // @public (undocumented) type FragmentMatcher = (rootValue: any, typeCondition: string, context: any) => boolean; -// Warning: (ae-forgotten-export) The symbol "_getApolloClientCacheStatus" needs to be exported by the entry point index.d.ts -// // @internal -const getApolloClientCacheStatus: typeof _getApolloClientCacheStatus | undefined; +const getApolloCacheMemoryInternals: (() => { + fragmentQueryDocuments: number | undefined; +}) | undefined; -// @public (undocumented) -function _getApolloClientCacheStatus(this: ApolloClient): { +// @internal +const getApolloClientMemoryInternals: (() => { limits: CacheSizes; sizes: { global: { @@ -740,26 +744,16 @@ function _getApolloClientCacheStatus(this: ApolloClient): { parser: number | undefined; canonicalStringify: number | undefined; }; - links: number[]; + links: unknown[]; queryManager: { Transforms: number; documentTransforms: number[]; }; cache: { - addTypenameTransform: number[]; - storeReader: { - executeSelectionSet: number | undefined; - executeSubSelectedArray: number | undefined; - }; - maybeBroadcastWatch: number | undefined; - fragmentRegistry: { - findFragmentSpreads: number | undefined; - lookup: number | undefined; - transform: number | undefined; - }; + fragmentQueryDocuments: number | undefined; } | undefined; }; -}; +}) | undefined; // @public (undocumented) export function graphql> & Partial>>(document: DocumentNode, operationOptions?: OperationOption): (WrappedComponent: ReactTypes.ComponentType) => ReactTypes.ComponentClass; @@ -1697,7 +1691,7 @@ export function withSubscription implements DataProxy { abstract extract(optimistic?: boolean): TSerialized; // (undocumented) gc(): string[]; + // Warning: (ae-forgotten-export) The symbol "getApolloCacheMemoryInternals" needs to be exported by the entry point index.d.ts + // + // @internal + getMemoryInternals?: typeof getApolloCacheMemoryInternals; // Warning: (ae-forgotten-export) The symbol "StoreObject" needs to be exported by the entry point index.d.ts // // (undocumented) @@ -113,10 +117,10 @@ class ApolloClient implements DataProxy { // Warning: (ae-forgotten-export) The symbol "DocumentTransform" needs to be exported by the entry point index.d.ts get documentTransform(): DocumentTransform; extract(optimistic?: boolean): TCacheShape; - // Warning: (ae-forgotten-export) The symbol "getApolloClientCacheStatus" needs to be exported by the entry point index.d.ts + // Warning: (ae-forgotten-export) The symbol "getApolloClientMemoryInternals" needs to be exported by the entry point index.d.ts // // @internal - getCacheStatus?: typeof getApolloClientCacheStatus; + getMemoryInternals?: typeof getApolloClientMemoryInternals; // Warning: (ae-forgotten-export) The symbol "RefetchQueriesInclude" needs to be exported by the entry point index.d.ts getObservableQueries(include?: RefetchQueriesInclude): Map>; getResolvers(): Resolvers; @@ -249,8 +253,6 @@ interface ApolloErrorOptions { // @public (undocumented) class ApolloLink { constructor(request?: RequestHandler); - // @internal - readonly cacheSize?: number; // (undocumented) static concat(first: ApolloLink | RequestHandler, second: ApolloLink | RequestHandler): ApolloLink; // (undocumented) @@ -264,6 +266,8 @@ class ApolloLink { // (undocumented) static from(links: (ApolloLink | RequestHandler)[]): ApolloLink; // @internal + getMemoryInternals?: () => unknown; + // @internal readonly left?: ApolloLink; // (undocumented) protected onError(error: any, observer?: Observer): false | void; @@ -810,13 +814,13 @@ interface FulfilledPromise extends Promise { value: TValue; } -// Warning: (ae-forgotten-export) The symbol "_getApolloClientCacheStatus" needs to be exported by the entry point index.d.ts -// // @internal -const getApolloClientCacheStatus: typeof _getApolloClientCacheStatus | undefined; +const getApolloCacheMemoryInternals: (() => { + fragmentQueryDocuments: number | undefined; +}) | undefined; -// @public (undocumented) -function _getApolloClientCacheStatus(this: ApolloClient): { +// @internal +const getApolloClientMemoryInternals: (() => { limits: CacheSizes; sizes: { global: { @@ -824,26 +828,16 @@ function _getApolloClientCacheStatus(this: ApolloClient): { parser: number | undefined; canonicalStringify: number | undefined; }; - links: number[]; + links: unknown[]; queryManager: { Transforms: number; documentTransforms: number[]; }; cache: { - addTypenameTransform: number[]; - storeReader: { - executeSelectionSet: number | undefined; - executeSubSelectedArray: number | undefined; - }; - maybeBroadcastWatch: number | undefined; - fragmentRegistry: { - findFragmentSpreads: number | undefined; - lookup: number | undefined; - transform: number | undefined; - }; + fragmentQueryDocuments: number | undefined; } | undefined; }; -}; +}) | undefined; // @public (undocumented) type GraphQLErrors = ReadonlyArray; @@ -2221,7 +2215,7 @@ interface WatchQueryOptions implements DataProxy { abstract extract(optimistic?: boolean): TSerialized; // (undocumented) gc(): string[]; + // Warning: (ae-forgotten-export) The symbol "getApolloCacheMemoryInternals" needs to be exported by the entry point index.d.ts + // + // @internal + getMemoryInternals?: typeof getApolloCacheMemoryInternals; // Warning: (ae-forgotten-export) The symbol "StoreObject" needs to be exported by the entry point index.d.ts // // (undocumented) @@ -114,10 +118,10 @@ class ApolloClient implements DataProxy { // Warning: (ae-forgotten-export) The symbol "DocumentTransform" needs to be exported by the entry point index.d.ts get documentTransform(): DocumentTransform; extract(optimistic?: boolean): TCacheShape; - // Warning: (ae-forgotten-export) The symbol "getApolloClientCacheStatus" needs to be exported by the entry point index.d.ts + // Warning: (ae-forgotten-export) The symbol "getApolloClientMemoryInternals" needs to be exported by the entry point index.d.ts // // @internal - getCacheStatus?: typeof getApolloClientCacheStatus; + getMemoryInternals?: typeof getApolloClientMemoryInternals; // Warning: (ae-forgotten-export) The symbol "RefetchQueriesInclude" needs to be exported by the entry point index.d.ts getObservableQueries(include?: RefetchQueriesInclude): Map>; getResolvers(): Resolvers; @@ -250,8 +254,6 @@ interface ApolloErrorOptions { // @public (undocumented) class ApolloLink { constructor(request?: RequestHandler); - // @internal - readonly cacheSize?: number; // (undocumented) static concat(first: ApolloLink | RequestHandler, second: ApolloLink | RequestHandler): ApolloLink; // (undocumented) @@ -265,6 +267,8 @@ class ApolloLink { // (undocumented) static from(links: (ApolloLink | RequestHandler)[]): ApolloLink; // @internal + getMemoryInternals?: () => unknown; + // @internal readonly left?: ApolloLink; // (undocumented) protected onError(error: any, observer?: Observer): false | void; @@ -685,13 +689,13 @@ interface FragmentMap { // @public (undocumented) type FragmentMatcher = (rootValue: any, typeCondition: string, context: any) => boolean; -// Warning: (ae-forgotten-export) The symbol "_getApolloClientCacheStatus" needs to be exported by the entry point index.d.ts -// // @internal -const getApolloClientCacheStatus: typeof _getApolloClientCacheStatus | undefined; +const getApolloCacheMemoryInternals: (() => { + fragmentQueryDocuments: number | undefined; +}) | undefined; -// @public (undocumented) -function _getApolloClientCacheStatus(this: ApolloClient): { +// @internal +const getApolloClientMemoryInternals: (() => { limits: CacheSizes; sizes: { global: { @@ -699,26 +703,16 @@ function _getApolloClientCacheStatus(this: ApolloClient): { parser: number | undefined; canonicalStringify: number | undefined; }; - links: number[]; + links: unknown[]; queryManager: { Transforms: number; documentTransforms: number[]; }; cache: { - addTypenameTransform: number[]; - storeReader: { - executeSelectionSet: number | undefined; - executeSubSelectedArray: number | undefined; - }; - maybeBroadcastWatch: number | undefined; - fragmentRegistry: { - findFragmentSpreads: number | undefined; - lookup: number | undefined; - transform: number | undefined; - }; + fragmentQueryDocuments: number | undefined; } | undefined; }; -}; +}) | undefined; // @public (undocumented) export function getDataFromTree(tree: ReactTypes.ReactNode, context?: { @@ -1638,7 +1632,7 @@ interface WatchQueryOptions implements DataProxy { abstract extract(optimistic?: boolean): TSerialized; // (undocumented) gc(): string[]; + // Warning: (ae-forgotten-export) The symbol "getApolloCacheMemoryInternals" needs to be exported by the entry point index.d.ts + // + // @internal + getMemoryInternals?: typeof getApolloCacheMemoryInternals; // Warning: (ae-forgotten-export) The symbol "StoreObject" needs to be exported by the entry point index.d.ts // // (undocumented) @@ -114,10 +118,10 @@ class ApolloClient implements DataProxy { // Warning: (ae-forgotten-export) The symbol "DocumentTransform" needs to be exported by the entry point index.d.ts get documentTransform(): DocumentTransform; extract(optimistic?: boolean): TCacheShape; - // Warning: (ae-forgotten-export) The symbol "getApolloClientCacheStatus" needs to be exported by the entry point index.d.ts + // Warning: (ae-forgotten-export) The symbol "getApolloClientMemoryInternals" needs to be exported by the entry point index.d.ts // // @internal - getCacheStatus?: typeof getApolloClientCacheStatus; + getMemoryInternals?: typeof getApolloClientMemoryInternals; // Warning: (ae-forgotten-export) The symbol "RefetchQueriesInclude" needs to be exported by the entry point index.d.ts getObservableQueries(include?: RefetchQueriesInclude): Map>; getResolvers(): Resolvers; @@ -250,8 +254,6 @@ interface ApolloErrorOptions { // @public (undocumented) class ApolloLink { constructor(request?: RequestHandler); - // @internal - readonly cacheSize?: number; // (undocumented) static concat(first: ApolloLink | RequestHandler, second: ApolloLink | RequestHandler): ApolloLink; // (undocumented) @@ -265,6 +267,8 @@ class ApolloLink { // (undocumented) static from(links: (ApolloLink | RequestHandler)[]): ApolloLink; // @internal + getMemoryInternals?: () => unknown; + // @internal readonly left?: ApolloLink; // (undocumented) protected onError(error: any, observer?: Observer): false | void; @@ -679,13 +683,13 @@ interface FragmentMap { // @public (undocumented) type FragmentMatcher = (rootValue: any, typeCondition: string, context: any) => boolean; -// Warning: (ae-forgotten-export) The symbol "_getApolloClientCacheStatus" needs to be exported by the entry point index.d.ts -// // @internal -const getApolloClientCacheStatus: typeof _getApolloClientCacheStatus | undefined; +const getApolloCacheMemoryInternals: (() => { + fragmentQueryDocuments: number | undefined; +}) | undefined; -// @public (undocumented) -function _getApolloClientCacheStatus(this: ApolloClient): { +// @internal +const getApolloClientMemoryInternals: (() => { limits: CacheSizes; sizes: { global: { @@ -693,26 +697,16 @@ function _getApolloClientCacheStatus(this: ApolloClient): { parser: number | undefined; canonicalStringify: number | undefined; }; - links: number[]; + links: unknown[]; queryManager: { Transforms: number; documentTransforms: number[]; }; cache: { - addTypenameTransform: number[]; - storeReader: { - executeSelectionSet: number | undefined; - executeSubSelectedArray: number | undefined; - }; - maybeBroadcastWatch: number | undefined; - fragmentRegistry: { - findFragmentSpreads: number | undefined; - lookup: number | undefined; - transform: number | undefined; - }; + fragmentQueryDocuments: number | undefined; } | undefined; }; -}; +}) | undefined; // @public (undocumented) type GraphQLErrors = ReadonlyArray; @@ -1700,7 +1694,7 @@ export function withWarningSpy(it: (...args: TArgs // src/core/types.ts:174:3 - (ae-forgotten-export) The symbol "MutationQueryReducer" needs to be exported by the entry point index.d.ts // src/core/types.ts:201:5 - (ae-forgotten-export) The symbol "Resolver" needs to be exported by the entry point index.d.ts // src/core/watchQueryOptions.ts:253:2 - (ae-forgotten-export) The symbol "UpdateQueryFn" needs to be exported by the entry point index.d.ts -// src/utilities/caching/getCacheStatus.ts:47:61 - (ae-forgotten-export) The symbol "CacheSizes" needs to be exported by the entry point index.d.ts +// src/utilities/caching/getMemoryInternals.ts:40:44 - (ae-forgotten-export) The symbol "CacheSizes" 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 b732c178099..35a1c34b998 100644 --- a/.api-reports/api-report-testing_core.md +++ b/.api-reports/api-report-testing_core.md @@ -39,6 +39,10 @@ abstract class ApolloCache implements DataProxy { abstract extract(optimistic?: boolean): TSerialized; // (undocumented) gc(): string[]; + // Warning: (ae-forgotten-export) The symbol "getApolloCacheMemoryInternals" needs to be exported by the entry point index.d.ts + // + // @internal + getMemoryInternals?: typeof getApolloCacheMemoryInternals; // Warning: (ae-forgotten-export) The symbol "StoreObject" needs to be exported by the entry point index.d.ts // // (undocumented) @@ -113,10 +117,10 @@ class ApolloClient implements DataProxy { // Warning: (ae-forgotten-export) The symbol "DocumentTransform" needs to be exported by the entry point index.d.ts get documentTransform(): DocumentTransform; extract(optimistic?: boolean): TCacheShape; - // Warning: (ae-forgotten-export) The symbol "getApolloClientCacheStatus" needs to be exported by the entry point index.d.ts + // Warning: (ae-forgotten-export) The symbol "getApolloClientMemoryInternals" needs to be exported by the entry point index.d.ts // // @internal - getCacheStatus?: typeof getApolloClientCacheStatus; + getMemoryInternals?: typeof getApolloClientMemoryInternals; // Warning: (ae-forgotten-export) The symbol "RefetchQueriesInclude" needs to be exported by the entry point index.d.ts getObservableQueries(include?: RefetchQueriesInclude): Map>; getResolvers(): Resolvers; @@ -249,8 +253,6 @@ interface ApolloErrorOptions { // @public (undocumented) class ApolloLink { constructor(request?: RequestHandler); - // @internal - readonly cacheSize?: number; // (undocumented) static concat(first: ApolloLink | RequestHandler, second: ApolloLink | RequestHandler): ApolloLink; // (undocumented) @@ -264,6 +266,8 @@ class ApolloLink { // (undocumented) static from(links: (ApolloLink | RequestHandler)[]): ApolloLink; // @internal + getMemoryInternals?: () => unknown; + // @internal readonly left?: ApolloLink; // (undocumented) protected onError(error: any, observer?: Observer): false | void; @@ -678,13 +682,13 @@ interface FragmentMap { // @public (undocumented) type FragmentMatcher = (rootValue: any, typeCondition: string, context: any) => boolean; -// Warning: (ae-forgotten-export) The symbol "_getApolloClientCacheStatus" needs to be exported by the entry point index.d.ts -// // @internal -const getApolloClientCacheStatus: typeof _getApolloClientCacheStatus | undefined; +const getApolloCacheMemoryInternals: (() => { + fragmentQueryDocuments: number | undefined; +}) | undefined; -// @public (undocumented) -function _getApolloClientCacheStatus(this: ApolloClient): { +// @internal +const getApolloClientMemoryInternals: (() => { limits: CacheSizes; sizes: { global: { @@ -692,26 +696,16 @@ function _getApolloClientCacheStatus(this: ApolloClient): { parser: number | undefined; canonicalStringify: number | undefined; }; - links: number[]; + links: unknown[]; queryManager: { Transforms: number; documentTransforms: number[]; }; cache: { - addTypenameTransform: number[]; - storeReader: { - executeSelectionSet: number | undefined; - executeSubSelectedArray: number | undefined; - }; - maybeBroadcastWatch: number | undefined; - fragmentRegistry: { - findFragmentSpreads: number | undefined; - lookup: number | undefined; - transform: number | undefined; - }; + fragmentQueryDocuments: number | undefined; } | undefined; }; -}; +}) | undefined; // @public (undocumented) type GraphQLErrors = ReadonlyArray; @@ -1657,7 +1651,7 @@ export function withWarningSpy(it: (...args: TArgs // src/core/types.ts:174:3 - (ae-forgotten-export) The symbol "MutationQueryReducer" needs to be exported by the entry point index.d.ts // src/core/types.ts:201:5 - (ae-forgotten-export) The symbol "Resolver" needs to be exported by the entry point index.d.ts // src/core/watchQueryOptions.ts:253:2 - (ae-forgotten-export) The symbol "UpdateQueryFn" needs to be exported by the entry point index.d.ts -// src/utilities/caching/getCacheStatus.ts:47:61 - (ae-forgotten-export) The symbol "CacheSizes" needs to be exported by the entry point index.d.ts +// src/utilities/caching/getMemoryInternals.ts:40:44 - (ae-forgotten-export) The symbol "CacheSizes" 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 16ba72d5930..d9428aae329 100644 --- a/.api-reports/api-report-utilities.md +++ b/.api-reports/api-report-utilities.md @@ -57,6 +57,10 @@ abstract class ApolloCache implements DataProxy { abstract extract(optimistic?: boolean): TSerialized; // (undocumented) gc(): string[]; + // Warning: (ae-forgotten-export) The symbol "getApolloCacheMemoryInternals" needs to be exported by the entry point index.d.ts + // + // @internal + getMemoryInternals?: typeof getApolloCacheMemoryInternals; // (undocumented) identify(object: StoreObject | Reference): string | undefined; // (undocumented) @@ -126,10 +130,10 @@ class ApolloClient implements DataProxy { disableNetworkFetches: boolean; get documentTransform(): DocumentTransform; extract(optimistic?: boolean): TCacheShape; - // Warning: (ae-forgotten-export) The symbol "getApolloClientCacheStatus" needs to be exported by the entry point index.d.ts + // Warning: (ae-forgotten-export) The symbol "getApolloClientMemoryInternals" needs to be exported by the entry point index.d.ts // // @internal - getCacheStatus?: typeof getApolloClientCacheStatus; + getMemoryInternals?: typeof getApolloClientMemoryInternals; // Warning: (ae-forgotten-export) The symbol "RefetchQueriesInclude" needs to be exported by the entry point index.d.ts getObservableQueries(include?: RefetchQueriesInclude): Map>; getResolvers(): Resolvers; @@ -262,8 +266,6 @@ interface ApolloErrorOptions { // @public (undocumented) class ApolloLink { constructor(request?: RequestHandler); - // @internal - readonly cacheSize?: number; // (undocumented) static concat(first: ApolloLink | RequestHandler, second: ApolloLink | RequestHandler): ApolloLink; // (undocumented) @@ -277,6 +279,8 @@ class ApolloLink { // (undocumented) static from(links: (ApolloLink | RequestHandler)[]): ApolloLink; // @internal + getMemoryInternals?: () => unknown; + // @internal readonly left?: ApolloLink; // (undocumented) protected onError(error: any, observer?: Observer): false | void; @@ -1053,15 +1057,13 @@ interface FulfilledPromise extends Promise { value: TValue; } -// Warning: (ae-forgotten-export) The symbol "_getApolloClientCacheStatus" needs to be exported by the entry point index.d.ts -// // @internal -const getApolloClientCacheStatus: typeof _getApolloClientCacheStatus | undefined; +const getApolloCacheMemoryInternals: (() => { + fragmentQueryDocuments: number | undefined; +}) | undefined; -// Warning: (ae-forgotten-export) The symbol "ApolloClient" needs to be exported by the entry point index.d.ts -// -// @public (undocumented) -function _getApolloClientCacheStatus(this: ApolloClient): { +// @internal +const getApolloClientMemoryInternals: (() => { limits: CacheSizes; sizes: { global: { @@ -1069,26 +1071,16 @@ function _getApolloClientCacheStatus(this: ApolloClient): { parser: number | undefined; canonicalStringify: number | undefined; }; - links: number[]; + links: unknown[]; queryManager: { Transforms: number; documentTransforms: number[]; }; cache: { - addTypenameTransform: number[]; - storeReader: { - executeSelectionSet: number | undefined; - executeSubSelectedArray: number | undefined; - }; - maybeBroadcastWatch: number | undefined; - fragmentRegistry: { - findFragmentSpreads: number | undefined; - lookup: number | undefined; - transform: number | undefined; - }; + fragmentQueryDocuments: number | undefined; } | undefined; }; -}; +}) | undefined; // @public (undocumented) export function getDefaultValues(definition: OperationDefinitionNode | undefined): Record; @@ -1120,13 +1112,8 @@ export function getGraphQLErrorsFromResult(result: FetchResult): GraphQLEr // @public (undocumented) export function getInclusionDirectives(directives: ReadonlyArray): InclusionDirectives; -// Warning: (ae-forgotten-export) The symbol "_getInMemoryCacheStatus" needs to be exported by the entry point index.d.ts -// // @internal -const getInMemoryCacheStatus: typeof _getInMemoryCacheStatus | undefined; - -// @public (undocumented) -function _getInMemoryCacheStatus(this: InMemoryCache): { +const getInMemoryCacheMemoryInternals: (() => { addTypenameTransform: number[]; storeReader: { executeSelectionSet: number | undefined; @@ -1138,7 +1125,8 @@ function _getInMemoryCacheStatus(this: InMemoryCache): { lookup: number | undefined; transform: number | undefined; }; -}; + fragmentQueryDocuments: number | undefined; +}) | undefined; // @public export function getMainDefinition(queryDoc: DocumentNode): OperationDefinitionNode | FragmentDefinitionNode; @@ -1261,10 +1249,10 @@ class InMemoryCache extends ApolloCache { resetResultCache?: boolean; resetResultIdentities?: boolean; }): string[]; - // Warning: (ae-forgotten-export) The symbol "getInMemoryCacheStatus" needs to be exported by the entry point index.d.ts + // Warning: (ae-forgotten-export) The symbol "getInMemoryCacheMemoryInternals" needs to be exported by the entry point index.d.ts // // @internal - getCacheStatus?: typeof getInMemoryCacheStatus; + getMemoryInternals?: typeof getInMemoryCacheMemoryInternals; // (undocumented) identify(object: StoreObject | Reference): string | undefined; // Warning: (ae-forgotten-export) The symbol "makeVar" needs to be exported by the entry point index.d.ts @@ -2572,6 +2560,7 @@ interface WriteContext extends ReadMergeModifyContext { // src/cache/inmemory/policies.ts:163:3 - (ae-forgotten-export) The symbol "FieldMergeFunction" needs to be exported by the entry point index.d.ts // src/cache/inmemory/types.ts:132:3 - (ae-forgotten-export) The symbol "KeyFieldsFunction" needs to be exported by the entry point index.d.ts // src/cache/inmemory/writeToStore.ts:65:7 - (ae-forgotten-export) The symbol "MergeTree" needs to be exported by the entry point index.d.ts +// src/core/LocalState.ts:71:3 - (ae-forgotten-export) The symbol "ApolloClient" needs to be exported by the entry point index.d.ts // src/core/ObservableQuery.ts:113:5 - (ae-forgotten-export) The symbol "QueryManager" needs to be exported by the entry point index.d.ts // src/core/ObservableQuery.ts:114:5 - (ae-forgotten-export) The symbol "QueryInfo" needs to be exported by the entry point index.d.ts // src/core/QueryManager.ts:120:5 - (ae-forgotten-export) The symbol "MutationStoreValue" needs to be exported by the entry point index.d.ts diff --git a/.api-reports/api-report.md b/.api-reports/api-report.md index bea514b4a2a..81cf6eb7dc7 100644 --- a/.api-reports/api-report.md +++ b/.api-reports/api-report.md @@ -48,6 +48,10 @@ export abstract class ApolloCache implements DataProxy { abstract extract(optimistic?: boolean): TSerialized; // (undocumented) gc(): string[]; + // Warning: (ae-forgotten-export) The symbol "getApolloCacheMemoryInternals" needs to be exported by the entry point index.d.ts + // + // @internal + getMemoryInternals?: typeof getApolloCacheMemoryInternals; // (undocumented) identify(object: StoreObject | Reference): string | undefined; // (undocumented) @@ -106,10 +110,10 @@ export class ApolloClient implements DataProxy { disableNetworkFetches: boolean; get documentTransform(): DocumentTransform; extract(optimistic?: boolean): TCacheShape; - // Warning: (ae-forgotten-export) The symbol "getApolloClientCacheStatus" needs to be exported by the entry point index.d.ts + // Warning: (ae-forgotten-export) The symbol "getApolloClientMemoryInternals" needs to be exported by the entry point index.d.ts // // @internal - getCacheStatus?: typeof getApolloClientCacheStatus; + getMemoryInternals?: typeof getApolloClientMemoryInternals; getObservableQueries(include?: RefetchQueriesInclude): Map>; getResolvers(): Resolvers; // (undocumented) @@ -238,8 +242,6 @@ interface ApolloErrorOptions { // @public (undocumented) export class ApolloLink { constructor(request?: RequestHandler); - // @internal - readonly cacheSize?: number; // (undocumented) static concat(first: ApolloLink | RequestHandler, second: ApolloLink | RequestHandler): ApolloLink; // (undocumented) @@ -251,6 +253,8 @@ export class ApolloLink { // (undocumented) static from(links: (ApolloLink | RequestHandler)[]): ApolloLink; // @internal + getMemoryInternals?: () => unknown; + // @internal readonly left?: ApolloLink; // (undocumented) protected onError(error: any, observer?: Observer): false | void; @@ -1068,13 +1072,13 @@ interface FulfilledPromise extends Promise { value: TValue; } -// Warning: (ae-forgotten-export) The symbol "_getApolloClientCacheStatus" needs to be exported by the entry point index.d.ts -// // @internal -const getApolloClientCacheStatus: typeof _getApolloClientCacheStatus | undefined; +const getApolloCacheMemoryInternals: (() => { + fragmentQueryDocuments: number | undefined; +}) | undefined; -// @public (undocumented) -function _getApolloClientCacheStatus(this: ApolloClient): { +// @internal +const getApolloClientMemoryInternals: (() => { limits: CacheSizes; sizes: { global: { @@ -1082,37 +1086,22 @@ function _getApolloClientCacheStatus(this: ApolloClient): { parser: number | undefined; canonicalStringify: number | undefined; }; - links: number[]; + links: unknown[]; queryManager: { Transforms: number; documentTransforms: number[]; }; cache: { - addTypenameTransform: number[]; - storeReader: { - executeSelectionSet: number | undefined; - executeSubSelectedArray: number | undefined; - }; - maybeBroadcastWatch: number | undefined; - fragmentRegistry: { - findFragmentSpreads: number | undefined; - lookup: number | undefined; - transform: number | undefined; - }; + fragmentQueryDocuments: number | undefined; } | undefined; }; -}; +}) | undefined; // @public (undocumented) export function getApolloContext(): ReactTypes.Context; -// Warning: (ae-forgotten-export) The symbol "_getInMemoryCacheStatus" needs to be exported by the entry point index.d.ts -// // @internal -const getInMemoryCacheStatus: typeof _getInMemoryCacheStatus | undefined; - -// @public (undocumented) -function _getInMemoryCacheStatus(this: InMemoryCache): { +const getInMemoryCacheMemoryInternals: (() => { addTypenameTransform: number[]; storeReader: { executeSelectionSet: number | undefined; @@ -1124,7 +1113,8 @@ function _getInMemoryCacheStatus(this: InMemoryCache): { lookup: number | undefined; transform: number | undefined; }; -}; + fragmentQueryDocuments: number | undefined; +}) | undefined; export { gql } @@ -1249,10 +1239,10 @@ export class InMemoryCache extends ApolloCache { resetResultCache?: boolean; resetResultIdentities?: boolean; }): string[]; - // Warning: (ae-forgotten-export) The symbol "getInMemoryCacheStatus" needs to be exported by the entry point index.d.ts + // Warning: (ae-forgotten-export) The symbol "getInMemoryCacheMemoryInternals" needs to be exported by the entry point index.d.ts // // @internal - getCacheStatus?: typeof getInMemoryCacheStatus; + getMemoryInternals?: typeof getInMemoryCacheMemoryInternals; // (undocumented) identify(object: StoreObject | Reference): string | undefined; // (undocumented) @@ -2998,7 +2988,7 @@ interface WriteContext extends ReadMergeModifyContext { // src/react/hooks/useBackgroundQuery.ts:30:3 - (ae-forgotten-export) The symbol "FetchMoreFunction" needs to be exported by the entry point index.d.ts // src/react/hooks/useBackgroundQuery.ts:31:3 - (ae-forgotten-export) The symbol "RefetchFunction" needs to be exported by the entry point index.d.ts // src/react/hooks/useLoadableQuery.ts:50:5 - (ae-forgotten-export) The symbol "ResetFunction" needs to be exported by the entry point index.d.ts -// src/utilities/caching/getCacheStatus.ts:47:61 - (ae-forgotten-export) The symbol "CacheSizes" needs to be exported by the entry point index.d.ts +// src/utilities/caching/getMemoryInternals.ts:40:44 - (ae-forgotten-export) The symbol "CacheSizes" needs to be exported by the entry point index.d.ts // (No @packageDocumentation comment for this package) diff --git a/src/core/QueryInfo.ts b/src/core/QueryInfo.ts index 02e1768af17..b3dd4366cf2 100644 --- a/src/core/QueryInfo.ts +++ b/src/core/QueryInfo.ts @@ -7,7 +7,7 @@ import { mergeIncrementalData } from "../utilities/index.js"; import type { WatchQueryOptions, ErrorPolicy } from "./watchQueryOptions.js"; import type { ObservableQuery } from "./ObservableQuery.js"; import { reobserveCacheFirst } from "./ObservableQuery.js"; -import type { QueryListener, MethodKeys } from "./types.js"; +import type { QueryListener } from "./types.js"; import type { FetchResult } from "../link/core/index.js"; import { isNonEmptyArray, @@ -36,10 +36,11 @@ const destructiveMethodCounts = new (canUseWeakMap ? WeakMap : Map)< function wrapDestructiveCacheMethod( cache: ApolloCache, - methodName: MethodKeys> + methodName: "evict" | "modify" | "reset" ) { const original = cache[methodName]; if (typeof original === "function") { + // @ts-expect-error this is just too generic to be typed correctly cache[methodName] = function () { destructiveMethodCounts.set( cache, From fee0f92d6c75d4f09f52dcf1de41887338b8e8ca Mon Sep 17 00:00:00 2001 From: Lenz Weber-Tronic Date: Tue, 12 Dec 2023 18:53:49 +0100 Subject: [PATCH 46/62] size-limits --- .size-limits.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.size-limits.json b/.size-limits.json index e91dca705dd..d500206c9fa 100644 --- a/.size-limits.json +++ b/.size-limits.json @@ -1,4 +1,4 @@ { "dist/apollo-client.min.cjs": 38948, - "import { ApolloClient, InMemoryCache, HttpLink } from \"dist/index.js\" (production)": 32732 + "import { ApolloClient, InMemoryCache, HttpLink } from \"dist/index.js\" (production)": 32736 } From 21c0c4b54b3746c30f452412e26202702519cba1 Mon Sep 17 00:00:00 2001 From: Lenz Weber-Tronic Date: Tue, 12 Dec 2023 19:01:50 +0100 Subject: [PATCH 47/62] Update wet-forks-rhyme.md --- .changeset/wet-forks-rhyme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/wet-forks-rhyme.md b/.changeset/wet-forks-rhyme.md index ec3cab55b77..2fc57066943 100644 --- a/.changeset/wet-forks-rhyme.md +++ b/.changeset/wet-forks-rhyme.md @@ -2,4 +2,4 @@ "@apollo/client": patch --- -Adds an experimental ApolloClient.getCacheStatus helper +Adds an experimental `ApolloClient.getMemoryInternals` helper From 9f3db9c09f97a36cbbb0381e31d00d3e74453f9a Mon Sep 17 00:00:00 2001 From: Lenz Weber-Tronic Date: Wed, 13 Dec 2023 19:01:36 +0100 Subject: [PATCH 48/62] PR feedback, long explanatory comment --- src/utilities/caching/getMemoryInternals.ts | 48 +++++++++++++++------ 1 file changed, 36 insertions(+), 12 deletions(-) diff --git a/src/utilities/caching/getMemoryInternals.ts b/src/utilities/caching/getMemoryInternals.ts index 5636e44341a..64e042b77b1 100644 --- a/src/utilities/caching/getMemoryInternals.ts +++ b/src/utilities/caching/getMemoryInternals.ts @@ -6,18 +6,8 @@ import type { ApolloCache, } from "../../core/index.js"; import type { ApolloClient } from "../../core/index.js"; -import type { CacheSizes } from "./sizes.js"; import { cacheSizes } from "./sizes.js"; -export type CacheStatus = { - limits: CacheSizes; - sizes: { - [K in keyof CacheSizes]?: number | number[]; - } & { - links?: number[]; - }; -}; - const globalCaches: { print?: () => number; parser?: () => number; @@ -31,6 +21,42 @@ export function registerGlobalCache( globalCaches[name] = getSize; } +/** + * Transformative helper type to turn a function of the form + * ```ts + * (this: any) => R + * ``` + * into a function of the form + * ```ts + * () => R + * ``` + * preserving the return type, but removing the `this` parameter. + * + * @remarks + * + * Further down in the definitions of `_getApolloClientMemoryInternals`, + * `_getApolloCacheMemoryInternals` and `_getInMemoryCacheMemoryInternals`, + * having the `this` parameter annotation is extremely useful for type checking + * inside the function. + * + * If this is preserved in the exported types, though, it leads to a situation + * where `ApolloCache.getMemoryInternals` is a function that requires a `this` + * of the type `ApolloCache`, while the extending class `InMemoryCache` has a + * `getMemoryInternals` function that requires a `this` of the type + * `InMemoryCache`. + * This is not compatible with TypeScript's inheritence system (although it is + * perfectly correct), and so TypeScript will complain loudly. + * + * We still want to define our functions with the `this` annotation, though, + * and have the return type inferred. + * (This requirement for return type inference here makes it impossible to use + * a function overload that is more explicit on the inner overload than it is + * on the external overload.) + * + * So in the end, we use this helper to remove the `this` annotation from the + * exported function types, while keeping it in the internal implementation. + * + */ type RemoveThis = T extends (this: any) => infer R ? () => R : never; /** @@ -153,5 +179,3 @@ function linkInfo(link?: ApolloLink): unknown[] { ...linkInfo(link?.right), ].filter((x) => x != null); } - -// removeTypenameFromVariables getVariableDefinitions From ade170d3f17fb603c38fe3a2562d281dce8d6c54 Mon Sep 17 00:00:00 2001 From: phryneas Date: Wed, 13 Dec 2023 18:04:08 +0000 Subject: [PATCH 49/62] Clean up Prettier, Size-limit, and Api-Extractor --- .api-reports/api-report-core.md | 2 +- .api-reports/api-report-react.md | 2 +- .api-reports/api-report-react_components.md | 2 +- .api-reports/api-report-react_context.md | 2 +- .api-reports/api-report-react_hoc.md | 2 +- .api-reports/api-report-react_hooks.md | 2 +- .api-reports/api-report-react_ssr.md | 2 +- .api-reports/api-report-testing.md | 2 +- .api-reports/api-report-testing_core.md | 2 +- .api-reports/api-report.md | 2 +- .size-limits.json | 4 ++-- 11 files changed, 12 insertions(+), 12 deletions(-) diff --git a/.api-reports/api-report-core.md b/.api-reports/api-report-core.md index 89b7a6ebc99..c8284bb752a 100644 --- a/.api-reports/api-report-core.md +++ b/.api-reports/api-report-core.md @@ -2201,7 +2201,7 @@ interface WriteContext extends ReadMergeModifyContext { // src/core/QueryManager.ts:395:7 - (ae-forgotten-export) The symbol "UpdateQueries" needs to be exported by the entry point index.d.ts // src/core/watchQueryOptions.ts:253:2 - (ae-forgotten-export) The symbol "UpdateQueryFn" needs to be exported by the entry point index.d.ts // src/link/http/selectHttpOptionsAndBody.ts:128:32 - (ae-forgotten-export) The symbol "HttpQueryOptions" needs to be exported by the entry point index.d.ts -// src/utilities/caching/getMemoryInternals.ts:40:44 - (ae-forgotten-export) The symbol "CacheSizes" needs to be exported by the entry point index.d.ts +// src/utilities/caching/getMemoryInternals.ts:66:44 - (ae-forgotten-export) The symbol "CacheSizes" needs to be exported by the entry point index.d.ts // (No @packageDocumentation comment for this package) diff --git a/.api-reports/api-report-react.md b/.api-reports/api-report-react.md index bd99988f5cb..9c6553d1baa 100644 --- a/.api-reports/api-report-react.md +++ b/.api-reports/api-report-react.md @@ -2324,7 +2324,7 @@ interface WatchQueryOptions(it: (...args: TArgs // src/core/types.ts:174:3 - (ae-forgotten-export) The symbol "MutationQueryReducer" needs to be exported by the entry point index.d.ts // src/core/types.ts:201:5 - (ae-forgotten-export) The symbol "Resolver" needs to be exported by the entry point index.d.ts // src/core/watchQueryOptions.ts:253:2 - (ae-forgotten-export) The symbol "UpdateQueryFn" needs to be exported by the entry point index.d.ts -// src/utilities/caching/getMemoryInternals.ts:40:44 - (ae-forgotten-export) The symbol "CacheSizes" needs to be exported by the entry point index.d.ts +// src/utilities/caching/getMemoryInternals.ts:66:44 - (ae-forgotten-export) The symbol "CacheSizes" 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 35a1c34b998..f872e59785d 100644 --- a/.api-reports/api-report-testing_core.md +++ b/.api-reports/api-report-testing_core.md @@ -1651,7 +1651,7 @@ export function withWarningSpy(it: (...args: TArgs // src/core/types.ts:174:3 - (ae-forgotten-export) The symbol "MutationQueryReducer" needs to be exported by the entry point index.d.ts // src/core/types.ts:201:5 - (ae-forgotten-export) The symbol "Resolver" needs to be exported by the entry point index.d.ts // src/core/watchQueryOptions.ts:253:2 - (ae-forgotten-export) The symbol "UpdateQueryFn" needs to be exported by the entry point index.d.ts -// src/utilities/caching/getMemoryInternals.ts:40:44 - (ae-forgotten-export) The symbol "CacheSizes" needs to be exported by the entry point index.d.ts +// src/utilities/caching/getMemoryInternals.ts:66:44 - (ae-forgotten-export) The symbol "CacheSizes" needs to be exported by the entry point index.d.ts // (No @packageDocumentation comment for this package) diff --git a/.api-reports/api-report.md b/.api-reports/api-report.md index 81cf6eb7dc7..da6cd5dc863 100644 --- a/.api-reports/api-report.md +++ b/.api-reports/api-report.md @@ -2988,7 +2988,7 @@ interface WriteContext extends ReadMergeModifyContext { // src/react/hooks/useBackgroundQuery.ts:30:3 - (ae-forgotten-export) The symbol "FetchMoreFunction" needs to be exported by the entry point index.d.ts // src/react/hooks/useBackgroundQuery.ts:31:3 - (ae-forgotten-export) The symbol "RefetchFunction" needs to be exported by the entry point index.d.ts // src/react/hooks/useLoadableQuery.ts:50:5 - (ae-forgotten-export) The symbol "ResetFunction" needs to be exported by the entry point index.d.ts -// src/utilities/caching/getMemoryInternals.ts:40:44 - (ae-forgotten-export) The symbol "CacheSizes" needs to be exported by the entry point index.d.ts +// src/utilities/caching/getMemoryInternals.ts:66:44 - (ae-forgotten-export) The symbol "CacheSizes" needs to be exported by the entry point index.d.ts // (No @packageDocumentation comment for this package) diff --git a/.size-limits.json b/.size-limits.json index d500206c9fa..b94a2894767 100644 --- a/.size-limits.json +++ b/.size-limits.json @@ -1,4 +1,4 @@ { - "dist/apollo-client.min.cjs": 38948, - "import { ApolloClient, InMemoryCache, HttpLink } from \"dist/index.js\" (production)": 32736 + "dist/apollo-client.min.cjs": 38888, + "import { ApolloClient, InMemoryCache, HttpLink } from \"dist/index.js\" (production)": 32680 } From ea82c2e1d8e3c28050f7275c11014a47bbc0df9d Mon Sep 17 00:00:00 2001 From: Lenz Weber-Tronic Date: Thu, 14 Dec 2023 12:19:22 +0100 Subject: [PATCH 50/62] adjust comments --- src/link/core/ApolloLink.ts | 4 ++-- src/utilities/graphql/DocumentTransform.ts | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/link/core/ApolloLink.ts b/src/link/core/ApolloLink.ts index 2e31d3d2702..4f7759915d6 100644 --- a/src/link/core/ApolloLink.ts +++ b/src/link/core/ApolloLink.ts @@ -161,12 +161,12 @@ export class ApolloLink { /** * @internal - * Used to iterate through all links for caches that are concatenations of `split` links. + * Used to iterate through all links that are concatenations or `split` links. */ readonly left?: ApolloLink; /** * @internal - * Used to iterate through all links for caches that are concatenations of `split` links. + * Used to iterate through all links that are concatenations or `split` links. */ readonly right?: ApolloLink; diff --git a/src/utilities/graphql/DocumentTransform.ts b/src/utilities/graphql/DocumentTransform.ts index 76649e87cdf..172d1f711fd 100644 --- a/src/utilities/graphql/DocumentTransform.ts +++ b/src/utilities/graphql/DocumentTransform.ts @@ -144,6 +144,14 @@ export class DocumentTransform { ); } + /** + * @internal + * Used to iterate through all transforms that are concatenations or `split` links. + */ readonly left?: DocumentTransform; + /** + * @internal + * Used to iterate through all transforms that are concatenations or `split` links. + */ readonly right?: DocumentTransform; } From 61c80a3af47caab33958233a1df8a378c5fef50c Mon Sep 17 00:00:00 2001 From: Lenz Weber-Tronic Date: Thu, 14 Dec 2023 12:23:15 +0100 Subject: [PATCH 51/62] remove `expect.objectContaining` --- .../caching/__tests__/getMemoryInternals.ts | 192 +++++++++--------- 1 file changed, 94 insertions(+), 98 deletions(-) diff --git a/src/utilities/caching/__tests__/getMemoryInternals.ts b/src/utilities/caching/__tests__/getMemoryInternals.ts index 6179db3d8d1..6e34d473736 100644 --- a/src/utilities/caching/__tests__/getMemoryInternals.ts +++ b/src/utilities/caching/__tests__/getMemoryInternals.ts @@ -36,59 +36,57 @@ it("returns information about cache usage (empty caches)", () => { .concat(removeTypenameFromVariables()) .concat(ApolloLink.empty()), }); - expect(client.getMemoryInternals?.()).toEqual( - expect.objectContaining({ - limits: { - canonicalStringify: 1000, - documentTransform: 2000, - executeSelectionSet: 10000, - executeSubSelectedArray: 5000, - fragmentQueryDocuments: 1000, - fragmentRegistryFindFragmentSpreads: 4000, - fragmentRegistryLookup: 1000, - fragmentRegistryTransform: 2000, - getVariableDefinitions: 2000, - maybeBroadcastWatch: 5000, - parser: 1000, - persistedQueryHashes: 2000, - print: 2000, - queryManagerTransforms: 2000, - }, - sizes: { - cache: { - addTypenameTransform: [0], - fragmentQueryDocuments: 0, - fragmentRegistry: { - findFragmentSpreads: 0, - lookup: 0, - transform: 0, - }, - maybeBroadcastWatch: 0, - storeReader: { - executeSelectionSet: 0, - executeSubSelectedArray: 0, - }, + expect(client.getMemoryInternals?.()).toEqual({ + limits: { + canonicalStringify: 1000, + documentTransform: 2000, + executeSelectionSet: 10000, + executeSubSelectedArray: 5000, + fragmentQueryDocuments: 1000, + fragmentRegistryFindFragmentSpreads: 4000, + fragmentRegistryLookup: 1000, + fragmentRegistryTransform: 2000, + getVariableDefinitions: 2000, + maybeBroadcastWatch: 5000, + parser: 1000, + persistedQueryHashes: 2000, + print: 2000, + queryManagerTransforms: 2000, + }, + sizes: { + cache: { + addTypenameTransform: [0], + fragmentQueryDocuments: 0, + fragmentRegistry: { + findFragmentSpreads: 0, + lookup: 0, + transform: 0, + }, + maybeBroadcastWatch: 0, + storeReader: { + executeSelectionSet: 0, + executeSubSelectedArray: 0, }, - global: { - canonicalStringify: 0, - parser: 0, - print: 0, + }, + global: { + canonicalStringify: 0, + parser: 0, + print: 0, + }, + links: [ + { + persistedQueryHashes: 0, }, - links: [ - { - persistedQueryHashes: 0, - }, - { - getVariableDefinitions: 0, - }, - ], - queryManager: { - Transforms: 0, - documentTransforms: [0, 0], + { + getVariableDefinitions: 0, }, + ], + queryManager: { + Transforms: 0, + documentTransforms: [0, 0], }, - }) - ); + }, + }); }); it("returns information about cache usage (some query triggered)", () => { @@ -117,57 +115,55 @@ it("returns information about cache usage (some query triggered)", () => { } `, }); - expect(client.getMemoryInternals?.()).toEqual( - expect.objectContaining({ - limits: { - canonicalStringify: 1000, - documentTransform: 2000, - executeSelectionSet: 10000, - executeSubSelectedArray: 5000, - fragmentQueryDocuments: 1000, - fragmentRegistryFindFragmentSpreads: 4000, - fragmentRegistryLookup: 1000, - fragmentRegistryTransform: 2000, - getVariableDefinitions: 2000, - maybeBroadcastWatch: 5000, - parser: 1000, - persistedQueryHashes: 2000, - print: 2000, - queryManagerTransforms: 2000, - }, - sizes: { - cache: { - addTypenameTransform: [1], - fragmentQueryDocuments: 0, - fragmentRegistry: { - findFragmentSpreads: 1, - lookup: 0, - transform: 1, - }, - maybeBroadcastWatch: 0, - storeReader: { - executeSelectionSet: 1, - executeSubSelectedArray: 0, - }, + expect(client.getMemoryInternals?.()).toStrictEqual({ + limits: { + canonicalStringify: 1000, + documentTransform: 2000, + executeSelectionSet: 10000, + executeSubSelectedArray: 5000, + fragmentQueryDocuments: 1000, + fragmentRegistryFindFragmentSpreads: 4000, + fragmentRegistryLookup: 1000, + fragmentRegistryTransform: 2000, + getVariableDefinitions: 2000, + maybeBroadcastWatch: 5000, + parser: 1000, + persistedQueryHashes: 2000, + print: 2000, + queryManagerTransforms: 2000, + }, + sizes: { + cache: { + addTypenameTransform: [1], + fragmentQueryDocuments: 0, + fragmentRegistry: { + findFragmentSpreads: 1, + lookup: 0, + transform: 1, + }, + maybeBroadcastWatch: 0, + storeReader: { + executeSelectionSet: 1, + executeSubSelectedArray: 0, }, - global: { - canonicalStringify: 0, - parser: 0, - print: 1, + }, + global: { + canonicalStringify: 0, + parser: 0, + print: 1, + }, + links: [ + { + persistedQueryHashes: 1, }, - links: [ - { - persistedQueryHashes: 1, - }, - { - getVariableDefinitions: 0, - }, - ], - queryManager: { - Transforms: 1, - documentTransforms: [1, 1], + { + getVariableDefinitions: 0, }, + ], + queryManager: { + Transforms: 1, + documentTransforms: [1, 1], }, - }) - ); + }, + }); }); From 2ccd22934c0ad5f95e5f6bfe7d857619b9df1b6d Mon Sep 17 00:00:00 2001 From: Lenz Weber-Tronic Date: Thu, 14 Dec 2023 12:27:34 +0100 Subject: [PATCH 52/62] flip conditionals --- src/utilities/caching/getMemoryInternals.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/utilities/caching/getMemoryInternals.ts b/src/utilities/caching/getMemoryInternals.ts index 64e042b77b1..fda55703c20 100644 --- a/src/utilities/caching/getMemoryInternals.ts +++ b/src/utilities/caching/getMemoryInternals.ts @@ -161,21 +161,21 @@ function getWrapperInformation(f?: Function) { } function transformInfo(transform?: DocumentTransform): number[] { - return !transform ? - [] - : [ + return transform ? + [ getWrapperInformation(transform?.["performWork"]), ...transformInfo(transform?.["left"]), ...transformInfo(transform?.["right"]), - ].filter((x): x is number => x != null); + ].filter((x): x is number => x != null) + : []; } function linkInfo(link?: ApolloLink): unknown[] { - return !link ? - [] - : [ + return link ? + [ link?.getMemoryInternals?.(), ...linkInfo(link?.left), ...linkInfo(link?.right), - ].filter((x) => x != null); + ].filter((x) => x != null) + : []; } From e283de3efc4ef51e07047a26f96b1629024406ca Mon Sep 17 00:00:00 2001 From: Lenz Weber-Tronic Date: Thu, 14 Dec 2023 12:30:33 +0100 Subject: [PATCH 53/62] extract function --- src/utilities/caching/getMemoryInternals.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/utilities/caching/getMemoryInternals.ts b/src/utilities/caching/getMemoryInternals.ts index fda55703c20..e59e5b927c2 100644 --- a/src/utilities/caching/getMemoryInternals.ts +++ b/src/utilities/caching/getMemoryInternals.ts @@ -160,13 +160,17 @@ function getWrapperInformation(f?: Function) { return isWrapper(f) ? f.size : undefined; } +function isDefined(value: T | undefined | null): value is T { + return value != null; +} + function transformInfo(transform?: DocumentTransform): number[] { return transform ? [ getWrapperInformation(transform?.["performWork"]), ...transformInfo(transform?.["left"]), ...transformInfo(transform?.["right"]), - ].filter((x): x is number => x != null) + ].filter(isDefined) : []; } @@ -176,6 +180,6 @@ function linkInfo(link?: ApolloLink): unknown[] { link?.getMemoryInternals?.(), ...linkInfo(link?.left), ...linkInfo(link?.right), - ].filter((x) => x != null) + ].filter(isDefined) : []; } From d84a05b54ef3a8e082cb8fd6f4b9b40957a6b40b Mon Sep 17 00:00:00 2001 From: phryneas Date: Fri, 15 Dec 2023 14:56:20 +0000 Subject: [PATCH 54/62] Clean up Prettier, Size-limit, and Api-Extractor --- .size-limits.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.size-limits.json b/.size-limits.json index 551d112bc87..cffdc4320a2 100644 --- a/.size-limits.json +++ b/.size-limits.json @@ -1,4 +1,4 @@ { - "dist/apollo-client.min.cjs": 38872, - "import { ApolloClient, InMemoryCache, HttpLink } from \"dist/index.js\" (production)": 32660 + "dist/apollo-client.min.cjs": 38813, + "import { ApolloClient, InMemoryCache, HttpLink } from \"dist/index.js\" (production)": 32610 } From 55cb41918195f9973cfdc17a37d25ac0cb2e0ad6 Mon Sep 17 00:00:00 2001 From: Lenz Weber-Tronic Date: Fri, 15 Dec 2023 16:15:33 +0100 Subject: [PATCH 55/62] report correct size limits --- .../caching/__tests__/getMemoryInternals.ts | 73 +++++++++++-------- src/utilities/caching/getMemoryInternals.ts | 38 +++++++++- 2 files changed, 77 insertions(+), 34 deletions(-) diff --git a/src/utilities/caching/__tests__/getMemoryInternals.ts b/src/utilities/caching/__tests__/getMemoryInternals.ts index 6e34d473736..f08cb01dcaf 100644 --- a/src/utilities/caching/__tests__/getMemoryInternals.ts +++ b/src/utilities/caching/__tests__/getMemoryInternals.ts @@ -11,6 +11,7 @@ import { removeTypenameFromVariables } from "../../../link/remove-typename"; import crypto from "crypto"; // importing react so the `parser` cache initializes import "../../../react"; +import { cacheSizes, defaultCacheSizes } from "../sizes"; function sha256(data: string) { const hash = crypto.createHash("sha256"); @@ -18,6 +19,31 @@ function sha256(data: string) { return hash.digest("hex"); } +const defaultCacheSizesAsObject = { + parser: defaultCacheSizes["parser"], + canonicalStringify: defaultCacheSizes["canonicalStringify"], + print: defaultCacheSizes["print"], + "documentTransform.cache": defaultCacheSizes["documentTransform.cache"], + "queryManager.getDocumentInfo": + defaultCacheSizes["queryManager.getDocumentInfo"], + "PersistedQueryLink.persistedQueryHashes": + defaultCacheSizes["PersistedQueryLink.persistedQueryHashes"], + "fragmentRegistry.transform": defaultCacheSizes["fragmentRegistry.transform"], + "fragmentRegistry.lookup": defaultCacheSizes["fragmentRegistry.lookup"], + "fragmentRegistry.findFragmentSpreads": + defaultCacheSizes["fragmentRegistry.findFragmentSpreads"], + "cache.fragmentQueryDocuments": + defaultCacheSizes["cache.fragmentQueryDocuments"], + "removeTypenameFromVariables.getVariableDefinitions": + defaultCacheSizes["removeTypenameFromVariables.getVariableDefinitions"], + "inMemoryCache.maybeBroadcastWatch": + defaultCacheSizes["inMemoryCache.maybeBroadcastWatch"], + "inMemoryCache.executeSelectionSet": + defaultCacheSizes["inMemoryCache.executeSelectionSet"], + "inMemoryCache.executeSubSelectedArray": + defaultCacheSizes["inMemoryCache.executeSubSelectedArray"], +}; + it("returns information about cache usage (empty caches)", () => { const client = new ApolloClient({ documentTransform: new DocumentTransform((x) => x, { @@ -37,22 +63,7 @@ it("returns information about cache usage (empty caches)", () => { .concat(ApolloLink.empty()), }); expect(client.getMemoryInternals?.()).toEqual({ - limits: { - canonicalStringify: 1000, - documentTransform: 2000, - executeSelectionSet: 10000, - executeSubSelectedArray: 5000, - fragmentQueryDocuments: 1000, - fragmentRegistryFindFragmentSpreads: 4000, - fragmentRegistryLookup: 1000, - fragmentRegistryTransform: 2000, - getVariableDefinitions: 2000, - maybeBroadcastWatch: 5000, - parser: 1000, - persistedQueryHashes: 2000, - print: 2000, - queryManagerTransforms: 2000, - }, + limits: defaultCacheSizesAsObject, sizes: { cache: { addTypenameTransform: [0], @@ -116,22 +127,7 @@ it("returns information about cache usage (some query triggered)", () => { `, }); expect(client.getMemoryInternals?.()).toStrictEqual({ - limits: { - canonicalStringify: 1000, - documentTransform: 2000, - executeSelectionSet: 10000, - executeSubSelectedArray: 5000, - fragmentQueryDocuments: 1000, - fragmentRegistryFindFragmentSpreads: 4000, - fragmentRegistryLookup: 1000, - fragmentRegistryTransform: 2000, - getVariableDefinitions: 2000, - maybeBroadcastWatch: 5000, - parser: 1000, - persistedQueryHashes: 2000, - print: 2000, - queryManagerTransforms: 2000, - }, + limits: defaultCacheSizesAsObject, sizes: { cache: { addTypenameTransform: [1], @@ -167,3 +163,16 @@ it("returns information about cache usage (some query triggered)", () => { }, }); }); + +it("reports user-declared cacheSizes", () => { + const client = new ApolloClient({ + cache: new InMemoryCache({}), + }); + + cacheSizes["inMemoryCache.executeSubSelectedArray"] = 90; + + expect(client.getMemoryInternals?.().limits).toStrictEqual({ + ...defaultCacheSizesAsObject, + "inMemoryCache.executeSubSelectedArray": 90, + }); +}); diff --git a/src/utilities/caching/getMemoryInternals.ts b/src/utilities/caching/getMemoryInternals.ts index e59e5b927c2..79341835a6a 100644 --- a/src/utilities/caching/getMemoryInternals.ts +++ b/src/utilities/caching/getMemoryInternals.ts @@ -6,7 +6,7 @@ import type { ApolloCache, } from "../../core/index.js"; import type { ApolloClient } from "../../core/index.js"; -import { cacheSizes } from "./sizes.js"; +import { CacheSizes, cacheSizes, defaultCacheSizes } from "./sizes.js"; const globalCaches: { print?: () => number; @@ -92,11 +92,45 @@ export const getApolloCacheMemoryInternals = >) : undefined; +function getCurrentCacheSizes() { + const defaults: Record = { + parser: defaultCacheSizes["parser"], + canonicalStringify: defaultCacheSizes["canonicalStringify"], + print: defaultCacheSizes["print"], + "documentTransform.cache": defaultCacheSizes["documentTransform.cache"], + "queryManager.getDocumentInfo": + defaultCacheSizes["queryManager.getDocumentInfo"], + "PersistedQueryLink.persistedQueryHashes": + defaultCacheSizes["PersistedQueryLink.persistedQueryHashes"], + "fragmentRegistry.transform": + defaultCacheSizes["fragmentRegistry.transform"], + "fragmentRegistry.lookup": defaultCacheSizes["fragmentRegistry.lookup"], + "fragmentRegistry.findFragmentSpreads": + defaultCacheSizes["fragmentRegistry.findFragmentSpreads"], + "cache.fragmentQueryDocuments": + defaultCacheSizes["cache.fragmentQueryDocuments"], + "removeTypenameFromVariables.getVariableDefinitions": + defaultCacheSizes["removeTypenameFromVariables.getVariableDefinitions"], + "inMemoryCache.maybeBroadcastWatch": + defaultCacheSizes["inMemoryCache.maybeBroadcastWatch"], + "inMemoryCache.executeSelectionSet": + defaultCacheSizes["inMemoryCache.executeSelectionSet"], + "inMemoryCache.executeSubSelectedArray": + defaultCacheSizes["inMemoryCache.executeSubSelectedArray"], + }; + return Object.fromEntries( + Object.entries(defaults).map(([k, v]) => [ + k, + cacheSizes[k as keyof CacheSizes] || v, + ]) + ); +} + function _getApolloClientMemoryInternals(this: ApolloClient) { if (!__DEV__) throw new Error("only supported in development mode"); return { - limits: cacheSizes, + limits: getCurrentCacheSizes(), sizes: { global: { print: globalCaches.print?.(), From c7a65aaf3df14df077933f14d55ed2ea5473c2a0 Mon Sep 17 00:00:00 2001 From: phryneas Date: Fri, 15 Dec 2023 15:18:13 +0000 Subject: [PATCH 56/62] Clean up Prettier, Size-limit, and Api-Extractor --- .api-reports/api-report-core.md | 23 +++------------------ .api-reports/api-report-react.md | 23 +++------------------ .api-reports/api-report-react_components.md | 23 +++------------------ .api-reports/api-report-react_context.md | 23 +++------------------ .api-reports/api-report-react_hoc.md | 23 +++------------------ .api-reports/api-report-react_hooks.md | 23 +++------------------ .api-reports/api-report-react_ssr.md | 23 +++------------------ .api-reports/api-report-testing.md | 23 +++------------------ .api-reports/api-report-testing_core.md | 23 +++------------------ .api-reports/api-report-utilities.md | 4 +++- .api-reports/api-report.md | 23 +++------------------ 11 files changed, 33 insertions(+), 201 deletions(-) diff --git a/.api-reports/api-report-core.md b/.api-reports/api-report-core.md index 1ade65e87b4..3f08edbad61 100644 --- a/.api-reports/api-report-core.md +++ b/.api-reports/api-report-core.md @@ -398,24 +398,6 @@ class CacheGroup { resetCaching(): void; } -// @public -interface CacheSizes { - "cache.fragmentQueryDocuments": number; - "documentTransform.cache": number; - "fragmentRegistry.findFragmentSpreads": number; - "fragmentRegistry.lookup": number; - "fragmentRegistry.transform": number; - "inMemoryCache.executeSelectionSet": number; - "inMemoryCache.executeSubSelectedArray": number; - "inMemoryCache.maybeBroadcastWatch": number; - "PersistedQueryLink.persistedQueryHashes": number; - "queryManager.getDocumentInfo": number; - "removeTypenameFromVariables.getVariableDefinitions": number; - canonicalStringify: number; - parser: number; - print: number; -} - // @public (undocumented) const enum CacheWriteBehavior { // (undocumented) @@ -906,7 +888,9 @@ const getApolloCacheMemoryInternals: (() => { // @internal const getApolloClientMemoryInternals: (() => { - limits: Partial; + limits: { + [k: string]: number; + }; sizes: { global: { print: number | undefined; @@ -2202,7 +2186,6 @@ interface WriteContext extends ReadMergeModifyContext { // src/core/QueryManager.ts:396:7 - (ae-forgotten-export) The symbol "UpdateQueries" needs to be exported by the entry point index.d.ts // src/core/watchQueryOptions.ts:260:2 - (ae-forgotten-export) The symbol "UpdateQueryFn" needs to be exported by the entry point index.d.ts // src/link/http/selectHttpOptionsAndBody.ts:128:32 - (ae-forgotten-export) The symbol "HttpQueryOptions" needs to be exported by the entry point index.d.ts -// src/utilities/caching/getMemoryInternals.ts:66:44 - (ae-forgotten-export) The symbol "CacheSizes" needs to be exported by the entry point index.d.ts // (No @packageDocumentation comment for this package) diff --git a/.api-reports/api-report-react.md b/.api-reports/api-report-react.md index 0fa50cfffd7..3c8426fc69e 100644 --- a/.api-reports/api-report-react.md +++ b/.api-reports/api-report-react.md @@ -508,24 +508,6 @@ namespace Cache_2 { import Fragment = DataProxy.Fragment; } -// @public -interface CacheSizes { - "cache.fragmentQueryDocuments": number; - "documentTransform.cache": number; - "fragmentRegistry.findFragmentSpreads": number; - "fragmentRegistry.lookup": number; - "fragmentRegistry.transform": number; - "inMemoryCache.executeSelectionSet": number; - "inMemoryCache.executeSubSelectedArray": number; - "inMemoryCache.maybeBroadcastWatch": number; - "PersistedQueryLink.persistedQueryHashes": number; - "queryManager.getDocumentInfo": number; - "removeTypenameFromVariables.getVariableDefinitions": number; - canonicalStringify: number; - parser: number; - print: number; -} - // @public (undocumented) const enum CacheWriteBehavior { // (undocumented) @@ -861,7 +843,9 @@ const getApolloCacheMemoryInternals: (() => { // @internal const getApolloClientMemoryInternals: (() => { - limits: Partial; + limits: { + [k: string]: number; + }; sizes: { global: { print: number | undefined; @@ -2325,7 +2309,6 @@ interface WatchQueryOptions { // @internal const getApolloClientMemoryInternals: (() => { - limits: Partial; + limits: { + [k: string]: number; + }; sizes: { global: { print: number | undefined; @@ -1751,7 +1735,6 @@ interface WatchQueryOptions { // @internal const getApolloClientMemoryInternals: (() => { - limits: Partial; + limits: { + [k: string]: number; + }; sizes: { global: { print: number | undefined; @@ -1647,7 +1631,6 @@ interface WatchQueryOptions { // @internal const getApolloClientMemoryInternals: (() => { - limits: Partial; + limits: { + [k: string]: number; + }; sizes: { global: { print: number | undefined; @@ -1692,7 +1676,6 @@ export function withSubscription { // @internal const getApolloClientMemoryInternals: (() => { - limits: Partial; + limits: { + [k: string]: number; + }; sizes: { global: { print: number | undefined; @@ -2216,7 +2200,6 @@ interface WatchQueryOptions { // @internal const getApolloClientMemoryInternals: (() => { - limits: Partial; + limits: { + [k: string]: number; + }; sizes: { global: { print: number | undefined; @@ -1633,7 +1617,6 @@ interface WatchQueryOptions { // @internal const getApolloClientMemoryInternals: (() => { - limits: Partial; + limits: { + [k: string]: number; + }; sizes: { global: { print: number | undefined; @@ -1695,7 +1679,6 @@ export function withWarningSpy(it: (...args: TArgs // src/core/types.ts:174:3 - (ae-forgotten-export) The symbol "MutationQueryReducer" needs to be exported by the entry point index.d.ts // src/core/types.ts:201:5 - (ae-forgotten-export) The symbol "Resolver" needs to be exported by the entry point index.d.ts // src/core/watchQueryOptions.ts:260:2 - (ae-forgotten-export) The symbol "UpdateQueryFn" needs to be exported by the entry point index.d.ts -// src/utilities/caching/getMemoryInternals.ts:66:44 - (ae-forgotten-export) The symbol "CacheSizes" 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 04e798c9d93..199422f6ffc 100644 --- a/.api-reports/api-report-testing_core.md +++ b/.api-reports/api-report-testing_core.md @@ -401,24 +401,6 @@ namespace Cache_2 { import Fragment = DataProxy.Fragment; } -// @public -interface CacheSizes { - "cache.fragmentQueryDocuments": number; - "documentTransform.cache": number; - "fragmentRegistry.findFragmentSpreads": number; - "fragmentRegistry.lookup": number; - "fragmentRegistry.transform": number; - "inMemoryCache.executeSelectionSet": number; - "inMemoryCache.executeSubSelectedArray": number; - "inMemoryCache.maybeBroadcastWatch": number; - "PersistedQueryLink.persistedQueryHashes": number; - "queryManager.getDocumentInfo": number; - "removeTypenameFromVariables.getVariableDefinitions": number; - canonicalStringify: number; - parser: number; - print: number; -} - // @public (undocumented) const enum CacheWriteBehavior { // (undocumented) @@ -689,7 +671,9 @@ const getApolloCacheMemoryInternals: (() => { // @internal const getApolloClientMemoryInternals: (() => { - limits: Partial; + limits: { + [k: string]: number; + }; sizes: { global: { print: number | undefined; @@ -1652,7 +1636,6 @@ export function withWarningSpy(it: (...args: TArgs // src/core/types.ts:174:3 - (ae-forgotten-export) The symbol "MutationQueryReducer" needs to be exported by the entry point index.d.ts // src/core/types.ts:201:5 - (ae-forgotten-export) The symbol "Resolver" needs to be exported by the entry point index.d.ts // src/core/watchQueryOptions.ts:260:2 - (ae-forgotten-export) The symbol "UpdateQueryFn" needs to be exported by the entry point index.d.ts -// src/utilities/caching/getMemoryInternals.ts:66:44 - (ae-forgotten-export) The symbol "CacheSizes" 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 e1bc1c2dbfe..c27f222390f 100644 --- a/.api-reports/api-report-utilities.md +++ b/.api-reports/api-report-utilities.md @@ -1096,7 +1096,9 @@ const getApolloCacheMemoryInternals: (() => { // @internal const getApolloClientMemoryInternals: (() => { - limits: Partial; + limits: { + [k: string]: number; + }; sizes: { global: { print: number | undefined; diff --git a/.api-reports/api-report.md b/.api-reports/api-report.md index bf86fe2759d..d4a14e89415 100644 --- a/.api-reports/api-report.md +++ b/.api-reports/api-report.md @@ -500,24 +500,6 @@ class CacheGroup { resetCaching(): void; } -// @public -interface CacheSizes { - "cache.fragmentQueryDocuments": number; - "documentTransform.cache": number; - "fragmentRegistry.findFragmentSpreads": number; - "fragmentRegistry.lookup": number; - "fragmentRegistry.transform": number; - "inMemoryCache.executeSelectionSet": number; - "inMemoryCache.executeSubSelectedArray": number; - "inMemoryCache.maybeBroadcastWatch": number; - "PersistedQueryLink.persistedQueryHashes": number; - "queryManager.getDocumentInfo": number; - "removeTypenameFromVariables.getVariableDefinitions": number; - canonicalStringify: number; - parser: number; - print: number; -} - // @public (undocumented) const enum CacheWriteBehavior { // (undocumented) @@ -1079,7 +1061,9 @@ const getApolloCacheMemoryInternals: (() => { // @internal const getApolloClientMemoryInternals: (() => { - limits: Partial; + limits: { + [k: string]: number; + }; sizes: { global: { print: number | undefined; @@ -2989,7 +2973,6 @@ interface WriteContext extends ReadMergeModifyContext { // src/react/hooks/useBackgroundQuery.ts:30:3 - (ae-forgotten-export) The symbol "FetchMoreFunction" needs to be exported by the entry point index.d.ts // src/react/hooks/useBackgroundQuery.ts:31:3 - (ae-forgotten-export) The symbol "RefetchFunction" needs to be exported by the entry point index.d.ts // src/react/hooks/useLoadableQuery.ts:50:5 - (ae-forgotten-export) The symbol "ResetFunction" needs to be exported by the entry point index.d.ts -// src/utilities/caching/getMemoryInternals.ts:66:44 - (ae-forgotten-export) The symbol "CacheSizes" needs to be exported by the entry point index.d.ts // (No @packageDocumentation comment for this package) From 4283e2280663e6916be3cd91cc38e40fec8e231f Mon Sep 17 00:00:00 2001 From: Lenz Weber-Tronic Date: Fri, 15 Dec 2023 16:37:16 +0100 Subject: [PATCH 57/62] adjust report shape to roughly match configuration --- src/link/persisted-queries/index.ts | 6 +- .../removeTypenameFromVariables.ts | 6 +- .../caching/__tests__/getMemoryInternals.ts | 110 +++++++++++------- src/utilities/caching/getMemoryInternals.ts | 35 +++--- 4 files changed, 98 insertions(+), 59 deletions(-) diff --git a/src/link/persisted-queries/index.ts b/src/link/persisted-queries/index.ts index f205a1eb4a9..920633bd7f3 100644 --- a/src/link/persisted-queries/index.ts +++ b/src/link/persisted-queries/index.ts @@ -307,7 +307,11 @@ export const createPersistedQueryLink = ( __DEV__ ? { getMemoryInternals() { - return { persistedQueryHashes: hashesByQuery?.size ?? 0 }; + return { + PersistedQueryLink: { + persistedQueryHashes: hashesByQuery?.size ?? 0, + }, + }; }, } : {} diff --git a/src/link/remove-typename/removeTypenameFromVariables.ts b/src/link/remove-typename/removeTypenameFromVariables.ts index 5673c5b439c..31ed9c58a9c 100644 --- a/src/link/remove-typename/removeTypenameFromVariables.ts +++ b/src/link/remove-typename/removeTypenameFromVariables.ts @@ -41,7 +41,11 @@ export function removeTypenameFromVariables( __DEV__ ? { getMemoryInternals() { - return { getVariableDefinitions: getVariableDefinitions?.size ?? 0 }; + return { + removeTypenameFromVariables: { + getVariableDefinitions: getVariableDefinitions?.size ?? 0, + }, + }; }, } : {} diff --git a/src/utilities/caching/__tests__/getMemoryInternals.ts b/src/utilities/caching/__tests__/getMemoryInternals.ts index f08cb01dcaf..c83f34da27f 100644 --- a/src/utilities/caching/__tests__/getMemoryInternals.ts +++ b/src/utilities/caching/__tests__/getMemoryInternals.ts @@ -65,37 +65,50 @@ it("returns information about cache usage (empty caches)", () => { expect(client.getMemoryInternals?.()).toEqual({ limits: defaultCacheSizesAsObject, sizes: { + parser: 0, + canonicalStringify: 0, + print: 0, + addTypenameDocumentTransform: [ + { + cache: 0, + }, + ], + queryManager: { + getDocumentInfo: 0, + documentTransforms: [ + { + cache: 0, + }, + { + cache: 0, + }, + ], + }, + fragmentRegistry: { + findFragmentSpreads: 0, + lookup: 0, + transform: 0, + }, cache: { - addTypenameTransform: [0], fragmentQueryDocuments: 0, - fragmentRegistry: { - findFragmentSpreads: 0, - lookup: 0, - transform: 0, - }, - maybeBroadcastWatch: 0, - storeReader: { - executeSelectionSet: 0, - executeSubSelectedArray: 0, - }, }, - global: { - canonicalStringify: 0, - parser: 0, - print: 0, + inMemoryCache: { + executeSelectionSet: 0, + executeSubSelectedArray: 0, + maybeBroadcastWatch: 0, }, links: [ { - persistedQueryHashes: 0, + PersistedQueryLink: { + persistedQueryHashes: 0, + }, }, { - getVariableDefinitions: 0, + removeTypenameFromVariables: { + getVariableDefinitions: 0, + }, }, ], - queryManager: { - Transforms: 0, - documentTransforms: [0, 0], - }, }, }); }); @@ -129,37 +142,50 @@ it("returns information about cache usage (some query triggered)", () => { expect(client.getMemoryInternals?.()).toStrictEqual({ limits: defaultCacheSizesAsObject, sizes: { + parser: 0, + canonicalStringify: 0, + print: 1, + addTypenameDocumentTransform: [ + { + cache: 1, + }, + ], + queryManager: { + getDocumentInfo: 1, + documentTransforms: [ + { + cache: 1, + }, + { + cache: 1, + }, + ], + }, + fragmentRegistry: { + findFragmentSpreads: 1, + lookup: 0, + transform: 1, + }, cache: { - addTypenameTransform: [1], fragmentQueryDocuments: 0, - fragmentRegistry: { - findFragmentSpreads: 1, - lookup: 0, - transform: 1, - }, - maybeBroadcastWatch: 0, - storeReader: { - executeSelectionSet: 1, - executeSubSelectedArray: 0, - }, }, - global: { - canonicalStringify: 0, - parser: 0, - print: 1, + inMemoryCache: { + executeSelectionSet: 1, + executeSubSelectedArray: 0, + maybeBroadcastWatch: 0, }, links: [ { - persistedQueryHashes: 1, + PersistedQueryLink: { + persistedQueryHashes: 1, + }, }, { - getVariableDefinitions: 0, + removeTypenameFromVariables: { + getVariableDefinitions: 0, + }, }, ], - queryManager: { - Transforms: 1, - documentTransforms: [1, 1], - }, }, }); }); diff --git a/src/utilities/caching/getMemoryInternals.ts b/src/utilities/caching/getMemoryInternals.ts index 79341835a6a..d05d3397a35 100644 --- a/src/utilities/caching/getMemoryInternals.ts +++ b/src/utilities/caching/getMemoryInternals.ts @@ -6,7 +6,8 @@ import type { ApolloCache, } from "../../core/index.js"; import type { ApolloClient } from "../../core/index.js"; -import { CacheSizes, cacheSizes, defaultCacheSizes } from "./sizes.js"; +import type { CacheSizes } from "./sizes.js"; +import { cacheSizes, defaultCacheSizes } from "./sizes.js"; const globalCaches: { print?: () => number; @@ -132,26 +133,26 @@ function _getApolloClientMemoryInternals(this: ApolloClient) { return { limits: getCurrentCacheSizes(), sizes: { - global: { - print: globalCaches.print?.(), - parser: globalCaches.parser?.(), - canonicalStringify: globalCaches.canonicalStringify?.(), - }, + print: globalCaches.print?.(), + parser: globalCaches.parser?.(), + canonicalStringify: globalCaches.canonicalStringify?.(), links: linkInfo(this.link), queryManager: { - Transforms: this["queryManager"]["transformCache"].size, + getDocumentInfo: this["queryManager"]["transformCache"].size, documentTransforms: transformInfo( this["queryManager"].documentTransform ), }, - cache: this.cache.getMemoryInternals?.(), + ...this.cache.getMemoryInternals?.(), }, }; } function _getApolloCacheMemoryInternals(this: ApolloCache) { return { - fragmentQueryDocuments: getWrapperInformation(this["getFragmentDoc"]), + cache: { + fragmentQueryDocuments: getWrapperInformation(this["getFragmentDoc"]), + }, }; } @@ -166,16 +167,16 @@ function _getInMemoryCacheMemoryInternals(this: InMemoryCache) { return { ..._getApolloCacheMemoryInternals.apply(this as any), - addTypenameTransform: transformInfo(this["addTypenameTransform"]), - storeReader: { + addTypenameDocumentTransform: transformInfo(this["addTypenameTransform"]), + inMemoryCache: { executeSelectionSet: getWrapperInformation( this["storeReader"]["executeSelectionSet"] ), executeSubSelectedArray: getWrapperInformation( this["storeReader"]["executeSubSelectedArray"] ), + maybeBroadcastWatch: getWrapperInformation(this["maybeBroadcastWatch"]), }, - maybeBroadcastWatch: getWrapperInformation(this["maybeBroadcastWatch"]), fragmentRegistry: { findFragmentSpreads: getWrapperInformation( fragments?.findFragmentSpreads @@ -198,12 +199,16 @@ function isDefined(value: T | undefined | null): value is T { return value != null; } -function transformInfo(transform?: DocumentTransform): number[] { +function transformInfo(transform?: DocumentTransform) { + return recurseTransformInfo(transform).map((cache) => ({ cache })); +} + +function recurseTransformInfo(transform?: DocumentTransform): number[] { return transform ? [ getWrapperInformation(transform?.["performWork"]), - ...transformInfo(transform?.["left"]), - ...transformInfo(transform?.["right"]), + ...recurseTransformInfo(transform?.["left"]), + ...recurseTransformInfo(transform?.["right"]), ].filter(isDefined) : []; } From 47534c85995da181a09ebf2295496df423c0f70f Mon Sep 17 00:00:00 2001 From: phryneas Date: Fri, 15 Dec 2023 15:39:45 +0000 Subject: [PATCH 58/62] Clean up Prettier, Size-limit, and Api-Extractor --- .api-reports/api-report-cache.md | 16 ++++++--- .api-reports/api-report-core.md | 36 +++++++++++-------- .../api-report-link_persisted-queries.md | 4 ++- .../api-report-link_remove-typename.md | 4 ++- .api-reports/api-report-react.md | 24 +++++++------ .api-reports/api-report-react_components.md | 24 +++++++------ .api-reports/api-report-react_context.md | 24 +++++++------ .api-reports/api-report-react_hoc.md | 24 +++++++------ .api-reports/api-report-react_hooks.md | 24 +++++++------ .api-reports/api-report-react_ssr.md | 24 +++++++------ .api-reports/api-report-testing.md | 24 +++++++------ .api-reports/api-report-testing_core.md | 24 +++++++------ .api-reports/api-report-utilities.md | 36 +++++++++++-------- .api-reports/api-report.md | 36 +++++++++++-------- 14 files changed, 184 insertions(+), 140 deletions(-) diff --git a/.api-reports/api-report-cache.md b/.api-reports/api-report-cache.md index ed31a3b8028..8cd3cb53be1 100644 --- a/.api-reports/api-report-cache.md +++ b/.api-reports/api-report-cache.md @@ -480,23 +480,29 @@ export interface FragmentRegistryAPI { // @internal const getApolloCacheMemoryInternals: (() => { - fragmentQueryDocuments: number | undefined; + cache: { + fragmentQueryDocuments: number | undefined; + }; }) | undefined; // @internal const getInMemoryCacheMemoryInternals: (() => { - addTypenameTransform: number[]; - storeReader: { + addTypenameDocumentTransform: { + cache: number; + }[]; + inMemoryCache: { executeSelectionSet: number | undefined; executeSubSelectedArray: number | undefined; + maybeBroadcastWatch: number | undefined; }; - maybeBroadcastWatch: number | undefined; fragmentRegistry: { findFragmentSpreads: number | undefined; lookup: number | undefined; transform: number | undefined; }; - fragmentQueryDocuments: number | undefined; + cache: { + fragmentQueryDocuments: number | undefined; + }; }) | undefined; // @public (undocumented) diff --git a/.api-reports/api-report-core.md b/.api-reports/api-report-core.md index 3f08edbad61..a0dd0d2e18f 100644 --- a/.api-reports/api-report-core.md +++ b/.api-reports/api-report-core.md @@ -883,7 +883,9 @@ export function fromPromise(promise: Promise): Observable; // @internal const getApolloCacheMemoryInternals: (() => { - fragmentQueryDocuments: number | undefined; + cache: { + fragmentQueryDocuments: number | undefined; + }; }) | undefined; // @internal @@ -892,36 +894,40 @@ const getApolloClientMemoryInternals: (() => { [k: string]: number; }; sizes: { - global: { - print: number | undefined; - parser: number | undefined; - canonicalStringify: number | undefined; - }; + cache?: { + fragmentQueryDocuments: number | undefined; + } | undefined; + print: number | undefined; + parser: number | undefined; + canonicalStringify: number | undefined; links: unknown[]; queryManager: { - Transforms: number; - documentTransforms: number[]; + getDocumentInfo: number; + documentTransforms: { + cache: number; + }[]; }; - cache: { - fragmentQueryDocuments: number | undefined; - } | undefined; }; }) | undefined; // @internal const getInMemoryCacheMemoryInternals: (() => { - addTypenameTransform: number[]; - storeReader: { + addTypenameDocumentTransform: { + cache: number; + }[]; + inMemoryCache: { executeSelectionSet: number | undefined; executeSubSelectedArray: number | undefined; + maybeBroadcastWatch: number | undefined; }; - maybeBroadcastWatch: number | undefined; fragmentRegistry: { findFragmentSpreads: number | undefined; lookup: number | undefined; transform: number | undefined; }; - fragmentQueryDocuments: number | undefined; + cache: { + fragmentQueryDocuments: number | undefined; + }; }) | undefined; export { gql } diff --git a/.api-reports/api-report-link_persisted-queries.md b/.api-reports/api-report-link_persisted-queries.md index 63c58b75323..14e7a0b47db 100644 --- a/.api-reports/api-report-link_persisted-queries.md +++ b/.api-reports/api-report-link_persisted-queries.md @@ -67,7 +67,9 @@ export const createPersistedQueryLink: (options: PersistedQueryLink.Options) => resetHashCache: () => void; } & ({ getMemoryInternals(): { - persistedQueryHashes: number; + PersistedQueryLink: { + persistedQueryHashes: number; + }; }; } | { getMemoryInternals?: undefined; diff --git a/.api-reports/api-report-link_remove-typename.md b/.api-reports/api-report-link_remove-typename.md index f9ac25babc8..f50798f5f02 100644 --- a/.api-reports/api-report-link_remove-typename.md +++ b/.api-reports/api-report-link_remove-typename.md @@ -168,7 +168,9 @@ type Path = ReadonlyArray; // @public (undocumented) export function removeTypenameFromVariables(options?: RemoveTypenameFromVariablesOptions): ApolloLink & ({ getMemoryInternals(): { - getVariableDefinitions: number; + removeTypenameFromVariables: { + getVariableDefinitions: number; + }; }; } | { getMemoryInternals?: undefined; diff --git a/.api-reports/api-report-react.md b/.api-reports/api-report-react.md index 3c8426fc69e..e2d31b93ad1 100644 --- a/.api-reports/api-report-react.md +++ b/.api-reports/api-report-react.md @@ -838,7 +838,9 @@ interface FulfilledPromise extends Promise { // @internal const getApolloCacheMemoryInternals: (() => { - fragmentQueryDocuments: number | undefined; + cache: { + fragmentQueryDocuments: number | undefined; + }; }) | undefined; // @internal @@ -847,19 +849,19 @@ const getApolloClientMemoryInternals: (() => { [k: string]: number; }; sizes: { - global: { - print: number | undefined; - parser: number | undefined; - canonicalStringify: number | undefined; - }; + cache?: { + fragmentQueryDocuments: number | undefined; + } | undefined; + print: number | undefined; + parser: number | undefined; + canonicalStringify: number | undefined; links: unknown[]; queryManager: { - Transforms: number; - documentTransforms: number[]; + getDocumentInfo: number; + documentTransforms: { + cache: number; + }[]; }; - cache: { - fragmentQueryDocuments: number | undefined; - } | undefined; }; }) | undefined; diff --git a/.api-reports/api-report-react_components.md b/.api-reports/api-report-react_components.md index deb5c560a94..9fe06f0019e 100644 --- a/.api-reports/api-report-react_components.md +++ b/.api-reports/api-report-react_components.md @@ -720,7 +720,9 @@ type FragmentMatcher = (rootValue: any, typeCondition: string, context: any) => // @internal const getApolloCacheMemoryInternals: (() => { - fragmentQueryDocuments: number | undefined; + cache: { + fragmentQueryDocuments: number | undefined; + }; }) | undefined; // @internal @@ -729,19 +731,19 @@ const getApolloClientMemoryInternals: (() => { [k: string]: number; }; sizes: { - global: { - print: number | undefined; - parser: number | undefined; - canonicalStringify: number | undefined; - }; + cache?: { + fragmentQueryDocuments: number | undefined; + } | undefined; + print: number | undefined; + parser: number | undefined; + canonicalStringify: number | undefined; links: unknown[]; queryManager: { - Transforms: number; - documentTransforms: number[]; + getDocumentInfo: number; + documentTransforms: { + cache: number; + }[]; }; - cache: { - fragmentQueryDocuments: number | undefined; - } | undefined; }; }) | undefined; diff --git a/.api-reports/api-report-react_context.md b/.api-reports/api-report-react_context.md index dec74847286..c522116be26 100644 --- a/.api-reports/api-report-react_context.md +++ b/.api-reports/api-report-react_context.md @@ -703,7 +703,9 @@ type FragmentMatcher = (rootValue: any, typeCondition: string, context: any) => // @internal const getApolloCacheMemoryInternals: (() => { - fragmentQueryDocuments: number | undefined; + cache: { + fragmentQueryDocuments: number | undefined; + }; }) | undefined; // @internal @@ -712,19 +714,19 @@ const getApolloClientMemoryInternals: (() => { [k: string]: number; }; sizes: { - global: { - print: number | undefined; - parser: number | undefined; - canonicalStringify: number | undefined; - }; + cache?: { + fragmentQueryDocuments: number | undefined; + } | undefined; + print: number | undefined; + parser: number | undefined; + canonicalStringify: number | undefined; links: unknown[]; queryManager: { - Transforms: number; - documentTransforms: number[]; + getDocumentInfo: number; + documentTransforms: { + cache: number; + }[]; }; - cache: { - fragmentQueryDocuments: number | undefined; - } | undefined; }; }) | undefined; diff --git a/.api-reports/api-report-react_hoc.md b/.api-reports/api-report-react_hoc.md index cf1cd619c58..a31dc211908 100644 --- a/.api-reports/api-report-react_hoc.md +++ b/.api-reports/api-report-react_hoc.md @@ -714,7 +714,9 @@ type FragmentMatcher = (rootValue: any, typeCondition: string, context: any) => // @internal const getApolloCacheMemoryInternals: (() => { - fragmentQueryDocuments: number | undefined; + cache: { + fragmentQueryDocuments: number | undefined; + }; }) | undefined; // @internal @@ -723,19 +725,19 @@ const getApolloClientMemoryInternals: (() => { [k: string]: number; }; sizes: { - global: { - print: number | undefined; - parser: number | undefined; - canonicalStringify: number | undefined; - }; + cache?: { + fragmentQueryDocuments: number | undefined; + } | undefined; + print: number | undefined; + parser: number | undefined; + canonicalStringify: number | undefined; links: unknown[]; queryManager: { - Transforms: number; - documentTransforms: number[]; + getDocumentInfo: number; + documentTransforms: { + cache: number; + }[]; }; - cache: { - fragmentQueryDocuments: number | undefined; - } | undefined; }; }) | undefined; diff --git a/.api-reports/api-report-react_hooks.md b/.api-reports/api-report-react_hooks.md index 87978f8630f..7f229d061b8 100644 --- a/.api-reports/api-report-react_hooks.md +++ b/.api-reports/api-report-react_hooks.md @@ -798,7 +798,9 @@ interface FulfilledPromise extends Promise { // @internal const getApolloCacheMemoryInternals: (() => { - fragmentQueryDocuments: number | undefined; + cache: { + fragmentQueryDocuments: number | undefined; + }; }) | undefined; // @internal @@ -807,19 +809,19 @@ const getApolloClientMemoryInternals: (() => { [k: string]: number; }; sizes: { - global: { - print: number | undefined; - parser: number | undefined; - canonicalStringify: number | undefined; - }; + cache?: { + fragmentQueryDocuments: number | undefined; + } | undefined; + print: number | undefined; + parser: number | undefined; + canonicalStringify: number | undefined; links: unknown[]; queryManager: { - Transforms: number; - documentTransforms: number[]; + getDocumentInfo: number; + documentTransforms: { + cache: number; + }[]; }; - cache: { - fragmentQueryDocuments: number | undefined; - } | undefined; }; }) | undefined; diff --git a/.api-reports/api-report-react_ssr.md b/.api-reports/api-report-react_ssr.md index 0b28bd464b6..3d786651daa 100644 --- a/.api-reports/api-report-react_ssr.md +++ b/.api-reports/api-report-react_ssr.md @@ -673,7 +673,9 @@ type FragmentMatcher = (rootValue: any, typeCondition: string, context: any) => // @internal const getApolloCacheMemoryInternals: (() => { - fragmentQueryDocuments: number | undefined; + cache: { + fragmentQueryDocuments: number | undefined; + }; }) | undefined; // @internal @@ -682,19 +684,19 @@ const getApolloClientMemoryInternals: (() => { [k: string]: number; }; sizes: { - global: { - print: number | undefined; - parser: number | undefined; - canonicalStringify: number | undefined; - }; + cache?: { + fragmentQueryDocuments: number | undefined; + } | undefined; + print: number | undefined; + parser: number | undefined; + canonicalStringify: number | undefined; links: unknown[]; queryManager: { - Transforms: number; - documentTransforms: number[]; + getDocumentInfo: number; + documentTransforms: { + cache: number; + }[]; }; - cache: { - fragmentQueryDocuments: number | undefined; - } | undefined; }; }) | undefined; diff --git a/.api-reports/api-report-testing.md b/.api-reports/api-report-testing.md index 728a145a346..2b9a826f052 100644 --- a/.api-reports/api-report-testing.md +++ b/.api-reports/api-report-testing.md @@ -667,7 +667,9 @@ type FragmentMatcher = (rootValue: any, typeCondition: string, context: any) => // @internal const getApolloCacheMemoryInternals: (() => { - fragmentQueryDocuments: number | undefined; + cache: { + fragmentQueryDocuments: number | undefined; + }; }) | undefined; // @internal @@ -676,19 +678,19 @@ const getApolloClientMemoryInternals: (() => { [k: string]: number; }; sizes: { - global: { - print: number | undefined; - parser: number | undefined; - canonicalStringify: number | undefined; - }; + cache?: { + fragmentQueryDocuments: number | undefined; + } | undefined; + print: number | undefined; + parser: number | undefined; + canonicalStringify: number | undefined; links: unknown[]; queryManager: { - Transforms: number; - documentTransforms: number[]; + getDocumentInfo: number; + documentTransforms: { + cache: number; + }[]; }; - cache: { - fragmentQueryDocuments: number | undefined; - } | undefined; }; }) | undefined; diff --git a/.api-reports/api-report-testing_core.md b/.api-reports/api-report-testing_core.md index 199422f6ffc..ae008c5549d 100644 --- a/.api-reports/api-report-testing_core.md +++ b/.api-reports/api-report-testing_core.md @@ -666,7 +666,9 @@ type FragmentMatcher = (rootValue: any, typeCondition: string, context: any) => // @internal const getApolloCacheMemoryInternals: (() => { - fragmentQueryDocuments: number | undefined; + cache: { + fragmentQueryDocuments: number | undefined; + }; }) | undefined; // @internal @@ -675,19 +677,19 @@ const getApolloClientMemoryInternals: (() => { [k: string]: number; }; sizes: { - global: { - print: number | undefined; - parser: number | undefined; - canonicalStringify: number | undefined; - }; + cache?: { + fragmentQueryDocuments: number | undefined; + } | undefined; + print: number | undefined; + parser: number | undefined; + canonicalStringify: number | undefined; links: unknown[]; queryManager: { - Transforms: number; - documentTransforms: number[]; + getDocumentInfo: number; + documentTransforms: { + cache: number; + }[]; }; - cache: { - fragmentQueryDocuments: number | undefined; - } | undefined; }; }) | undefined; diff --git a/.api-reports/api-report-utilities.md b/.api-reports/api-report-utilities.md index c27f222390f..e2855ba4cdc 100644 --- a/.api-reports/api-report-utilities.md +++ b/.api-reports/api-report-utilities.md @@ -1091,7 +1091,9 @@ interface FulfilledPromise extends Promise { // @internal const getApolloCacheMemoryInternals: (() => { - fragmentQueryDocuments: number | undefined; + cache: { + fragmentQueryDocuments: number | undefined; + }; }) | undefined; // @internal @@ -1100,19 +1102,19 @@ const getApolloClientMemoryInternals: (() => { [k: string]: number; }; sizes: { - global: { - print: number | undefined; - parser: number | undefined; - canonicalStringify: number | undefined; - }; + cache?: { + fragmentQueryDocuments: number | undefined; + } | undefined; + print: number | undefined; + parser: number | undefined; + canonicalStringify: number | undefined; links: unknown[]; queryManager: { - Transforms: number; - documentTransforms: number[]; + getDocumentInfo: number; + documentTransforms: { + cache: number; + }[]; }; - cache: { - fragmentQueryDocuments: number | undefined; - } | undefined; }; }) | undefined; @@ -1148,18 +1150,22 @@ export function getInclusionDirectives(directives: ReadonlyArray) // @internal const getInMemoryCacheMemoryInternals: (() => { - addTypenameTransform: number[]; - storeReader: { + addTypenameDocumentTransform: { + cache: number; + }[]; + inMemoryCache: { executeSelectionSet: number | undefined; executeSubSelectedArray: number | undefined; + maybeBroadcastWatch: number | undefined; }; - maybeBroadcastWatch: number | undefined; fragmentRegistry: { findFragmentSpreads: number | undefined; lookup: number | undefined; transform: number | undefined; }; - fragmentQueryDocuments: number | undefined; + cache: { + fragmentQueryDocuments: number | undefined; + }; }) | undefined; // @public diff --git a/.api-reports/api-report.md b/.api-reports/api-report.md index d4a14e89415..b0063ffb3cd 100644 --- a/.api-reports/api-report.md +++ b/.api-reports/api-report.md @@ -1056,7 +1056,9 @@ interface FulfilledPromise extends Promise { // @internal const getApolloCacheMemoryInternals: (() => { - fragmentQueryDocuments: number | undefined; + cache: { + fragmentQueryDocuments: number | undefined; + }; }) | undefined; // @internal @@ -1065,19 +1067,19 @@ const getApolloClientMemoryInternals: (() => { [k: string]: number; }; sizes: { - global: { - print: number | undefined; - parser: number | undefined; - canonicalStringify: number | undefined; - }; + cache?: { + fragmentQueryDocuments: number | undefined; + } | undefined; + print: number | undefined; + parser: number | undefined; + canonicalStringify: number | undefined; links: unknown[]; queryManager: { - Transforms: number; - documentTransforms: number[]; + getDocumentInfo: number; + documentTransforms: { + cache: number; + }[]; }; - cache: { - fragmentQueryDocuments: number | undefined; - } | undefined; }; }) | undefined; @@ -1086,18 +1088,22 @@ export function getApolloContext(): ReactTypes.Context; // @internal const getInMemoryCacheMemoryInternals: (() => { - addTypenameTransform: number[]; - storeReader: { + addTypenameDocumentTransform: { + cache: number; + }[]; + inMemoryCache: { executeSelectionSet: number | undefined; executeSubSelectedArray: number | undefined; + maybeBroadcastWatch: number | undefined; }; - maybeBroadcastWatch: number | undefined; fragmentRegistry: { findFragmentSpreads: number | undefined; lookup: number | undefined; transform: number | undefined; }; - fragmentQueryDocuments: number | undefined; + cache: { + fragmentQueryDocuments: number | undefined; + }; }) | undefined; export { gql } From 3fcab506e0c588dd074224fb9fe0039eb554a1be Mon Sep 17 00:00:00 2001 From: Lenz Weber-Tronic Date: Fri, 15 Dec 2023 16:51:36 +0100 Subject: [PATCH 59/62] Update src/utilities/caching/getMemoryInternals.ts --- src/utilities/caching/getMemoryInternals.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/utilities/caching/getMemoryInternals.ts b/src/utilities/caching/getMemoryInternals.ts index d05d3397a35..e344830b712 100644 --- a/src/utilities/caching/getMemoryInternals.ts +++ b/src/utilities/caching/getMemoryInternals.ts @@ -94,6 +94,7 @@ export const getApolloCacheMemoryInternals = : undefined; function getCurrentCacheSizes() { +// `defaultCacheSizes` is a `const enum` that will be inlined during build, so we have to reconstruct it's shape here const defaults: Record = { parser: defaultCacheSizes["parser"], canonicalStringify: defaultCacheSizes["canonicalStringify"], From a4c4aae961ce184b52ca51b9efdd48c8bb270734 Mon Sep 17 00:00:00 2001 From: phryneas Date: Fri, 15 Dec 2023 15:53:47 +0000 Subject: [PATCH 60/62] Clean up Prettier, Size-limit, and Api-Extractor --- src/utilities/caching/getMemoryInternals.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utilities/caching/getMemoryInternals.ts b/src/utilities/caching/getMemoryInternals.ts index e344830b712..a08fe82ad9b 100644 --- a/src/utilities/caching/getMemoryInternals.ts +++ b/src/utilities/caching/getMemoryInternals.ts @@ -94,7 +94,7 @@ export const getApolloCacheMemoryInternals = : undefined; function getCurrentCacheSizes() { -// `defaultCacheSizes` is a `const enum` that will be inlined during build, so we have to reconstruct it's shape here + // `defaultCacheSizes` is a `const enum` that will be inlined during build, so we have to reconstruct it's shape here const defaults: Record = { parser: defaultCacheSizes["parser"], canonicalStringify: defaultCacheSizes["canonicalStringify"], From 6f85640950a602ca871c76d170e0b0d4adbf28b0 Mon Sep 17 00:00:00 2001 From: Lenz Weber-Tronic Date: Fri, 15 Dec 2023 16:57:12 +0100 Subject: [PATCH 61/62] better types --- src/utilities/caching/getMemoryInternals.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/utilities/caching/getMemoryInternals.ts b/src/utilities/caching/getMemoryInternals.ts index a08fe82ad9b..ac28989c37b 100644 --- a/src/utilities/caching/getMemoryInternals.ts +++ b/src/utilities/caching/getMemoryInternals.ts @@ -144,7 +144,10 @@ function _getApolloClientMemoryInternals(this: ApolloClient) { this["queryManager"].documentTransform ), }, - ...this.cache.getMemoryInternals?.(), + ...(this.cache.getMemoryInternals?.() as Partial< + ReturnType + > & + Partial>), }, }; } From c3ad505cf2256397bea53da444c1cbaa6ac4faef Mon Sep 17 00:00:00 2001 From: phryneas Date: Fri, 15 Dec 2023 15:59:31 +0000 Subject: [PATCH 62/62] Clean up Prettier, Size-limit, and Api-Extractor --- .api-reports/api-report-core.md | 13 +++++++++++++ .api-reports/api-report-react.md | 13 +++++++++++++ .api-reports/api-report-react_components.md | 13 +++++++++++++ .api-reports/api-report-react_context.md | 13 +++++++++++++ .api-reports/api-report-react_hoc.md | 13 +++++++++++++ .api-reports/api-report-react_hooks.md | 13 +++++++++++++ .api-reports/api-report-react_ssr.md | 13 +++++++++++++ .api-reports/api-report-testing.md | 13 +++++++++++++ .api-reports/api-report-testing_core.md | 13 +++++++++++++ .api-reports/api-report-utilities.md | 13 +++++++++++++ .api-reports/api-report.md | 13 +++++++++++++ 11 files changed, 143 insertions(+) diff --git a/.api-reports/api-report-core.md b/.api-reports/api-report-core.md index a0dd0d2e18f..16c8ea5ed87 100644 --- a/.api-reports/api-report-core.md +++ b/.api-reports/api-report-core.md @@ -897,6 +897,19 @@ const getApolloClientMemoryInternals: (() => { cache?: { fragmentQueryDocuments: number | undefined; } | undefined; + addTypenameDocumentTransform?: { + cache: number; + }[] | undefined; + inMemoryCache?: { + executeSelectionSet: number | undefined; + executeSubSelectedArray: number | undefined; + maybeBroadcastWatch: number | undefined; + } | undefined; + fragmentRegistry?: { + findFragmentSpreads: number | undefined; + lookup: number | undefined; + transform: number | undefined; + } | undefined; print: number | undefined; parser: number | undefined; canonicalStringify: number | undefined; diff --git a/.api-reports/api-report-react.md b/.api-reports/api-report-react.md index e2d31b93ad1..4b1402c6440 100644 --- a/.api-reports/api-report-react.md +++ b/.api-reports/api-report-react.md @@ -852,6 +852,19 @@ const getApolloClientMemoryInternals: (() => { cache?: { fragmentQueryDocuments: number | undefined; } | undefined; + addTypenameDocumentTransform?: { + cache: number; + }[] | undefined; + inMemoryCache?: { + executeSelectionSet: number | undefined; + executeSubSelectedArray: number | undefined; + maybeBroadcastWatch: number | undefined; + } | undefined; + fragmentRegistry?: { + findFragmentSpreads: number | undefined; + lookup: number | undefined; + transform: number | undefined; + } | undefined; print: number | undefined; parser: number | undefined; canonicalStringify: number | undefined; diff --git a/.api-reports/api-report-react_components.md b/.api-reports/api-report-react_components.md index 9fe06f0019e..96429688c38 100644 --- a/.api-reports/api-report-react_components.md +++ b/.api-reports/api-report-react_components.md @@ -734,6 +734,19 @@ const getApolloClientMemoryInternals: (() => { cache?: { fragmentQueryDocuments: number | undefined; } | undefined; + addTypenameDocumentTransform?: { + cache: number; + }[] | undefined; + inMemoryCache?: { + executeSelectionSet: number | undefined; + executeSubSelectedArray: number | undefined; + maybeBroadcastWatch: number | undefined; + } | undefined; + fragmentRegistry?: { + findFragmentSpreads: number | undefined; + lookup: number | undefined; + transform: number | undefined; + } | undefined; print: number | undefined; parser: number | undefined; canonicalStringify: number | undefined; diff --git a/.api-reports/api-report-react_context.md b/.api-reports/api-report-react_context.md index c522116be26..48fee485c29 100644 --- a/.api-reports/api-report-react_context.md +++ b/.api-reports/api-report-react_context.md @@ -717,6 +717,19 @@ const getApolloClientMemoryInternals: (() => { cache?: { fragmentQueryDocuments: number | undefined; } | undefined; + addTypenameDocumentTransform?: { + cache: number; + }[] | undefined; + inMemoryCache?: { + executeSelectionSet: number | undefined; + executeSubSelectedArray: number | undefined; + maybeBroadcastWatch: number | undefined; + } | undefined; + fragmentRegistry?: { + findFragmentSpreads: number | undefined; + lookup: number | undefined; + transform: number | undefined; + } | undefined; print: number | undefined; parser: number | undefined; canonicalStringify: number | undefined; diff --git a/.api-reports/api-report-react_hoc.md b/.api-reports/api-report-react_hoc.md index a31dc211908..1a4c9bbedc9 100644 --- a/.api-reports/api-report-react_hoc.md +++ b/.api-reports/api-report-react_hoc.md @@ -728,6 +728,19 @@ const getApolloClientMemoryInternals: (() => { cache?: { fragmentQueryDocuments: number | undefined; } | undefined; + addTypenameDocumentTransform?: { + cache: number; + }[] | undefined; + inMemoryCache?: { + executeSelectionSet: number | undefined; + executeSubSelectedArray: number | undefined; + maybeBroadcastWatch: number | undefined; + } | undefined; + fragmentRegistry?: { + findFragmentSpreads: number | undefined; + lookup: number | undefined; + transform: number | undefined; + } | undefined; print: number | undefined; parser: number | undefined; canonicalStringify: number | undefined; diff --git a/.api-reports/api-report-react_hooks.md b/.api-reports/api-report-react_hooks.md index 7f229d061b8..457f93bddd0 100644 --- a/.api-reports/api-report-react_hooks.md +++ b/.api-reports/api-report-react_hooks.md @@ -812,6 +812,19 @@ const getApolloClientMemoryInternals: (() => { cache?: { fragmentQueryDocuments: number | undefined; } | undefined; + addTypenameDocumentTransform?: { + cache: number; + }[] | undefined; + inMemoryCache?: { + executeSelectionSet: number | undefined; + executeSubSelectedArray: number | undefined; + maybeBroadcastWatch: number | undefined; + } | undefined; + fragmentRegistry?: { + findFragmentSpreads: number | undefined; + lookup: number | undefined; + transform: number | undefined; + } | undefined; print: number | undefined; parser: number | undefined; canonicalStringify: number | undefined; diff --git a/.api-reports/api-report-react_ssr.md b/.api-reports/api-report-react_ssr.md index 3d786651daa..74218bc5e08 100644 --- a/.api-reports/api-report-react_ssr.md +++ b/.api-reports/api-report-react_ssr.md @@ -687,6 +687,19 @@ const getApolloClientMemoryInternals: (() => { cache?: { fragmentQueryDocuments: number | undefined; } | undefined; + addTypenameDocumentTransform?: { + cache: number; + }[] | undefined; + inMemoryCache?: { + executeSelectionSet: number | undefined; + executeSubSelectedArray: number | undefined; + maybeBroadcastWatch: number | undefined; + } | undefined; + fragmentRegistry?: { + findFragmentSpreads: number | undefined; + lookup: number | undefined; + transform: number | undefined; + } | undefined; print: number | undefined; parser: number | undefined; canonicalStringify: number | undefined; diff --git a/.api-reports/api-report-testing.md b/.api-reports/api-report-testing.md index 2b9a826f052..2a69d2c4e80 100644 --- a/.api-reports/api-report-testing.md +++ b/.api-reports/api-report-testing.md @@ -681,6 +681,19 @@ const getApolloClientMemoryInternals: (() => { cache?: { fragmentQueryDocuments: number | undefined; } | undefined; + addTypenameDocumentTransform?: { + cache: number; + }[] | undefined; + inMemoryCache?: { + executeSelectionSet: number | undefined; + executeSubSelectedArray: number | undefined; + maybeBroadcastWatch: number | undefined; + } | undefined; + fragmentRegistry?: { + findFragmentSpreads: number | undefined; + lookup: number | undefined; + transform: number | undefined; + } | undefined; print: number | undefined; parser: number | undefined; canonicalStringify: number | undefined; diff --git a/.api-reports/api-report-testing_core.md b/.api-reports/api-report-testing_core.md index ae008c5549d..dd02053d327 100644 --- a/.api-reports/api-report-testing_core.md +++ b/.api-reports/api-report-testing_core.md @@ -680,6 +680,19 @@ const getApolloClientMemoryInternals: (() => { cache?: { fragmentQueryDocuments: number | undefined; } | undefined; + addTypenameDocumentTransform?: { + cache: number; + }[] | undefined; + inMemoryCache?: { + executeSelectionSet: number | undefined; + executeSubSelectedArray: number | undefined; + maybeBroadcastWatch: number | undefined; + } | undefined; + fragmentRegistry?: { + findFragmentSpreads: number | undefined; + lookup: number | undefined; + transform: number | undefined; + } | undefined; print: number | undefined; parser: number | undefined; canonicalStringify: number | undefined; diff --git a/.api-reports/api-report-utilities.md b/.api-reports/api-report-utilities.md index e2855ba4cdc..6a64515659b 100644 --- a/.api-reports/api-report-utilities.md +++ b/.api-reports/api-report-utilities.md @@ -1105,6 +1105,19 @@ const getApolloClientMemoryInternals: (() => { cache?: { fragmentQueryDocuments: number | undefined; } | undefined; + addTypenameDocumentTransform?: { + cache: number; + }[] | undefined; + inMemoryCache?: { + executeSelectionSet: number | undefined; + executeSubSelectedArray: number | undefined; + maybeBroadcastWatch: number | undefined; + } | undefined; + fragmentRegistry?: { + findFragmentSpreads: number | undefined; + lookup: number | undefined; + transform: number | undefined; + } | undefined; print: number | undefined; parser: number | undefined; canonicalStringify: number | undefined; diff --git a/.api-reports/api-report.md b/.api-reports/api-report.md index b0063ffb3cd..ac97e197077 100644 --- a/.api-reports/api-report.md +++ b/.api-reports/api-report.md @@ -1070,6 +1070,19 @@ const getApolloClientMemoryInternals: (() => { cache?: { fragmentQueryDocuments: number | undefined; } | undefined; + addTypenameDocumentTransform?: { + cache: number; + }[] | undefined; + inMemoryCache?: { + executeSelectionSet: number | undefined; + executeSubSelectedArray: number | undefined; + maybeBroadcastWatch: number | undefined; + } | undefined; + fragmentRegistry?: { + findFragmentSpreads: number | undefined; + lookup: number | undefined; + transform: number | undefined; + } | undefined; print: number | undefined; parser: number | undefined; canonicalStringify: number | undefined;