@@ -33,18 +33,17 @@ export type ApolloMutationClient<TResult, TVariables extends OperationVariables>
3333// Mutation function with typings
3434export type MutationOperationFunction < TResult , TVariables extends OperationVariables , TError = ApolloError > = (
3535 app : VueAppWithApollo ,
36- params : Omit < MutationOperationParams < TVariables , TError > , 'mutation' > ,
36+ params : Omit < MutationOperationParams < TResult , TVariables , TError > , 'mutation' > ,
3737 client ?: ApolloMutationClient < TResult , TVariables > ,
3838) => Promise < MutationResult < TResult > > ;
3939
4040// Parameters given to a MutationOperationFunction
4141export interface MutationOperationParams <
42+ TResult ,
4243 TVariables extends OperationVariables ,
4344 TError = ApolloError ,
4445 TContext = ApolloOperationContext ,
45- > {
46- mutation : DocumentNode ;
47- variables : TVariables ;
46+ > extends MutationOptions < TResult , TVariables > {
4847 context ?: TContext ;
4948 onError ?: ApolloOperationErrorHandlerFunction < TError > ;
5049}
@@ -86,10 +85,10 @@ export async function mutateWithErrorHandling<
8685 TApp extends VueAppWithApollo = VueAppWithApollo ,
8786> (
8887 app : TApp ,
89- { mutation , variables , onError , context } : MutationOperationParams < TVariables , TError > ,
88+ params : MutationOperationParams < TResult , TVariables , TError > ,
9089 client ?: ApolloMutationClient < TResult , TVariables > ,
9190) : Promise < MutationResult < TResult > > {
92- const mutate =
91+ const mutate : ApolloClientMutationFunction | ApolloComponentMutationFunction =
9392 client === undefined
9493 ? app . $apollo . mutate . bind ( app . $apollo )
9594 : typeof client === 'function'
@@ -98,8 +97,8 @@ export async function mutateWithErrorHandling<
9897
9998 try {
10099 const result = await mutate ( {
101- mutation ,
102- variables : cleanInput ( variables ) ,
100+ ... params ,
101+ variables : params . variables != null ? cleanInput ( params . variables ) : undefined ,
103102 } ) ;
104103
105104 if ( result == null ) {
@@ -108,6 +107,7 @@ export async function mutateWithErrorHandling<
108107
109108 return { success : true , data : result . data } ;
110109 } catch ( error ) {
110+ const { onError, context } = params ;
111111 const errorHandlerResult : ApolloErrorHandlerResult | undefined =
112112 onError != null ? onError ( error , app , context ) : undefined ;
113113
@@ -130,16 +130,15 @@ export function createMutationFunction<
130130) : MutationOperationFunction < TResult , TVariables , TError > {
131131 return (
132132 app : TApp ,
133- params : Omit < MutationOperationParams < TVariables , TError > , 'mutation' > ,
133+ params : Omit < MutationOperationParams < TResult , TVariables , TError > , 'mutation' > ,
134134 client ?: ApolloMutationClient < TResult , TVariables > ,
135135 ) : Promise < MutationResult < TResult > > => {
136136 return mutateWithErrorHandling (
137137 app ,
138138 {
139139 mutation,
140- variables : params . variables ,
141- onError : params . onError ?? onError ,
142- context : params . context ,
140+ onError,
141+ ...params ,
143142 } ,
144143 client ,
145144 ) ;
0 commit comments