From 1f0460a60fc613e8d6f218a74ded69e81e960791 Mon Sep 17 00:00:00 2001 From: Jerel Miller Date: Thu, 27 Jun 2024 13:52:18 -0600 Subject: [PATCH] Allow `undefined` as return value from `cache.modify` modifier function (#11911) --- .api-reports/api-report-cache.api.md | 2 +- .api-reports/api-report-core.api.md | 2 +- .api-reports/api-report-react.api.md | 2 +- .api-reports/api-report-react_components.api.md | 2 +- .api-reports/api-report-react_context.api.md | 2 +- .api-reports/api-report-react_hoc.api.md | 2 +- .api-reports/api-report-react_hooks.api.md | 2 +- .api-reports/api-report-react_internal.api.md | 2 +- .api-reports/api-report-react_ssr.api.md | 2 +- .api-reports/api-report-testing.api.md | 2 +- .api-reports/api-report-testing_core.api.md | 2 +- .api-reports/api-report-utilities.api.md | 2 +- .api-reports/api-report.api.md | 2 +- .changeset/breezy-points-carry.md | 5 +++++ .size-limits.json | 2 +- src/cache/core/__tests__/cache.ts | 12 ++++++++++++ src/cache/core/types/common.ts | 2 +- 17 files changed, 32 insertions(+), 15 deletions(-) create mode 100644 .changeset/breezy-points-carry.md diff --git a/.api-reports/api-report-cache.api.md b/.api-reports/api-report-cache.api.md index 0f075697b78..30ec666b306 100644 --- a/.api-reports/api-report-cache.api.md +++ b/.api-reports/api-report-cache.api.md @@ -741,7 +741,7 @@ export type MissingTree = string | { // Warning: (ae-forgotten-export) The symbol "InvalidateModifier" needs to be exported by the entry point index.d.ts // // @public (undocumented) -export type Modifier = (value: T, details: ModifierDetails) => T | DeleteModifier | InvalidateModifier; +export type Modifier = (value: T, details: ModifierDetails) => T | DeleteModifier | InvalidateModifier | undefined; // @public (undocumented) export type ModifierDetails = { diff --git a/.api-reports/api-report-core.api.md b/.api-reports/api-report-core.api.md index 10908320829..de8b71f9153 100644 --- a/.api-reports/api-report-core.api.md +++ b/.api-reports/api-report-core.api.md @@ -1354,7 +1354,7 @@ type MissingTree = string | { // Warning: (ae-forgotten-export) The symbol "InvalidateModifier" needs to be exported by the entry point index.d.ts // // @public (undocumented) -type Modifier = (value: T, details: ModifierDetails) => T | DeleteModifier | InvalidateModifier; +type Modifier = (value: T, details: ModifierDetails) => T | DeleteModifier | InvalidateModifier | undefined; // @public (undocumented) type ModifierDetails = { diff --git a/.api-reports/api-report-react.api.md b/.api-reports/api-report-react.api.md index 2cca5fc273d..74721b26f76 100644 --- a/.api-reports/api-report-react.api.md +++ b/.api-reports/api-report-react.api.md @@ -1078,7 +1078,7 @@ type MissingTree = string | { // Warning: (ae-forgotten-export) The symbol "InvalidateModifier" needs to be exported by the entry point index.d.ts // // @public (undocumented) -type Modifier = (value: T, details: ModifierDetails) => T | DeleteModifier | InvalidateModifier; +type Modifier = (value: T, details: ModifierDetails) => T | DeleteModifier | InvalidateModifier | undefined; // @public (undocumented) type ModifierDetails = { diff --git a/.api-reports/api-report-react_components.api.md b/.api-reports/api-report-react_components.api.md index 6836aa12fc6..b9bd5eda67e 100644 --- a/.api-reports/api-report-react_components.api.md +++ b/.api-reports/api-report-react_components.api.md @@ -938,7 +938,7 @@ type MissingTree = string | { // Warning: (ae-forgotten-export) The symbol "InvalidateModifier" needs to be exported by the entry point index.d.ts // // @public (undocumented) -type Modifier = (value: T, details: ModifierDetails) => T | DeleteModifier | InvalidateModifier; +type Modifier = (value: T, details: ModifierDetails) => T | DeleteModifier | InvalidateModifier | undefined; // @public (undocumented) type ModifierDetails = { diff --git a/.api-reports/api-report-react_context.api.md b/.api-reports/api-report-react_context.api.md index 38e7ead74f0..bc1878779ad 100644 --- a/.api-reports/api-report-react_context.api.md +++ b/.api-reports/api-report-react_context.api.md @@ -939,7 +939,7 @@ type MissingTree = string | { // Warning: (ae-forgotten-export) The symbol "InvalidateModifier" needs to be exported by the entry point index.d.ts // // @public (undocumented) -type Modifier = (value: T, details: ModifierDetails) => T | DeleteModifier | InvalidateModifier; +type Modifier = (value: T, details: ModifierDetails) => T | DeleteModifier | InvalidateModifier | undefined; // @public (undocumented) type ModifierDetails = { diff --git a/.api-reports/api-report-react_hoc.api.md b/.api-reports/api-report-react_hoc.api.md index 0a317833d96..a5cf57a3c8d 100644 --- a/.api-reports/api-report-react_hoc.api.md +++ b/.api-reports/api-report-react_hoc.api.md @@ -946,7 +946,7 @@ type MissingTree = string | { // Warning: (ae-forgotten-export) The symbol "InvalidateModifier" needs to be exported by the entry point index.d.ts // // @public (undocumented) -type Modifier = (value: T, details: ModifierDetails) => T | DeleteModifier | InvalidateModifier; +type Modifier = (value: T, details: ModifierDetails) => T | DeleteModifier | InvalidateModifier | undefined; // @public (undocumented) type ModifierDetails = { diff --git a/.api-reports/api-report-react_hooks.api.md b/.api-reports/api-report-react_hooks.api.md index 5be79349a8d..9a8d8096055 100644 --- a/.api-reports/api-report-react_hooks.api.md +++ b/.api-reports/api-report-react_hooks.api.md @@ -1027,7 +1027,7 @@ type MissingTree = string | { // Warning: (ae-forgotten-export) The symbol "InvalidateModifier" needs to be exported by the entry point index.d.ts // // @public (undocumented) -type Modifier = (value: T, details: ModifierDetails) => T | DeleteModifier | InvalidateModifier; +type Modifier = (value: T, details: ModifierDetails) => T | DeleteModifier | InvalidateModifier | undefined; // @public (undocumented) type ModifierDetails = { diff --git a/.api-reports/api-report-react_internal.api.md b/.api-reports/api-report-react_internal.api.md index f5105f59ccf..0a95e96c2d2 100644 --- a/.api-reports/api-report-react_internal.api.md +++ b/.api-reports/api-report-react_internal.api.md @@ -1035,7 +1035,7 @@ type MissingTree = string | { // Warning: (ae-forgotten-export) The symbol "InvalidateModifier" needs to be exported by the entry point index.d.ts // // @public (undocumented) -type Modifier = (value: T, details: ModifierDetails) => T | DeleteModifier | InvalidateModifier; +type Modifier = (value: T, details: ModifierDetails) => T | DeleteModifier | InvalidateModifier | undefined; // @public (undocumented) type ModifierDetails = { diff --git a/.api-reports/api-report-react_ssr.api.md b/.api-reports/api-report-react_ssr.api.md index bb7ff99d0c7..f4ca55a6daf 100644 --- a/.api-reports/api-report-react_ssr.api.md +++ b/.api-reports/api-report-react_ssr.api.md @@ -924,7 +924,7 @@ type MissingTree = string | { // Warning: (ae-forgotten-export) The symbol "InvalidateModifier" needs to be exported by the entry point index.d.ts // // @public (undocumented) -type Modifier = (value: T, details: ModifierDetails) => T | DeleteModifier | InvalidateModifier; +type Modifier = (value: T, details: ModifierDetails) => T | DeleteModifier | InvalidateModifier | undefined; // @public (undocumented) type ModifierDetails = { diff --git a/.api-reports/api-report-testing.api.md b/.api-reports/api-report-testing.api.md index 8d6b8afd6b7..c147f00f820 100644 --- a/.api-reports/api-report-testing.api.md +++ b/.api-reports/api-report-testing.api.md @@ -1045,7 +1045,7 @@ export class MockSubscriptionLink extends ApolloLink { // Warning: (ae-forgotten-export) The symbol "InvalidateModifier" needs to be exported by the entry point index.d.ts // // @public (undocumented) -type Modifier = (value: T, details: ModifierDetails) => T | DeleteModifier | InvalidateModifier; +type Modifier = (value: T, details: ModifierDetails) => T | DeleteModifier | InvalidateModifier | undefined; // @public (undocumented) type ModifierDetails = { diff --git a/.api-reports/api-report-testing_core.api.md b/.api-reports/api-report-testing_core.api.md index ea769454e5a..1cbfc54605f 100644 --- a/.api-reports/api-report-testing_core.api.md +++ b/.api-reports/api-report-testing_core.api.md @@ -1000,7 +1000,7 @@ export class MockSubscriptionLink extends ApolloLink { // Warning: (ae-forgotten-export) The symbol "InvalidateModifier" needs to be exported by the entry point index.d.ts // // @public (undocumented) -type Modifier = (value: T, details: ModifierDetails) => T | DeleteModifier | InvalidateModifier; +type Modifier = (value: T, details: ModifierDetails) => T | DeleteModifier | InvalidateModifier | undefined; // @public (undocumented) type ModifierDetails = { diff --git a/.api-reports/api-report-utilities.api.md b/.api-reports/api-report-utilities.api.md index 52f9e3225b1..c53a249f699 100644 --- a/.api-reports/api-report-utilities.api.md +++ b/.api-reports/api-report-utilities.api.md @@ -1648,7 +1648,7 @@ type MissingTree = string | { // Warning: (ae-forgotten-export) The symbol "InvalidateModifier" needs to be exported by the entry point index.d.ts // // @public (undocumented) -type Modifier = (value: T, details: ModifierDetails) => T | DeleteModifier | InvalidateModifier; +type Modifier = (value: T, details: ModifierDetails) => T | DeleteModifier | InvalidateModifier | undefined; // @public (undocumented) type ModifierDetails = { diff --git a/.api-reports/api-report.api.md b/.api-reports/api-report.api.md index 8f968187dcf..95cc0a4694b 100644 --- a/.api-reports/api-report.api.md +++ b/.api-reports/api-report.api.md @@ -1532,7 +1532,7 @@ type MissingTree = string | { // Warning: (ae-forgotten-export) The symbol "InvalidateModifier" needs to be exported by the entry point index.d.ts // // @public (undocumented) -type Modifier = (value: T, details: ModifierDetails) => T | DeleteModifier | InvalidateModifier; +type Modifier = (value: T, details: ModifierDetails) => T | DeleteModifier | InvalidateModifier | undefined; // @public (undocumented) type ModifierDetails = { diff --git a/.changeset/breezy-points-carry.md b/.changeset/breezy-points-carry.md new file mode 100644 index 00000000000..6b1e19ab1a2 --- /dev/null +++ b/.changeset/breezy-points-carry.md @@ -0,0 +1,5 @@ +--- +"@apollo/client": patch +--- + +Allow `undefined` to be returned from a `cache.modify` modifier function when a generic type argument is used. diff --git a/.size-limits.json b/.size-limits.json index 09bf55362fa..b13d95f84a8 100644 --- a/.size-limits.json +++ b/.size-limits.json @@ -1,4 +1,4 @@ { - "dist/apollo-client.min.cjs": 39604, + "dist/apollo-client.min.cjs": 39605, "import { ApolloClient, InMemoryCache, HttpLink } from \"dist/index.js\" (production)": 32852 } diff --git a/src/cache/core/__tests__/cache.ts b/src/cache/core/__tests__/cache.ts index 6ca7e77e8b6..e56a6b0621f 100644 --- a/src/cache/core/__tests__/cache.ts +++ b/src/cache/core/__tests__/cache.ts @@ -505,5 +505,17 @@ describe.skip("Cache type tests", () => { }, }); }); + + test("allows undefined as return value", () => { + const cache = new TestCache(); + cache.modify<{ foo: string }>({ + id: "foo", + fields: { + foo: () => undefined, + // @ts-expect-error needs return statement + bar: () => {}, + }, + }); + }); }); }); diff --git a/src/cache/core/types/common.ts b/src/cache/core/types/common.ts index 886ccb63458..30fca541a9e 100644 --- a/src/cache/core/types/common.ts +++ b/src/cache/core/types/common.ts @@ -107,7 +107,7 @@ export type ModifierDetails = { export type Modifier = ( value: T, details: ModifierDetails -) => T | DeleteModifier | InvalidateModifier; +) => T | DeleteModifier | InvalidateModifier | undefined; type StoreObjectValueMaybeReference = StoreVal extends Array> ?