From 0ad08c792ea00587bca574909257cd2e7fa88d4c Mon Sep 17 00:00:00 2001 From: Brian Bugh Date: Fri, 10 Jan 2020 17:03:14 -0600 Subject: [PATCH] fix(useMutation): useMutation not taking a Ref --- packages/vue-apollo-composable/src/useMutation.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/vue-apollo-composable/src/useMutation.ts b/packages/vue-apollo-composable/src/useMutation.ts index 47836cc..f1d62fb 100644 --- a/packages/vue-apollo-composable/src/useMutation.ts +++ b/packages/vue-apollo-composable/src/useMutation.ts @@ -1,6 +1,6 @@ import { DocumentNode } from 'graphql' import { MutationOptions, OperationVariables } from 'apollo-client' -import { ref, onBeforeUnmount } from '@vue/composition-api' +import { ref, onBeforeUnmount, isRef, Ref } from '@vue/composition-api' import { FetchResult } from 'apollo-link' import { useApolloClient } from './useApolloClient' import { ReactiveFunction } from './util/ReactiveFunction' @@ -18,8 +18,8 @@ export function useMutation< TResult = any, TVariables = OperationVariables > ( - document: DocumentNode | ReactiveFunction, - options: UseMutationOptions | ReactiveFunction> = null, + document: DocumentNode | Ref | ReactiveFunction, + options: UseMutationOptions | Ref> | ReactiveFunction> = null, ) { if (!options) options = {} @@ -38,6 +38,8 @@ export function useMutation< let currentDocument: DocumentNode if (typeof document === 'function') { currentDocument = document() + } else if (isRef(document)) { + currentDocument = document.value } else { currentDocument = document } @@ -45,6 +47,8 @@ export function useMutation< let currentOptions: UseMutationOptions if (typeof options === 'function') { currentOptions = options() + } else if (isRef(options)) { + currentOptions = options.value } else { currentOptions = options }