Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix optimisticResponse function return type #11944

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .api-reports/api-report-core.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1391,9 +1391,10 @@ interface MutationBaseOptions<TData = any, TVariables = OperationVariables, TCon
context?: TContext;
errorPolicy?: ErrorPolicy;
onQueryUpdated?: OnQueryUpdated<any>;
// 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<TData>) => InternalRefetchQueriesInclude) | InternalRefetchQueriesInclude;
update?: MutationUpdaterFunction<TData, TVariables, TContext, TCache>;
updateQueries?: MutationQueryReducersMap<TData>;
Expand Down
3 changes: 2 additions & 1 deletion .api-reports/api-report-react.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1119,9 +1119,10 @@ interface MutationBaseOptions<TData = any, TVariables = OperationVariables, TCon
errorPolicy?: ErrorPolicy;
// Warning: (ae-forgotten-export) The symbol "OnQueryUpdated" needs to be exported by the entry point index.d.ts
onQueryUpdated?: OnQueryUpdated<any>;
// 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<TData>) => InternalRefetchQueriesInclude) | InternalRefetchQueriesInclude;
// Warning: (ae-forgotten-export) The symbol "MutationUpdaterFunction" needs to be exported by the entry point index.d.ts
update?: MutationUpdaterFunction<TData, TVariables, TContext, TCache>;
Expand Down
3 changes: 2 additions & 1 deletion .api-reports/api-report-react_components.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -995,9 +995,10 @@ interface MutationBaseOptions<TData = any, TVariables = OperationVariables, TCon
errorPolicy?: ErrorPolicy;
// Warning: (ae-forgotten-export) The symbol "OnQueryUpdated" needs to be exported by the entry point index.d.ts
onQueryUpdated?: OnQueryUpdated<any>;
// 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<TData>) => InternalRefetchQueriesInclude) | InternalRefetchQueriesInclude;
// Warning: (ae-forgotten-export) The symbol "MutationUpdaterFunction" needs to be exported by the entry point index.d.ts
update?: MutationUpdaterFunction<TData, TVariables, TContext, TCache>;
Expand Down
3 changes: 2 additions & 1 deletion .api-reports/api-report-react_context.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -978,9 +978,10 @@ interface MutationBaseOptions<TData = any, TVariables = OperationVariables, TCon
errorPolicy?: ErrorPolicy;
// Warning: (ae-forgotten-export) The symbol "OnQueryUpdated" needs to be exported by the entry point index.d.ts
onQueryUpdated?: OnQueryUpdated<any>;
// 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<TData>) => InternalRefetchQueriesInclude) | InternalRefetchQueriesInclude;
// Warning: (ae-forgotten-export) The symbol "MutationUpdaterFunction" needs to be exported by the entry point index.d.ts
update?: MutationUpdaterFunction<TData, TVariables, TContext, TCache>;
Expand Down
3 changes: 2 additions & 1 deletion .api-reports/api-report-react_hoc.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -997,9 +997,10 @@ interface MutationBaseOptions<TData = any, TVariables = OperationVariables, TCon
errorPolicy?: ErrorPolicy;
// Warning: (ae-forgotten-export) The symbol "OnQueryUpdated" needs to be exported by the entry point index.d.ts
onQueryUpdated?: OnQueryUpdated<any>;
// 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<TData>) => InternalRefetchQueriesInclude) | InternalRefetchQueriesInclude;
// Warning: (ae-forgotten-export) The symbol "MutationUpdaterFunction" needs to be exported by the entry point index.d.ts
update?: MutationUpdaterFunction<TData, TVariables, TContext, TCache>;
Expand Down
3 changes: 2 additions & 1 deletion .api-reports/api-report-react_hooks.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1068,9 +1068,10 @@ interface MutationBaseOptions<TData = any, TVariables = OperationVariables, TCon
errorPolicy?: ErrorPolicy;
// Warning: (ae-forgotten-export) The symbol "OnQueryUpdated" needs to be exported by the entry point index.d.ts
onQueryUpdated?: OnQueryUpdated<any>;
// 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<TData>) => InternalRefetchQueriesInclude) | InternalRefetchQueriesInclude;
// Warning: (ae-forgotten-export) The symbol "MutationUpdaterFunction" needs to be exported by the entry point index.d.ts
update?: MutationUpdaterFunction<TData, TVariables, TContext, TCache>;
Expand Down
3 changes: 2 additions & 1 deletion .api-reports/api-report-react_internal.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1079,9 +1079,10 @@ interface MutationBaseOptions<TData = any, TVariables = OperationVariables, TCon
errorPolicy?: ErrorPolicy;
// Warning: (ae-forgotten-export) The symbol "OnQueryUpdated" needs to be exported by the entry point index.d.ts
onQueryUpdated?: OnQueryUpdated<any>;
// 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<TData>) => InternalRefetchQueriesInclude) | InternalRefetchQueriesInclude;
// Warning: (ae-forgotten-export) The symbol "MutationUpdaterFunction" needs to be exported by the entry point index.d.ts
update?: MutationUpdaterFunction<TData, TVariables, TContext, TCache>;
Expand Down
3 changes: 2 additions & 1 deletion .api-reports/api-report-react_ssr.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -963,9 +963,10 @@ interface MutationBaseOptions<TData = any, TVariables = OperationVariables, TCon
errorPolicy?: ErrorPolicy;
// Warning: (ae-forgotten-export) The symbol "OnQueryUpdated" needs to be exported by the entry point index.d.ts
onQueryUpdated?: OnQueryUpdated<any>;
// 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<TData>) => InternalRefetchQueriesInclude) | InternalRefetchQueriesInclude;
// Warning: (ae-forgotten-export) The symbol "MutationUpdaterFunction" needs to be exported by the entry point index.d.ts
update?: MutationUpdaterFunction<TData, TVariables, TContext, TCache>;
Expand Down
3 changes: 2 additions & 1 deletion .api-reports/api-report-testing.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1084,9 +1084,10 @@ interface MutationBaseOptions<TData = any, TVariables = OperationVariables, TCon
errorPolicy?: ErrorPolicy;
// Warning: (ae-forgotten-export) The symbol "OnQueryUpdated" needs to be exported by the entry point index.d.ts
onQueryUpdated?: OnQueryUpdated<any>;
// 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<TData>) => InternalRefetchQueriesInclude) | InternalRefetchQueriesInclude;
// Warning: (ae-forgotten-export) The symbol "MutationUpdaterFunction" needs to be exported by the entry point index.d.ts
update?: MutationUpdaterFunction<TData, TVariables, TContext, TCache>;
Expand Down
3 changes: 2 additions & 1 deletion .api-reports/api-report-testing_core.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1039,9 +1039,10 @@ interface MutationBaseOptions<TData = any, TVariables = OperationVariables, TCon
errorPolicy?: ErrorPolicy;
// Warning: (ae-forgotten-export) The symbol "OnQueryUpdated" needs to be exported by the entry point index.d.ts
onQueryUpdated?: OnQueryUpdated<any>;
// 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<TData>) => InternalRefetchQueriesInclude) | InternalRefetchQueriesInclude;
// Warning: (ae-forgotten-export) The symbol "MutationUpdaterFunction" needs to be exported by the entry point index.d.ts
update?: MutationUpdaterFunction<TData, TVariables, TContext, TCache>;
Expand Down
3 changes: 2 additions & 1 deletion .api-reports/api-report-utilities.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1687,9 +1687,10 @@ interface MutationBaseOptions<TData = any, TVariables = OperationVariables, TCon
errorPolicy?: ErrorPolicy;
// Warning: (ae-forgotten-export) The symbol "OnQueryUpdated" needs to be exported by the entry point index.d.ts
onQueryUpdated?: OnQueryUpdated<any>;
// 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<TData>) => InternalRefetchQueriesInclude) | InternalRefetchQueriesInclude;
// Warning: (ae-forgotten-export) The symbol "MutationUpdaterFunction" needs to be exported by the entry point index.d.ts
update?: MutationUpdaterFunction<TData, TVariables, TContext, TCache>;
Expand Down
3 changes: 2 additions & 1 deletion .api-reports/api-report.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1572,9 +1572,10 @@ interface MutationBaseOptions<TData = any, TVariables = OperationVariables, TCon
context?: TContext;
errorPolicy?: ErrorPolicy;
onQueryUpdated?: OnQueryUpdated<any>;
// 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<TData>) => InternalRefetchQueriesInclude) | InternalRefetchQueriesInclude;
update?: MutationUpdaterFunction<TData, TVariables, TContext, TCache>;
updateQueries?: MutationQueryReducersMap<TData>;
Expand Down
5 changes: 5 additions & 0 deletions .changeset/pink-flowers-switch.md
Original file line number Diff line number Diff line change
@@ -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.
20 changes: 20 additions & 0 deletions src/__tests__/optimistic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
ApolloLink,
ApolloCache,
MutationQueryReducersMap,
TypedDocumentNode,
} from "../core";

import { QueryManager } from "../core/QueryManager";
Expand Down Expand Up @@ -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`", () => {
Expand Down
5 changes: 4 additions & 1 deletion src/core/watchQueryOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<TData>;
Expand Down
Loading