Skip to content

Commit 8f3d7eb

Browse files
sneyderdevphryneas
andauthored
Fix optimisticResponse function return type (#11944)
* fix(types): explicitly return `IgnoreModifier` from `optimisticResponse` function * Add changeset * Add test that allows returning `IgnoreModifier` when inferring from a generic TypedDocumentNode mutation --------- Co-authored-by: Lenz Weber-Tronic <[email protected]>
1 parent c4cf577 commit 8f3d7eb

15 files changed

+53
-13
lines changed

.api-reports/api-report-core.api.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1391,9 +1391,10 @@ interface MutationBaseOptions<TData = any, TVariables = OperationVariables, TCon
13911391
context?: TContext;
13921392
errorPolicy?: ErrorPolicy;
13931393
onQueryUpdated?: OnQueryUpdated<any>;
1394+
// Warning: (ae-forgotten-export) The symbol "IgnoreModifier" needs to be exported by the entry point index.d.ts
13941395
optimisticResponse?: TData | ((vars: TVariables, { IGNORE }: {
13951396
IGNORE: IgnoreModifier;
1396-
}) => TData);
1397+
}) => TData | IgnoreModifier);
13971398
refetchQueries?: ((result: FetchResult<TData>) => InternalRefetchQueriesInclude) | InternalRefetchQueriesInclude;
13981399
update?: MutationUpdaterFunction<TData, TVariables, TContext, TCache>;
13991400
updateQueries?: MutationQueryReducersMap<TData>;

.api-reports/api-report-react.api.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1119,9 +1119,10 @@ interface MutationBaseOptions<TData = any, TVariables = OperationVariables, TCon
11191119
errorPolicy?: ErrorPolicy;
11201120
// Warning: (ae-forgotten-export) The symbol "OnQueryUpdated" needs to be exported by the entry point index.d.ts
11211121
onQueryUpdated?: OnQueryUpdated<any>;
1122+
// Warning: (ae-forgotten-export) The symbol "IgnoreModifier" needs to be exported by the entry point index.d.ts
11221123
optimisticResponse?: TData | ((vars: TVariables, { IGNORE }: {
11231124
IGNORE: IgnoreModifier;
1124-
}) => TData);
1125+
}) => TData | IgnoreModifier);
11251126
refetchQueries?: ((result: FetchResult<TData>) => InternalRefetchQueriesInclude) | InternalRefetchQueriesInclude;
11261127
// Warning: (ae-forgotten-export) The symbol "MutationUpdaterFunction" needs to be exported by the entry point index.d.ts
11271128
update?: MutationUpdaterFunction<TData, TVariables, TContext, TCache>;

.api-reports/api-report-react_components.api.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -995,9 +995,10 @@ interface MutationBaseOptions<TData = any, TVariables = OperationVariables, TCon
995995
errorPolicy?: ErrorPolicy;
996996
// Warning: (ae-forgotten-export) The symbol "OnQueryUpdated" needs to be exported by the entry point index.d.ts
997997
onQueryUpdated?: OnQueryUpdated<any>;
998+
// Warning: (ae-forgotten-export) The symbol "IgnoreModifier" needs to be exported by the entry point index.d.ts
998999
optimisticResponse?: TData | ((vars: TVariables, { IGNORE }: {
9991000
IGNORE: IgnoreModifier;
1000-
}) => TData);
1001+
}) => TData | IgnoreModifier);
10011002
refetchQueries?: ((result: FetchResult<TData>) => InternalRefetchQueriesInclude) | InternalRefetchQueriesInclude;
10021003
// Warning: (ae-forgotten-export) The symbol "MutationUpdaterFunction" needs to be exported by the entry point index.d.ts
10031004
update?: MutationUpdaterFunction<TData, TVariables, TContext, TCache>;

.api-reports/api-report-react_context.api.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -978,9 +978,10 @@ interface MutationBaseOptions<TData = any, TVariables = OperationVariables, TCon
978978
errorPolicy?: ErrorPolicy;
979979
// Warning: (ae-forgotten-export) The symbol "OnQueryUpdated" needs to be exported by the entry point index.d.ts
980980
onQueryUpdated?: OnQueryUpdated<any>;
981+
// Warning: (ae-forgotten-export) The symbol "IgnoreModifier" needs to be exported by the entry point index.d.ts
981982
optimisticResponse?: TData | ((vars: TVariables, { IGNORE }: {
982983
IGNORE: IgnoreModifier;
983-
}) => TData);
984+
}) => TData | IgnoreModifier);
984985
refetchQueries?: ((result: FetchResult<TData>) => InternalRefetchQueriesInclude) | InternalRefetchQueriesInclude;
985986
// Warning: (ae-forgotten-export) The symbol "MutationUpdaterFunction" needs to be exported by the entry point index.d.ts
986987
update?: MutationUpdaterFunction<TData, TVariables, TContext, TCache>;

.api-reports/api-report-react_hoc.api.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -997,9 +997,10 @@ interface MutationBaseOptions<TData = any, TVariables = OperationVariables, TCon
997997
errorPolicy?: ErrorPolicy;
998998
// Warning: (ae-forgotten-export) The symbol "OnQueryUpdated" needs to be exported by the entry point index.d.ts
999999
onQueryUpdated?: OnQueryUpdated<any>;
1000+
// Warning: (ae-forgotten-export) The symbol "IgnoreModifier" needs to be exported by the entry point index.d.ts
10001001
optimisticResponse?: TData | ((vars: TVariables, { IGNORE }: {
10011002
IGNORE: IgnoreModifier;
1002-
}) => TData);
1003+
}) => TData | IgnoreModifier);
10031004
refetchQueries?: ((result: FetchResult<TData>) => InternalRefetchQueriesInclude) | InternalRefetchQueriesInclude;
10041005
// Warning: (ae-forgotten-export) The symbol "MutationUpdaterFunction" needs to be exported by the entry point index.d.ts
10051006
update?: MutationUpdaterFunction<TData, TVariables, TContext, TCache>;

.api-reports/api-report-react_hooks.api.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1068,9 +1068,10 @@ interface MutationBaseOptions<TData = any, TVariables = OperationVariables, TCon
10681068
errorPolicy?: ErrorPolicy;
10691069
// Warning: (ae-forgotten-export) The symbol "OnQueryUpdated" needs to be exported by the entry point index.d.ts
10701070
onQueryUpdated?: OnQueryUpdated<any>;
1071+
// Warning: (ae-forgotten-export) The symbol "IgnoreModifier" needs to be exported by the entry point index.d.ts
10711072
optimisticResponse?: TData | ((vars: TVariables, { IGNORE }: {
10721073
IGNORE: IgnoreModifier;
1073-
}) => TData);
1074+
}) => TData | IgnoreModifier);
10741075
refetchQueries?: ((result: FetchResult<TData>) => InternalRefetchQueriesInclude) | InternalRefetchQueriesInclude;
10751076
// Warning: (ae-forgotten-export) The symbol "MutationUpdaterFunction" needs to be exported by the entry point index.d.ts
10761077
update?: MutationUpdaterFunction<TData, TVariables, TContext, TCache>;

.api-reports/api-report-react_internal.api.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1079,9 +1079,10 @@ interface MutationBaseOptions<TData = any, TVariables = OperationVariables, TCon
10791079
errorPolicy?: ErrorPolicy;
10801080
// Warning: (ae-forgotten-export) The symbol "OnQueryUpdated" needs to be exported by the entry point index.d.ts
10811081
onQueryUpdated?: OnQueryUpdated<any>;
1082+
// Warning: (ae-forgotten-export) The symbol "IgnoreModifier" needs to be exported by the entry point index.d.ts
10821083
optimisticResponse?: TData | ((vars: TVariables, { IGNORE }: {
10831084
IGNORE: IgnoreModifier;
1084-
}) => TData);
1085+
}) => TData | IgnoreModifier);
10851086
refetchQueries?: ((result: FetchResult<TData>) => InternalRefetchQueriesInclude) | InternalRefetchQueriesInclude;
10861087
// Warning: (ae-forgotten-export) The symbol "MutationUpdaterFunction" needs to be exported by the entry point index.d.ts
10871088
update?: MutationUpdaterFunction<TData, TVariables, TContext, TCache>;

.api-reports/api-report-react_ssr.api.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -963,9 +963,10 @@ interface MutationBaseOptions<TData = any, TVariables = OperationVariables, TCon
963963
errorPolicy?: ErrorPolicy;
964964
// Warning: (ae-forgotten-export) The symbol "OnQueryUpdated" needs to be exported by the entry point index.d.ts
965965
onQueryUpdated?: OnQueryUpdated<any>;
966+
// Warning: (ae-forgotten-export) The symbol "IgnoreModifier" needs to be exported by the entry point index.d.ts
966967
optimisticResponse?: TData | ((vars: TVariables, { IGNORE }: {
967968
IGNORE: IgnoreModifier;
968-
}) => TData);
969+
}) => TData | IgnoreModifier);
969970
refetchQueries?: ((result: FetchResult<TData>) => InternalRefetchQueriesInclude) | InternalRefetchQueriesInclude;
970971
// Warning: (ae-forgotten-export) The symbol "MutationUpdaterFunction" needs to be exported by the entry point index.d.ts
971972
update?: MutationUpdaterFunction<TData, TVariables, TContext, TCache>;

.api-reports/api-report-testing.api.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1084,9 +1084,10 @@ interface MutationBaseOptions<TData = any, TVariables = OperationVariables, TCon
10841084
errorPolicy?: ErrorPolicy;
10851085
// Warning: (ae-forgotten-export) The symbol "OnQueryUpdated" needs to be exported by the entry point index.d.ts
10861086
onQueryUpdated?: OnQueryUpdated<any>;
1087+
// Warning: (ae-forgotten-export) The symbol "IgnoreModifier" needs to be exported by the entry point index.d.ts
10871088
optimisticResponse?: TData | ((vars: TVariables, { IGNORE }: {
10881089
IGNORE: IgnoreModifier;
1089-
}) => TData);
1090+
}) => TData | IgnoreModifier);
10901091
refetchQueries?: ((result: FetchResult<TData>) => InternalRefetchQueriesInclude) | InternalRefetchQueriesInclude;
10911092
// Warning: (ae-forgotten-export) The symbol "MutationUpdaterFunction" needs to be exported by the entry point index.d.ts
10921093
update?: MutationUpdaterFunction<TData, TVariables, TContext, TCache>;

.api-reports/api-report-testing_core.api.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1039,9 +1039,10 @@ interface MutationBaseOptions<TData = any, TVariables = OperationVariables, TCon
10391039
errorPolicy?: ErrorPolicy;
10401040
// Warning: (ae-forgotten-export) The symbol "OnQueryUpdated" needs to be exported by the entry point index.d.ts
10411041
onQueryUpdated?: OnQueryUpdated<any>;
1042+
// Warning: (ae-forgotten-export) The symbol "IgnoreModifier" needs to be exported by the entry point index.d.ts
10421043
optimisticResponse?: TData | ((vars: TVariables, { IGNORE }: {
10431044
IGNORE: IgnoreModifier;
1044-
}) => TData);
1045+
}) => TData | IgnoreModifier);
10451046
refetchQueries?: ((result: FetchResult<TData>) => InternalRefetchQueriesInclude) | InternalRefetchQueriesInclude;
10461047
// Warning: (ae-forgotten-export) The symbol "MutationUpdaterFunction" needs to be exported by the entry point index.d.ts
10471048
update?: MutationUpdaterFunction<TData, TVariables, TContext, TCache>;

.api-reports/api-report-utilities.api.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1687,9 +1687,10 @@ interface MutationBaseOptions<TData = any, TVariables = OperationVariables, TCon
16871687
errorPolicy?: ErrorPolicy;
16881688
// Warning: (ae-forgotten-export) The symbol "OnQueryUpdated" needs to be exported by the entry point index.d.ts
16891689
onQueryUpdated?: OnQueryUpdated<any>;
1690+
// Warning: (ae-forgotten-export) The symbol "IgnoreModifier" needs to be exported by the entry point index.d.ts
16901691
optimisticResponse?: TData | ((vars: TVariables, { IGNORE }: {
16911692
IGNORE: IgnoreModifier;
1692-
}) => TData);
1693+
}) => TData | IgnoreModifier);
16931694
refetchQueries?: ((result: FetchResult<TData>) => InternalRefetchQueriesInclude) | InternalRefetchQueriesInclude;
16941695
// Warning: (ae-forgotten-export) The symbol "MutationUpdaterFunction" needs to be exported by the entry point index.d.ts
16951696
update?: MutationUpdaterFunction<TData, TVariables, TContext, TCache>;

.api-reports/api-report.api.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1572,9 +1572,10 @@ interface MutationBaseOptions<TData = any, TVariables = OperationVariables, TCon
15721572
context?: TContext;
15731573
errorPolicy?: ErrorPolicy;
15741574
onQueryUpdated?: OnQueryUpdated<any>;
1575+
// Warning: (ae-forgotten-export) The symbol "IgnoreModifier" needs to be exported by the entry point index.d.ts
15751576
optimisticResponse?: TData | ((vars: TVariables, { IGNORE }: {
15761577
IGNORE: IgnoreModifier;
1577-
}) => TData);
1578+
}) => TData | IgnoreModifier);
15781579
refetchQueries?: ((result: FetchResult<TData>) => InternalRefetchQueriesInclude) | InternalRefetchQueriesInclude;
15791580
update?: MutationUpdaterFunction<TData, TVariables, TContext, TCache>;
15801581
updateQueries?: MutationQueryReducersMap<TData>;

.changeset/pink-flowers-switch.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@apollo/client": patch
3+
---
4+
5+
Allow `IgnoreModifier` to be returned from a `optimisticResponse` function when inferring from a `TypedDocumentNode` when used with a generic argument.

src/__tests__/optimistic.ts

+20
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
ApolloLink,
1010
ApolloCache,
1111
MutationQueryReducersMap,
12+
TypedDocumentNode,
1213
} from "../core";
1314

1415
import { QueryManager } from "../core/QueryManager";
@@ -1089,6 +1090,25 @@ describe("optimistic mutation results", () => {
10891090
resolve();
10901091
}
10911092
);
1093+
1094+
it("allows IgnoreModifier as return value when inferring from a TypedDocumentNode mutation", () => {
1095+
const mutation: TypedDocumentNode<{ bar: string }> = gql`
1096+
mutation foo {
1097+
foo {
1098+
bar
1099+
}
1100+
}
1101+
`;
1102+
1103+
const client = new ApolloClient({
1104+
cache: new InMemoryCache(),
1105+
});
1106+
1107+
client.mutate({
1108+
mutation,
1109+
optimisticResponse: (vars, { IGNORE }) => IGNORE,
1110+
});
1111+
});
10921112
});
10931113

10941114
describe("optimistic updates using `updateQueries`", () => {

src/core/watchQueryOptions.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,10 @@ export interface MutationBaseOptions<
220220
/** {@inheritDoc @apollo/client!MutationOptionsDocumentation#optimisticResponse:member} */
221221
optimisticResponse?:
222222
| TData
223-
| ((vars: TVariables, { IGNORE }: { IGNORE: IgnoreModifier }) => TData);
223+
| ((
224+
vars: TVariables,
225+
{ IGNORE }: { IGNORE: IgnoreModifier }
226+
) => TData | IgnoreModifier);
224227

225228
/** {@inheritDoc @apollo/client!MutationOptionsDocumentation#updateQueries:member} */
226229
updateQueries?: MutationQueryReducersMap<TData>;

0 commit comments

Comments
 (0)