Minor Changes
-
#13206
08fccabThanks @jerelmiller! - Extend thedefaultOptionstype-safety work toclient.mutateanduseMutation.The
errorPolicyoption now flows through to the result types for mutations in the same way it already does for queries:ApolloClient.MutateResult<TData, TErrorPolicy>mapserrorPolicyto the concrete shape ofdataanderror:"none"→{ data: TData; error?: never }"all"→{ data: TData | undefined; error?: ErrorLike }"ignore"→{ data: TData | undefined; error?: never }
client.mutateanduseMutationpick up the declareddefaultOptions.mutate.errorPolicyand the expliciterrorPolicyon each call to narrow return types accordingly.useMutation.Result.erroris narrowed toundefinedwhenerrorPolicyis"ignore", sinceclient.mutatenever resolves with an error in that case.
DeclareDefaultOptions.Mutatealready acceptederrorPolicy; the new behavior is that once you declare it, hook and method return types reflect it:// apollo.d.ts import "@apollo/client"; declare module "@apollo/client" { namespace ApolloClient { namespace DeclareDefaultOptions { interface Mutate { errorPolicy: "all"; } } } }
const result = await client.mutate({ mutation: MUTATION }); result.data; // ^? TData | undefined result.error; // ^? ErrorLike | undefined
Setting
errorPolicyon an individual call overrides the default for that call's return type.