From 4db815951eabd95fb578a61b1c0c7e017e1260b4 Mon Sep 17 00:00:00 2001 From: Lenz Weber-Tronic Date: Wed, 6 Dec 2023 14:20:09 +0100 Subject: [PATCH 01/17] add a "memory management" documentation page --- config/apiExtractor.ts | 106 ++++++++++++++-------- docs/source/caching/memory-management.mdx | 49 ++++++++++ docs/source/config.json | 1 + 3 files changed, 119 insertions(+), 37 deletions(-) create mode 100644 docs/source/caching/memory-management.mdx diff --git a/config/apiExtractor.ts b/config/apiExtractor.ts index f50d25a875a..f64b0d7b525 100644 --- a/config/apiExtractor.ts +++ b/config/apiExtractor.ts @@ -6,6 +6,7 @@ import { IConfigFile, } from "@microsoft/api-extractor"; import { parseArgs } from "node:util"; +import fs from "node:fs"; // @ts-ignore import { map } from "./entryPoints.js"; @@ -40,37 +41,67 @@ const packageJsonFullPath = path.resolve(__dirname, "../package.json"); process.exitCode = 0; -map((entryPoint: { dirs: string[] }) => { - if (entryPoint.dirs.length > 0 && parsed.values["main-only"]) return; +const tempDir = fs.mkdtempSync("api-model"); +try { + if (parsed.values.generate?.includes("docModel")) { + console.log( + "\n\nCreating API extractor docmodel for the a combination of all entry points" + ); + const dist = path.resolve(__dirname, "../dist"); + const entryPoints = map((entryPoint: { dirs: string[] }) => { + return `export * from "${dist}/${entryPoint.dirs.join("/")}/index.d.ts";`; + }).join("\n"); + const entryPointFile = path.join(tempDir, "entry.d.ts"); + fs.writeFileSync(entryPointFile, entryPoints); + + buildReport(entryPointFile, "docModel"); + } - const path = entryPoint.dirs.join("/"); - const mainEntryPointFilePath = - `/dist/${path}/index.d.ts`.replace("//", "/"); - console.log( - "\n\nCreating API extractor report for " + mainEntryPointFilePath - ); + if (parsed.values.generate?.includes("apiReport")) { + map((entryPoint: { dirs: string[] }) => { + const path = entryPoint.dirs.join("/"); + const mainEntryPointFilePath = + `/dist/${path}/index.d.ts`.replace("//", "/"); + console.log( + "\n\nCreating API extractor report for " + mainEntryPointFilePath + ); + buildReport( + mainEntryPointFilePath, + "apiReport", + `api-report${path ? "-" + path.replace(/\//g, "_") : ""}.md` + ); + }); + } +} finally { + fs.rmSync(tempDir, { recursive: true }); +} +function buildReport( + mainEntryPointFilePath: string, + mode: "apiReport" | "docModel", + reportFileName = "" +) { const configObject: IConfigFile = { ...(JSON.parse(JSON.stringify(baseConfig)) as IConfigFile), mainEntryPointFilePath, }; - configObject.apiReport!.reportFileName = `api-report${ - path ? "-" + path.replace(/\//g, "_") : "" - }.md`; - - configObject.apiReport!.enabled = - parsed.values.generate?.includes("apiReport") || false; - - configObject.docModel!.enabled = - parsed.values.generate?.includes("docModel") || false; - - if (entryPoint.dirs.length !== 0) { + if (mode === "apiReport") { + configObject.apiReport!.enabled = true; configObject.docModel = { enabled: false }; - configObject.tsdocMetadata = { enabled: false }; configObject.messages!.extractorMessageReporting![ "ae-unresolved-link" ]!.logLevel = ExtractorLogLevel.None; + configObject.apiReport!.reportFileName = reportFileName; + } else { + configObject.docModel!.enabled = true; + configObject.apiReport = { + enabled: false, + // this has to point to an existing folder, otherwise the extractor will fail + // but it will not write the file + reportFileName: "disabled.md", + reportFolder: tempDir, + }; } const extractorConfig = ExtractorConfig.prepare({ @@ -85,22 +116,23 @@ map((entryPoint: { dirs: string[] }) => { }); let succeededAdditionalChecks = true; - const contents = readFileSync(extractorConfig.reportFilePath, "utf8"); - - if (contents.includes("rehackt")) { - succeededAdditionalChecks = false; - console.error( - "❗ %s contains a reference to the `rehackt` package!", - extractorConfig.reportFilePath - ); - } - if (contents.includes('/// ')) { - succeededAdditionalChecks = false; - console.error( - "❗ %s contains a reference to the global `React` type!/n" + - 'Use `import type * as ReactTypes from "react";` instead', - extractorConfig.reportFilePath - ); + if (fs.existsSync(extractorConfig.reportFilePath)) { + const contents = readFileSync(extractorConfig.reportFilePath, "utf8"); + if (contents.includes("rehackt")) { + succeededAdditionalChecks = false; + console.error( + "❗ %s contains a reference to the `rehackt` package!", + extractorConfig.reportFilePath + ); + } + if (contents.includes('/// ')) { + succeededAdditionalChecks = false; + console.error( + "❗ %s contains a reference to the global `React` type!/n" + + 'Use `import type * as ReactTypes from "react";` instead', + extractorConfig.reportFilePath + ); + } } if (extractorResult.succeeded && succeededAdditionalChecks) { @@ -115,4 +147,4 @@ map((entryPoint: { dirs: string[] }) => { } process.exitCode = 1; } -}); +} diff --git a/docs/source/caching/memory-management.mdx b/docs/source/caching/memory-management.mdx new file mode 100644 index 00000000000..9a9222bf0ce --- /dev/null +++ b/docs/source/caching/memory-management.mdx @@ -0,0 +1,49 @@ +--- +title: Memory management +api_doc: + - "@apollo/client!cacheSizes:var" + - "@apollo/client!CacheSizes:interface" +--- + +## Cache Sizes + +For better performance, Apollo Client caches a lot of internally calculated values. +In most cases, these values are cached in WeakCaches, which means that if the +source object is garbage-collected, the cached value will be garbage-collected, +too. + +Additionally, those caches are LRU caches, which means that if the cache is full, +the least recently used value will be garbage-collected. + +Depending on your application you might want to tweak the cache size to fit your +needs. + +You can do this in two ways: + +### Setting Cache Sizes before loading the Apollo Client library + +This is the recommended way to set the cache sizes, as it will allow you to set +cache sizes before the Apollo Client library is loaded (some caches will already +be initialized when the library is loaded, and changed cache sizes will only +affect caches created after the fact). + + + +### Adjusting Cache Sizes after loading the Apollo Client library + +You can also adjust cache sizes after loading the library. + +```js +import { cacheSizes } from '@apollo/client/utilities'; +import { print } from '@apollo/client' + +cacheSizes.print = 100; +// cache sizes changed this way will only take effect for caches created after +// the cache size has been changed, so we need to reset the cache for it to be effective + +print.reset(); +``` + +### Cache Details + + diff --git a/docs/source/config.json b/docs/source/config.json index 6862f2e7836..60b6f0b1b6e 100644 --- a/docs/source/config.json +++ b/docs/source/config.json @@ -28,6 +28,7 @@ "Reading and writing": "/caching/cache-interaction", "Garbage collection and eviction": "/caching/garbage-collection", "Customizing field behavior": "/caching/cache-field-behavior", + "Memory Management": "/caching/memory-management", "Advanced topics": "/caching/advanced-topics" }, "Pagination": { From 23eda87acaddff9a330e840cc7754aac6d8c92c2 Mon Sep 17 00:00:00 2001 From: Lenz Weber-Tronic Date: Wed, 6 Dec 2023 14:44:03 +0100 Subject: [PATCH 02/17] inline example --- docs/source/caching/memory-management.mdx | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/docs/source/caching/memory-management.mdx b/docs/source/caching/memory-management.mdx index 9a9222bf0ce..4b24fed94da 100644 --- a/docs/source/caching/memory-management.mdx +++ b/docs/source/caching/memory-management.mdx @@ -27,7 +27,13 @@ cache sizes before the Apollo Client library is loaded (some caches will already be initialized when the library is loaded, and changed cache sizes will only affect caches created after the fact). - + ```ts +import type { CacheSizes } from '@apollo/client/utilities'; + + globalThis[Symbol.for("apollo.cacheSize")] = { + parser: 100 + } satisfies Partial + ``` ### Adjusting Cache Sizes after loading the Apollo Client library From 5c6e6afdf002a3f006b11cd72c26c8c8c50693bb Mon Sep 17 00:00:00 2001 From: Lenz Weber-Tronic Date: Wed, 6 Dec 2023 15:33:04 +0100 Subject: [PATCH 03/17] use local ApiDocs components --- docs/source/caching/memory-management.mdx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/source/caching/memory-management.mdx b/docs/source/caching/memory-management.mdx index 4b24fed94da..62373805865 100644 --- a/docs/source/caching/memory-management.mdx +++ b/docs/source/caching/memory-management.mdx @@ -5,6 +5,8 @@ api_doc: - "@apollo/client!CacheSizes:interface" --- +import { InterfaceDetails } from '../../shared/ApiDoc'; + ## Cache Sizes For better performance, Apollo Client caches a lot of internally calculated values. From 76d6fdbfac2d6d73c236e5ad7042f659e4fd6012 Mon Sep 17 00:00:00 2001 From: Lenz Weber-Tronic Date: Fri, 15 Dec 2023 17:47:02 +0100 Subject: [PATCH 04/17] collapsible remarks --- docs/shared/ApiDoc/PropertySignatureTable.js | 7 ++++++- docs/source/caching/memory-management.mdx | 6 +++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/docs/shared/ApiDoc/PropertySignatureTable.js b/docs/shared/ApiDoc/PropertySignatureTable.js index 317b2926f0f..b5d31feb18d 100644 --- a/docs/shared/ApiDoc/PropertySignatureTable.js +++ b/docs/shared/ApiDoc/PropertySignatureTable.js @@ -98,7 +98,12 @@ export function PropertySignatureTable({ - + ))} diff --git a/docs/source/caching/memory-management.mdx b/docs/source/caching/memory-management.mdx index 62373805865..c4ba42700c2 100644 --- a/docs/source/caching/memory-management.mdx +++ b/docs/source/caching/memory-management.mdx @@ -1,7 +1,6 @@ --- title: Memory management api_doc: - - "@apollo/client!cacheSizes:var" - "@apollo/client!CacheSizes:interface" --- @@ -33,7 +32,8 @@ affect caches created after the fact). import type { CacheSizes } from '@apollo/client/utilities'; globalThis[Symbol.for("apollo.cacheSize")] = { - parser: 100 + parser: 100, + "fragmentRegistry.lookup": 500 } satisfies Partial ``` @@ -54,4 +54,4 @@ print.reset(); ### Cache Details - + From 21f8eead621472b6de55cc94c1427d19962743e1 Mon Sep 17 00:00:00 2001 From: Lenz Weber-Tronic Date: Mon, 18 Dec 2023 12:50:54 +0100 Subject: [PATCH 05/17] progress --- docs/shared/ApiDoc/DocBlock.js | 2 +- docs/source/caching/memory-management.mdx | 76 +++++++++++++++++++++-- src/core/ApolloClient.ts | 75 +++++++++++++++++++++- src/utilities/caching/sizes.ts | 15 +++-- 4 files changed, 156 insertions(+), 12 deletions(-) diff --git a/docs/shared/ApiDoc/DocBlock.js b/docs/shared/ApiDoc/DocBlock.js index 333bda75afd..157ece36fdc 100644 --- a/docs/shared/ApiDoc/DocBlock.js +++ b/docs/shared/ApiDoc/DocBlock.js @@ -138,7 +138,7 @@ export function Example({ if (!value) return null; return ( - {mdToReact(value)} + {mdToReact(value)} ); } diff --git a/docs/source/caching/memory-management.mdx b/docs/source/caching/memory-management.mdx index c4ba42700c2..4e1c2ffe6d4 100644 --- a/docs/source/caching/memory-management.mdx +++ b/docs/source/caching/memory-management.mdx @@ -2,13 +2,15 @@ title: Memory management api_doc: - "@apollo/client!CacheSizes:interface" + - "@apollo/client!ApolloClient:class" --- -import { InterfaceDetails } from '../../shared/ApiDoc'; +import { Remarks, PropertySignatureTable, Example } from '../../shared/ApiDoc'; ## Cache Sizes -For better performance, Apollo Client caches a lot of internally calculated values. +For better performance, Apollo Client caches (or, in other words, memoizes) a lot +of internally calculated values. In most cases, these values are cached in WeakCaches, which means that if the source object is garbage-collected, the cached value will be garbage-collected, too. @@ -52,6 +54,70 @@ cacheSizes.print = 100; print.reset(); ``` -### Cache Details - - +### Choosing good cache sizes + + + +To choose good sizes for our memoization caches, you need to know what they +use as source values, and have a general understanding of the data flow inside of +Apollo Client. + +For most memoized values, the source value will be a parsed GraphQL document - +a `DocumentNode`. Here, we need to distinguish between two types of documents: + +* User-supplied `DocumentNode`s: These are DocumentNode objects that are created + by the user, for example by using the `gql` template literal tag. + These are the `QUERY`, `MUTATION` or `SUBSCRIPTION` variables that you pass e.g. + into your `useQuery` hook, or as the `query` option to `client.query`. +* Transformed `DocumentNode`s: These are DocumentNode objects are derived from + user-supplied `DocumentNode`s, e.g. by applying `DocumentTransform`s to them. + +As a rule of thumb, you should set the cache sizes for caches using a Transformed +`DocumentNode` at least to the same size as for caches using a user-supplied +`DocumentNode`. If your application uses a custom `DocumentTransform` that does +not always transform the same input to the same output, you should set the cache +size for caches using a Transformed `DocumentNode` to a higher value than for +caches using a user-supplied `DocumentNode`. + +By default, Apollo Client uses a "base value" of 1000 for caches using +user-supplied `DocumentNode` instances, and scales other cache sizes relative +to that. + +This should be plenty for almost all applications out there, but you might want +to tweak them if you have different requirements. + +#### Measuring cache usage + +As it can be hard to estimate good cache sizes for your application, Apollo Client +exposes an API for cache usage measurement.
+This way, you can click around in your application and then take a look at the +actual usage of the memoizing caches. + +Keep in mind that this API is primarily meant for usage with our DevTools +(we will release an integration for this soon), and we might change it at any +point in time.
+It is also only included in development builds, not in production builds. + +So please only use this for manual measurements, and don't rely on it in production +code or tests. + + + + + +### Cache options + + diff --git a/src/core/ApolloClient.ts b/src/core/ApolloClient.ts index a3216fdda34..d1d8d34b342 100644 --- a/src/core/ApolloClient.ts +++ b/src/core/ApolloClient.ts @@ -750,10 +750,83 @@ export class ApolloClient 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! + * For more details, see [Memory Management](https://www.apollographql.com/docs/react/caching/memory-management/#measuring-cache-usage) + * + * @example + * ```ts + * console.log(client.getMemoryInternals()) + * ``` + * will log something in the form of + * @example + * ```json + *{ + * limits: { + * parser: 1000, + * canonicalStringify: 1000, + * print: 2000, + * 'documentTransform.cache': 2000, + * 'queryManager.getDocumentInfo': 2000, + * 'PersistedQueryLink.persistedQueryHashes': 2000, + * 'fragmentRegistry.transform': 2000, + * 'fragmentRegistry.lookup': 1000, + * 'fragmentRegistry.findFragmentSpreads': 4000, + * 'cache.fragmentQueryDocuments': 1000, + * 'removeTypenameFromVariables.getVariableDefinitions': 2000, + * 'inMemoryCache.maybeBroadcastWatch': 5000, + * 'inMemoryCache.executeSelectionSet': 10000, + * 'inMemoryCache.executeSubSelectedArray': 5000 + * }, + * sizes: { + * parser: 26, + * canonicalStringify: 4, + * print: 14, + * addTypenameDocumentTransform: [ + * { + * cache: 14, + * }, + * ], + * queryManager: { + * getDocumentInfo: 14, + * documentTransforms: [ + * { + * cache: 14, + * }, + * { + * cache: 14, + * }, + * ], + * }, + * fragmentRegistry: { + * findFragmentSpreads: 34, + * lookup: 20, + * transform: 14, + * }, + * cache: { + * fragmentQueryDocuments: 22, + * }, + * inMemoryCache: { + * executeSelectionSet: 4345, + * executeSubSelectedArray: 1206, + * maybeBroadcastWatch: 32, + * }, + * links: [ + * { + * PersistedQueryLink: { + * persistedQueryHashes: 14, + * }, + * }, + * { + * removeTypenameFromVariables: { + * getVariableDefinitions: 14, + * }, + * }, + * ], + * }, + * } + *``` */ public getMemoryInternals?: typeof getApolloClientMemoryInternals; } diff --git a/src/utilities/caching/sizes.ts b/src/utilities/caching/sizes.ts index 998537740a3..4faccd6a44b 100644 --- a/src/utilities/caching/sizes.ts +++ b/src/utilities/caching/sizes.ts @@ -9,13 +9,18 @@ declare global { /** * 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. + * @remarks + * All configurable caches hold derivative (memoized) values and if an item is + * cache-collected, that only means a small performance hit, but it will not + * cause data loss, and a smaller cache size might save you memory. * * 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. - * + * encountered, but rather to hold a reasonable number of values. + * To prevent too much recalculation, cache sizes should at least be chosen + * big enough to hold memoized values for all hooks/queries that are + * 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. From 08fe05d354477e3da7b5e59d7e8cc2e23fc159cd Mon Sep 17 00:00:00 2001 From: Lenz Weber-Tronic Date: Mon, 18 Dec 2023 14:16:52 +0100 Subject: [PATCH 06/17] work on DocBlocks --- docs/source/caching/memory-management.mdx | 1 - src/utilities/caching/sizes.ts | 137 +++++++++++++++------- 2 files changed, 95 insertions(+), 43 deletions(-) diff --git a/docs/source/caching/memory-management.mdx b/docs/source/caching/memory-management.mdx index 4e1c2ffe6d4..ebd3d55d23a 100644 --- a/docs/source/caching/memory-management.mdx +++ b/docs/source/caching/memory-management.mdx @@ -118,6 +118,5 @@ code or tests. diff --git a/src/utilities/caching/sizes.ts b/src/utilities/caching/sizes.ts index 4faccd6a44b..9a99058ef23 100644 --- a/src/utilities/caching/sizes.ts +++ b/src/utilities/caching/sizes.ts @@ -27,84 +27,116 @@ declare global { */ export interface CacheSizes { /** - * Cache size for the [`print`](../../utilities/graphql/print.ts) function. + * Cache size for the [`print`](https://github.com/apollographql/apollo-client/blob/main/src/utilities/graphql/print.ts) function. + * + * It is called with transformed `DocumentNode`s. * * @defaultValue * Defaults to `2000`. * * @remarks - * This method is called from the `QueryManager` and various `Link`s, + * This method is called to transform a GraphQL query AST parsed by `gql` + * back into a GraphQL string. + * + * @privateRemarks + * This method is called from the `QueryManager` and various `ApolloLink`s, * always with the "serverQuery", so the server-facing part of a transformed - * DocumentNode. + * `DocumentNode`. */ print: number; /** - * Cache size for the [`parser`](../../react/parser/index.ts) function. + * Cache size for the [`parser`](https://github.com/apollographql/apollo-client/blob/main/src/react/parser/index.ts) function. + * + * It is called with user-provided `DocumentNode`s. * * @defaultValue * Defaults to `1000`. * * @remarks + * This method is called by HOCs and hooks. + * + * @privateRemarks * 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). + * Cache size for the cache of [`DocumentTransform`](https://github.com/apollographql/apollo-client/blob/main/src/utilities/graphql/DocumentTransform.ts) + * instances with the `cache`option set to `true`. + * + * Can be called with user-defined or already-transformed `DocumentNode`s. * * @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, + * For example, if there was a DocumentTransform that would take `x` 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. + * online or offline, then we assume that the cache returns `2*x` documents. + * If that were concatenated with another DocumentTransform that would + * also duplicate the cache size, you'd need to account for `4*x` documents + * returned by the second transform. * - * No user-provided DocumentNode will actually be "the last one", as we run the - * `defaultDocumentTransform` before *and* after the user-provided transforms. + * Due to an implementation detail of Apollo Client, if you use custom document + * transforms you should always add `n` (the "base" number of user-provided + * Documents) to the resulting cache size. * * 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`. + * If we assume that the chain of user-provided transforms receive `n` documents and + * return `4*n` documents, the cache size should be `5*n`. * * This size should also then be used in every other cache that mentions that * it operates on a "transformed" DocumentNode. + * + * @privateRemarks + * Cache size for the `performWork` method of each [`DocumentTransform`](https://github.com/apollographql/apollo-client/blob/main/src/utilities/graphql/DocumentTransform.ts). + * + * No user-provided DocumentNode will actually be "the last one", as we run the + * `defaultDocumentTransform` before *and* after the user-provided transforms. + * For that reason, we need the extra `n` here - `n` for "before transformation" + * plus the actual maximum cache size of the user-provided transform chain. + * + * 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. + * */ "documentTransform.cache": number; /** - * Cache size for the `transformCache` used in the `getDocumentInfo` method of - * [`QueryManager`](../../core/QueryManager.ts). + * A cache inside of [`QueryManager`](https://github.com/apollographql/apollo-client/blob/main/src/core/QueryManager.ts). + * + * It is called with transformed `DocumentNode`s. * * @defaultValue * Defaults to `2000`. * - * @remarks - * `getDocumentInfo` is called throughout the `QueryManager` with transformed - * DocumentNodes. + * @privateRemarks + * Cache size for the `transformCache` used in the `getDocumentInfo` method of `QueryManager`. + * Called throughout the `QueryManager` with transformed DocumentNodes. */ "queryManager.getDocumentInfo": number; /** - * Cache size for the `hashesByQuery` cache in the [`PersistedQueryLink`](../../link/persisted-queries/index.ts). + * A cache inside of [`PersistedQueryLink`](https://github.com/apollographql/apollo-client/blob/main/src/link/persisted-queries/index.ts). + * + * It is called with transformed `DocumentNode`s. * * @defaultValue * Defaults to `2000`. * * @remarks - * This cache is used to cache the hashes of persisted queries. It is working with - * transformed DocumentNodes. + * This cache is used to cache the hashes of persisted queries. + * + * @privateRemarks + * Cache size for the `hashesByQuery` cache in the `PersistedQueryLink`. */ "PersistedQueryLink.persistedQueryHashes": number; /** - * Cache for the `sortingMap` used by [`canonicalStringify`](../../utilities/common/canonicalStringify.ts). + * Cache used by [`canonicalStringify`](https://github.com/apollographql/apollo-client/blob/main/src/utilities/common/canonicalStringify.ts). * * @defaultValue * Defaults to `1000`. @@ -115,52 +147,68 @@ export interface CacheSizes { * 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. + * + * @privateRemarks + * Cache size for the `sortingMap` in `canonicalStringify`. */ canonicalStringify: number; /** - * Cache size for the `transform` method of [`FragmentRegistry`](../../cache/inmemory/fragmentRegistry.ts). + * A cache inside of [`FragmentRegistry`](https://github.com/apollographql/apollo-client/blob/main/src/cache/inmemory/fragmentRegistry.ts). + * + * Can be called with user-defined or already-transformed `DocumentNode`s. * * @defaultValue * Defaults to `2000`. * - * @remarks + * @privateRemarks + * + * Cache size for the `transform` method of FragmentRegistry. * This function is called as part of the `defaultDocumentTransform` which will be called with * user-provided and already-transformed DocumentNodes. * */ "fragmentRegistry.transform": number; /** - * Cache size for the `lookup` method of [`FragmentRegistry`](../../cache/inmemory/fragmentRegistry.ts). + * A cache inside of [`FragmentRegistry`](https://github.com/apollographql/apollo-client/blob/main/src/cache/inmemory/fragmentRegistry.ts). + * + * This function is called with fragment names in the form of a string. * * @defaultValue * Defaults to `1000`. * * @remarks - * This function is called with fragment names in the form of a string. + * The size of this case should be chosen with the number of fragments in + * your application in mind. * * Note: - * This function is a dependency of `transform`, so having a too small cache size here + * This function is a dependency of `fragmentRegistry.transform`, so having a too small cache size here * might involuntarily invalidate values in the `transform` cache. + * + * @privateRemarks + * Cache size for the `lookup` method of FragmentRegistry. */ "fragmentRegistry.lookup": number; /** - * Cache size for the `findFragmentSpreads` method of [`FragmentRegistry`](../../cache/inmemory/fragmentRegistry.ts). + * Cache size for the `findFragmentSpreads` method of [`FragmentRegistry`](https://github.com/apollographql/apollo-client/blob/main/src/cache/inmemory/fragmentRegistry.ts). + * + * 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. * * @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 + * This function is a dependency of `fragmentRegistry.transform`, so having a too small cache size here * might involuntarily invalidate values in the `transform` cache. */ "fragmentRegistry.findFragmentSpreads": number; /** - * Cache size for the `getFragmentDoc` method of [`ApolloCache`](../../cache/core/cache.ts). + * Cache size for the `getFragmentDoc` method of [`ApolloCache`](https://github.com/apollographql/apollo-client/blob/main/src/cache/core/cache.ts). + * + * This function is called with user-provided fragment definitions. * * @defaultValue * Defaults to `1000`. @@ -170,18 +218,21 @@ export interface CacheSizes { */ "cache.fragmentQueryDocuments": number; /** - * Cache size for the `getVariableDefinitions` function in [`removeTypenameFromVariables`](../../link/remove-typename/removeTypenameFromVariables.ts). + * Cache used in [`removeTypenameFromVariables`](https://github.com/apollographql/apollo-client/blob/main/src/link/remove-typename/removeTypenameFromVariables.ts). + * + * This function is called transformed DocumentNodes. * * @defaultValue * Defaults to `2000`. * - * @remarks - * This function is called in a link with transformed DocumentNodes. + * @privateRemarks + * Cache size for the `getVariableDefinitions` function of `removeTypenameFromVariables`. */ "removeTypenameFromVariables.getVariableDefinitions": number; /** - * Cache size for the `maybeBroadcastWatch` method on [`InMemoryCache`](../../cache/inmemory/inMemoryCache.ts). + * Cache size for the `maybeBroadcastWatch` method on [`InMemoryCache`](https://github.com/apollographql/apollo-client/blob/main/src/cache/inmemory/inMemoryCache.ts). * + * Note: * `maybeBroadcastWatch` will be set to the `resultCacheMaxSize` option and * will fall back to this configuration value if the option is not set. * @@ -197,8 +248,9 @@ export interface CacheSizes { */ "inMemoryCache.maybeBroadcastWatch": number; /** - * Cache size for the `executeSelectionSet` method on [`StoreReader`](../../cache/inmemory/readFromStore.ts). + * Cache size for the `executeSelectionSet` method on [`StoreReader`](https://github.com/apollographql/apollo-client/blob/main/src/cache/inmemory/readFromStore.ts). * + * Note: * `executeSelectionSet` will be set to the `resultCacheMaxSize` option and * will fall back to this configuration value if the option is not set. * @@ -211,8 +263,9 @@ export interface CacheSizes { */ "inMemoryCache.executeSelectionSet": number; /** - * Cache size for the `executeSubSelectedArray` method on [`StoreReader`](../../cache/inmemory/readFromStore.ts). + * Cache size for the `executeSubSelectedArray` method on [`StoreReader`](https://github.com/apollographql/apollo-client/blob/main/src/cache/inmemory/readFromStore.ts). * + * Note: * `executeSubSelectedArray` will be set to the `resultCacheMaxSize` option and * will fall back to this configuration value if the option is not set. * From 01962e0ede0f1ffdfa8a71895de7984f1dcb992c Mon Sep 17 00:00:00 2001 From: Lenz Weber-Tronic Date: Wed, 20 Dec 2023 20:27:22 +0100 Subject: [PATCH 07/17] Apply suggestions from code review Co-authored-by: Maria Elisabeth Schreiber --- docs/source/caching/memory-management.mdx | 54 ++++++++++++----------- src/core/ApolloClient.ts | 2 +- src/utilities/caching/sizes.ts | 6 +-- 3 files changed, 32 insertions(+), 30 deletions(-) diff --git a/docs/source/caching/memory-management.mdx b/docs/source/caching/memory-management.mdx index ebd3d55d23a..92e41473362 100644 --- a/docs/source/caching/memory-management.mdx +++ b/docs/source/caching/memory-management.mdx @@ -3,32 +3,32 @@ title: Memory management api_doc: - "@apollo/client!CacheSizes:interface" - "@apollo/client!ApolloClient:class" +subtitle: Learn how to choose and set custom cache sizes +description: Learn how to choose and set custom cache sizes with Apollo Client. --- import { Remarks, PropertySignatureTable, Example } from '../../shared/ApiDoc'; ## Cache Sizes -For better performance, Apollo Client caches (or, in other words, memoizes) a lot -of internally calculated values. -In most cases, these values are cached in WeakCaches, which means that if the +For better performance, Apollo Client caches (or, in other words, memoizes) many +internally calculated values. +In most cases, these values are cached in [weak caches](https://en.wikipedia.org/wiki/Weak_reference), which means that if the source object is garbage-collected, the cached value will be garbage-collected, too. -Additionally, those caches are LRU caches, which means that if the cache is full, +These caches are also Least Recently Used (LRU) caches, meaning that if the cache is full, the least recently used value will be garbage-collected. -Depending on your application you might want to tweak the cache size to fit your +Depending on your application, you might want to tweak the cache size to fit your needs. -You can do this in two ways: +You can set your cache size [before (recommended)](#set-cache-sizes-before-loading-the-apollo-client-library) or [after](#adjust-cache-sizes-after-loading-the-apollo-client-library) loading the Apollo Client library. -### Setting Cache Sizes before loading the Apollo Client library +### Setting cache sizes before loading the Apollo Client library -This is the recommended way to set the cache sizes, as it will allow you to set -cache sizes before the Apollo Client library is loaded (some caches will already -be initialized when the library is loaded, and changed cache sizes will only -affect caches created after the fact). +Setting cache sizes before loading the Apollo Client library is recommended because some caches are already initialized when the library is loaded, and changed cache sizes only +affect caches created after the fact, so you'd have to write additional runtime codes to recreate these caches after changing their size. ```ts import type { CacheSizes } from '@apollo/client/utilities'; @@ -39,7 +39,7 @@ import type { CacheSizes } from '@apollo/client/utilities'; } satisfies Partial ``` -### Adjusting Cache Sizes after loading the Apollo Client library +### Adjusting cache sizes after loading the Apollo Client library You can also adjust cache sizes after loading the library. @@ -64,15 +64,15 @@ To choose good sizes for our memoization caches, you need to know what they use as source values, and have a general understanding of the data flow inside of Apollo Client. -For most memoized values, the source value will be a parsed GraphQL document - -a `DocumentNode`. Here, we need to distinguish between two types of documents: +For most memoized values, the source value is a parsed GraphQL document— +a `DocumentNode`. There are two types: -* User-supplied `DocumentNode`s: These are DocumentNode objects that are created +* **User-supplied `DocumentNode`s** are created by the user, for example by using the `gql` template literal tag. - These are the `QUERY`, `MUTATION` or `SUBSCRIPTION` variables that you pass e.g. - into your `useQuery` hook, or as the `query` option to `client.query`. -* Transformed `DocumentNode`s: These are DocumentNode objects are derived from - user-supplied `DocumentNode`s, e.g. by applying `DocumentTransform`s to them. + These are the `QUERY`, `MUTATION`, or `SUBSCRIPTION` variables passed + into a [`useQuery` hook](../data/queries/#usequery-api) or as the `query` option to `client.query`. +* *Transformed `DocumentNode`s** are derived from + user-supplied `DocumentNode`s, for example, by applying [`DocumentTransform`s](../data/document-transforms/) to them. As a rule of thumb, you should set the cache sizes for caches using a Transformed `DocumentNode` at least to the same size as for caches using a user-supplied @@ -85,23 +85,25 @@ By default, Apollo Client uses a "base value" of 1000 for caches using user-supplied `DocumentNode` instances, and scales other cache sizes relative to that. -This should be plenty for almost all applications out there, but you might want -to tweak them if you have different requirements. +This base value should be plenty for most applications, but you can tweak them if you have different requirements. #### Measuring cache usage -As it can be hard to estimate good cache sizes for your application, Apollo Client +Since estimating appropriate cache sizes for your application can be hard, Apollo Client exposes an API for cache usage measurement.
This way, you can click around in your application and then take a look at the actual usage of the memoizing caches. -Keep in mind that this API is primarily meant for usage with our DevTools -(we will release an integration for this soon), and we might change it at any +Keep in mind that this API is primarily meant for usage with the Apollo DevTools +(an integration is coming soon), and the API may change at any point in time.
It is also only included in development builds, not in production builds. -So please only use this for manual measurements, and don't rely on it in production -code or tests. + + +The cache usage API is only meant for manual measurements. Don't rely on it in production code or tests. + + implements DataProxy { * ```ts * console.log(client.getMemoryInternals()) * ``` - * will log something in the form of + * Logs output in the following JSON format: * @example * ```json *{ diff --git a/src/utilities/caching/sizes.ts b/src/utilities/caching/sizes.ts index 9a99058ef23..7ca2ef4fe8a 100644 --- a/src/utilities/caching/sizes.ts +++ b/src/utilities/caching/sizes.ts @@ -10,9 +10,9 @@ declare global { * The cache sizes used by various Apollo Client caches. * * @remarks - * All configurable caches hold derivative (memoized) values and if an item is - * cache-collected, that only means a small performance hit, but it will not - * cause data loss, and a smaller cache size might save you memory. + * All configurable caches hold memoized values. If an item is + * cache-collected, it incurs only a small performance impact and + * doesn't cause data loss. A smaller cache size might save you memory. * * 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. From 74a3ba5289eef9dc03b47bca78a4ae15133bea71 Mon Sep 17 00:00:00 2001 From: Lenz Weber-Tronic Date: Wed, 20 Dec 2023 20:28:10 +0100 Subject: [PATCH 08/17] Apply suggestions from code review Co-authored-by: Maria Elisabeth Schreiber --- docs/source/caching/memory-management.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/caching/memory-management.mdx b/docs/source/caching/memory-management.mdx index 92e41473362..bf67b12f6da 100644 --- a/docs/source/caching/memory-management.mdx +++ b/docs/source/caching/memory-management.mdx @@ -54,7 +54,7 @@ cacheSizes.print = 100; print.reset(); ``` -### Choosing good cache sizes +### Choosing appropriate cache sizes Date: Wed, 20 Dec 2023 20:30:33 +0100 Subject: [PATCH 09/17] review feedback --- src/utilities/caching/sizes.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/utilities/caching/sizes.ts b/src/utilities/caching/sizes.ts index 7ca2ef4fe8a..c130eb2c263 100644 --- a/src/utilities/caching/sizes.ts +++ b/src/utilities/caching/sizes.ts @@ -14,11 +14,10 @@ declare global { * cache-collected, it incurs only a small performance impact and * doesn't cause data loss. A smaller cache size might save you memory. * - * 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. - * To prevent too much recalculation, cache sizes should at least be chosen - * big enough to hold memoized values for all hooks/queries that are - * on the screen at any given time. + * You should choose cache sizes appropriate for storing a reasonable + * number of values rather than every value. To prevent too much recalculation, + * choose cache sizes that are at least large enough to hold memoized values for + * all hooks/queries on the screen at any given time. */ /* * We assume a "base value" of 1000 here, which is already very generous. From 9969c0773cf6ac5a46de7fb118caa0ca7bc90f3c Mon Sep 17 00:00:00 2001 From: Jerel Miller Date: Wed, 20 Dec 2023 12:59:23 -0700 Subject: [PATCH 10/17] Add minVersion to frontmatter --- docs/source/caching/memory-management.mdx | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/source/caching/memory-management.mdx b/docs/source/caching/memory-management.mdx index bf67b12f6da..44064ba534e 100644 --- a/docs/source/caching/memory-management.mdx +++ b/docs/source/caching/memory-management.mdx @@ -5,6 +5,7 @@ api_doc: - "@apollo/client!ApolloClient:class" subtitle: Learn how to choose and set custom cache sizes description: Learn how to choose and set custom cache sizes with Apollo Client. +minVersion: 3.9.0 --- import { Remarks, PropertySignatureTable, Example } from '../../shared/ApiDoc'; From d21e117a98457eb970f48a7962ca9fb9559f54f6 Mon Sep 17 00:00:00 2001 From: Jerel Miller Date: Wed, 20 Dec 2023 12:59:48 -0700 Subject: [PATCH 11/17] Fix anchor links in intro section --- docs/source/caching/memory-management.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/caching/memory-management.mdx b/docs/source/caching/memory-management.mdx index 44064ba534e..c55f9883cef 100644 --- a/docs/source/caching/memory-management.mdx +++ b/docs/source/caching/memory-management.mdx @@ -24,7 +24,7 @@ the least recently used value will be garbage-collected. Depending on your application, you might want to tweak the cache size to fit your needs. -You can set your cache size [before (recommended)](#set-cache-sizes-before-loading-the-apollo-client-library) or [after](#adjust-cache-sizes-after-loading-the-apollo-client-library) loading the Apollo Client library. +You can set your cache size [before (recommended)](#setting-cache-sizes-before-loading-the-apollo-client-library) or [after](#adjusting-cache-sizes-after-loading-the-apollo-client-library) loading the Apollo Client library. ### Setting cache sizes before loading the Apollo Client library From 873c1c5ae0f7b913239c7ca900b05c590f71f96d Mon Sep 17 00:00:00 2001 From: Jerel Miller Date: Wed, 20 Dec 2023 13:00:53 -0700 Subject: [PATCH 12/17] Split into two sentences --- docs/source/caching/memory-management.mdx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/source/caching/memory-management.mdx b/docs/source/caching/memory-management.mdx index c55f9883cef..baddf0f0b43 100644 --- a/docs/source/caching/memory-management.mdx +++ b/docs/source/caching/memory-management.mdx @@ -28,8 +28,8 @@ You can set your cache size [before (recommended)](#setting-cache-sizes-before-l ### Setting cache sizes before loading the Apollo Client library -Setting cache sizes before loading the Apollo Client library is recommended because some caches are already initialized when the library is loaded, and changed cache sizes only -affect caches created after the fact, so you'd have to write additional runtime codes to recreate these caches after changing their size. +Setting cache sizes before loading the Apollo Client library is recommended because some caches are already initialized when the library is loaded. Changed cache sizes only +affect caches created after the fact, so you'd have to write additional runtime code to recreate these caches after changing their size. ```ts import type { CacheSizes } from '@apollo/client/utilities'; From 46a318aa551da452d222fb5dc6b7a111cece9b4d Mon Sep 17 00:00:00 2001 From: Jerel Miller Date: Wed, 20 Dec 2023 13:04:36 -0700 Subject: [PATCH 13/17] Shorten comment to avoid horizontal scroll --- docs/source/caching/memory-management.mdx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/source/caching/memory-management.mdx b/docs/source/caching/memory-management.mdx index baddf0f0b43..7a16514d0f7 100644 --- a/docs/source/caching/memory-management.mdx +++ b/docs/source/caching/memory-management.mdx @@ -49,8 +49,9 @@ import { cacheSizes } from '@apollo/client/utilities'; import { print } from '@apollo/client' cacheSizes.print = 100; -// cache sizes changed this way will only take effect for caches created after -// the cache size has been changed, so we need to reset the cache for it to be effective +// cache sizes changed this way will only take effect for caches +// created after the cache size has been changed, so we need to +// reset the cache for it to be effective print.reset(); ``` From ada53483d80e20cc62f2f67b361c63f13f892c14 Mon Sep 17 00:00:00 2001 From: Maria Elisabeth Schreiber Date: Wed, 20 Dec 2023 15:05:38 -0500 Subject: [PATCH 14/17] Apply suggestions from code review Co-authored-by: Jerel Miller --- docs/source/caching/memory-management.mdx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/source/caching/memory-management.mdx b/docs/source/caching/memory-management.mdx index 7a16514d0f7..c74a32d1b0a 100644 --- a/docs/source/caching/memory-management.mdx +++ b/docs/source/caching/memory-management.mdx @@ -71,12 +71,12 @@ a `DocumentNode`. There are two types: * **User-supplied `DocumentNode`s** are created by the user, for example by using the `gql` template literal tag. - These are the `QUERY`, `MUTATION`, or `SUBSCRIPTION` variables passed + This is the `QUERY`, `MUTATION`, or `SUBSCRIPTION` argument passed into a [`useQuery` hook](../data/queries/#usequery-api) or as the `query` option to `client.query`. -* *Transformed `DocumentNode`s** are derived from +* **Transformed `DocumentNode`s** are derived from user-supplied `DocumentNode`s, for example, by applying [`DocumentTransform`s](../data/document-transforms/) to them. -As a rule of thumb, you should set the cache sizes for caches using a Transformed +As a rule of thumb, you should set the cache sizes for caches using a transformed `DocumentNode` at least to the same size as for caches using a user-supplied `DocumentNode`. If your application uses a custom `DocumentTransform` that does not always transform the same input to the same output, you should set the cache From 0f5841c8d2d320c231452858d10aa0cc37105962 Mon Sep 17 00:00:00 2001 From: Jerel Miller Date: Wed, 20 Dec 2023 13:14:37 -0700 Subject: [PATCH 15/17] Minor tweak to explanation of base value Co-authored-by: Maria Elisabeth Schreiber --- docs/source/caching/memory-management.mdx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/source/caching/memory-management.mdx b/docs/source/caching/memory-management.mdx index c74a32d1b0a..cf40fc27d8d 100644 --- a/docs/source/caching/memory-management.mdx +++ b/docs/source/caching/memory-management.mdx @@ -83,9 +83,9 @@ not always transform the same input to the same output, you should set the cache size for caches using a Transformed `DocumentNode` to a higher value than for caches using a user-supplied `DocumentNode`. -By default, Apollo Client uses a "base value" of 1000 for caches using +By default, Apollo Client uses a base value of 1000 cached objects for caches using user-supplied `DocumentNode` instances, and scales other cache sizes relative -to that. +to that. For example, the default base value of 1000 for user-provided `DocumentNode`s would scale to 2000, 4000, etc. for transformed `DocumentNode`s, depending on the transformation performed. This base value should be plenty for most applications, but you can tweak them if you have different requirements. From 3ac76cffa8a146790fa1b41c966b72aca69fe748 Mon Sep 17 00:00:00 2001 From: Jerel Miller Date: Wed, 20 Dec 2023 13:25:24 -0700 Subject: [PATCH 16/17] Minor tweaks to CacheSize descriptions for consistency --- src/utilities/caching/sizes.ts | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/src/utilities/caching/sizes.ts b/src/utilities/caching/sizes.ts index c130eb2c263..28ace70a8c2 100644 --- a/src/utilities/caching/sizes.ts +++ b/src/utilities/caching/sizes.ts @@ -62,7 +62,7 @@ export interface CacheSizes { parser: number; /** * Cache size for the cache of [`DocumentTransform`](https://github.com/apollographql/apollo-client/blob/main/src/utilities/graphql/DocumentTransform.ts) - * instances with the `cache`option set to `true`. + * instances with the `cache` option set to `true`. * * Can be called with user-defined or already-transformed `DocumentNode`s. * @@ -70,11 +70,11 @@ export interface CacheSizes { * Defaults to `2000`. * * @remarks - * The cache size here should be chosen with other DocumentTransforms in mind. - * For example, if there was a DocumentTransform that would take `x` DocumentNodes, - * and returned a differently-transformed DocumentNode depending if the app is + * The cache size here should be chosen with other `DocumentTransform`s in mind. + * For example, if there was a `DocumentTransform` that would take `x` `DocumentNode`s, + * and returned a differently-transformed `DocumentNode` depending if the app is * online or offline, then we assume that the cache returns `2*x` documents. - * If that were concatenated with another DocumentTransform that would + * If that were concatenated with another `DocumentTransform` that would * also duplicate the cache size, you'd need to account for `4*x` documents * returned by the second transform. * @@ -82,14 +82,14 @@ export interface CacheSizes { * transforms you should always add `n` (the "base" number of user-provided * Documents) to the resulting cache size. * - * So if we assume that the user-provided transforms receive `n` documents and + * 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 chain of user-provided transforms receive `n` documents and * return `4*n` documents, the cache size should be `5*n`. * * This size should also then be used in every other cache that mentions that - * it operates on a "transformed" DocumentNode. + * it operates on a "transformed" `DocumentNode`. * * @privateRemarks * Cache size for the `performWork` method of each [`DocumentTransform`](https://github.com/apollographql/apollo-client/blob/main/src/utilities/graphql/DocumentTransform.ts). @@ -180,7 +180,7 @@ export interface CacheSizes { * your application in mind. * * Note: - * This function is a dependency of `fragmentRegistry.transform`, so having a too small cache size here + * This function is a dependency of `fragmentRegistry.transform`, so having too small of a cache size here * might involuntarily invalidate values in the `transform` cache. * * @privateRemarks @@ -190,7 +190,7 @@ export interface CacheSizes { /** * Cache size for the `findFragmentSpreads` method of [`FragmentRegistry`](https://github.com/apollographql/apollo-client/blob/main/src/cache/inmemory/fragmentRegistry.ts). * - * This function is called with transformed DocumentNodes, as well as recursively + * This function is called with transformed `DocumentNode`s, as well as recursively * with every fragment spread referenced within that, or a fragment referenced by a * fragment spread. * @@ -199,8 +199,7 @@ export interface CacheSizes { * * @remarks * - * Note: - * This function is a dependency of `fragmentRegistry.transform`, so having a too small cache size here + * Note: This function is a dependency of `fragmentRegistry.transform`, so having too small of cache size here * might involuntarily invalidate values in the `transform` cache. */ "fragmentRegistry.findFragmentSpreads": number; @@ -219,7 +218,7 @@ export interface CacheSizes { /** * Cache used in [`removeTypenameFromVariables`](https://github.com/apollographql/apollo-client/blob/main/src/link/remove-typename/removeTypenameFromVariables.ts). * - * This function is called transformed DocumentNodes. + * This function is called transformed `DocumentNode`s. * * @defaultValue * Defaults to `2000`. @@ -231,8 +230,7 @@ export interface CacheSizes { /** * Cache size for the `maybeBroadcastWatch` method on [`InMemoryCache`](https://github.com/apollographql/apollo-client/blob/main/src/cache/inmemory/inMemoryCache.ts). * - * Note: - * `maybeBroadcastWatch` will be set to the `resultCacheMaxSize` option and + * Note: `maybeBroadcastWatch` will be set to the `resultCacheMaxSize` option and * will fall back to this configuration value if the option is not set. * * @defaultValue From b4dfd1e0ab94e45fa2def909f28e6246494649c3 Mon Sep 17 00:00:00 2001 From: jerelmiller Date: Wed, 20 Dec 2023 20:27:55 +0000 Subject: [PATCH 17/17] 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_internal.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-utilities.md | 2 -- .api-reports/api-report.md | 2 -- 12 files changed, 24 deletions(-) diff --git a/.api-reports/api-report-core.md b/.api-reports/api-report-core.md index 04da92c9c0a..54622181969 100644 --- a/.api-reports/api-report-core.md +++ b/.api-reports/api-report-core.md @@ -109,8 +109,6 @@ export class ApolloClient implements DataProxy { get documentTransform(): DocumentTransform; extract(optimistic?: boolean): TCacheShape; // Warning: (ae-forgotten-export) The symbol "getApolloClientMemoryInternals" needs to be exported by the entry point index.d.ts - // - // @internal getMemoryInternals?: typeof getApolloClientMemoryInternals; getObservableQueries(include?: RefetchQueriesInclude): Map>; getResolvers(): Resolvers; diff --git a/.api-reports/api-report-react.md b/.api-reports/api-report-react.md index c6de1672ff0..14db26ad941 100644 --- a/.api-reports/api-report-react.md +++ b/.api-reports/api-report-react.md @@ -120,8 +120,6 @@ class ApolloClient implements DataProxy { get documentTransform(): DocumentTransform; extract(optimistic?: boolean): TCacheShape; // Warning: (ae-forgotten-export) The symbol "getApolloClientMemoryInternals" needs to be exported by the entry point index.d.ts - // - // @internal 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>; diff --git a/.api-reports/api-report-react_components.md b/.api-reports/api-report-react_components.md index 0775e0c9cbb..fed0f1ea60b 100644 --- a/.api-reports/api-report-react_components.md +++ b/.api-reports/api-report-react_components.md @@ -120,8 +120,6 @@ class ApolloClient implements DataProxy { get documentTransform(): DocumentTransform; extract(optimistic?: boolean): TCacheShape; // Warning: (ae-forgotten-export) The symbol "getApolloClientMemoryInternals" needs to be exported by the entry point index.d.ts - // - // @internal 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>; diff --git a/.api-reports/api-report-react_context.md b/.api-reports/api-report-react_context.md index c93ef634c07..01f8cfa71d1 100644 --- a/.api-reports/api-report-react_context.md +++ b/.api-reports/api-report-react_context.md @@ -119,8 +119,6 @@ class ApolloClient implements DataProxy { get documentTransform(): DocumentTransform; extract(optimistic?: boolean): TCacheShape; // Warning: (ae-forgotten-export) The symbol "getApolloClientMemoryInternals" needs to be exported by the entry point index.d.ts - // - // @internal 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>; diff --git a/.api-reports/api-report-react_hoc.md b/.api-reports/api-report-react_hoc.md index ca318274946..044cb10cc77 100644 --- a/.api-reports/api-report-react_hoc.md +++ b/.api-reports/api-report-react_hoc.md @@ -119,8 +119,6 @@ class ApolloClient implements DataProxy { get documentTransform(): DocumentTransform; extract(optimistic?: boolean): TCacheShape; // Warning: (ae-forgotten-export) The symbol "getApolloClientMemoryInternals" needs to be exported by the entry point index.d.ts - // - // @internal 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>; diff --git a/.api-reports/api-report-react_hooks.md b/.api-reports/api-report-react_hooks.md index f6d137505ce..3296d232fd0 100644 --- a/.api-reports/api-report-react_hooks.md +++ b/.api-reports/api-report-react_hooks.md @@ -118,8 +118,6 @@ class ApolloClient implements DataProxy { get documentTransform(): DocumentTransform; extract(optimistic?: boolean): TCacheShape; // Warning: (ae-forgotten-export) The symbol "getApolloClientMemoryInternals" needs to be exported by the entry point index.d.ts - // - // @internal 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>; diff --git a/.api-reports/api-report-react_internal.md b/.api-reports/api-report-react_internal.md index 6eab8934062..a54ec58ee63 100644 --- a/.api-reports/api-report-react_internal.md +++ b/.api-reports/api-report-react_internal.md @@ -118,8 +118,6 @@ class ApolloClient implements DataProxy { get documentTransform(): DocumentTransform; extract(optimistic?: boolean): TCacheShape; // Warning: (ae-forgotten-export) The symbol "getApolloClientMemoryInternals" needs to be exported by the entry point index.d.ts - // - // @internal 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>; diff --git a/.api-reports/api-report-react_ssr.md b/.api-reports/api-report-react_ssr.md index 060eb9c79e6..8f22892c265 100644 --- a/.api-reports/api-report-react_ssr.md +++ b/.api-reports/api-report-react_ssr.md @@ -119,8 +119,6 @@ class ApolloClient implements DataProxy { get documentTransform(): DocumentTransform; extract(optimistic?: boolean): TCacheShape; // Warning: (ae-forgotten-export) The symbol "getApolloClientMemoryInternals" needs to be exported by the entry point index.d.ts - // - // @internal 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>; diff --git a/.api-reports/api-report-testing.md b/.api-reports/api-report-testing.md index 57c3dc01694..54327b058c4 100644 --- a/.api-reports/api-report-testing.md +++ b/.api-reports/api-report-testing.md @@ -119,8 +119,6 @@ class ApolloClient implements DataProxy { get documentTransform(): DocumentTransform; extract(optimistic?: boolean): TCacheShape; // Warning: (ae-forgotten-export) The symbol "getApolloClientMemoryInternals" needs to be exported by the entry point index.d.ts - // - // @internal 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>; diff --git a/.api-reports/api-report-testing_core.md b/.api-reports/api-report-testing_core.md index 341da7c1d35..1b505f4d121 100644 --- a/.api-reports/api-report-testing_core.md +++ b/.api-reports/api-report-testing_core.md @@ -118,8 +118,6 @@ class ApolloClient implements DataProxy { get documentTransform(): DocumentTransform; extract(optimistic?: boolean): TCacheShape; // Warning: (ae-forgotten-export) The symbol "getApolloClientMemoryInternals" needs to be exported by the entry point index.d.ts - // - // @internal 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>; diff --git a/.api-reports/api-report-utilities.md b/.api-reports/api-report-utilities.md index 1478b419cec..8028dbdf360 100644 --- a/.api-reports/api-report-utilities.md +++ b/.api-reports/api-report-utilities.md @@ -131,8 +131,6 @@ class ApolloClient implements DataProxy { get documentTransform(): DocumentTransform; extract(optimistic?: boolean): TCacheShape; // Warning: (ae-forgotten-export) The symbol "getApolloClientMemoryInternals" needs to be exported by the entry point index.d.ts - // - // @internal 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>; diff --git a/.api-reports/api-report.md b/.api-reports/api-report.md index 9057e4f8f2a..627586c9bd9 100644 --- a/.api-reports/api-report.md +++ b/.api-reports/api-report.md @@ -111,8 +111,6 @@ export class ApolloClient implements DataProxy { get documentTransform(): DocumentTransform; extract(optimistic?: boolean): TCacheShape; // Warning: (ae-forgotten-export) The symbol "getApolloClientMemoryInternals" needs to be exported by the entry point index.d.ts - // - // @internal getMemoryInternals?: typeof getApolloClientMemoryInternals; getObservableQueries(include?: RefetchQueriesInclude): Map>; getResolvers(): Resolvers;