From 082acf90c2c22edf28f443306da39b535d2b0a1d Mon Sep 17 00:00:00 2001 From: Neil Chen Date: Tue, 3 May 2022 16:39:28 +0800 Subject: [PATCH] fix: useQuery loading and debounce issues (#1313) fix #1235 fix #1271 --- packages/vue-apollo-composable/src/useQuery.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/vue-apollo-composable/src/useQuery.ts b/packages/vue-apollo-composable/src/useQuery.ts index 83b8ee8..7cbc45f 100644 --- a/packages/vue-apollo-composable/src/useQuery.ts +++ b/packages/vue-apollo-composable/src/useQuery.ts @@ -1,6 +1,7 @@ import { ref, Ref, + unref, isRef, computed, watch, @@ -360,7 +361,7 @@ export function useQueryImpl< function updateRestartFn () { // On server, will be called before currentOptions is initialized // @TODO investigate - if (!currentOptions) { + if (!currentOptions.value) { debouncedRestart = baseRestart } else { if (currentOptions.value?.throttle) { @@ -404,7 +405,7 @@ export function useQueryImpl< }) // Applying options - watch(() => isRef(optionsRef) ? optionsRef.value : optionsRef, value => { + watch(() => unref(optionsRef), value => { if (currentOptions.value && ( currentOptions.value.throttle !== value.throttle || currentOptions.value.debounce !== value.debounce @@ -418,7 +419,7 @@ export function useQueryImpl< immediate: true, }) - // Fefetch + // Refetch function refetch (variables: TVariables | undefined = undefined) { if (query.value) { @@ -426,6 +427,7 @@ export function useQueryImpl< currentVariables = variables } error.value = null + loading.value = true return query.value.refetch(variables) } }