From b182a7822c2f95da7c392052bc61ec028f2bbcc4 Mon Sep 17 00:00:00 2001 From: Jerel Miller Date: Wed, 25 Jun 2025 18:29:05 -0600 Subject: [PATCH 01/43] Use doc ref for remaining canonizeResults option --- src/cache/core/types/Cache.ts | 8 +------- src/cache/inmemory/readFromStore.ts | 2 ++ src/cache/inmemory/types.ts | 7 +------ 3 files changed, 4 insertions(+), 13 deletions(-) diff --git a/src/cache/core/types/Cache.ts b/src/cache/core/types/Cache.ts index 58916943212..2c1da782292 100644 --- a/src/cache/core/types/Cache.ts +++ b/src/cache/core/types/Cache.ts @@ -15,13 +15,7 @@ export namespace Cache { previousResult?: any; optimistic: boolean; returnPartialData?: boolean; - /** - * @deprecated - * Using `canonizeResults` can result in memory leaks so we generally do not - * recommend using this option anymore. - * A future version of Apollo Client will contain a similar feature without - * the risk of memory leaks. - */ + /** {@inheritDoc @apollo/client!QueryOptionsDocumentation#canonizeResults:member} */ canonizeResults?: boolean; } diff --git a/src/cache/inmemory/readFromStore.ts b/src/cache/inmemory/readFromStore.ts index d89876d85c9..0d00ec9bb3e 100644 --- a/src/cache/inmemory/readFromStore.ts +++ b/src/cache/inmemory/readFromStore.ts @@ -60,6 +60,7 @@ export type VariableMap = { [name: string]: any }; interface ReadContext extends ReadMergeModifyContext { query: DocumentNode; policies: Policies; + /** {@inheritDoc @apollo/client!QueryOptionsDocumentation#canonizeResults:member} */ canonizeResults: boolean; fragmentMap: FragmentMap; lookupFragment: FragmentMapFunction; @@ -88,6 +89,7 @@ export interface StoreReaderConfig { cache: InMemoryCache; addTypename?: boolean; resultCacheMaxSize?: number; + /** {@inheritDoc @apollo/client!QueryOptionsDocumentation#canonizeResults:member} */ canonizeResults?: boolean; canon?: ObjectCanon; fragments?: InMemoryCacheConfig["fragments"]; diff --git a/src/cache/inmemory/types.ts b/src/cache/inmemory/types.ts index 10678ce5ad7..fc049472824 100644 --- a/src/cache/inmemory/types.ts +++ b/src/cache/inmemory/types.ts @@ -149,12 +149,7 @@ export interface InMemoryCacheConfig extends ApolloReducerConfig { * Please use `cacheSizes` instead. */ resultCacheMaxSize?: number; - /** - * @deprecated - * Using `canonizeResults` can result in memory leaks so we generally do not - * recommend using this option anymore. - * A future version of Apollo Client will contain a similar feature. - */ + /** {@inheritDoc @apollo/client!QueryOptionsDocumentation#canonizeResults:member} */ canonizeResults?: boolean; fragments?: FragmentRegistryAPI; } From b33a5ab251ab959a34baca371815ba9fba57319f Mon Sep 17 00:00:00 2001 From: Jerel Miller Date: Wed, 25 Jun 2025 18:29:25 -0600 Subject: [PATCH 02/43] Update description of canonizeResults --- src/react/types/types.documentation.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/react/types/types.documentation.ts b/src/react/types/types.documentation.ts index f04aa9f1c9e..8fef82577d6 100644 --- a/src/react/types/types.documentation.ts +++ b/src/react/types/types.documentation.ts @@ -123,9 +123,8 @@ export interface QueryOptionsDocumentation { * * @deprecated * Using `canonizeResults` can result in memory leaks so we generally do not - * recommend using this option anymore. - * A future version of Apollo Client will contain a similar feature without - * the risk of memory leaks. + * recommend using this option. `canonizeResults` will be removed in + * Apollo Client 4.0. */ canonizeResults: unknown; From 9921db603b702d16607a8027e9365f8742bacf9b Mon Sep 17 00:00:00 2001 From: Jerel Miller Date: Wed, 25 Jun 2025 18:34:23 -0600 Subject: [PATCH 03/43] Don't use defaultProps and instead use default value --- src/testing/react/MockedProvider.tsx | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/testing/react/MockedProvider.tsx b/src/testing/react/MockedProvider.tsx index 86d4e921821..0c41e383efd 100644 --- a/src/testing/react/MockedProvider.tsx +++ b/src/testing/react/MockedProvider.tsx @@ -54,16 +54,12 @@ export class MockedProvider extends React.Component< MockedProviderProps, MockedProviderState > { - public static defaultProps: MockedProviderProps = { - addTypename: true, - }; - constructor(props: MockedProviderProps) { super(props); const { mocks, - addTypename, + addTypename = true, defaultOptions, cache, resolvers, From 63fb929eacf7a759a7780c8d9abacb3059a32b0f Mon Sep 17 00:00:00 2001 From: Jerel Miller Date: Wed, 25 Jun 2025 18:36:14 -0600 Subject: [PATCH 04/43] Deprecate addTypename --- src/cache/inmemory/types.ts | 10 ++++++++++ src/testing/react/MockedProvider.tsx | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/cache/inmemory/types.ts b/src/cache/inmemory/types.ts index fc049472824..7656d7e858b 100644 --- a/src/cache/inmemory/types.ts +++ b/src/cache/inmemory/types.ts @@ -137,6 +137,16 @@ export type DiffQueryAgainstStoreOptions = ReadQueryOptions & { export type ApolloReducerConfig = { dataIdFromObject?: KeyFieldsFunction; + /** + * @defaultValue true + * + * @deprecated `addTypename` will be removed in Apollo Client 4.0. + * + * **Recommended now** + * + * Please set `addTypename` to `true` or remove the option entirely to use the + * default. + */ addTypename?: boolean; }; diff --git a/src/testing/react/MockedProvider.tsx b/src/testing/react/MockedProvider.tsx index 0c41e383efd..502bdf7515a 100644 --- a/src/testing/react/MockedProvider.tsx +++ b/src/testing/react/MockedProvider.tsx @@ -14,6 +14,16 @@ import { invariant } from "../../utilities/globals/index.js"; export interface MockedProviderProps { mocks?: ReadonlyArray>; + /** + * @deprecated `addTypename` will be removed in Apollo Client 4.0. + * + * **Recommended now** + * + * Please set `addTypename` to `true` or remove the prop entirely to use the + * default. It is recommended to add `__typename` to your mock objects if it is + * not already defined. This ensures the cache more closely resembles the + * production environment. + */ addTypename?: boolean; defaultOptions?: DefaultOptions; cache?: ApolloCache; From a44b73a29d22609718b914c1b7eab838c712508b Mon Sep 17 00:00:00 2001 From: Jerel Miller Date: Wed, 25 Jun 2025 18:45:16 -0600 Subject: [PATCH 05/43] Add warings for addTypename --- src/cache/inmemory/inMemoryCache.ts | 9 +++++++++ src/testing/react/MockedProvider.tsx | 16 ++++++++++++---- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/cache/inmemory/inMemoryCache.ts b/src/cache/inmemory/inMemoryCache.ts index faec01efeac..3f135ea134c 100644 --- a/src/cache/inmemory/inMemoryCache.ts +++ b/src/cache/inmemory/inMemoryCache.ts @@ -71,6 +71,15 @@ export class InMemoryCache extends ApolloCache { constructor(config: InMemoryCacheConfig = {}) { super(); + + if (__DEV__) { + if ("addTypename" in config) { + invariant.warn( + "`addTypename` is deprecated and will be removed in Apollo Client 4.0. Please remove the `addTypename` option." + ); + } + } + this.config = normalizeConfig(config); this.addTypename = !!this.config.addTypename; diff --git a/src/testing/react/MockedProvider.tsx b/src/testing/react/MockedProvider.tsx index 502bdf7515a..9c7b4afead9 100644 --- a/src/testing/react/MockedProvider.tsx +++ b/src/testing/react/MockedProvider.tsx @@ -79,10 +79,18 @@ export class MockedProvider extends React.Component< connectToDevTools = false, } = this.props; if (__DEV__) { - if ("connectToDevTools" in this.props) { - invariant.warn( - "`connectToDevTools` is deprecated and will be removed in Apollo Client 4.0. Please use `devtools.enabled` instead." - ); + if (showWarnings) { + if ("connectToDevTools" in this.props) { + invariant.warn( + "`connectToDevTools` is deprecated and will be removed in Apollo Client 4.0. Please use `devtools.enabled` instead." + ); + } + + if ("addTypename" in this.props) { + invariant.warn( + "`addTypename` is deprecated and will be removed in Apollo Client 4.0. Please remove the `addTypename` prop." + ); + } } } From 04c43414df4da6c923f730730d2e2de13d3f3c55 Mon Sep 17 00:00:00 2001 From: Jerel Miller Date: Wed, 25 Jun 2025 18:48:25 -0600 Subject: [PATCH 06/43] Add warning for canonizeResults --- src/cache/inmemory/inMemoryCache.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/cache/inmemory/inMemoryCache.ts b/src/cache/inmemory/inMemoryCache.ts index 3f135ea134c..a2e9378acee 100644 --- a/src/cache/inmemory/inMemoryCache.ts +++ b/src/cache/inmemory/inMemoryCache.ts @@ -34,6 +34,7 @@ import { Policies } from "./policies.js"; import { hasOwn, normalizeConfig, shouldCanonizeResults } from "./helpers.js"; import type { OperationVariables } from "../../core/index.js"; import { getInMemoryCacheMemoryInternals } from "../../utilities/caching/getMemoryInternals.js"; +import { __esDecorate } from "tslib"; type BroadcastOptions = Pick< Cache.BatchOptions, @@ -78,6 +79,12 @@ export class InMemoryCache extends ApolloCache { "`addTypename` is deprecated and will be removed in Apollo Client 4.0. Please remove the `addTypename` option." ); } + + if ("canonizeResults" in config) { + invariant.warn( + "`canonizeResults` is deprecated and will be removed in Apollo Client 4.0. Please remove the `canonizeResults` option." + ); + } } this.config = normalizeConfig(config); @@ -191,6 +198,14 @@ export class InMemoryCache extends ApolloCache { } public read(options: Cache.ReadOptions): T | null { + if (__DEV__) { + if ("canonizeResults" in options) { + invariant.warn( + "`canonizeResults` is deprecated and will be removed in Apollo Client 4.0. Please remove this option." + ); + } + } + const { // Since read returns data or null, without any additional metadata // about whether/where there might have been missing fields, the From 4b66d773d9f62ca9df24c5d1d97809aa84d70a12 Mon Sep 17 00:00:00 2001 From: Jerel Miller Date: Thu, 26 Jun 2025 14:38:02 -0600 Subject: [PATCH 07/43] Add prefixes to warnings in constructor --- src/cache/inmemory/inMemoryCache.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cache/inmemory/inMemoryCache.ts b/src/cache/inmemory/inMemoryCache.ts index a2e9378acee..71145d7e49d 100644 --- a/src/cache/inmemory/inMemoryCache.ts +++ b/src/cache/inmemory/inMemoryCache.ts @@ -76,13 +76,13 @@ export class InMemoryCache extends ApolloCache { if (__DEV__) { if ("addTypename" in config) { invariant.warn( - "`addTypename` is deprecated and will be removed in Apollo Client 4.0. Please remove the `addTypename` option." + "[InMemoryCache]: `addTypename` is deprecated and will be removed in Apollo Client 4.0. Please remove the `addTypename` option when instantiating `InMemoryCache`." ); } if ("canonizeResults" in config) { invariant.warn( - "`canonizeResults` is deprecated and will be removed in Apollo Client 4.0. Please remove the `canonizeResults` option." + "[InMemoryCache]: `canonizeResults` is deprecated and will be removed in Apollo Client 4.0. Please remove the `canonizeResults` option when instantiating `InMemoryCache`." ); } } From adbb61a95d75deb71f6fdd73cb210e9bfc14f26f Mon Sep 17 00:00:00 2001 From: Jerel Miller Date: Thu, 26 Jun 2025 14:38:19 -0600 Subject: [PATCH 08/43] Track issued warnings and prefix with API --- src/cache/core/cache.ts | 53 +++++++++++++++++++++++++++++ src/cache/inmemory/inMemoryCache.ts | 15 ++++++-- 2 files changed, 66 insertions(+), 2 deletions(-) diff --git a/src/cache/core/cache.ts b/src/cache/core/cache.ts index 8f443cbc319..1eca7d26b31 100644 --- a/src/cache/core/cache.ts +++ b/src/cache/core/cache.ts @@ -102,6 +102,10 @@ export type WatchFragmentResult = export abstract class ApolloCache implements DataProxy { public readonly assumeImmutableResults: boolean = false; + // Remove with Apollo Client 4.0. Used to track which deprecation warnings + // we've issued to prevent them from showing up multiple times. + protected deprecationWarnings: Record = {}; + // required to implement // core API public abstract read( @@ -239,6 +243,16 @@ export abstract class ApolloCache implements DataProxy { options: Cache.ReadQueryOptions, optimistic = !!options.optimistic ): Unmasked | null { + if (__DEV__) { + if ("canonizeResults" in options && !this.deprecationWarnings.readQuery) { + invariant.warn( + "[cache.readQuery]: `canonizeResults` is deprecated and will be removed in Apollo Client 4.0. Please remove this option." + ); + } + + this.deprecationWarnings.readQuery = true; + } + return this.read({ ...options, rootId: options.id || "ROOT_QUERY", @@ -348,6 +362,19 @@ export abstract class ApolloCache implements DataProxy { options: Cache.ReadFragmentOptions, optimistic = !!options.optimistic ): Unmasked | null { + if (__DEV__) { + if ( + "canonizeResults" in options && + !this.deprecationWarnings.readFragment + ) { + invariant.warn( + "[cache.readFragment]: `canonizeResults` is deprecated and will be removed in Apollo Client 4.0. Please remove this option." + ); + } + + this.deprecationWarnings.readFragment = true; + } + return this.read({ ...options, query: this.getFragmentDoc(options.fragment, options.fragmentName), @@ -389,6 +416,19 @@ export abstract class ApolloCache implements DataProxy { options: Cache.UpdateQueryOptions, update: (data: Unmasked | null) => Unmasked | null | void ): Unmasked | null { + if (__DEV__) { + if ( + "canonizeResults" in options && + !this.deprecationWarnings.updateQuery + ) { + invariant.warn( + "[cache.updateQuery]: `canonizeResults` is deprecated and will be removed in Apollo Client 4.0. Please remove this option." + ); + + this.deprecationWarnings.updateQuery = true; + } + } + return this.batch({ update(cache) { const value = cache.readQuery(options); @@ -404,6 +444,19 @@ export abstract class ApolloCache implements DataProxy { options: Cache.UpdateFragmentOptions, update: (data: Unmasked | null) => Unmasked | null | void ): Unmasked | null { + if (__DEV__) { + if ( + "canonizeResults" in options && + !this.deprecationWarnings.updateFragment + ) { + invariant.warn( + "[cache.updateFragment]: `canonizeResults` is deprecated and will be removed in Apollo Client 4.0. Please remove this option." + ); + + this.deprecationWarnings.updateFragment = true; + } + } + return this.batch({ update(cache) { const value = cache.readFragment(options); diff --git a/src/cache/inmemory/inMemoryCache.ts b/src/cache/inmemory/inMemoryCache.ts index 71145d7e49d..3410344711a 100644 --- a/src/cache/inmemory/inMemoryCache.ts +++ b/src/cache/inmemory/inMemoryCache.ts @@ -199,10 +199,11 @@ export class InMemoryCache extends ApolloCache { public read(options: Cache.ReadOptions): T | null { if (__DEV__) { - if ("canonizeResults" in options) { + if ("canonizeResults" in options && !this.deprecationWarnings.read) { invariant.warn( - "`canonizeResults` is deprecated and will be removed in Apollo Client 4.0. Please remove this option." + "[cache.read] `canonizeResults` is deprecated and will be removed in Apollo Client 4.0. Please remove this option." ); + this.deprecationWarnings.read = true; } } @@ -283,6 +284,16 @@ export class InMemoryCache extends ApolloCache { public diff( options: Cache.DiffOptions ): Cache.DiffResult { + if (__DEV__) { + if ("canonizeResults" in options && !this.deprecationWarnings.diff) { + invariant.warn( + "[cache.diff]: `canonizeResults` is deprecated and will be removed in Apollo Client 4.0. Please remove this option." + ); + } + + this.deprecationWarnings.diff = true; + } + return this.storeReader.diffQueryAgainstStore({ ...options, store: options.optimistic ? this.optimisticData : this.data, From 6929890187e4f28c0de7f124b10fda376c334a30 Mon Sep 17 00:00:00 2001 From: Jerel Miller Date: Thu, 26 Jun 2025 14:57:24 -0600 Subject: [PATCH 09/43] Prefix warning in MockedProvider. Add additional detail --- src/testing/react/MockedProvider.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/testing/react/MockedProvider.tsx b/src/testing/react/MockedProvider.tsx index 9c7b4afead9..a80322b6570 100644 --- a/src/testing/react/MockedProvider.tsx +++ b/src/testing/react/MockedProvider.tsx @@ -82,13 +82,13 @@ export class MockedProvider extends React.Component< if (showWarnings) { if ("connectToDevTools" in this.props) { invariant.warn( - "`connectToDevTools` is deprecated and will be removed in Apollo Client 4.0. Please use `devtools.enabled` instead." + "[MockedProvider]: `connectToDevTools` is deprecated and will be removed in Apollo Client 4.0. Please use `devtools.enabled` instead." ); } if ("addTypename" in this.props) { invariant.warn( - "`addTypename` is deprecated and will be removed in Apollo Client 4.0. Please remove the `addTypename` prop." + "[MockedProvider]: `addTypename` is deprecated and will be removed in Apollo Client 4.0. Please remove the `addTypename` prop. For best results, ensure the provided `mocks` return a `__typename` for all objects to ensure the cache behaves the same as the runtime app." ); } } From ca039009ddcdfa80c9feba74772e91f0bed04d26 Mon Sep 17 00:00:00 2001 From: Jerel Miller Date: Thu, 26 Jun 2025 15:24:40 -0600 Subject: [PATCH 10/43] Add tools to silence warnings deeper in call --- src/utilities/deprecation/index.ts | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/utilities/deprecation/index.ts diff --git a/src/utilities/deprecation/index.ts b/src/utilities/deprecation/index.ts new file mode 100644 index 00000000000..e3d92ef11fb --- /dev/null +++ b/src/utilities/deprecation/index.ts @@ -0,0 +1,30 @@ +import { Slot } from "optimism"; + +const slot = new Slot(); + +type WithValueArgs = [ + callback: (this: TThis, ...args: TArgs) => TResult, + args?: TArgs | undefined, + thisArg?: TThis | undefined, +]; + +export function silenceDeprecations( + name: string | string[], + ...args: WithValueArgs +) { + const keys = Array.isArray(name) ? name : [name]; + + return slot.withValue(keys, ...args); +} + +export function warnRemovedOption>( + options: TOptions, + name: keyof TOptions, + cb: () => void +) { + const silenced = (slot.getValue() || []).includes(name as string); + + if (name in options && !silenced) { + cb(); + } +} From 308d8607ab7bf70102ef2ce77a9ee1735e4bc5ef Mon Sep 17 00:00:00 2001 From: Jerel Miller Date: Thu, 26 Jun 2025 15:27:37 -0600 Subject: [PATCH 11/43] Use dep tools in MockedProvider --- src/testing/react/MockedProvider.tsx | 35 +++++++++++++++++----------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/src/testing/react/MockedProvider.tsx b/src/testing/react/MockedProvider.tsx index a80322b6570..294f79ecf99 100644 --- a/src/testing/react/MockedProvider.tsx +++ b/src/testing/react/MockedProvider.tsx @@ -11,6 +11,10 @@ import type { Resolvers } from "../../core/index.js"; import type { ApolloCache } from "../../cache/index.js"; import type { DevtoolsOptions } from "../../core/ApolloClient.js"; import { invariant } from "../../utilities/globals/index.js"; +import { + warnRemovedOption, + silenceDeprecations, +} from "../../utilities/deprecation/index.js"; export interface MockedProviderProps { mocks?: ReadonlyArray>; @@ -80,29 +84,34 @@ export class MockedProvider extends React.Component< } = this.props; if (__DEV__) { if (showWarnings) { - if ("connectToDevTools" in this.props) { + warnRemovedOption(this.props, "connectToDevTools", () => { invariant.warn( "[MockedProvider]: `connectToDevTools` is deprecated and will be removed in Apollo Client 4.0. Please use `devtools.enabled` instead." ); - } + }); - if ("addTypename" in this.props) { + warnRemovedOption(this.props, "addTypename", () => { invariant.warn( "[MockedProvider]: `addTypename` is deprecated and will be removed in Apollo Client 4.0. Please remove the `addTypename` prop. For best results, ensure the provided `mocks` return a `__typename` for all objects to ensure the cache behaves the same as the runtime app." ); - } + }); } } - const client = new ApolloClient({ - cache: cache || new Cache({ addTypename }), - defaultOptions, - devtools: devtools ?? { - enabled: connectToDevTools, - }, - link: link || new MockLink(mocks || [], addTypename, { showWarnings }), - resolvers, - }); + const client = silenceDeprecations( + ["connectToDevTools", "addTypename"], + () => + new ApolloClient({ + cache: cache || new Cache({ addTypename }), + defaultOptions, + devtools: devtools ?? { + enabled: connectToDevTools, + }, + link: + link || new MockLink(mocks || [], addTypename, { showWarnings }), + resolvers, + }) + ); this.state = { client, From c9c8e859b21205a25c4254e2d1c7ce8c80ff66ee Mon Sep 17 00:00:00 2001 From: Jerel Miller Date: Thu, 26 Jun 2025 15:32:24 -0600 Subject: [PATCH 12/43] Show warnings regardless of showWarnings prop --- src/testing/react/MockedProvider.tsx | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/testing/react/MockedProvider.tsx b/src/testing/react/MockedProvider.tsx index 294f79ecf99..c6df9d25cd6 100644 --- a/src/testing/react/MockedProvider.tsx +++ b/src/testing/react/MockedProvider.tsx @@ -83,19 +83,17 @@ export class MockedProvider extends React.Component< connectToDevTools = false, } = this.props; if (__DEV__) { - if (showWarnings) { - warnRemovedOption(this.props, "connectToDevTools", () => { - invariant.warn( - "[MockedProvider]: `connectToDevTools` is deprecated and will be removed in Apollo Client 4.0. Please use `devtools.enabled` instead." - ); - }); + warnRemovedOption(this.props, "connectToDevTools", () => { + invariant.warn( + "[MockedProvider]: `connectToDevTools` is deprecated and will be removed in Apollo Client 4.0. Please use `devtools.enabled` instead." + ); + }); - warnRemovedOption(this.props, "addTypename", () => { - invariant.warn( - "[MockedProvider]: `addTypename` is deprecated and will be removed in Apollo Client 4.0. Please remove the `addTypename` prop. For best results, ensure the provided `mocks` return a `__typename` for all objects to ensure the cache behaves the same as the runtime app." - ); - }); - } + warnRemovedOption(this.props, "addTypename", () => { + invariant.warn( + "[MockedProvider]: `addTypename` is deprecated and will be removed in Apollo Client 4.0. Please remove the `addTypename` prop. For best results, ensure the provided `mocks` return a `__typename` for all objects to ensure the cache behaves the same as the runtime app." + ); + }); } const client = silenceDeprecations( From 8d41215cd5de60b1bffae95e148f606f0cb70b40 Mon Sep 17 00:00:00 2001 From: Jerel Miller Date: Thu, 26 Jun 2025 15:34:14 -0600 Subject: [PATCH 13/43] Tweak error message --- src/testing/react/MockedProvider.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/testing/react/MockedProvider.tsx b/src/testing/react/MockedProvider.tsx index c6df9d25cd6..5a1828fa7af 100644 --- a/src/testing/react/MockedProvider.tsx +++ b/src/testing/react/MockedProvider.tsx @@ -91,7 +91,7 @@ export class MockedProvider extends React.Component< warnRemovedOption(this.props, "addTypename", () => { invariant.warn( - "[MockedProvider]: `addTypename` is deprecated and will be removed in Apollo Client 4.0. Please remove the `addTypename` prop. For best results, ensure the provided `mocks` return a `__typename` for all objects to ensure the cache behaves the same as the runtime app." + "[MockedProvider]: `addTypename` is deprecated and will be removed in Apollo Client 4.0. Please remove the `addTypename` prop. For best results, ensure the provided `mocks` include a `__typename` property on all mock objects to ensure the cache more closely behaves like production." ); }); } From 1dcf26a1dfe7e3bbcee52c6d94664eace11bc28b Mon Sep 17 00:00:00 2001 From: Jerel Miller Date: Thu, 26 Jun 2025 15:36:31 -0600 Subject: [PATCH 14/43] Use helper to warn in InMemoryCache initialization --- src/cache/inmemory/inMemoryCache.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/cache/inmemory/inMemoryCache.ts b/src/cache/inmemory/inMemoryCache.ts index 3410344711a..078c29cea3b 100644 --- a/src/cache/inmemory/inMemoryCache.ts +++ b/src/cache/inmemory/inMemoryCache.ts @@ -35,6 +35,7 @@ import { hasOwn, normalizeConfig, shouldCanonizeResults } from "./helpers.js"; import type { OperationVariables } from "../../core/index.js"; import { getInMemoryCacheMemoryInternals } from "../../utilities/caching/getMemoryInternals.js"; import { __esDecorate } from "tslib"; +import { warnRemovedOption } from "../../utilities/deprecation/index.js"; type BroadcastOptions = Pick< Cache.BatchOptions, @@ -74,17 +75,16 @@ export class InMemoryCache extends ApolloCache { super(); if (__DEV__) { - if ("addTypename" in config) { + warnRemovedOption(config, "addTypename", () => { invariant.warn( "[InMemoryCache]: `addTypename` is deprecated and will be removed in Apollo Client 4.0. Please remove the `addTypename` option when instantiating `InMemoryCache`." ); - } - - if ("canonizeResults" in config) { + }); + warnRemovedOption(config, "canonizeResults", () => { invariant.warn( "[InMemoryCache]: `canonizeResults` is deprecated and will be removed in Apollo Client 4.0. Please remove the `canonizeResults` option when instantiating `InMemoryCache`." ); - } + }); } this.config = normalizeConfig(config); From 8efb84e99087b1a366f74d39ff03c892be1d249e Mon Sep 17 00:00:00 2001 From: Jerel Miller Date: Thu, 26 Jun 2025 15:44:03 -0600 Subject: [PATCH 15/43] Use helper to warn for canonizeResults in inMemoryCache --- src/cache/inmemory/inMemoryCache.ts | 35 +++++++++++++++++------------ 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/src/cache/inmemory/inMemoryCache.ts b/src/cache/inmemory/inMemoryCache.ts index 078c29cea3b..a2561e3719b 100644 --- a/src/cache/inmemory/inMemoryCache.ts +++ b/src/cache/inmemory/inMemoryCache.ts @@ -35,7 +35,10 @@ import { hasOwn, normalizeConfig, shouldCanonizeResults } from "./helpers.js"; import type { OperationVariables } from "../../core/index.js"; import { getInMemoryCacheMemoryInternals } from "../../utilities/caching/getMemoryInternals.js"; import { __esDecorate } from "tslib"; -import { warnRemovedOption } from "../../utilities/deprecation/index.js"; +import { + silenceDeprecations, + warnRemovedOption, +} from "../../utilities/deprecation/index.js"; type BroadcastOptions = Pick< Cache.BatchOptions, @@ -199,12 +202,14 @@ export class InMemoryCache extends ApolloCache { public read(options: Cache.ReadOptions): T | null { if (__DEV__) { - if ("canonizeResults" in options && !this.deprecationWarnings.read) { - invariant.warn( - "[cache.read] `canonizeResults` is deprecated and will be removed in Apollo Client 4.0. Please remove this option." - ); - this.deprecationWarnings.read = true; - } + warnRemovedOption(options, "canonizeResults", () => { + if (!this.deprecationWarnings.read) { + invariant.warn( + "[cache.read] `canonizeResults` is deprecated and will be removed in Apollo Client 4.0. Please remove this option." + ); + this.deprecationWarnings.read = true; + } + }); } const { @@ -285,13 +290,15 @@ export class InMemoryCache extends ApolloCache { options: Cache.DiffOptions ): Cache.DiffResult { if (__DEV__) { - if ("canonizeResults" in options && !this.deprecationWarnings.diff) { - invariant.warn( - "[cache.diff]: `canonizeResults` is deprecated and will be removed in Apollo Client 4.0. Please remove this option." - ); - } - - this.deprecationWarnings.diff = true; + warnRemovedOption(options, "canonizeResults", () => { + if (!this.deprecationWarnings.diff) { + invariant.warn( + "[cache.diff]: `canonizeResults` is deprecated and will be removed in Apollo Client 4.0. Please remove this option." + ); + } + + this.deprecationWarnings.diff = true; + }); } return this.storeReader.diffQueryAgainstStore({ From 180040035edc80fd3d643fff09d6283d5c487eed Mon Sep 17 00:00:00 2001 From: Jerel Miller Date: Thu, 26 Jun 2025 15:44:29 -0600 Subject: [PATCH 16/43] Silence some calls to getDiff --- src/cache/inmemory/inMemoryCache.ts | 4 +++- src/core/QueryInfo.ts | 9 +++++++-- src/core/QueryManager.ts | 5 ++++- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/cache/inmemory/inMemoryCache.ts b/src/cache/inmemory/inMemoryCache.ts index a2561e3719b..6a1499fb632 100644 --- a/src/cache/inmemory/inMemoryCache.ts +++ b/src/cache/inmemory/inMemoryCache.ts @@ -619,7 +619,9 @@ export class InMemoryCache extends ApolloCache { // object, and without having to enumerate the relevant properties (query, // variables, etc.) explicitly. There will be some additional properties // (lastDiff, callback, etc.), but cache.diff ignores them. - const diff = this.diff(c); + const diff = silenceDeprecations("canonizeResults", () => + this.diff(c) + ); if (options) { if (c.optimistic && typeof options.optimistic === "string") { diff --git a/src/core/QueryInfo.ts b/src/core/QueryInfo.ts index 2a228eb8d13..e124a6f1677 100644 --- a/src/core/QueryInfo.ts +++ b/src/core/QueryInfo.ts @@ -16,6 +16,7 @@ import { NetworkStatus } from "./networkStatus.js"; import type { ApolloError } from "../errors/index.js"; import type { QueryManager } from "./QueryManager.js"; import type { Unmasked } from "../masking/index.js"; +import { silenceDeprecations } from "../utilities/deprecation/index.js"; export type QueryStoreValue = Pick< QueryInfo, @@ -160,7 +161,9 @@ export class QueryInfo { return { complete: false }; } - const diff = this.cache.diff(options); + const diff = silenceDeprecations("canonizeResults", () => + this.cache.diff(options) + ); this.updateLastDiff(diff, options); return diff; } @@ -394,7 +397,9 @@ export class QueryInfo { } const diffOptions = this.getDiffOptions(options.variables); - const diff = cache.diff(diffOptions); + const diff = silenceDeprecations("canonizeResults", () => + cache.diff(diffOptions) + ); // In case the QueryManager stops this QueryInfo before its // results are delivered, it's important to avoid restarting the diff --git a/src/core/QueryManager.ts b/src/core/QueryManager.ts index fbd58b36d5a..27eafb5e468 100644 --- a/src/core/QueryManager.ts +++ b/src/core/QueryManager.ts @@ -110,6 +110,7 @@ import { Trie } from "@wry/trie"; import { AutoCleanedWeakCache, cacheSizes } from "../utilities/index.js"; import { maskFragment, maskOperation } from "../masking/index.js"; import type { MaybeMasked, Unmasked } from "../masking/index.js"; +import { silenceDeprecations } from "../utilities/deprecation/index.js"; interface MaskFragmentOptions { fragment: DocumentNode; @@ -1545,7 +1546,9 @@ export class QueryManager { // queries, even the QueryOptions ones. if (onQueryUpdated) { if (!diff) { - diff = this.cache.diff(oq["queryInfo"]["getDiffOptions"]()); + diff = silenceDeprecations("canonizeResults", () => + this.cache.diff(oq["queryInfo"]["getDiffOptions"]()) + ); } result = onQueryUpdated(oq, diff, lastDiff); } From 5511fba898c639ace382b22a3234a00da16abb93 Mon Sep 17 00:00:00 2001 From: Jerel Miller Date: Thu, 26 Jun 2025 15:47:04 -0600 Subject: [PATCH 17/43] Use helper in readQuery --- src/cache/core/cache.ts | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/src/cache/core/cache.ts b/src/cache/core/cache.ts index 1eca7d26b31..d5679d69836 100644 --- a/src/cache/core/cache.ts +++ b/src/cache/core/cache.ts @@ -36,6 +36,10 @@ import type { MaybeMasked, Unmasked, } from "../../masking/index.js"; +import { + silenceDeprecations, + warnRemovedOption, +} from "../../utilities/deprecation/index.js"; export type Transaction = (c: ApolloCache) => void; @@ -244,20 +248,24 @@ export abstract class ApolloCache implements DataProxy { optimistic = !!options.optimistic ): Unmasked | null { if (__DEV__) { - if ("canonizeResults" in options && !this.deprecationWarnings.readQuery) { - invariant.warn( - "[cache.readQuery]: `canonizeResults` is deprecated and will be removed in Apollo Client 4.0. Please remove this option." - ); - } - - this.deprecationWarnings.readQuery = true; + warnRemovedOption(options, "canonizeResults", () => { + if (!this.deprecationWarnings.readQuery) { + invariant.warn( + "[cache.readQuery]: `canonizeResults` is deprecated and will be removed in Apollo Client 4.0. Please remove this option." + ); + } + + this.deprecationWarnings.readQuery = true; + }); } - return this.read({ - ...options, - rootId: options.id || "ROOT_QUERY", - optimistic, - }); + return silenceDeprecations("canonizeResults", () => + this.read({ + ...options, + rootId: options.id || "ROOT_QUERY", + optimistic, + }) + ); } /** {@inheritDoc @apollo/client!ApolloClient#watchFragment:member(1)} */ From fd1144a1837ac2090442bb3df72c17f0bd971cf8 Mon Sep 17 00:00:00 2001 From: Jerel Miller Date: Thu, 26 Jun 2025 15:48:21 -0600 Subject: [PATCH 18/43] Use helpers in readFragment --- src/cache/core/cache.ts | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/src/cache/core/cache.ts b/src/cache/core/cache.ts index d5679d69836..025e01594a2 100644 --- a/src/cache/core/cache.ts +++ b/src/cache/core/cache.ts @@ -371,24 +371,25 @@ export abstract class ApolloCache implements DataProxy { optimistic = !!options.optimistic ): Unmasked | null { if (__DEV__) { - if ( - "canonizeResults" in options && - !this.deprecationWarnings.readFragment - ) { - invariant.warn( - "[cache.readFragment]: `canonizeResults` is deprecated and will be removed in Apollo Client 4.0. Please remove this option." - ); - } + warnRemovedOption(options, "canonizeResults", () => { + if (!this.deprecationWarnings.readFragment) { + invariant.warn( + "[cache.readFragment]: `canonizeResults` is deprecated and will be removed in Apollo Client 4.0. Please remove this option." + ); + } - this.deprecationWarnings.readFragment = true; + this.deprecationWarnings.readFragment = true; + }); } - return this.read({ - ...options, - query: this.getFragmentDoc(options.fragment, options.fragmentName), - rootId: options.id, - optimistic, - }); + return silenceDeprecations("canonizeResults", () => + this.read({ + ...options, + query: this.getFragmentDoc(options.fragment, options.fragmentName), + rootId: options.id, + optimistic, + }) + ); } public writeQuery({ From 3cc6197453b7c9f66df48ed6fe66c6ddc6d465c6 Mon Sep 17 00:00:00 2001 From: Jerel Miller Date: Thu, 26 Jun 2025 15:51:14 -0600 Subject: [PATCH 19/43] Use helpers in readFragment/updateFragment --- src/cache/core/cache.ts | 42 +++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/src/cache/core/cache.ts b/src/cache/core/cache.ts index 025e01594a2..bb8b22de220 100644 --- a/src/cache/core/cache.ts +++ b/src/cache/core/cache.ts @@ -426,21 +426,22 @@ export abstract class ApolloCache implements DataProxy { update: (data: Unmasked | null) => Unmasked | null | void ): Unmasked | null { if (__DEV__) { - if ( - "canonizeResults" in options && - !this.deprecationWarnings.updateQuery - ) { - invariant.warn( - "[cache.updateQuery]: `canonizeResults` is deprecated and will be removed in Apollo Client 4.0. Please remove this option." - ); + warnRemovedOption(options, "canonizeResults", () => { + if (!this.deprecationWarnings.updateQuery) { + invariant.warn( + "[cache.updateQuery]: `canonizeResults` is deprecated and will be removed in Apollo Client 4.0. Please remove this option." + ); - this.deprecationWarnings.updateQuery = true; - } + this.deprecationWarnings.updateQuery = true; + } + }); } return this.batch({ update(cache) { - const value = cache.readQuery(options); + const value = silenceDeprecations("canonizeResults", () => + cache.readQuery(options) + ); const data = update(value); if (data === void 0 || data === null) return value; cache.writeQuery({ ...options, data }); @@ -454,21 +455,22 @@ export abstract class ApolloCache implements DataProxy { update: (data: Unmasked | null) => Unmasked | null | void ): Unmasked | null { if (__DEV__) { - if ( - "canonizeResults" in options && - !this.deprecationWarnings.updateFragment - ) { - invariant.warn( - "[cache.updateFragment]: `canonizeResults` is deprecated and will be removed in Apollo Client 4.0. Please remove this option." - ); + warnRemovedOption(options, "canonizeResults", () => { + if (!this.deprecationWarnings.updateFragment) { + invariant.warn( + "[cache.updateFragment]: `canonizeResults` is deprecated and will be removed in Apollo Client 4.0. Please remove this option." + ); - this.deprecationWarnings.updateFragment = true; - } + this.deprecationWarnings.updateFragment = true; + } + }); } return this.batch({ update(cache) { - const value = cache.readFragment(options); + const value = silenceDeprecations("canonizeResults", () => + cache.readFragment(options) + ); const data = update(value); if (data === void 0 || data === null) return value; cache.writeFragment({ ...options, data }); From b2a27628af55dfa1444d073ecfc73782b4b6434d Mon Sep 17 00:00:00 2001 From: Jerel Miller Date: Thu, 26 Jun 2025 15:52:55 -0600 Subject: [PATCH 20/43] Remove tracked usage --- src/cache/core/cache.ts | 44 ++++++++--------------------- src/cache/inmemory/inMemoryCache.ts | 19 ++++--------- src/core/ApolloClient.ts | 5 ++-- 3 files changed, 21 insertions(+), 47 deletions(-) diff --git a/src/cache/core/cache.ts b/src/cache/core/cache.ts index bb8b22de220..93a38b2316d 100644 --- a/src/cache/core/cache.ts +++ b/src/cache/core/cache.ts @@ -106,10 +106,6 @@ export type WatchFragmentResult = export abstract class ApolloCache implements DataProxy { public readonly assumeImmutableResults: boolean = false; - // Remove with Apollo Client 4.0. Used to track which deprecation warnings - // we've issued to prevent them from showing up multiple times. - protected deprecationWarnings: Record = {}; - // required to implement // core API public abstract read( @@ -249,13 +245,9 @@ export abstract class ApolloCache implements DataProxy { ): Unmasked | null { if (__DEV__) { warnRemovedOption(options, "canonizeResults", () => { - if (!this.deprecationWarnings.readQuery) { - invariant.warn( - "[cache.readQuery]: `canonizeResults` is deprecated and will be removed in Apollo Client 4.0. Please remove this option." - ); - } - - this.deprecationWarnings.readQuery = true; + invariant.warn( + "[cache.readQuery]: `canonizeResults` is deprecated and will be removed in Apollo Client 4.0. Please remove this option." + ); }); } @@ -372,13 +364,9 @@ export abstract class ApolloCache implements DataProxy { ): Unmasked | null { if (__DEV__) { warnRemovedOption(options, "canonizeResults", () => { - if (!this.deprecationWarnings.readFragment) { - invariant.warn( - "[cache.readFragment]: `canonizeResults` is deprecated and will be removed in Apollo Client 4.0. Please remove this option." - ); - } - - this.deprecationWarnings.readFragment = true; + invariant.warn( + "[cache.readFragment]: `canonizeResults` is deprecated and will be removed in Apollo Client 4.0. Please remove this option." + ); }); } @@ -427,13 +415,9 @@ export abstract class ApolloCache implements DataProxy { ): Unmasked | null { if (__DEV__) { warnRemovedOption(options, "canonizeResults", () => { - if (!this.deprecationWarnings.updateQuery) { - invariant.warn( - "[cache.updateQuery]: `canonizeResults` is deprecated and will be removed in Apollo Client 4.0. Please remove this option." - ); - - this.deprecationWarnings.updateQuery = true; - } + invariant.warn( + "[cache.updateQuery]: `canonizeResults` is deprecated and will be removed in Apollo Client 4.0. Please remove this option." + ); }); } @@ -456,13 +440,9 @@ export abstract class ApolloCache implements DataProxy { ): Unmasked | null { if (__DEV__) { warnRemovedOption(options, "canonizeResults", () => { - if (!this.deprecationWarnings.updateFragment) { - invariant.warn( - "[cache.updateFragment]: `canonizeResults` is deprecated and will be removed in Apollo Client 4.0. Please remove this option." - ); - - this.deprecationWarnings.updateFragment = true; - } + invariant.warn( + "[cache.updateFragment]: `canonizeResults` is deprecated and will be removed in Apollo Client 4.0. Please remove this option." + ); }); } diff --git a/src/cache/inmemory/inMemoryCache.ts b/src/cache/inmemory/inMemoryCache.ts index 6a1499fb632..6f029e96cf1 100644 --- a/src/cache/inmemory/inMemoryCache.ts +++ b/src/cache/inmemory/inMemoryCache.ts @@ -203,12 +203,9 @@ export class InMemoryCache extends ApolloCache { public read(options: Cache.ReadOptions): T | null { if (__DEV__) { warnRemovedOption(options, "canonizeResults", () => { - if (!this.deprecationWarnings.read) { - invariant.warn( - "[cache.read] `canonizeResults` is deprecated and will be removed in Apollo Client 4.0. Please remove this option." - ); - this.deprecationWarnings.read = true; - } + invariant.warn( + "[cache.read] `canonizeResults` is deprecated and will be removed in Apollo Client 4.0. Please remove this option." + ); }); } @@ -291,13 +288,9 @@ export class InMemoryCache extends ApolloCache { ): Cache.DiffResult { if (__DEV__) { warnRemovedOption(options, "canonizeResults", () => { - if (!this.deprecationWarnings.diff) { - invariant.warn( - "[cache.diff]: `canonizeResults` is deprecated and will be removed in Apollo Client 4.0. Please remove this option." - ); - } - - this.deprecationWarnings.diff = true; + invariant.warn( + "[cache.diff]: `canonizeResults` is deprecated and will be removed in Apollo Client 4.0. Please remove this option." + ); }); } diff --git a/src/core/ApolloClient.ts b/src/core/ApolloClient.ts index 792fad81296..3aa6b58a11e 100644 --- a/src/core/ApolloClient.ts +++ b/src/core/ApolloClient.ts @@ -292,6 +292,7 @@ import type { WatchFragmentResult, } from "../cache/core/cache.js"; import type { MaybeMasked, Unmasked } from "../masking/index.js"; +import { warnRemovedOption } from "../utilities/deprecation/index.js"; export { mergeOptions }; /** @@ -402,11 +403,11 @@ export class ApolloClient implements DataProxy { } = options; if (__DEV__) { - if ("connectToDevTools" in options) { + warnRemovedOption(options, "connectToDevTools", () => { invariant.warn( "`connectToDevTools` is deprecated and will be removed in Apollo Client 4.0. Please use `devtools.enabled` instead." ); - } + }); if (!options.link) { invariant.warn( From f9a1c29764e0c41fd238c9a63765c42d32af2a48 Mon Sep 17 00:00:00 2001 From: Jerel Miller Date: Thu, 26 Jun 2025 15:59:38 -0600 Subject: [PATCH 21/43] Use helpers. Add prefix to warning --- src/core/ApolloClient.ts | 46 +++++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/src/core/ApolloClient.ts b/src/core/ApolloClient.ts index 3aa6b58a11e..50710919518 100644 --- a/src/core/ApolloClient.ts +++ b/src/core/ApolloClient.ts @@ -405,35 +405,43 @@ export class ApolloClient implements DataProxy { if (__DEV__) { warnRemovedOption(options, "connectToDevTools", () => { invariant.warn( - "`connectToDevTools` is deprecated and will be removed in Apollo Client 4.0. Please use `devtools.enabled` instead." + "[ApolloClient]: `connectToDevTools` is deprecated and will be removed in Apollo Client 4.0. Please use `devtools.enabled` instead." ); }); - - if (!options.link) { + warnRemovedOption(options, "uri", () => { invariant.warn( - "Apollo Client 4.0 will require a `link` option and will not create a default link when not provided. Please provide a `link` option." + "[ApolloClient]: `uri` is deprecated and will be removed in Apollo Client 4.0. Please initialize an instance of `HttpLink` with `uri` instead." ); - } - - if ( - "uri" in options || - "credentials" in options || - "headers" in options - ) { + }); + warnRemovedOption(options, "credentials", () => { invariant.warn( - "Apollo Client 4.0 will no longer support the `uri`, `credentials` or `headers` options. Please instantiate an instance of `HttpLink` with these options instead." + "[ApolloClient]: `credentials` is deprecated and will be removed in Apollo Client 4.0. Please initialize an instance of `HttpLink` with `credentials` instead." ); - } - - if ("name" in options || "version" in options) { + }); + warnRemovedOption(options, "headers", () => { invariant.warn( - "Apollo Client 4.0 will no longer support the `name` or `version` options. To use client awareness features, please use the `clientAwareness.name` and `clientAwareness.version` options instead." + "[ApolloClient]: `headers` is deprecated and will be removed in Apollo Client 4.0. Please initialize an instance of `HttpLink` with `headers` instead." ); - } + }); + warnRemovedOption(options, "name", () => { + invariant.warn( + "[ApolloClient]: `name` is deprecated and will be removed in Apollo Client 4.0. Please use the `clientAwareness.name` option instead." + ); + }); + warnRemovedOption(options, "version", () => { + invariant.warn( + "[ApolloClient]: `version` is deprecated and will be removed in Apollo Client 4.0. Please use the `clientAwareness.version` option instead." + ); + }); + warnRemovedOption(options, "typeDefs", () => { + invariant.warn( + "[ApolloClient]: `typeDefs` is deprecated and will be removed in Apollo Client 4.0. Please remove this option." + ); + }); - if (typeDefs) { + if (!options.link) { invariant.warn( - "Apollo Client 4.0 will no longer support `typeDefs`. Please remove this option." + "[ApolloClient]: Apollo Client 4.0 will require a `link` option and will not create a default link when not provided. Please provide a `link` option." ); } } From 81daf1282a59706745d5bbe1110f952b9d4fefe3 Mon Sep 17 00:00:00 2001 From: Jerel Miller Date: Thu, 26 Jun 2025 16:12:59 -0600 Subject: [PATCH 22/43] Use common template for removed option --- src/cache/core/cache.ts | 24 ++------- src/cache/inmemory/inMemoryCache.ts | 34 +++++------- src/core/ApolloClient.ts | 78 +++++++++++++++------------- src/testing/react/MockedProvider.tsx | 24 ++++----- src/utilities/deprecation/index.ts | 11 +++- 5 files changed, 82 insertions(+), 89 deletions(-) diff --git a/src/cache/core/cache.ts b/src/cache/core/cache.ts index 93a38b2316d..d73b8573343 100644 --- a/src/cache/core/cache.ts +++ b/src/cache/core/cache.ts @@ -244,11 +244,7 @@ export abstract class ApolloCache implements DataProxy { optimistic = !!options.optimistic ): Unmasked | null { if (__DEV__) { - warnRemovedOption(options, "canonizeResults", () => { - invariant.warn( - "[cache.readQuery]: `canonizeResults` is deprecated and will be removed in Apollo Client 4.0. Please remove this option." - ); - }); + warnRemovedOption(options, "canonizeResults", "cache.readQuery"); } return silenceDeprecations("canonizeResults", () => @@ -363,11 +359,7 @@ export abstract class ApolloCache implements DataProxy { optimistic = !!options.optimistic ): Unmasked | null { if (__DEV__) { - warnRemovedOption(options, "canonizeResults", () => { - invariant.warn( - "[cache.readFragment]: `canonizeResults` is deprecated and will be removed in Apollo Client 4.0. Please remove this option." - ); - }); + warnRemovedOption(options, "canonizeResults", "cache.readFragment"); } return silenceDeprecations("canonizeResults", () => @@ -414,11 +406,7 @@ export abstract class ApolloCache implements DataProxy { update: (data: Unmasked | null) => Unmasked | null | void ): Unmasked | null { if (__DEV__) { - warnRemovedOption(options, "canonizeResults", () => { - invariant.warn( - "[cache.updateQuery]: `canonizeResults` is deprecated and will be removed in Apollo Client 4.0. Please remove this option." - ); - }); + warnRemovedOption(options, "canonizeResults", "cache.updateQuery"); } return this.batch({ @@ -439,11 +427,7 @@ export abstract class ApolloCache implements DataProxy { update: (data: Unmasked | null) => Unmasked | null | void ): Unmasked | null { if (__DEV__) { - warnRemovedOption(options, "canonizeResults", () => { - invariant.warn( - "[cache.updateFragment]: `canonizeResults` is deprecated and will be removed in Apollo Client 4.0. Please remove this option." - ); - }); + warnRemovedOption(options, "canonizeResults", "cache.updateFragment"); } return this.batch({ diff --git a/src/cache/inmemory/inMemoryCache.ts b/src/cache/inmemory/inMemoryCache.ts index 6f029e96cf1..5d99b5d0688 100644 --- a/src/cache/inmemory/inMemoryCache.ts +++ b/src/cache/inmemory/inMemoryCache.ts @@ -78,16 +78,18 @@ export class InMemoryCache extends ApolloCache { super(); if (__DEV__) { - warnRemovedOption(config, "addTypename", () => { - invariant.warn( - "[InMemoryCache]: `addTypename` is deprecated and will be removed in Apollo Client 4.0. Please remove the `addTypename` option when instantiating `InMemoryCache`." - ); - }); - warnRemovedOption(config, "canonizeResults", () => { - invariant.warn( - "[InMemoryCache]: `canonizeResults` is deprecated and will be removed in Apollo Client 4.0. Please remove the `canonizeResults` option when instantiating `InMemoryCache`." - ); - }); + warnRemovedOption( + config, + "addTypename", + "InMemoryCache", + "Please remove the `addTypename` option when initializing `InMemoryCache`." + ); + warnRemovedOption( + config, + "canonizeResults", + "InMemoryCache", + "Please remove the `canonizeResults` option when initializing `InMemoryCache`." + ); } this.config = normalizeConfig(config); @@ -202,11 +204,7 @@ export class InMemoryCache extends ApolloCache { public read(options: Cache.ReadOptions): T | null { if (__DEV__) { - warnRemovedOption(options, "canonizeResults", () => { - invariant.warn( - "[cache.read] `canonizeResults` is deprecated and will be removed in Apollo Client 4.0. Please remove this option." - ); - }); + warnRemovedOption(options, "canonizeResults", "cache.read"); } const { @@ -287,11 +285,7 @@ export class InMemoryCache extends ApolloCache { options: Cache.DiffOptions ): Cache.DiffResult { if (__DEV__) { - warnRemovedOption(options, "canonizeResults", () => { - invariant.warn( - "[cache.diff]: `canonizeResults` is deprecated and will be removed in Apollo Client 4.0. Please remove this option." - ); - }); + warnRemovedOption(options, "canonizeResults", "cache.diff"); } return this.storeReader.diffQueryAgainstStore({ diff --git a/src/core/ApolloClient.ts b/src/core/ApolloClient.ts index 50710919518..9b345efb6dc 100644 --- a/src/core/ApolloClient.ts +++ b/src/core/ApolloClient.ts @@ -403,41 +403,49 @@ export class ApolloClient implements DataProxy { } = options; if (__DEV__) { - warnRemovedOption(options, "connectToDevTools", () => { - invariant.warn( - "[ApolloClient]: `connectToDevTools` is deprecated and will be removed in Apollo Client 4.0. Please use `devtools.enabled` instead." - ); - }); - warnRemovedOption(options, "uri", () => { - invariant.warn( - "[ApolloClient]: `uri` is deprecated and will be removed in Apollo Client 4.0. Please initialize an instance of `HttpLink` with `uri` instead." - ); - }); - warnRemovedOption(options, "credentials", () => { - invariant.warn( - "[ApolloClient]: `credentials` is deprecated and will be removed in Apollo Client 4.0. Please initialize an instance of `HttpLink` with `credentials` instead." - ); - }); - warnRemovedOption(options, "headers", () => { - invariant.warn( - "[ApolloClient]: `headers` is deprecated and will be removed in Apollo Client 4.0. Please initialize an instance of `HttpLink` with `headers` instead." - ); - }); - warnRemovedOption(options, "name", () => { - invariant.warn( - "[ApolloClient]: `name` is deprecated and will be removed in Apollo Client 4.0. Please use the `clientAwareness.name` option instead." - ); - }); - warnRemovedOption(options, "version", () => { - invariant.warn( - "[ApolloClient]: `version` is deprecated and will be removed in Apollo Client 4.0. Please use the `clientAwareness.version` option instead." - ); - }); - warnRemovedOption(options, "typeDefs", () => { - invariant.warn( - "[ApolloClient]: `typeDefs` is deprecated and will be removed in Apollo Client 4.0. Please remove this option." - ); - }); + warnRemovedOption( + options, + "connectToDevTools", + "ApolloClient", + "Please use `devtools.enabled` instead." + ); + warnRemovedOption( + options, + "uri", + "ApolloClient", + "Please initialize an instance of `HttpLink` with `uri` instead." + ); + warnRemovedOption( + options, + "credentials", + "ApolloClient", + "Please initialize an instance of `HttpLink` with `credentials` instead." + ); + warnRemovedOption( + options, + "headers", + "ApolloClient", + "Please initialize an instance of `HttpLink` with `headers` instead." + ); + warnRemovedOption( + options, + "name", + "ApolloClient", + "Please use the `clientAwareness.name` option instead." + ); + warnRemovedOption( + options, + "version", + "ApolloClient", + "Please use the `clientAwareness.version` option instead." + ); + warnRemovedOption( + options, + "version", + "ApolloClient", + "Please use the `clientAwareness.version` option instead." + ); + warnRemovedOption(options, "typeDefs", "ApolloClient"); if (!options.link) { invariant.warn( diff --git a/src/testing/react/MockedProvider.tsx b/src/testing/react/MockedProvider.tsx index 5a1828fa7af..9e707f5c9da 100644 --- a/src/testing/react/MockedProvider.tsx +++ b/src/testing/react/MockedProvider.tsx @@ -10,7 +10,6 @@ import type { ApolloLink } from "../../link/core/index.js"; import type { Resolvers } from "../../core/index.js"; import type { ApolloCache } from "../../cache/index.js"; import type { DevtoolsOptions } from "../../core/ApolloClient.js"; -import { invariant } from "../../utilities/globals/index.js"; import { warnRemovedOption, silenceDeprecations, @@ -83,17 +82,18 @@ export class MockedProvider extends React.Component< connectToDevTools = false, } = this.props; if (__DEV__) { - warnRemovedOption(this.props, "connectToDevTools", () => { - invariant.warn( - "[MockedProvider]: `connectToDevTools` is deprecated and will be removed in Apollo Client 4.0. Please use `devtools.enabled` instead." - ); - }); - - warnRemovedOption(this.props, "addTypename", () => { - invariant.warn( - "[MockedProvider]: `addTypename` is deprecated and will be removed in Apollo Client 4.0. Please remove the `addTypename` prop. For best results, ensure the provided `mocks` include a `__typename` property on all mock objects to ensure the cache more closely behaves like production." - ); - }); + warnRemovedOption( + this.props, + "connectToDevTools", + "MockedProvider", + "Please use `devtools.enabled` instead." + ); + warnRemovedOption( + this.props, + "addTypename", + "MockedProvider", + "Please remove the `addTypename` prop. For best results, ensure the provided `mocks` include a `__typename` property on all mock objects to ensure the cache more closely behaves like production." + ); } const client = silenceDeprecations( diff --git a/src/utilities/deprecation/index.ts b/src/utilities/deprecation/index.ts index e3d92ef11fb..00fb4707bb8 100644 --- a/src/utilities/deprecation/index.ts +++ b/src/utilities/deprecation/index.ts @@ -1,4 +1,5 @@ import { Slot } from "optimism"; +import { invariant } from "../globals/index.js"; const slot = new Slot(); @@ -20,11 +21,17 @@ export function silenceDeprecations( export function warnRemovedOption>( options: TOptions, name: keyof TOptions, - cb: () => void + callSite: string, + recommendation: string = "Please remove this option." ) { const silenced = (slot.getValue() || []).includes(name as string); if (name in options && !silenced) { - cb(); + invariant.warn( + "[%s]: `%s` is deprecated and will be removed in Apollo Client 4.0. %s", + callSite, + name, + recommendation + ); } } From bd23690a0c3202b3c8b7d2638892b5ac6a7b444d Mon Sep 17 00:00:00 2001 From: Jerel Miller Date: Thu, 26 Jun 2025 16:46:41 -0600 Subject: [PATCH 23/43] Warn on client.query and client.watchQuery --- src/core/ApolloClient.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/core/ApolloClient.ts b/src/core/ApolloClient.ts index 9b345efb6dc..aa1ed904c28 100644 --- a/src/core/ApolloClient.ts +++ b/src/core/ApolloClient.ts @@ -644,6 +644,10 @@ export class ApolloClient implements DataProxy { options = { ...options, fetchPolicy: "cache-first" }; } + if (__DEV__) { + warnRemovedOption(options, "canonizeResults", "client.watchQuery"); + } + return this.queryManager.watchQuery(options); } @@ -678,6 +682,10 @@ export class ApolloClient implements DataProxy { options = { ...options, fetchPolicy: "cache-first" }; } + if (__DEV__) { + warnRemovedOption(options, "canonizeResults", "client.query"); + } + return this.queryManager.query(options); } From 0d43a100b198fc5f882c8583b758c72d0bf29c81 Mon Sep 17 00:00:00 2001 From: Jerel Miller Date: Thu, 26 Jun 2025 17:02:10 -0600 Subject: [PATCH 24/43] Silence deprecations in ObservableQuery tests that check console.warn --- src/core/__tests__/ObservableQuery.ts | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/core/__tests__/ObservableQuery.ts b/src/core/__tests__/ObservableQuery.ts index 21da5da9f7a..d95d858b28c 100644 --- a/src/core/__tests__/ObservableQuery.ts +++ b/src/core/__tests__/ObservableQuery.ts @@ -27,6 +27,7 @@ import { expectTypeOf } from "expect-type"; import { SubscriptionObserver } from "zen-observable-ts"; import { waitFor } from "@testing-library/react"; import { ObservableStream, spyOnConsole } from "../../testing/internal"; +import { silenceDeprecations } from "../../utilities/deprecation"; export const mockFetchQuery = (queryManager: QueryManager) => { const fetchConcastWithInfo = queryManager["fetchConcastWithInfo"]; @@ -1771,9 +1772,11 @@ describe("ObservableQuery", () => { }; } - const client = new ApolloClient({ - cache: new InMemoryCache({ addTypename: false }), - link: new MockLink([makeMock("a", "b", "c"), makeMock("d", "e")]), + const client = silenceDeprecations("addTypename", () => { + return new ApolloClient({ + cache: new InMemoryCache({ addTypename: false }), + link: new MockLink([makeMock("a", "b", "c"), makeMock("d", "e")]), + }); }); const observableWithoutVariables = client.watchQuery({ query: queryWithoutVariables, @@ -1857,9 +1860,11 @@ describe("ObservableQuery", () => { const mocks = [makeMock("a", "b", "c"), makeMock("d", "e")]; const firstRequest = mocks[0].request; - const client = new ApolloClient({ - cache: new InMemoryCache({ addTypename: false }), - link: new MockLink(mocks, true, { showWarnings: false }), + const client = silenceDeprecations("addTypename", () => { + return new ApolloClient({ + cache: new InMemoryCache({ addTypename: false }), + link: new MockLink(mocks, true, { showWarnings: false }), + }); }); const observableWithVarsVar = client.watchQuery({ @@ -1952,9 +1957,11 @@ describe("ObservableQuery", () => { }; } - const client = new ApolloClient({ - cache: new InMemoryCache({ addTypename: false }), - link: new MockLink([makeMock("a", "b", "c"), makeMock("d", "e")]), + const client = silenceDeprecations("addTypename", () => { + return new ApolloClient({ + cache: new InMemoryCache({ addTypename: false }), + link: new MockLink([makeMock("a", "b", "c"), makeMock("d", "e")]), + }); }); const observableWithVariablesVar = client.watchQuery({ From 2adc3bc311185d5eb5ad93cffbefcdfca414ca98 Mon Sep 17 00:00:00 2001 From: Jerel Miller Date: Thu, 26 Jun 2025 17:14:06 -0600 Subject: [PATCH 25/43] Add hook to warn for removed option --- src/react/hooks/internal/index.ts | 1 + .../hooks/internal/useWarnRemovedOption.ts | 27 +++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 src/react/hooks/internal/useWarnRemovedOption.ts diff --git a/src/react/hooks/internal/index.ts b/src/react/hooks/internal/index.ts index 85aad7cb932..c5834435910 100644 --- a/src/react/hooks/internal/index.ts +++ b/src/react/hooks/internal/index.ts @@ -2,5 +2,6 @@ export { useDeepMemo } from "./useDeepMemo.js"; export { useIsomorphicLayoutEffect } from "./useIsomorphicLayoutEffect.js"; export { useRenderGuard } from "./useRenderGuard.js"; +export { useWarnRemovedOption } from "./useWarnRemovedOption.js"; export { __use } from "./__use.js"; export { wrapHook } from "./wrapHook.js"; diff --git a/src/react/hooks/internal/useWarnRemovedOption.ts b/src/react/hooks/internal/useWarnRemovedOption.ts new file mode 100644 index 00000000000..e0feb5fb8d2 --- /dev/null +++ b/src/react/hooks/internal/useWarnRemovedOption.ts @@ -0,0 +1,27 @@ +import * as React from "rehackt"; +import { invariant } from "../../../utilities/globals/index.js"; + +// Remove with Apollo Client 4.0 +export function useWarnRemovedOption>( + options: TOptions, + name: keyof TOptions, + callSite: string, + recommendation: string = "Please remove this option." +) { + "use no memo"; + const didWarn = React.useRef(false); + + if (__DEV__) { + if (name in options && !didWarn.current) { + invariant.warn( + "[%s]: `%s` is deprecated and will be removed in Apollo Client 4.0. %s", + callSite, + name, + recommendation + ); + } + + // eslint-disable-next-line react-compiler/react-compiler + didWarn.current = true; + } +} From e6851c74c3b0bace92ea9eb00c67d96e695fde24 Mon Sep 17 00:00:00 2001 From: Jerel Miller Date: Thu, 26 Jun 2025 17:21:17 -0600 Subject: [PATCH 26/43] Add canonizeResults warning to useQuery --- src/react/hooks/useQuery.ts | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/react/hooks/useQuery.ts b/src/react/hooks/useQuery.ts index 55d1637dbc3..777f7f496b7 100644 --- a/src/react/hooks/useQuery.ts +++ b/src/react/hooks/useQuery.ts @@ -51,9 +51,10 @@ import { isNonEmptyArray, maybeDeepFreeze, } from "../../utilities/index.js"; -import { wrapHook } from "./internal/index.js"; +import { useWarnRemovedOption, wrapHook } from "./internal/index.js"; import type { RenderPromises } from "../ssr/RenderPromises.js"; import type { MaybeMasked } from "../../masking/index.js"; +import { silenceDeprecations } from "../../utilities/deprecation/index.js"; const { prototype: { hasOwnProperty }, @@ -158,6 +159,8 @@ function useQuery_< query: DocumentNode | TypedDocumentNode, options: QueryHookOptions, NoInfer> ) { + useWarnRemovedOption(options, "canonizeResults", "useQuery"); + const { result, obsQueryFields } = useQueryInternals(query, options); return React.useMemo( () => ({ ...result, ...obsQueryFields }), @@ -188,9 +191,16 @@ function useInternalState< (renderPromises && renderPromises.getSSRObservable(makeWatchQueryOptions())) || ObservableQuery["inactiveOnCreation"].withValue(!renderPromises, () => - client.watchQuery( - getObsQueryOptions(void 0, client, options, makeWatchQueryOptions()) - ) + silenceDeprecations("canonizeResults", () => { + return client.watchQuery( + getObsQueryOptions( + void 0, + client, + options, + makeWatchQueryOptions() + ) + ); + }) ), resultData: { // Reuse previousData from previous InternalState (if any) to provide From f75e75455fdb753acdb011152f59048d8ed994ec Mon Sep 17 00:00:00 2001 From: Jerel Miller Date: Thu, 26 Jun 2025 17:23:52 -0600 Subject: [PATCH 27/43] Add warning to useLazyQuery --- src/react/hooks/useLazyQuery.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/react/hooks/useLazyQuery.ts b/src/react/hooks/useLazyQuery.ts index 3f51b242fc6..b76eb2f7697 100644 --- a/src/react/hooks/useLazyQuery.ts +++ b/src/react/hooks/useLazyQuery.ts @@ -27,6 +27,7 @@ import { useQueryInternals, } from "./useQuery.js"; import { useIsomorphicLayoutEffect } from "./internal/useIsomorphicLayoutEffect.js"; +import { useWarnRemovedOption } from "./internal/useWarnRemovedOption.js"; // The following methods, when called will execute the query, regardless of // whether the useLazyQuery execute function was called before. @@ -92,6 +93,8 @@ export function useLazyQuery< const merged = mergeOptions(options, execOptionsRef.current || {}); const document = merged?.query ?? query; + useWarnRemovedOption(merged, "canonizeResults", "useLazyQuery"); + // Use refs to track options and the used query to ensure the `execute` // function remains referentially stable between renders. optionsRef.current = options; From 8e24af883b3ef6182d400d3d07e83d4ef30e42ad Mon Sep 17 00:00:00 2001 From: Jerel Miller Date: Thu, 26 Jun 2025 17:27:35 -0600 Subject: [PATCH 28/43] Add warning to useSuspenseQuery --- src/react/hooks/useSuspenseQuery.ts | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/react/hooks/useSuspenseQuery.ts b/src/react/hooks/useSuspenseQuery.ts index af634110fe6..ac0aeb90be8 100644 --- a/src/react/hooks/useSuspenseQuery.ts +++ b/src/react/hooks/useSuspenseQuery.ts @@ -21,7 +21,13 @@ import type { ObservableQueryFields, NoInfer, } from "../types/types.js"; -import { __use, useDeepMemo, wrapHook } from "./internal/index.js"; +import { + __use, + useDeepMemo, + useWarnRemovedOption, + wrapHook, +} from "./internal/index.js"; +import { silenceDeprecations } from "../../utilities/deprecation/index.js"; import { getSuspenseCache } from "../internal/index.js"; import { canonicalStringify } from "../../cache/index.js"; import { skipToken } from "./constants.js"; @@ -189,6 +195,12 @@ function useSuspenseQuery_< | (SkipToken & Partial>) | SuspenseQueryHookOptions ): UseSuspenseQueryResult { + useWarnRemovedOption( + typeof options === "symbol" ? {} : options, + "canonizeResults", + "useSuspenseQuery" + ); + const client = useApolloClient(options.client); const suspenseCache = getSuspenseCache(client); const watchQueryOptions = useWatchQueryOptions({ @@ -205,8 +217,10 @@ function useSuspenseQuery_< ...([] as any[]).concat(queryKey), ]; - const queryRef = suspenseCache.getQueryRef(cacheKey, () => - client.watchQuery(watchQueryOptions) + const queryRef = silenceDeprecations("canonizeResults", () => + suspenseCache.getQueryRef(cacheKey, () => + client.watchQuery(watchQueryOptions) + ) ); let [current, setPromise] = React.useState< From a3d3d3fcaf7a654a1f8386498dd5cc189133cfb9 Mon Sep 17 00:00:00 2001 From: Jerel Miller Date: Thu, 26 Jun 2025 17:29:42 -0600 Subject: [PATCH 29/43] Add warning to useBackgroundQuery --- src/react/hooks/useBackgroundQuery.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/react/hooks/useBackgroundQuery.ts b/src/react/hooks/useBackgroundQuery.ts index 256d3175c90..4311b41a382 100644 --- a/src/react/hooks/useBackgroundQuery.ts +++ b/src/react/hooks/useBackgroundQuery.ts @@ -16,12 +16,13 @@ import { } from "../internal/index.js"; import type { CacheKey, QueryRef } from "../internal/index.js"; import type { BackgroundQueryHookOptions, NoInfer } from "../types/types.js"; -import { wrapHook } from "./internal/index.js"; +import { useWarnRemovedOption, wrapHook } from "./internal/index.js"; import { useWatchQueryOptions } from "./useSuspenseQuery.js"; import type { FetchMoreFunction, RefetchFunction } from "./useSuspenseQuery.js"; import { canonicalStringify } from "../../cache/index.js"; import type { DeepPartial } from "../../utilities/index.js"; import type { SkipToken } from "./constants.js"; +import { silenceDeprecations } from "../../utilities/deprecation/index.js"; export type UseBackgroundQueryResult< TData = unknown, @@ -206,6 +207,11 @@ function useBackgroundQuery_< QueryRef | undefined, UseBackgroundQueryResult, ] { + useWarnRemovedOption( + typeof options === "symbol" ? {} : options, + "canonizeResults", + "useBackgroundQuery" + ); const client = useApolloClient(options.client); const suspenseCache = getSuspenseCache(client); const watchQueryOptions = useWatchQueryOptions({ client, query, options }); @@ -227,8 +233,10 @@ function useBackgroundQuery_< ...([] as any[]).concat(queryKey), ]; - const queryRef = suspenseCache.getQueryRef(cacheKey, () => - client.watchQuery(watchQueryOptions as WatchQueryOptions) + const queryRef = silenceDeprecations("canonizeResults", () => + suspenseCache.getQueryRef(cacheKey, () => + client.watchQuery(watchQueryOptions as WatchQueryOptions) + ) ); const [wrappedQueryRef, setWrappedQueryRef] = React.useState( From 3a272a7e206e44a41802e6bcd3f7a9f7f8df8516 Mon Sep 17 00:00:00 2001 From: Jerel Miller Date: Thu, 26 Jun 2025 17:33:56 -0600 Subject: [PATCH 30/43] Add warning to useFragment --- src/react/hooks/useFragment.ts | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/src/react/hooks/useFragment.ts b/src/react/hooks/useFragment.ts index 98cdfa6b274..b8021e07259 100644 --- a/src/react/hooks/useFragment.ts +++ b/src/react/hooks/useFragment.ts @@ -12,9 +12,14 @@ import { useApolloClient } from "./useApolloClient.js"; import { useSyncExternalStore } from "./useSyncExternalStore.js"; import type { ApolloClient, OperationVariables } from "../../core/index.js"; import type { NoInfer } from "../types/types.js"; -import { useDeepMemo, wrapHook } from "./internal/index.js"; +import { + useDeepMemo, + useWarnRemovedOption, + wrapHook, +} from "./internal/index.js"; import equal from "@wry/equality"; import type { FragmentType, MaybeMasked } from "../../masking/index.js"; +import { silenceDeprecations } from "../../utilities/deprecation/index.js"; export interface UseFragmentOptions extends Omit< @@ -65,6 +70,7 @@ export function useFragment( function useFragment_( options: UseFragmentOptions ): UseFragmentResult { + useWarnRemovedOption(options, "canonizeResults", "useFragment"); const client = useApolloClient(options.client); const { cache } = client; const { from, ...rest } = options; @@ -98,13 +104,15 @@ function useFragment_( } const { cache } = client; - const diff = cache.diff({ - ...stableOptions, - returnPartialData: true, - id: from, - query: cache["getFragmentDoc"](fragment, fragmentName), - optimistic, - }); + const diff = silenceDeprecations("canonizeResults", () => + cache.diff({ + ...stableOptions, + returnPartialData: true, + id: from, + query: cache["getFragmentDoc"](fragment, fragmentName), + optimistic, + }) + ); return { result: diffToResult({ @@ -126,7 +134,7 @@ function useFragment_( (forceUpdate) => { let lastTimeout = 0; - const subscription = + const subscription = silenceDeprecations("canonizeResults", () => stableOptions.from === null ? null : client.watchFragment(stableOptions).subscribe({ @@ -144,7 +152,8 @@ function useFragment_( clearTimeout(lastTimeout); lastTimeout = setTimeout(forceUpdate) as any; }, - }); + }) + ); return () => { subscription?.unsubscribe(); clearTimeout(lastTimeout); From 4196063e985ec342c73e218a817ce4f0ff8d7a5b Mon Sep 17 00:00:00 2001 From: Jerel Miller Date: Thu, 26 Jun 2025 17:37:54 -0600 Subject: [PATCH 31/43] Add warning to useLoadableQuery --- src/react/hooks/useLoadableQuery.ts | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/react/hooks/useLoadableQuery.ts b/src/react/hooks/useLoadableQuery.ts index d520b96668c..be9fa1da493 100644 --- a/src/react/hooks/useLoadableQuery.ts +++ b/src/react/hooks/useLoadableQuery.ts @@ -20,7 +20,11 @@ import { } from "../internal/index.js"; import type { CacheKey, QueryRef } from "../internal/index.js"; import type { LoadableQueryHookOptions } from "../types/types.js"; -import { __use, useRenderGuard } from "./internal/index.js"; +import { + __use, + useRenderGuard, + useWarnRemovedOption, +} from "./internal/index.js"; import { useWatchQueryOptions } from "./useSuspenseQuery.js"; import type { FetchMoreFunction, RefetchFunction } from "./useSuspenseQuery.js"; import { canonicalStringify } from "../../cache/index.js"; @@ -29,6 +33,7 @@ import type { OnlyRequiredProperties, } from "../../utilities/index.js"; import { invariant } from "../../utilities/globals/index.js"; +import { silenceDeprecations } from "../../utilities/deprecation/index.js"; export type LoadQueryFunction = ( // Use variadic args to handle cases where TVariables is type `never`, in @@ -170,6 +175,8 @@ export function useLoadableQuery< query: DocumentNode | TypedDocumentNode, options: LoadableQueryHookOptions = Object.create(null) ): UseLoadableQueryResult { + useWarnRemovedOption(options, "canonizeResults", "useLoadableQuery"); + const client = useApolloClient(options.client); const suspenseCache = getSuspenseCache(client); const watchQueryOptions = useWatchQueryOptions({ client, query, options }); @@ -242,11 +249,13 @@ export function useLoadableQuery< ...([] as any[]).concat(queryKey), ]; - const queryRef = suspenseCache.getQueryRef(cacheKey, () => - client.watchQuery({ - ...watchQueryOptions, - variables, - } as WatchQueryOptions) + const queryRef = silenceDeprecations("canonizeResults", () => + suspenseCache.getQueryRef(cacheKey, () => + client.watchQuery({ + ...watchQueryOptions, + variables, + } as WatchQueryOptions) + ) ); setQueryRef(wrapQueryRef(queryRef)); From b236a4cc3f0a51c9be78558d90b41f431ba5a4d9 Mon Sep 17 00:00:00 2001 From: Jerel Miller Date: Thu, 26 Jun 2025 17:41:20 -0600 Subject: [PATCH 32/43] Add warning to createQueryPreloader --- .../query-preloader/createQueryPreloader.ts | 28 +++++++++++++------ 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/src/react/query-preloader/createQueryPreloader.ts b/src/react/query-preloader/createQueryPreloader.ts index 50b9e500579..08564670254 100644 --- a/src/react/query-preloader/createQueryPreloader.ts +++ b/src/react/query-preloader/createQueryPreloader.ts @@ -17,6 +17,10 @@ import { InternalQueryReference, wrapQueryRef } from "../internal/index.js"; import type { PreloadedQueryRef } from "../internal/index.js"; import type { NoInfer, VariablesOption } from "../index.js"; import { wrapHook } from "../hooks/internal/index.js"; +import { + silenceDeprecations, + warnRemovedOption, +} from "../../utilities/deprecation/index.js"; export type PreloadQueryFetchPolicy = Extract< WatchQueryFetchPolicy, @@ -169,15 +173,21 @@ const _createQueryPreloader: typeof createQueryPreloader = (client) => { options: PreloadQueryOptions> & VariablesOption = Object.create(null) ): PreloadedQueryRef { - const queryRef = new InternalQueryReference( - client.watchQuery({ - ...options, - query, - } as WatchQueryOptions), - { - autoDisposeTimeoutMs: - client.defaultOptions.react?.suspense?.autoDisposeTimeoutMs, - } + warnRemovedOption(options, "canonizeResults", "preloadQuery"); + + const queryRef = silenceDeprecations( + "canonizeResults", + () => + new InternalQueryReference( + client.watchQuery({ + ...options, + query, + } as WatchQueryOptions), + { + autoDisposeTimeoutMs: + client.defaultOptions.react?.suspense?.autoDisposeTimeoutMs, + } + ) ); return wrapQueryRef(queryRef) as PreloadedQueryRef; From 29a39ec59f5eaa8beb9e35c8a84dc8dad57d0e32 Mon Sep 17 00:00:00 2001 From: Jerel Miller Date: Thu, 26 Jun 2025 17:45:09 -0600 Subject: [PATCH 33/43] rerun api report --- .api-reports/api-report-cache.api.md | 6 +++--- .api-reports/api-report-core.api.md | 8 ++++---- .api-reports/api-report-masking.api.md | 2 +- .api-reports/api-report-react.api.md | 12 ++++++------ .api-reports/api-report-react_components.api.md | 6 +++--- .api-reports/api-report-react_context.api.md | 6 +++--- .api-reports/api-report-react_hoc.api.md | 6 +++--- .api-reports/api-report-react_hooks.api.md | 12 ++++++------ .api-reports/api-report-react_internal.api.md | 14 +++++++------- .api-reports/api-report-react_ssr.api.md | 6 +++--- .api-reports/api-report-testing.api.md | 10 ++++------ .api-reports/api-report-testing_core.api.md | 6 +++--- .api-reports/api-report-utilities.api.md | 8 ++++---- .api-reports/api-report.api.md | 14 +++++++------- 14 files changed, 57 insertions(+), 59 deletions(-) diff --git a/.api-reports/api-report-cache.api.md b/.api-reports/api-report-cache.api.md index 8c362513806..0bdf4326705 100644 --- a/.api-reports/api-report-cache.api.md +++ b/.api-reports/api-report-cache.api.md @@ -138,7 +138,7 @@ namespace Cache_2 { } // (undocumented) interface ReadOptions extends DataProxy.Query { - // @deprecated (undocumented) + // @deprecated canonizeResults?: boolean; // (undocumented) optimistic: boolean; @@ -682,7 +682,7 @@ export class InMemoryCache extends ApolloCache { // @public (undocumented) export interface InMemoryCacheConfig extends ApolloReducerConfig { - // @deprecated (undocumented) + // @deprecated canonizeResults?: boolean; // (undocumented) fragments?: FragmentRegistryAPI; @@ -1182,7 +1182,7 @@ interface WriteContext extends ReadMergeModifyContext { // Warnings were encountered during analysis: // -// src/cache/core/cache.ts:92:7 - (ae-forgotten-export) The symbol "MaybeMasked" needs to be exported by the entry point index.d.ts +// src/cache/core/cache.ts:96:7 - (ae-forgotten-export) The symbol "MaybeMasked" needs to be exported by the entry point index.d.ts // src/cache/inmemory/policies.ts:93:3 - (ae-forgotten-export) The symbol "FragmentMap" needs to be exported by the entry point index.d.ts // src/cache/inmemory/policies.ts:162:3 - (ae-forgotten-export) The symbol "KeySpecifier" needs to be exported by the entry point index.d.ts // src/cache/inmemory/policies.ts:162:3 - (ae-forgotten-export) The symbol "KeyArgsFunction" needs to be exported by the entry point index.d.ts diff --git a/.api-reports/api-report-core.api.md b/.api-reports/api-report-core.api.md index 1114aa3b35d..7ea9161156f 100644 --- a/.api-reports/api-report-core.api.md +++ b/.api-reports/api-report-core.api.md @@ -362,7 +362,7 @@ namespace Cache_2 { } // (undocumented) interface ReadOptions extends DataProxy.Query { - // @deprecated (undocumented) + // @deprecated canonizeResults?: boolean; // (undocumented) optimistic: boolean; @@ -1221,7 +1221,7 @@ export class InMemoryCache extends ApolloCache { // @public (undocumented) export interface InMemoryCacheConfig extends ApolloReducerConfig { - // @deprecated (undocumented) + // @deprecated canonizeResults?: boolean; // Warning: (ae-forgotten-export) The symbol "FragmentRegistryAPI" needs to be exported by the entry point index.d.ts // @@ -2549,8 +2549,8 @@ interface WriteContext extends ReadMergeModifyContext { // src/cache/inmemory/types.ts:139:3 - (ae-forgotten-export) The symbol "KeyFieldsFunction" needs to be exported by the entry point index.d.ts // src/core/ObservableQuery.ts:128:5 - (ae-forgotten-export) The symbol "QueryManager" needs to be exported by the entry point index.d.ts // src/core/ObservableQuery.ts:129:5 - (ae-forgotten-export) The symbol "QueryInfo" needs to be exported by the entry point index.d.ts -// src/core/QueryManager.ts:159:5 - (ae-forgotten-export) The symbol "MutationStoreValue" needs to be exported by the entry point index.d.ts -// src/core/QueryManager.ts:414:7 - (ae-forgotten-export) The symbol "UpdateQueries" needs to be exported by the entry point index.d.ts +// src/core/QueryManager.ts:160:5 - (ae-forgotten-export) The symbol "MutationStoreValue" needs to be exported by the entry point index.d.ts +// src/core/QueryManager.ts:415:7 - (ae-forgotten-export) The symbol "UpdateQueries" 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 // (No @packageDocumentation comment for this package) diff --git a/.api-reports/api-report-masking.api.md b/.api-reports/api-report-masking.api.md index 37019fcb7bc..609e6d6469b 100644 --- a/.api-reports/api-report-masking.api.md +++ b/.api-reports/api-report-masking.api.md @@ -143,7 +143,7 @@ namespace Cache_2 { } // (undocumented) interface ReadOptions extends DataProxy.Query { - // @deprecated (undocumented) + // @deprecated canonizeResults?: boolean; // (undocumented) optimistic: boolean; diff --git a/.api-reports/api-report-react.api.md b/.api-reports/api-report-react.api.md index 66a0c1c0741..2cce6cbc604 100644 --- a/.api-reports/api-report-react.api.md +++ b/.api-reports/api-report-react.api.md @@ -478,7 +478,7 @@ namespace Cache_2 { } // (undocumented) interface ReadOptions extends DataProxy.Query { - // @deprecated (undocumented) + // @deprecated canonizeResults?: boolean; // (undocumented) optimistic: boolean; @@ -2606,14 +2606,14 @@ interface WatchQueryOptions extends DataProxy.Query { - // @deprecated (undocumented) + // @deprecated canonizeResults?: boolean; // (undocumented) optimistic: boolean; @@ -2056,8 +2056,8 @@ interface WatchQueryOptions extends DataProxy.Query { - // @deprecated (undocumented) + // @deprecated canonizeResults?: boolean; // (undocumented) optimistic: boolean; @@ -1975,8 +1975,8 @@ interface WatchQueryOptions extends DataProxy.Query { - // @deprecated (undocumented) + // @deprecated canonizeResults?: boolean; // (undocumented) optimistic: boolean; @@ -1986,8 +1986,8 @@ export function withSubscription extends DataProxy.Query { - // @deprecated (undocumented) + // @deprecated canonizeResults?: boolean; // (undocumented) optimistic: boolean; @@ -2445,14 +2445,14 @@ interface WatchQueryOptions extends DataProxy.Query { - // @deprecated (undocumented) + // @deprecated canonizeResults?: boolean; // (undocumented) optimistic: boolean; @@ -2557,16 +2557,16 @@ export function wrapQueryRef(inter // src/core/LocalState.ts:46:5 - (ae-forgotten-export) The symbol "FragmentMap" needs to be exported by the entry point index.d.ts // src/core/ObservableQuery.ts:128:5 - (ae-forgotten-export) The symbol "QueryManager" needs to be exported by the entry point index.d.ts // src/core/ObservableQuery.ts:129:5 - (ae-forgotten-export) The symbol "QueryInfo" needs to be exported by the entry point index.d.ts -// src/core/QueryManager.ts:159:5 - (ae-forgotten-export) The symbol "MutationStoreValue" needs to be exported by the entry point index.d.ts -// src/core/QueryManager.ts:414:7 - (ae-forgotten-export) The symbol "UpdateQueries" needs to be exported by the entry point index.d.ts +// src/core/QueryManager.ts:160:5 - (ae-forgotten-export) The symbol "MutationStoreValue" needs to be exported by the entry point index.d.ts +// src/core/QueryManager.ts:415:7 - (ae-forgotten-export) The symbol "UpdateQueries" needs to be exported by the entry point index.d.ts // src/core/types.ts:172: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:357:2 - (ae-forgotten-export) The symbol "UpdateQueryOptions" needs to be exported by the entry point index.d.ts -// src/react/hooks/useBackgroundQuery.ts:51:3 - (ae-forgotten-export) The symbol "FetchMoreFunction" needs to be exported by the entry point index.d.ts -// src/react/hooks/useBackgroundQuery.ts:75:4 - (ae-forgotten-export) The symbol "RefetchFunction" needs to be exported by the entry point index.d.ts +// src/react/hooks/useBackgroundQuery.ts:52:3 - (ae-forgotten-export) The symbol "FetchMoreFunction" needs to be exported by the entry point index.d.ts +// src/react/hooks/useBackgroundQuery.ts:76:4 - (ae-forgotten-export) The symbol "RefetchFunction" needs to be exported by the entry point index.d.ts // src/react/hooks/useSuspenseFragment.ts:70:5 - (ae-forgotten-export) The symbol "From" needs to be exported by the entry point index.d.ts -// src/react/query-preloader/createQueryPreloader.ts:77:5 - (ae-forgotten-export) The symbol "PreloadQueryFetchPolicy" needs to be exported by the entry point index.d.ts -// src/react/query-preloader/createQueryPreloader.ts:117:3 - (ae-forgotten-export) The symbol "RefetchWritePolicy" needs to be exported by the entry point index.d.ts +// src/react/query-preloader/createQueryPreloader.ts:81:5 - (ae-forgotten-export) The symbol "PreloadQueryFetchPolicy" needs to be exported by the entry point index.d.ts +// src/react/query-preloader/createQueryPreloader.ts:121:3 - (ae-forgotten-export) The symbol "RefetchWritePolicy" 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_ssr.api.md b/.api-reports/api-report-react_ssr.api.md index a6bbf6809ac..7c4cc86dee8 100644 --- a/.api-reports/api-report-react_ssr.api.md +++ b/.api-reports/api-report-react_ssr.api.md @@ -391,7 +391,7 @@ namespace Cache_2 { } // (undocumented) interface ReadOptions extends DataProxy.Query { - // @deprecated (undocumented) + // @deprecated canonizeResults?: boolean; // (undocumented) optimistic: boolean; @@ -1960,8 +1960,8 @@ interface WatchQueryOptions extends DataProxy.Query { - // @deprecated (undocumented) + // @deprecated canonizeResults?: boolean; // (undocumented) optimistic: boolean; @@ -1080,14 +1080,12 @@ export class MockedProvider extends React_2.Component { - // (undocumented) + // @deprecated (undocumented) addTypename?: boolean; // (undocumented) cache?: ApolloCache; @@ -2021,8 +2019,8 @@ export function withWarningSpy(it: (...args: TArgs // src/core/LocalState.ts:46:5 - (ae-forgotten-export) The symbol "FragmentMap" needs to be exported by the entry point index.d.ts // src/core/ObservableQuery.ts:128:5 - (ae-forgotten-export) The symbol "QueryManager" needs to be exported by the entry point index.d.ts // src/core/ObservableQuery.ts:129:5 - (ae-forgotten-export) The symbol "QueryInfo" needs to be exported by the entry point index.d.ts -// src/core/QueryManager.ts:159:5 - (ae-forgotten-export) The symbol "MutationStoreValue" needs to be exported by the entry point index.d.ts -// src/core/QueryManager.ts:414:7 - (ae-forgotten-export) The symbol "UpdateQueries" needs to be exported by the entry point index.d.ts +// src/core/QueryManager.ts:160:5 - (ae-forgotten-export) The symbol "MutationStoreValue" needs to be exported by the entry point index.d.ts +// src/core/QueryManager.ts:415:7 - (ae-forgotten-export) The symbol "UpdateQueries" needs to be exported by the entry point index.d.ts // src/core/types.ts:172: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:357:2 - (ae-forgotten-export) The symbol "UpdateQueryOptions" needs to be exported by the entry point index.d.ts diff --git a/.api-reports/api-report-testing_core.api.md b/.api-reports/api-report-testing_core.api.md index 6afbd68cf4e..ac4f66d83e7 100644 --- a/.api-reports/api-report-testing_core.api.md +++ b/.api-reports/api-report-testing_core.api.md @@ -380,7 +380,7 @@ namespace Cache_2 { } // (undocumented) interface ReadOptions extends DataProxy.Query { - // @deprecated (undocumented) + // @deprecated canonizeResults?: boolean; // (undocumented) optimistic: boolean; @@ -1976,8 +1976,8 @@ export function withWarningSpy(it: (...args: TArgs // src/core/LocalState.ts:46:5 - (ae-forgotten-export) The symbol "FragmentMap" needs to be exported by the entry point index.d.ts // src/core/ObservableQuery.ts:128:5 - (ae-forgotten-export) The symbol "QueryManager" needs to be exported by the entry point index.d.ts // src/core/ObservableQuery.ts:129:5 - (ae-forgotten-export) The symbol "QueryInfo" needs to be exported by the entry point index.d.ts -// src/core/QueryManager.ts:159:5 - (ae-forgotten-export) The symbol "MutationStoreValue" needs to be exported by the entry point index.d.ts -// src/core/QueryManager.ts:414:7 - (ae-forgotten-export) The symbol "UpdateQueries" needs to be exported by the entry point index.d.ts +// src/core/QueryManager.ts:160:5 - (ae-forgotten-export) The symbol "MutationStoreValue" needs to be exported by the entry point index.d.ts +// src/core/QueryManager.ts:415:7 - (ae-forgotten-export) The symbol "UpdateQueries" needs to be exported by the entry point index.d.ts // src/core/types.ts:172: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:357:2 - (ae-forgotten-export) The symbol "UpdateQueryOptions" needs to be exported by the entry point index.d.ts diff --git a/.api-reports/api-report-utilities.api.md b/.api-reports/api-report-utilities.api.md index 8e3a2c27fc9..4ae8363f916 100644 --- a/.api-reports/api-report-utilities.api.md +++ b/.api-reports/api-report-utilities.api.md @@ -438,7 +438,7 @@ namespace Cache_2 { } // (undocumented) interface ReadOptions extends DataProxy.Query { - // @deprecated (undocumented) + // @deprecated canonizeResults?: boolean; // (undocumented) optimistic: boolean; @@ -1443,7 +1443,7 @@ class InMemoryCache extends ApolloCache { // // @public (undocumented) interface InMemoryCacheConfig extends ApolloReducerConfig { - // @deprecated (undocumented) + // @deprecated canonizeResults?: boolean; // Warning: (ae-forgotten-export) The symbol "FragmentRegistryAPI" needs to be exported by the entry point index.d.ts // @@ -2921,8 +2921,8 @@ interface WriteContext extends ReadMergeModifyContext { // 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:128:5 - (ae-forgotten-export) The symbol "QueryManager" needs to be exported by the entry point index.d.ts // src/core/ObservableQuery.ts:129:5 - (ae-forgotten-export) The symbol "QueryInfo" needs to be exported by the entry point index.d.ts -// src/core/QueryManager.ts:159:5 - (ae-forgotten-export) The symbol "MutationStoreValue" needs to be exported by the entry point index.d.ts -// src/core/QueryManager.ts:414:7 - (ae-forgotten-export) The symbol "UpdateQueries" needs to be exported by the entry point index.d.ts +// src/core/QueryManager.ts:160:5 - (ae-forgotten-export) The symbol "MutationStoreValue" needs to be exported by the entry point index.d.ts +// src/core/QueryManager.ts:415:7 - (ae-forgotten-export) The symbol "UpdateQueries" needs to be exported by the entry point index.d.ts // src/core/types.ts:172: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:357:2 - (ae-forgotten-export) The symbol "UpdateQueryOptions" needs to be exported by the entry point index.d.ts diff --git a/.api-reports/api-report.api.md b/.api-reports/api-report.api.md index 3c837f3c67b..2b38db0fa12 100644 --- a/.api-reports/api-report.api.md +++ b/.api-reports/api-report.api.md @@ -455,7 +455,7 @@ namespace Cache_2 { } // (undocumented) interface ReadOptions extends DataProxy.Query { - // @deprecated (undocumented) + // @deprecated canonizeResults?: boolean; // (undocumented) optimistic: boolean; @@ -1359,7 +1359,7 @@ export class InMemoryCache extends ApolloCache { // @public (undocumented) export interface InMemoryCacheConfig extends ApolloReducerConfig { - // @deprecated (undocumented) + // @deprecated canonizeResults?: boolean; // Warning: (ae-forgotten-export) The symbol "FragmentRegistryAPI" needs to be exported by the entry point index.d.ts // @@ -3295,12 +3295,12 @@ interface WriteContext extends ReadMergeModifyContext { // src/cache/inmemory/types.ts:139:3 - (ae-forgotten-export) The symbol "KeyFieldsFunction" needs to be exported by the entry point index.d.ts // src/core/ObservableQuery.ts:128:5 - (ae-forgotten-export) The symbol "QueryManager" needs to be exported by the entry point index.d.ts // src/core/ObservableQuery.ts:129:5 - (ae-forgotten-export) The symbol "QueryInfo" needs to be exported by the entry point index.d.ts -// src/core/QueryManager.ts:159:5 - (ae-forgotten-export) The symbol "MutationStoreValue" needs to be exported by the entry point index.d.ts -// src/core/QueryManager.ts:414:7 - (ae-forgotten-export) The symbol "UpdateQueries" needs to be exported by the entry point index.d.ts +// src/core/QueryManager.ts:160:5 - (ae-forgotten-export) The symbol "MutationStoreValue" needs to be exported by the entry point index.d.ts +// src/core/QueryManager.ts:415:7 - (ae-forgotten-export) The symbol "UpdateQueries" 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/react/hooks/useBackgroundQuery.ts:51:3 - (ae-forgotten-export) The symbol "FetchMoreFunction" needs to be exported by the entry point index.d.ts -// src/react/hooks/useBackgroundQuery.ts:75:4 - (ae-forgotten-export) The symbol "RefetchFunction" needs to be exported by the entry point index.d.ts -// src/react/hooks/useLoadableQuery.ts:120:9 - (ae-forgotten-export) The symbol "ResetFunction" needs to be exported by the entry point index.d.ts +// src/react/hooks/useBackgroundQuery.ts:52:3 - (ae-forgotten-export) The symbol "FetchMoreFunction" needs to be exported by the entry point index.d.ts +// src/react/hooks/useBackgroundQuery.ts:76:4 - (ae-forgotten-export) The symbol "RefetchFunction" needs to be exported by the entry point index.d.ts +// src/react/hooks/useLoadableQuery.ts:125:9 - (ae-forgotten-export) The symbol "ResetFunction" needs to be exported by the entry point index.d.ts // src/react/hooks/useSuspenseFragment.ts:70:5 - (ae-forgotten-export) The symbol "From" needs to be exported by the entry point index.d.ts // (No @packageDocumentation comment for this package) From 6665d6941923fadf8ae8c2bfe33ce2a08661163e Mon Sep 17 00:00:00 2001 From: Jerel Miller Date: Thu, 26 Jun 2025 17:47:09 -0600 Subject: [PATCH 34/43] 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 a50c8ed9535..2a9671356a3 100644 --- a/.size-limits.json +++ b/.size-limits.json @@ -1,4 +1,4 @@ { - "dist/apollo-client.min.cjs": 42398, - "import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\" (production)": 34595 + "dist/apollo-client.min.cjs": 42604, + "import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\" (production)": 34714 } From dcf005a06f11c5f5bc695c2e09d9aebd72c1bfe4 Mon Sep 17 00:00:00 2001 From: Jerel Miller Date: Thu, 26 Jun 2025 17:48:24 -0600 Subject: [PATCH 35/43] Add changesets --- .changeset/smooth-countries-cough.md | 5 +++++ .changeset/spotty-walls-repair.md | 5 +++++ 2 files changed, 10 insertions(+) create mode 100644 .changeset/smooth-countries-cough.md create mode 100644 .changeset/spotty-walls-repair.md diff --git a/.changeset/smooth-countries-cough.md b/.changeset/smooth-countries-cough.md new file mode 100644 index 00000000000..374af89f715 --- /dev/null +++ b/.changeset/smooth-countries-cough.md @@ -0,0 +1,5 @@ +--- +"@apollo/client": minor +--- + +Add deprecations and warnings for `addTypename` in `InMemoryCache` and `MockedProvider`. diff --git a/.changeset/spotty-walls-repair.md b/.changeset/spotty-walls-repair.md new file mode 100644 index 00000000000..4a5d6a20be6 --- /dev/null +++ b/.changeset/spotty-walls-repair.md @@ -0,0 +1,5 @@ +--- +"@apollo/client": minor +--- + +Add deprecations and warnings for `canonizeResults`. From 8ed408264c41ebc688e761c2fd37b9d19fea944e Mon Sep 17 00:00:00 2001 From: Jerel Miller Date: Thu, 26 Jun 2025 17:53:41 -0600 Subject: [PATCH 36/43] Remove duplicate warning --- src/core/ApolloClient.ts | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/core/ApolloClient.ts b/src/core/ApolloClient.ts index aa1ed904c28..91da3755171 100644 --- a/src/core/ApolloClient.ts +++ b/src/core/ApolloClient.ts @@ -439,12 +439,6 @@ export class ApolloClient implements DataProxy { "ApolloClient", "Please use the `clientAwareness.version` option instead." ); - warnRemovedOption( - options, - "version", - "ApolloClient", - "Please use the `clientAwareness.version` option instead." - ); warnRemovedOption(options, "typeDefs", "ApolloClient"); if (!options.link) { From b3ba89a4251408c2a2a37a8fbaa825feb62f6f34 Mon Sep 17 00:00:00 2001 From: Jerel Miller Date: Thu, 26 Jun 2025 18:05:23 -0600 Subject: [PATCH 37/43] Silence warnings in useSubscription tests that check console.warn --- .../hooks/__tests__/useSubscription.test.tsx | 33 ++++++++++++------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/src/react/hooks/__tests__/useSubscription.test.tsx b/src/react/hooks/__tests__/useSubscription.test.tsx index 2290401b550..090d41c02b2 100644 --- a/src/react/hooks/__tests__/useSubscription.test.tsx +++ b/src/react/hooks/__tests__/useSubscription.test.tsx @@ -26,6 +26,7 @@ import { disableActEnvironment, renderHookToSnapshotStream, } from "@testing-library/react-render-stream"; +import { silenceDeprecations } from "../../../utilities/deprecation"; const IS_REACT_17 = React.version.startsWith("17"); @@ -744,9 +745,11 @@ describe("useSubscription Hook", () => { `; const link = new MockSubscriptionLink(); - const client = new ApolloClient({ - link, - cache: new Cache({ addTypename: false }), + const client = silenceDeprecations("addTypename", () => { + return new ApolloClient({ + link, + cache: new Cache({ addTypename: false }), + }); }); renderHook( @@ -874,9 +877,11 @@ describe("useSubscription Hook", () => { `; const link = new MockSubscriptionLink(); - const client = new ApolloClient({ - link, - cache: new Cache({ addTypename: false }), + const client = silenceDeprecations("addTypename", () => { + return new ApolloClient({ + link, + cache: new Cache({ addTypename: false }), + }); }); const { rerender } = renderHook( @@ -907,9 +912,11 @@ describe("useSubscription Hook", () => { `; const link = new MockSubscriptionLink(); - const client = new ApolloClient({ - link, - cache: new Cache({ addTypename: false }), + const client = silenceDeprecations("addTypename", () => { + return new ApolloClient({ + link, + cache: new Cache({ addTypename: false }), + }); }); renderHook( @@ -1041,9 +1048,11 @@ describe("useSubscription Hook", () => { `; const link = new MockSubscriptionLink(); - const client = new ApolloClient({ - link, - cache: new Cache({ addTypename: false }), + const client = silenceDeprecations("addTypename", () => { + return new ApolloClient({ + link, + cache: new Cache({ addTypename: false }), + }); }); const { rerender } = renderHook( From aeed5c0dc7a636fb9c76e21bb2d8a3327e8c547b Mon Sep 17 00:00:00 2001 From: Jerel Miller Date: Thu, 26 Jun 2025 18:07:13 -0600 Subject: [PATCH 38/43] Stricter type for silenceDeprecations --- src/utilities/deprecation/index.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/utilities/deprecation/index.ts b/src/utilities/deprecation/index.ts index 00fb4707bb8..a8e952cfe77 100644 --- a/src/utilities/deprecation/index.ts +++ b/src/utilities/deprecation/index.ts @@ -9,8 +9,10 @@ type WithValueArgs = [ thisArg?: TThis | undefined, ]; +type DeprecationName = "addTypename" | "canonizeResults" | "connectToDevTools"; + export function silenceDeprecations( - name: string | string[], + name: DeprecationName | DeprecationName[], ...args: WithValueArgs ) { const keys = Array.isArray(name) ? name : [name]; From 3fb530f7254ca09773e26925862d08ba12332554 Mon Sep 17 00:00:00 2001 From: Jerel Miller Date: Thu, 26 Jun 2025 18:08:56 -0600 Subject: [PATCH 39/43] Rename to muteDeprecations --- src/cache/core/cache.ts | 10 +++++----- src/cache/inmemory/inMemoryCache.ts | 6 ++---- src/core/QueryInfo.ts | 6 +++--- src/core/QueryManager.ts | 4 ++-- src/core/__tests__/ObservableQuery.ts | 8 ++++---- src/react/hooks/__tests__/useSubscription.test.tsx | 10 +++++----- src/react/hooks/useBackgroundQuery.ts | 4 ++-- src/react/hooks/useFragment.ts | 6 +++--- src/react/hooks/useLoadableQuery.ts | 4 ++-- src/react/hooks/useQuery.ts | 4 ++-- src/react/hooks/useSuspenseQuery.ts | 4 ++-- src/react/query-preloader/createQueryPreloader.ts | 4 ++-- src/testing/react/MockedProvider.tsx | 4 ++-- src/utilities/deprecation/index.ts | 2 +- 14 files changed, 37 insertions(+), 39 deletions(-) diff --git a/src/cache/core/cache.ts b/src/cache/core/cache.ts index d73b8573343..e49feefe075 100644 --- a/src/cache/core/cache.ts +++ b/src/cache/core/cache.ts @@ -37,7 +37,7 @@ import type { Unmasked, } from "../../masking/index.js"; import { - silenceDeprecations, + muteDeprecations, warnRemovedOption, } from "../../utilities/deprecation/index.js"; @@ -247,7 +247,7 @@ export abstract class ApolloCache implements DataProxy { warnRemovedOption(options, "canonizeResults", "cache.readQuery"); } - return silenceDeprecations("canonizeResults", () => + return muteDeprecations("canonizeResults", () => this.read({ ...options, rootId: options.id || "ROOT_QUERY", @@ -362,7 +362,7 @@ export abstract class ApolloCache implements DataProxy { warnRemovedOption(options, "canonizeResults", "cache.readFragment"); } - return silenceDeprecations("canonizeResults", () => + return muteDeprecations("canonizeResults", () => this.read({ ...options, query: this.getFragmentDoc(options.fragment, options.fragmentName), @@ -411,7 +411,7 @@ export abstract class ApolloCache implements DataProxy { return this.batch({ update(cache) { - const value = silenceDeprecations("canonizeResults", () => + const value = muteDeprecations("canonizeResults", () => cache.readQuery(options) ); const data = update(value); @@ -432,7 +432,7 @@ export abstract class ApolloCache implements DataProxy { return this.batch({ update(cache) { - const value = silenceDeprecations("canonizeResults", () => + const value = muteDeprecations("canonizeResults", () => cache.readFragment(options) ); const data = update(value); diff --git a/src/cache/inmemory/inMemoryCache.ts b/src/cache/inmemory/inMemoryCache.ts index 5d99b5d0688..bf85537e70b 100644 --- a/src/cache/inmemory/inMemoryCache.ts +++ b/src/cache/inmemory/inMemoryCache.ts @@ -36,7 +36,7 @@ import type { OperationVariables } from "../../core/index.js"; import { getInMemoryCacheMemoryInternals } from "../../utilities/caching/getMemoryInternals.js"; import { __esDecorate } from "tslib"; import { - silenceDeprecations, + muteDeprecations, warnRemovedOption, } from "../../utilities/deprecation/index.js"; @@ -606,9 +606,7 @@ export class InMemoryCache extends ApolloCache { // object, and without having to enumerate the relevant properties (query, // variables, etc.) explicitly. There will be some additional properties // (lastDiff, callback, etc.), but cache.diff ignores them. - const diff = silenceDeprecations("canonizeResults", () => - this.diff(c) - ); + const diff = muteDeprecations("canonizeResults", () => this.diff(c)); if (options) { if (c.optimistic && typeof options.optimistic === "string") { diff --git a/src/core/QueryInfo.ts b/src/core/QueryInfo.ts index e124a6f1677..3118229fe95 100644 --- a/src/core/QueryInfo.ts +++ b/src/core/QueryInfo.ts @@ -16,7 +16,7 @@ import { NetworkStatus } from "./networkStatus.js"; import type { ApolloError } from "../errors/index.js"; import type { QueryManager } from "./QueryManager.js"; import type { Unmasked } from "../masking/index.js"; -import { silenceDeprecations } from "../utilities/deprecation/index.js"; +import { muteDeprecations } from "../utilities/deprecation/index.js"; export type QueryStoreValue = Pick< QueryInfo, @@ -161,7 +161,7 @@ export class QueryInfo { return { complete: false }; } - const diff = silenceDeprecations("canonizeResults", () => + const diff = muteDeprecations("canonizeResults", () => this.cache.diff(options) ); this.updateLastDiff(diff, options); @@ -397,7 +397,7 @@ export class QueryInfo { } const diffOptions = this.getDiffOptions(options.variables); - const diff = silenceDeprecations("canonizeResults", () => + const diff = muteDeprecations("canonizeResults", () => cache.diff(diffOptions) ); diff --git a/src/core/QueryManager.ts b/src/core/QueryManager.ts index 27eafb5e468..429fef6194c 100644 --- a/src/core/QueryManager.ts +++ b/src/core/QueryManager.ts @@ -110,7 +110,7 @@ import { Trie } from "@wry/trie"; import { AutoCleanedWeakCache, cacheSizes } from "../utilities/index.js"; import { maskFragment, maskOperation } from "../masking/index.js"; import type { MaybeMasked, Unmasked } from "../masking/index.js"; -import { silenceDeprecations } from "../utilities/deprecation/index.js"; +import { muteDeprecations } from "../utilities/deprecation/index.js"; interface MaskFragmentOptions { fragment: DocumentNode; @@ -1546,7 +1546,7 @@ export class QueryManager { // queries, even the QueryOptions ones. if (onQueryUpdated) { if (!diff) { - diff = silenceDeprecations("canonizeResults", () => + diff = muteDeprecations("canonizeResults", () => this.cache.diff(oq["queryInfo"]["getDiffOptions"]()) ); } diff --git a/src/core/__tests__/ObservableQuery.ts b/src/core/__tests__/ObservableQuery.ts index d95d858b28c..98e1e002cb0 100644 --- a/src/core/__tests__/ObservableQuery.ts +++ b/src/core/__tests__/ObservableQuery.ts @@ -27,7 +27,7 @@ import { expectTypeOf } from "expect-type"; import { SubscriptionObserver } from "zen-observable-ts"; import { waitFor } from "@testing-library/react"; import { ObservableStream, spyOnConsole } from "../../testing/internal"; -import { silenceDeprecations } from "../../utilities/deprecation"; +import { muteDeprecations } from "../../utilities/deprecation"; export const mockFetchQuery = (queryManager: QueryManager) => { const fetchConcastWithInfo = queryManager["fetchConcastWithInfo"]; @@ -1772,7 +1772,7 @@ describe("ObservableQuery", () => { }; } - const client = silenceDeprecations("addTypename", () => { + const client = muteDeprecations("addTypename", () => { return new ApolloClient({ cache: new InMemoryCache({ addTypename: false }), link: new MockLink([makeMock("a", "b", "c"), makeMock("d", "e")]), @@ -1860,7 +1860,7 @@ describe("ObservableQuery", () => { const mocks = [makeMock("a", "b", "c"), makeMock("d", "e")]; const firstRequest = mocks[0].request; - const client = silenceDeprecations("addTypename", () => { + const client = muteDeprecations("addTypename", () => { return new ApolloClient({ cache: new InMemoryCache({ addTypename: false }), link: new MockLink(mocks, true, { showWarnings: false }), @@ -1957,7 +1957,7 @@ describe("ObservableQuery", () => { }; } - const client = silenceDeprecations("addTypename", () => { + const client = muteDeprecations("addTypename", () => { return new ApolloClient({ cache: new InMemoryCache({ addTypename: false }), link: new MockLink([makeMock("a", "b", "c"), makeMock("d", "e")]), diff --git a/src/react/hooks/__tests__/useSubscription.test.tsx b/src/react/hooks/__tests__/useSubscription.test.tsx index 090d41c02b2..28a535a887b 100644 --- a/src/react/hooks/__tests__/useSubscription.test.tsx +++ b/src/react/hooks/__tests__/useSubscription.test.tsx @@ -26,7 +26,7 @@ import { disableActEnvironment, renderHookToSnapshotStream, } from "@testing-library/react-render-stream"; -import { silenceDeprecations } from "../../../utilities/deprecation"; +import { muteDeprecations } from "../../../utilities/deprecation"; const IS_REACT_17 = React.version.startsWith("17"); @@ -745,7 +745,7 @@ describe("useSubscription Hook", () => { `; const link = new MockSubscriptionLink(); - const client = silenceDeprecations("addTypename", () => { + const client = muteDeprecations("addTypename", () => { return new ApolloClient({ link, cache: new Cache({ addTypename: false }), @@ -877,7 +877,7 @@ describe("useSubscription Hook", () => { `; const link = new MockSubscriptionLink(); - const client = silenceDeprecations("addTypename", () => { + const client = muteDeprecations("addTypename", () => { return new ApolloClient({ link, cache: new Cache({ addTypename: false }), @@ -912,7 +912,7 @@ describe("useSubscription Hook", () => { `; const link = new MockSubscriptionLink(); - const client = silenceDeprecations("addTypename", () => { + const client = muteDeprecations("addTypename", () => { return new ApolloClient({ link, cache: new Cache({ addTypename: false }), @@ -1048,7 +1048,7 @@ describe("useSubscription Hook", () => { `; const link = new MockSubscriptionLink(); - const client = silenceDeprecations("addTypename", () => { + const client = muteDeprecations("addTypename", () => { return new ApolloClient({ link, cache: new Cache({ addTypename: false }), diff --git a/src/react/hooks/useBackgroundQuery.ts b/src/react/hooks/useBackgroundQuery.ts index 4311b41a382..15b30b11d33 100644 --- a/src/react/hooks/useBackgroundQuery.ts +++ b/src/react/hooks/useBackgroundQuery.ts @@ -22,7 +22,7 @@ import type { FetchMoreFunction, RefetchFunction } from "./useSuspenseQuery.js"; import { canonicalStringify } from "../../cache/index.js"; import type { DeepPartial } from "../../utilities/index.js"; import type { SkipToken } from "./constants.js"; -import { silenceDeprecations } from "../../utilities/deprecation/index.js"; +import { muteDeprecations } from "../../utilities/deprecation/index.js"; export type UseBackgroundQueryResult< TData = unknown, @@ -233,7 +233,7 @@ function useBackgroundQuery_< ...([] as any[]).concat(queryKey), ]; - const queryRef = silenceDeprecations("canonizeResults", () => + const queryRef = muteDeprecations("canonizeResults", () => suspenseCache.getQueryRef(cacheKey, () => client.watchQuery(watchQueryOptions as WatchQueryOptions) ) diff --git a/src/react/hooks/useFragment.ts b/src/react/hooks/useFragment.ts index b8021e07259..cf2a54cbb4a 100644 --- a/src/react/hooks/useFragment.ts +++ b/src/react/hooks/useFragment.ts @@ -19,7 +19,7 @@ import { } from "./internal/index.js"; import equal from "@wry/equality"; import type { FragmentType, MaybeMasked } from "../../masking/index.js"; -import { silenceDeprecations } from "../../utilities/deprecation/index.js"; +import { muteDeprecations } from "../../utilities/deprecation/index.js"; export interface UseFragmentOptions extends Omit< @@ -104,7 +104,7 @@ function useFragment_( } const { cache } = client; - const diff = silenceDeprecations("canonizeResults", () => + const diff = muteDeprecations("canonizeResults", () => cache.diff({ ...stableOptions, returnPartialData: true, @@ -134,7 +134,7 @@ function useFragment_( (forceUpdate) => { let lastTimeout = 0; - const subscription = silenceDeprecations("canonizeResults", () => + const subscription = muteDeprecations("canonizeResults", () => stableOptions.from === null ? null : client.watchFragment(stableOptions).subscribe({ diff --git a/src/react/hooks/useLoadableQuery.ts b/src/react/hooks/useLoadableQuery.ts index be9fa1da493..dfaacf9eb72 100644 --- a/src/react/hooks/useLoadableQuery.ts +++ b/src/react/hooks/useLoadableQuery.ts @@ -33,7 +33,7 @@ import type { OnlyRequiredProperties, } from "../../utilities/index.js"; import { invariant } from "../../utilities/globals/index.js"; -import { silenceDeprecations } from "../../utilities/deprecation/index.js"; +import { muteDeprecations } from "../../utilities/deprecation/index.js"; export type LoadQueryFunction = ( // Use variadic args to handle cases where TVariables is type `never`, in @@ -249,7 +249,7 @@ export function useLoadableQuery< ...([] as any[]).concat(queryKey), ]; - const queryRef = silenceDeprecations("canonizeResults", () => + const queryRef = muteDeprecations("canonizeResults", () => suspenseCache.getQueryRef(cacheKey, () => client.watchQuery({ ...watchQueryOptions, diff --git a/src/react/hooks/useQuery.ts b/src/react/hooks/useQuery.ts index 777f7f496b7..89df4fef4ef 100644 --- a/src/react/hooks/useQuery.ts +++ b/src/react/hooks/useQuery.ts @@ -54,7 +54,7 @@ import { import { useWarnRemovedOption, wrapHook } from "./internal/index.js"; import type { RenderPromises } from "../ssr/RenderPromises.js"; import type { MaybeMasked } from "../../masking/index.js"; -import { silenceDeprecations } from "../../utilities/deprecation/index.js"; +import { muteDeprecations } from "../../utilities/deprecation/index.js"; const { prototype: { hasOwnProperty }, @@ -191,7 +191,7 @@ function useInternalState< (renderPromises && renderPromises.getSSRObservable(makeWatchQueryOptions())) || ObservableQuery["inactiveOnCreation"].withValue(!renderPromises, () => - silenceDeprecations("canonizeResults", () => { + muteDeprecations("canonizeResults", () => { return client.watchQuery( getObsQueryOptions( void 0, diff --git a/src/react/hooks/useSuspenseQuery.ts b/src/react/hooks/useSuspenseQuery.ts index ac0aeb90be8..69f1133683c 100644 --- a/src/react/hooks/useSuspenseQuery.ts +++ b/src/react/hooks/useSuspenseQuery.ts @@ -27,7 +27,7 @@ import { useWarnRemovedOption, wrapHook, } from "./internal/index.js"; -import { silenceDeprecations } from "../../utilities/deprecation/index.js"; +import { muteDeprecations } from "../../utilities/deprecation/index.js"; import { getSuspenseCache } from "../internal/index.js"; import { canonicalStringify } from "../../cache/index.js"; import { skipToken } from "./constants.js"; @@ -217,7 +217,7 @@ function useSuspenseQuery_< ...([] as any[]).concat(queryKey), ]; - const queryRef = silenceDeprecations("canonizeResults", () => + const queryRef = muteDeprecations("canonizeResults", () => suspenseCache.getQueryRef(cacheKey, () => client.watchQuery(watchQueryOptions) ) diff --git a/src/react/query-preloader/createQueryPreloader.ts b/src/react/query-preloader/createQueryPreloader.ts index 08564670254..8f02b75b80c 100644 --- a/src/react/query-preloader/createQueryPreloader.ts +++ b/src/react/query-preloader/createQueryPreloader.ts @@ -18,7 +18,7 @@ import type { PreloadedQueryRef } from "../internal/index.js"; import type { NoInfer, VariablesOption } from "../index.js"; import { wrapHook } from "../hooks/internal/index.js"; import { - silenceDeprecations, + muteDeprecations, warnRemovedOption, } from "../../utilities/deprecation/index.js"; @@ -175,7 +175,7 @@ const _createQueryPreloader: typeof createQueryPreloader = (client) => { ): PreloadedQueryRef { warnRemovedOption(options, "canonizeResults", "preloadQuery"); - const queryRef = silenceDeprecations( + const queryRef = muteDeprecations( "canonizeResults", () => new InternalQueryReference( diff --git a/src/testing/react/MockedProvider.tsx b/src/testing/react/MockedProvider.tsx index 9e707f5c9da..09e640a97e2 100644 --- a/src/testing/react/MockedProvider.tsx +++ b/src/testing/react/MockedProvider.tsx @@ -12,7 +12,7 @@ import type { ApolloCache } from "../../cache/index.js"; import type { DevtoolsOptions } from "../../core/ApolloClient.js"; import { warnRemovedOption, - silenceDeprecations, + muteDeprecations, } from "../../utilities/deprecation/index.js"; export interface MockedProviderProps { @@ -96,7 +96,7 @@ export class MockedProvider extends React.Component< ); } - const client = silenceDeprecations( + const client = muteDeprecations( ["connectToDevTools", "addTypename"], () => new ApolloClient({ diff --git a/src/utilities/deprecation/index.ts b/src/utilities/deprecation/index.ts index a8e952cfe77..9545284f147 100644 --- a/src/utilities/deprecation/index.ts +++ b/src/utilities/deprecation/index.ts @@ -11,7 +11,7 @@ type WithValueArgs = [ type DeprecationName = "addTypename" | "canonizeResults" | "connectToDevTools"; -export function silenceDeprecations( +export function muteDeprecations( name: DeprecationName | DeprecationName[], ...args: WithValueArgs ) { From a7259b6f6037d4ebf72b16bbba117c7c10224e7d Mon Sep 17 00:00:00 2001 From: Jerel Miller Date: Thu, 26 Jun 2025 18:10:07 -0600 Subject: [PATCH 40/43] Inline --- src/utilities/deprecation/index.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/utilities/deprecation/index.ts b/src/utilities/deprecation/index.ts index 9545284f147..7ba465ccfc3 100644 --- a/src/utilities/deprecation/index.ts +++ b/src/utilities/deprecation/index.ts @@ -15,9 +15,7 @@ export function muteDeprecations( name: DeprecationName | DeprecationName[], ...args: WithValueArgs ) { - const keys = Array.isArray(name) ? name : [name]; - - return slot.withValue(keys, ...args); + return slot.withValue(Array.isArray(name) ? name : [name], ...args); } export function warnRemovedOption>( From ce96b10d11946b5475f57e313097e21beec190bb Mon Sep 17 00:00:00 2001 From: Jerel Miller Date: Thu, 26 Jun 2025 18:12:02 -0600 Subject: [PATCH 41/43] Remove rogue import --- src/cache/inmemory/inMemoryCache.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/cache/inmemory/inMemoryCache.ts b/src/cache/inmemory/inMemoryCache.ts index bf85537e70b..9bd7010e556 100644 --- a/src/cache/inmemory/inMemoryCache.ts +++ b/src/cache/inmemory/inMemoryCache.ts @@ -34,7 +34,6 @@ import { Policies } from "./policies.js"; import { hasOwn, normalizeConfig, shouldCanonizeResults } from "./helpers.js"; import type { OperationVariables } from "../../core/index.js"; import { getInMemoryCacheMemoryInternals } from "../../utilities/caching/getMemoryInternals.js"; -import { __esDecorate } from "tslib"; import { muteDeprecations, warnRemovedOption, From c8295cd397820993739420ae705325d6b27ca5f9 Mon Sep 17 00:00:00 2001 From: Jerel Miller Date: Thu, 26 Jun 2025 18:15:37 -0600 Subject: [PATCH 42/43] Add warning for setOptions --- src/core/ObservableQuery.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/core/ObservableQuery.ts b/src/core/ObservableQuery.ts index 889d4501c9b..58a88181044 100644 --- a/src/core/ObservableQuery.ts +++ b/src/core/ObservableQuery.ts @@ -41,6 +41,7 @@ import { equalByQuery } from "./equalByQuery.js"; import type { TODO } from "../utilities/types/TODO.js"; import type { MaybeMasked, Unmasked } from "../masking/index.js"; import { Slot } from "optimism"; +import { warnRemovedOption } from "../utilities/deprecation/index.js"; const { assign, hasOwnProperty } = Object; @@ -690,6 +691,10 @@ Did you mean to call refetch(variables) instead of refetch({ variables })?`, public setOptions( newOptions: Partial> ): Promise>> { + if (__DEV__) { + warnRemovedOption(newOptions, "canonizeResults", "setOptions"); + } + return this.reobserve(newOptions); } From 750d5b72a0ee24258c2510820c34605b1c698b2c Mon Sep 17 00:00:00 2001 From: Jerel Miller Date: Thu, 26 Jun 2025 18:25:23 -0600 Subject: [PATCH 43/43] Rerun api report --- .api-reports/api-report-core.api.md | 4 ++-- .api-reports/api-report-react.api.md | 4 ++-- .api-reports/api-report-react_components.api.md | 4 ++-- .api-reports/api-report-react_context.api.md | 4 ++-- .api-reports/api-report-react_hoc.api.md | 4 ++-- .api-reports/api-report-react_hooks.api.md | 4 ++-- .api-reports/api-report-react_internal.api.md | 4 ++-- .api-reports/api-report-react_ssr.api.md | 4 ++-- .api-reports/api-report-testing.api.md | 4 ++-- .api-reports/api-report-testing_core.api.md | 4 ++-- .api-reports/api-report-utilities.api.md | 4 ++-- .api-reports/api-report.api.md | 4 ++-- 12 files changed, 24 insertions(+), 24 deletions(-) diff --git a/.api-reports/api-report-core.api.md b/.api-reports/api-report-core.api.md index 7ea9161156f..4a20396933e 100644 --- a/.api-reports/api-report-core.api.md +++ b/.api-reports/api-report-core.api.md @@ -2547,8 +2547,8 @@ interface WriteContext extends ReadMergeModifyContext { // src/cache/inmemory/policies.ts:162:3 - (ae-forgotten-export) The symbol "KeySpecifier" needs to be exported by the entry point index.d.ts // src/cache/inmemory/policies.ts:162:3 - (ae-forgotten-export) The symbol "KeyArgsFunction" needs to be exported by the entry point index.d.ts // src/cache/inmemory/types.ts:139:3 - (ae-forgotten-export) The symbol "KeyFieldsFunction" needs to be exported by the entry point index.d.ts -// src/core/ObservableQuery.ts:128:5 - (ae-forgotten-export) The symbol "QueryManager" needs to be exported by the entry point index.d.ts -// src/core/ObservableQuery.ts:129:5 - (ae-forgotten-export) The symbol "QueryInfo" needs to be exported by the entry point index.d.ts +// src/core/ObservableQuery.ts:129:5 - (ae-forgotten-export) The symbol "QueryManager" needs to be exported by the entry point index.d.ts +// src/core/ObservableQuery.ts:130:5 - (ae-forgotten-export) The symbol "QueryInfo" needs to be exported by the entry point index.d.ts // src/core/QueryManager.ts:160:5 - (ae-forgotten-export) The symbol "MutationStoreValue" needs to be exported by the entry point index.d.ts // src/core/QueryManager.ts:415:7 - (ae-forgotten-export) The symbol "UpdateQueries" 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 diff --git a/.api-reports/api-report-react.api.md b/.api-reports/api-report-react.api.md index 2cce6cbc604..b1eb9c01ccf 100644 --- a/.api-reports/api-report-react.api.md +++ b/.api-reports/api-report-react.api.md @@ -2604,8 +2604,8 @@ interface WatchQueryOptions(inter // src/cache/core/types/common.ts:104:3 - (ae-forgotten-export) The symbol "ToReferenceFunction" needs to be exported by the entry point index.d.ts // src/cache/core/types/common.ts:105:3 - (ae-forgotten-export) The symbol "StorageType" needs to be exported by the entry point index.d.ts // src/core/LocalState.ts:46:5 - (ae-forgotten-export) The symbol "FragmentMap" needs to be exported by the entry point index.d.ts -// src/core/ObservableQuery.ts:128:5 - (ae-forgotten-export) The symbol "QueryManager" needs to be exported by the entry point index.d.ts -// src/core/ObservableQuery.ts:129:5 - (ae-forgotten-export) The symbol "QueryInfo" needs to be exported by the entry point index.d.ts +// src/core/ObservableQuery.ts:129:5 - (ae-forgotten-export) The symbol "QueryManager" needs to be exported by the entry point index.d.ts +// src/core/ObservableQuery.ts:130:5 - (ae-forgotten-export) The symbol "QueryInfo" needs to be exported by the entry point index.d.ts // src/core/QueryManager.ts:160:5 - (ae-forgotten-export) The symbol "MutationStoreValue" needs to be exported by the entry point index.d.ts // src/core/QueryManager.ts:415:7 - (ae-forgotten-export) The symbol "UpdateQueries" needs to be exported by the entry point index.d.ts // src/core/types.ts:172:3 - (ae-forgotten-export) The symbol "MutationQueryReducer" needs to be exported by the entry point index.d.ts diff --git a/.api-reports/api-report-react_ssr.api.md b/.api-reports/api-report-react_ssr.api.md index 7c4cc86dee8..83208cda7af 100644 --- a/.api-reports/api-report-react_ssr.api.md +++ b/.api-reports/api-report-react_ssr.api.md @@ -1958,8 +1958,8 @@ interface WatchQueryOptions(it: (...args: TArgs // src/cache/core/types/common.ts:104:3 - (ae-forgotten-export) The symbol "ToReferenceFunction" needs to be exported by the entry point index.d.ts // src/cache/core/types/common.ts:105:3 - (ae-forgotten-export) The symbol "StorageType" needs to be exported by the entry point index.d.ts // src/core/LocalState.ts:46:5 - (ae-forgotten-export) The symbol "FragmentMap" needs to be exported by the entry point index.d.ts -// src/core/ObservableQuery.ts:128:5 - (ae-forgotten-export) The symbol "QueryManager" needs to be exported by the entry point index.d.ts -// src/core/ObservableQuery.ts:129:5 - (ae-forgotten-export) The symbol "QueryInfo" needs to be exported by the entry point index.d.ts +// src/core/ObservableQuery.ts:129:5 - (ae-forgotten-export) The symbol "QueryManager" needs to be exported by the entry point index.d.ts +// src/core/ObservableQuery.ts:130:5 - (ae-forgotten-export) The symbol "QueryInfo" needs to be exported by the entry point index.d.ts // src/core/QueryManager.ts:160:5 - (ae-forgotten-export) The symbol "MutationStoreValue" needs to be exported by the entry point index.d.ts // src/core/QueryManager.ts:415:7 - (ae-forgotten-export) The symbol "UpdateQueries" needs to be exported by the entry point index.d.ts // src/core/types.ts:172:3 - (ae-forgotten-export) The symbol "MutationQueryReducer" needs to be exported by the entry point index.d.ts diff --git a/.api-reports/api-report-testing_core.api.md b/.api-reports/api-report-testing_core.api.md index ac4f66d83e7..e4f434f086d 100644 --- a/.api-reports/api-report-testing_core.api.md +++ b/.api-reports/api-report-testing_core.api.md @@ -1974,8 +1974,8 @@ export function withWarningSpy(it: (...args: TArgs // src/cache/core/types/common.ts:104:3 - (ae-forgotten-export) The symbol "ToReferenceFunction" needs to be exported by the entry point index.d.ts // src/cache/core/types/common.ts:105:3 - (ae-forgotten-export) The symbol "StorageType" needs to be exported by the entry point index.d.ts // src/core/LocalState.ts:46:5 - (ae-forgotten-export) The symbol "FragmentMap" needs to be exported by the entry point index.d.ts -// src/core/ObservableQuery.ts:128:5 - (ae-forgotten-export) The symbol "QueryManager" needs to be exported by the entry point index.d.ts -// src/core/ObservableQuery.ts:129:5 - (ae-forgotten-export) The symbol "QueryInfo" needs to be exported by the entry point index.d.ts +// src/core/ObservableQuery.ts:129:5 - (ae-forgotten-export) The symbol "QueryManager" needs to be exported by the entry point index.d.ts +// src/core/ObservableQuery.ts:130:5 - (ae-forgotten-export) The symbol "QueryInfo" needs to be exported by the entry point index.d.ts // src/core/QueryManager.ts:160:5 - (ae-forgotten-export) The symbol "MutationStoreValue" needs to be exported by the entry point index.d.ts // src/core/QueryManager.ts:415:7 - (ae-forgotten-export) The symbol "UpdateQueries" needs to be exported by the entry point index.d.ts // src/core/types.ts:172:3 - (ae-forgotten-export) The symbol "MutationQueryReducer" needs to be exported by the entry point index.d.ts diff --git a/.api-reports/api-report-utilities.api.md b/.api-reports/api-report-utilities.api.md index 4ae8363f916..5cec109b104 100644 --- a/.api-reports/api-report-utilities.api.md +++ b/.api-reports/api-report-utilities.api.md @@ -2919,8 +2919,8 @@ interface WriteContext extends ReadMergeModifyContext { // src/cache/inmemory/types.ts:139: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:128:5 - (ae-forgotten-export) The symbol "QueryManager" needs to be exported by the entry point index.d.ts -// src/core/ObservableQuery.ts:129:5 - (ae-forgotten-export) The symbol "QueryInfo" needs to be exported by the entry point index.d.ts +// src/core/ObservableQuery.ts:129:5 - (ae-forgotten-export) The symbol "QueryManager" needs to be exported by the entry point index.d.ts +// src/core/ObservableQuery.ts:130:5 - (ae-forgotten-export) The symbol "QueryInfo" needs to be exported by the entry point index.d.ts // src/core/QueryManager.ts:160:5 - (ae-forgotten-export) The symbol "MutationStoreValue" needs to be exported by the entry point index.d.ts // src/core/QueryManager.ts:415:7 - (ae-forgotten-export) The symbol "UpdateQueries" needs to be exported by the entry point index.d.ts // src/core/types.ts:172:3 - (ae-forgotten-export) The symbol "MutationQueryReducer" needs to be exported by the entry point index.d.ts diff --git a/.api-reports/api-report.api.md b/.api-reports/api-report.api.md index 2b38db0fa12..0a3cbd62c30 100644 --- a/.api-reports/api-report.api.md +++ b/.api-reports/api-report.api.md @@ -3293,8 +3293,8 @@ interface WriteContext extends ReadMergeModifyContext { // src/cache/inmemory/policies.ts:162:3 - (ae-forgotten-export) The symbol "KeySpecifier" needs to be exported by the entry point index.d.ts // src/cache/inmemory/policies.ts:162:3 - (ae-forgotten-export) The symbol "KeyArgsFunction" needs to be exported by the entry point index.d.ts // src/cache/inmemory/types.ts:139:3 - (ae-forgotten-export) The symbol "KeyFieldsFunction" needs to be exported by the entry point index.d.ts -// src/core/ObservableQuery.ts:128:5 - (ae-forgotten-export) The symbol "QueryManager" needs to be exported by the entry point index.d.ts -// src/core/ObservableQuery.ts:129:5 - (ae-forgotten-export) The symbol "QueryInfo" needs to be exported by the entry point index.d.ts +// src/core/ObservableQuery.ts:129:5 - (ae-forgotten-export) The symbol "QueryManager" needs to be exported by the entry point index.d.ts +// src/core/ObservableQuery.ts:130:5 - (ae-forgotten-export) The symbol "QueryInfo" needs to be exported by the entry point index.d.ts // src/core/QueryManager.ts:160:5 - (ae-forgotten-export) The symbol "MutationStoreValue" needs to be exported by the entry point index.d.ts // src/core/QueryManager.ts:415:7 - (ae-forgotten-export) The symbol "UpdateQueries" 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