Skip to content

Commit

Permalink
Allow undefined as return value from cache.modify modifier functi…
Browse files Browse the repository at this point in the history
…on (#11911)
  • Loading branch information
jerelmiller authored Jun 27, 2024
1 parent 7111de2 commit 1f0460a
Show file tree
Hide file tree
Showing 17 changed files with 32 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .api-reports/api-report-cache.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> = (value: T, details: ModifierDetails) => T | DeleteModifier | InvalidateModifier;
export type Modifier<T> = (value: T, details: ModifierDetails) => T | DeleteModifier | InvalidateModifier | undefined;

// @public (undocumented)
export type ModifierDetails = {
Expand Down
2 changes: 1 addition & 1 deletion .api-reports/api-report-core.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> = (value: T, details: ModifierDetails) => T | DeleteModifier | InvalidateModifier;
type Modifier<T> = (value: T, details: ModifierDetails) => T | DeleteModifier | InvalidateModifier | undefined;

// @public (undocumented)
type ModifierDetails = {
Expand Down
2 changes: 1 addition & 1 deletion .api-reports/api-report-react.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> = (value: T, details: ModifierDetails) => T | DeleteModifier | InvalidateModifier;
type Modifier<T> = (value: T, details: ModifierDetails) => T | DeleteModifier | InvalidateModifier | undefined;

// @public (undocumented)
type ModifierDetails = {
Expand Down
2 changes: 1 addition & 1 deletion .api-reports/api-report-react_components.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> = (value: T, details: ModifierDetails) => T | DeleteModifier | InvalidateModifier;
type Modifier<T> = (value: T, details: ModifierDetails) => T | DeleteModifier | InvalidateModifier | undefined;

// @public (undocumented)
type ModifierDetails = {
Expand Down
2 changes: 1 addition & 1 deletion .api-reports/api-report-react_context.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> = (value: T, details: ModifierDetails) => T | DeleteModifier | InvalidateModifier;
type Modifier<T> = (value: T, details: ModifierDetails) => T | DeleteModifier | InvalidateModifier | undefined;

// @public (undocumented)
type ModifierDetails = {
Expand Down
2 changes: 1 addition & 1 deletion .api-reports/api-report-react_hoc.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> = (value: T, details: ModifierDetails) => T | DeleteModifier | InvalidateModifier;
type Modifier<T> = (value: T, details: ModifierDetails) => T | DeleteModifier | InvalidateModifier | undefined;

// @public (undocumented)
type ModifierDetails = {
Expand Down
2 changes: 1 addition & 1 deletion .api-reports/api-report-react_hooks.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> = (value: T, details: ModifierDetails) => T | DeleteModifier | InvalidateModifier;
type Modifier<T> = (value: T, details: ModifierDetails) => T | DeleteModifier | InvalidateModifier | undefined;

// @public (undocumented)
type ModifierDetails = {
Expand Down
2 changes: 1 addition & 1 deletion .api-reports/api-report-react_internal.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> = (value: T, details: ModifierDetails) => T | DeleteModifier | InvalidateModifier;
type Modifier<T> = (value: T, details: ModifierDetails) => T | DeleteModifier | InvalidateModifier | undefined;

// @public (undocumented)
type ModifierDetails = {
Expand Down
2 changes: 1 addition & 1 deletion .api-reports/api-report-react_ssr.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> = (value: T, details: ModifierDetails) => T | DeleteModifier | InvalidateModifier;
type Modifier<T> = (value: T, details: ModifierDetails) => T | DeleteModifier | InvalidateModifier | undefined;

// @public (undocumented)
type ModifierDetails = {
Expand Down
2 changes: 1 addition & 1 deletion .api-reports/api-report-testing.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> = (value: T, details: ModifierDetails) => T | DeleteModifier | InvalidateModifier;
type Modifier<T> = (value: T, details: ModifierDetails) => T | DeleteModifier | InvalidateModifier | undefined;

// @public (undocumented)
type ModifierDetails = {
Expand Down
2 changes: 1 addition & 1 deletion .api-reports/api-report-testing_core.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> = (value: T, details: ModifierDetails) => T | DeleteModifier | InvalidateModifier;
type Modifier<T> = (value: T, details: ModifierDetails) => T | DeleteModifier | InvalidateModifier | undefined;

// @public (undocumented)
type ModifierDetails = {
Expand Down
2 changes: 1 addition & 1 deletion .api-reports/api-report-utilities.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> = (value: T, details: ModifierDetails) => T | DeleteModifier | InvalidateModifier;
type Modifier<T> = (value: T, details: ModifierDetails) => T | DeleteModifier | InvalidateModifier | undefined;

// @public (undocumented)
type ModifierDetails = {
Expand Down
2 changes: 1 addition & 1 deletion .api-reports/api-report.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> = (value: T, details: ModifierDetails) => T | DeleteModifier | InvalidateModifier;
type Modifier<T> = (value: T, details: ModifierDetails) => T | DeleteModifier | InvalidateModifier | undefined;

// @public (undocumented)
type ModifierDetails = {
Expand Down
5 changes: 5 additions & 0 deletions .changeset/breezy-points-carry.md
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 1 addition & 1 deletion .size-limits.json
Original file line number Diff line number Diff line change
@@ -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
}
12 changes: 12 additions & 0 deletions src/cache/core/__tests__/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: () => {},
},
});
});
});
});
2 changes: 1 addition & 1 deletion src/cache/core/types/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export type ModifierDetails = {
export type Modifier<T> = (
value: T,
details: ModifierDetails
) => T | DeleteModifier | InvalidateModifier;
) => T | DeleteModifier | InvalidateModifier | undefined;

type StoreObjectValueMaybeReference<StoreVal> =
StoreVal extends Array<Record<string, any>> ?
Expand Down

0 comments on commit 1f0460a

Please sign in to comment.