fea(useMutation): throws option

This commit is contained in:
Guillaume
2021-07-04 23:00:21 +02:00
parent fabd27ebe7
commit bfd8db4e4b
2 changed files with 9 additions and 1 deletions
@@ -14,6 +14,7 @@ export interface UseMutationOptions<
TVariables = OperationVariables
> extends Omit<MutationOptions<TResult, TVariables>, 'mutation'> {
clientId?: string
throws?: 'auto' | 'always' | 'never'
}
type DocumentParameter<TResult, TVariables> = DocumentNode | Ref<DocumentNode> | ReactiveFunction<DocumentNode> | TypedDocumentNode<TResult, TVariables> | Ref<TypedDocumentNode<TResult, TVariables>> | ReactiveFunction<TypedDocumentNode<TResult, TVariables>>
@@ -96,7 +97,9 @@ export function useMutation<
error.value = e
loading.value = false
errorEvent.trigger(e)
throw e
if (currentOptions.throws === 'always' || (currentOptions.throws !== 'never' && !errorEvent.getCount())) {
throw e
}
}
}
@@ -21,9 +21,14 @@ export function useEventHook<TParam = any> () {
}
}
function getCount () {
return fns.length
}
return {
on,
off,
trigger,
getCount,
}
}