diff --git a/.api-reports/api-report-core.api.md b/.api-reports/api-report-core.api.md index 237eac1a463..e91bf2384b9 100644 --- a/.api-reports/api-report-core.api.md +++ b/.api-reports/api-report-core.api.md @@ -1391,9 +1391,10 @@ interface MutationBaseOptions; + // Warning: (ae-forgotten-export) The symbol "IgnoreModifier" needs to be exported by the entry point index.d.ts optimisticResponse?: TData | ((vars: TVariables, { IGNORE }: { IGNORE: IgnoreModifier; - }) => TData); + }) => TData | IgnoreModifier); refetchQueries?: ((result: FetchResult) => InternalRefetchQueriesInclude) | InternalRefetchQueriesInclude; update?: MutationUpdaterFunction; updateQueries?: MutationQueryReducersMap; diff --git a/.api-reports/api-report-react.api.md b/.api-reports/api-report-react.api.md index 5b8b33b8ae6..f2acc1ef23f 100644 --- a/.api-reports/api-report-react.api.md +++ b/.api-reports/api-report-react.api.md @@ -1119,9 +1119,10 @@ interface MutationBaseOptions; + // Warning: (ae-forgotten-export) The symbol "IgnoreModifier" needs to be exported by the entry point index.d.ts optimisticResponse?: TData | ((vars: TVariables, { IGNORE }: { IGNORE: IgnoreModifier; - }) => TData); + }) => TData | IgnoreModifier); refetchQueries?: ((result: FetchResult) => InternalRefetchQueriesInclude) | InternalRefetchQueriesInclude; // Warning: (ae-forgotten-export) The symbol "MutationUpdaterFunction" needs to be exported by the entry point index.d.ts update?: MutationUpdaterFunction; diff --git a/.api-reports/api-report-react_components.api.md b/.api-reports/api-report-react_components.api.md index 24881bcaf5d..dd2edf25377 100644 --- a/.api-reports/api-report-react_components.api.md +++ b/.api-reports/api-report-react_components.api.md @@ -995,9 +995,10 @@ interface MutationBaseOptions; + // Warning: (ae-forgotten-export) The symbol "IgnoreModifier" needs to be exported by the entry point index.d.ts optimisticResponse?: TData | ((vars: TVariables, { IGNORE }: { IGNORE: IgnoreModifier; - }) => TData); + }) => TData | IgnoreModifier); refetchQueries?: ((result: FetchResult) => InternalRefetchQueriesInclude) | InternalRefetchQueriesInclude; // Warning: (ae-forgotten-export) The symbol "MutationUpdaterFunction" needs to be exported by the entry point index.d.ts update?: MutationUpdaterFunction; diff --git a/.api-reports/api-report-react_context.api.md b/.api-reports/api-report-react_context.api.md index fa3fd404a7d..14776931c35 100644 --- a/.api-reports/api-report-react_context.api.md +++ b/.api-reports/api-report-react_context.api.md @@ -978,9 +978,10 @@ interface MutationBaseOptions; + // Warning: (ae-forgotten-export) The symbol "IgnoreModifier" needs to be exported by the entry point index.d.ts optimisticResponse?: TData | ((vars: TVariables, { IGNORE }: { IGNORE: IgnoreModifier; - }) => TData); + }) => TData | IgnoreModifier); refetchQueries?: ((result: FetchResult) => InternalRefetchQueriesInclude) | InternalRefetchQueriesInclude; // Warning: (ae-forgotten-export) The symbol "MutationUpdaterFunction" needs to be exported by the entry point index.d.ts update?: MutationUpdaterFunction; diff --git a/.api-reports/api-report-react_hoc.api.md b/.api-reports/api-report-react_hoc.api.md index 6be8fbce071..1e4fe900ffa 100644 --- a/.api-reports/api-report-react_hoc.api.md +++ b/.api-reports/api-report-react_hoc.api.md @@ -997,9 +997,10 @@ interface MutationBaseOptions; + // Warning: (ae-forgotten-export) The symbol "IgnoreModifier" needs to be exported by the entry point index.d.ts optimisticResponse?: TData | ((vars: TVariables, { IGNORE }: { IGNORE: IgnoreModifier; - }) => TData); + }) => TData | IgnoreModifier); refetchQueries?: ((result: FetchResult) => InternalRefetchQueriesInclude) | InternalRefetchQueriesInclude; // Warning: (ae-forgotten-export) The symbol "MutationUpdaterFunction" needs to be exported by the entry point index.d.ts update?: MutationUpdaterFunction; diff --git a/.api-reports/api-report-react_hooks.api.md b/.api-reports/api-report-react_hooks.api.md index 0691c35d9ba..beee82502e3 100644 --- a/.api-reports/api-report-react_hooks.api.md +++ b/.api-reports/api-report-react_hooks.api.md @@ -1068,9 +1068,10 @@ interface MutationBaseOptions; + // Warning: (ae-forgotten-export) The symbol "IgnoreModifier" needs to be exported by the entry point index.d.ts optimisticResponse?: TData | ((vars: TVariables, { IGNORE }: { IGNORE: IgnoreModifier; - }) => TData); + }) => TData | IgnoreModifier); refetchQueries?: ((result: FetchResult) => InternalRefetchQueriesInclude) | InternalRefetchQueriesInclude; // Warning: (ae-forgotten-export) The symbol "MutationUpdaterFunction" needs to be exported by the entry point index.d.ts update?: MutationUpdaterFunction; diff --git a/.api-reports/api-report-react_internal.api.md b/.api-reports/api-report-react_internal.api.md index 98443e3b6b8..3e85f01b867 100644 --- a/.api-reports/api-report-react_internal.api.md +++ b/.api-reports/api-report-react_internal.api.md @@ -1079,9 +1079,10 @@ interface MutationBaseOptions; + // Warning: (ae-forgotten-export) The symbol "IgnoreModifier" needs to be exported by the entry point index.d.ts optimisticResponse?: TData | ((vars: TVariables, { IGNORE }: { IGNORE: IgnoreModifier; - }) => TData); + }) => TData | IgnoreModifier); refetchQueries?: ((result: FetchResult) => InternalRefetchQueriesInclude) | InternalRefetchQueriesInclude; // Warning: (ae-forgotten-export) The symbol "MutationUpdaterFunction" needs to be exported by the entry point index.d.ts update?: MutationUpdaterFunction; diff --git a/.api-reports/api-report-react_ssr.api.md b/.api-reports/api-report-react_ssr.api.md index eb50183646e..1816993de87 100644 --- a/.api-reports/api-report-react_ssr.api.md +++ b/.api-reports/api-report-react_ssr.api.md @@ -963,9 +963,10 @@ interface MutationBaseOptions; + // Warning: (ae-forgotten-export) The symbol "IgnoreModifier" needs to be exported by the entry point index.d.ts optimisticResponse?: TData | ((vars: TVariables, { IGNORE }: { IGNORE: IgnoreModifier; - }) => TData); + }) => TData | IgnoreModifier); refetchQueries?: ((result: FetchResult) => InternalRefetchQueriesInclude) | InternalRefetchQueriesInclude; // Warning: (ae-forgotten-export) The symbol "MutationUpdaterFunction" needs to be exported by the entry point index.d.ts update?: MutationUpdaterFunction; diff --git a/.api-reports/api-report-testing.api.md b/.api-reports/api-report-testing.api.md index ebd148cf04e..7019af419eb 100644 --- a/.api-reports/api-report-testing.api.md +++ b/.api-reports/api-report-testing.api.md @@ -1084,9 +1084,10 @@ interface MutationBaseOptions; + // Warning: (ae-forgotten-export) The symbol "IgnoreModifier" needs to be exported by the entry point index.d.ts optimisticResponse?: TData | ((vars: TVariables, { IGNORE }: { IGNORE: IgnoreModifier; - }) => TData); + }) => TData | IgnoreModifier); refetchQueries?: ((result: FetchResult) => InternalRefetchQueriesInclude) | InternalRefetchQueriesInclude; // Warning: (ae-forgotten-export) The symbol "MutationUpdaterFunction" needs to be exported by the entry point index.d.ts update?: MutationUpdaterFunction; diff --git a/.api-reports/api-report-testing_core.api.md b/.api-reports/api-report-testing_core.api.md index ef631e90da1..07be1d04650 100644 --- a/.api-reports/api-report-testing_core.api.md +++ b/.api-reports/api-report-testing_core.api.md @@ -1039,9 +1039,10 @@ interface MutationBaseOptions; + // Warning: (ae-forgotten-export) The symbol "IgnoreModifier" needs to be exported by the entry point index.d.ts optimisticResponse?: TData | ((vars: TVariables, { IGNORE }: { IGNORE: IgnoreModifier; - }) => TData); + }) => TData | IgnoreModifier); refetchQueries?: ((result: FetchResult) => InternalRefetchQueriesInclude) | InternalRefetchQueriesInclude; // Warning: (ae-forgotten-export) The symbol "MutationUpdaterFunction" needs to be exported by the entry point index.d.ts update?: MutationUpdaterFunction; diff --git a/.api-reports/api-report-utilities.api.md b/.api-reports/api-report-utilities.api.md index ab3858c6f0d..2d2108cade6 100644 --- a/.api-reports/api-report-utilities.api.md +++ b/.api-reports/api-report-utilities.api.md @@ -1687,9 +1687,10 @@ interface MutationBaseOptions; + // Warning: (ae-forgotten-export) The symbol "IgnoreModifier" needs to be exported by the entry point index.d.ts optimisticResponse?: TData | ((vars: TVariables, { IGNORE }: { IGNORE: IgnoreModifier; - }) => TData); + }) => TData | IgnoreModifier); refetchQueries?: ((result: FetchResult) => InternalRefetchQueriesInclude) | InternalRefetchQueriesInclude; // Warning: (ae-forgotten-export) The symbol "MutationUpdaterFunction" needs to be exported by the entry point index.d.ts update?: MutationUpdaterFunction; diff --git a/.api-reports/api-report.api.md b/.api-reports/api-report.api.md index ef88362554a..ca7d586070f 100644 --- a/.api-reports/api-report.api.md +++ b/.api-reports/api-report.api.md @@ -1572,9 +1572,10 @@ interface MutationBaseOptions; + // Warning: (ae-forgotten-export) The symbol "IgnoreModifier" needs to be exported by the entry point index.d.ts optimisticResponse?: TData | ((vars: TVariables, { IGNORE }: { IGNORE: IgnoreModifier; - }) => TData); + }) => TData | IgnoreModifier); refetchQueries?: ((result: FetchResult) => InternalRefetchQueriesInclude) | InternalRefetchQueriesInclude; update?: MutationUpdaterFunction; updateQueries?: MutationQueryReducersMap; diff --git a/.changeset/pink-flowers-switch.md b/.changeset/pink-flowers-switch.md new file mode 100644 index 00000000000..c85a3e59376 --- /dev/null +++ b/.changeset/pink-flowers-switch.md @@ -0,0 +1,5 @@ +--- +"@apollo/client": patch +--- + +Allow `IgnoreModifier` to be returned from a `optimisticResponse` function when inferring from a `TypedDocumentNode` when used with a generic argument. diff --git a/src/__tests__/optimistic.ts b/src/__tests__/optimistic.ts index 3cc984868ed..ed53dc8cf9c 100644 --- a/src/__tests__/optimistic.ts +++ b/src/__tests__/optimistic.ts @@ -9,6 +9,7 @@ import { ApolloLink, ApolloCache, MutationQueryReducersMap, + TypedDocumentNode, } from "../core"; import { QueryManager } from "../core/QueryManager"; @@ -1089,6 +1090,25 @@ describe("optimistic mutation results", () => { resolve(); } ); + + it("allows IgnoreModifier as return value when inferring from a TypedDocumentNode mutation", () => { + const mutation: TypedDocumentNode<{ bar: string }> = gql` + mutation foo { + foo { + bar + } + } + `; + + const client = new ApolloClient({ + cache: new InMemoryCache(), + }); + + client.mutate({ + mutation, + optimisticResponse: (vars, { IGNORE }) => IGNORE, + }); + }); }); describe("optimistic updates using `updateQueries`", () => { diff --git a/src/core/watchQueryOptions.ts b/src/core/watchQueryOptions.ts index b05cdb13c33..0627f04ebc5 100644 --- a/src/core/watchQueryOptions.ts +++ b/src/core/watchQueryOptions.ts @@ -220,7 +220,10 @@ export interface MutationBaseOptions< /** {@inheritDoc @apollo/client!MutationOptionsDocumentation#optimisticResponse:member} */ optimisticResponse?: | TData - | ((vars: TVariables, { IGNORE }: { IGNORE: IgnoreModifier }) => TData); + | (( + vars: TVariables, + { IGNORE }: { IGNORE: IgnoreModifier } + ) => TData | IgnoreModifier); /** {@inheritDoc @apollo/client!MutationOptionsDocumentation#updateQueries:member} */ updateQueries?: MutationQueryReducersMap;