From fbff0da751ceba7c0523b6eda2d9a0940611238f Mon Sep 17 00:00:00 2001 From: warflash Date: Thu, 4 Apr 2024 03:54:46 +0200 Subject: [PATCH] feat: allow `watch: false` in useQuery --- src/client/decorationProxy.ts | 2 +- src/client/types.ts | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/client/decorationProxy.ts b/src/client/decorationProxy.ts index 7c605ff..ebe7e15 100644 --- a/src/client/decorationProxy.ts +++ b/src/client/decorationProxy.ts @@ -50,7 +50,7 @@ export function createNuxtProxyDecoration (name: stri const controller = createAbortController(trpc); const queryKey = customQueryKey || getQueryKeyInternal(path, toValue(input)) - const watch = isRefOrGetter(input) ? [...(asyncDataOptions.watch || []), input] : asyncDataOptions.watch + const watch = asyncDataOptions.watch === false ? [] : isRefOrGetter(input) ? [...(asyncDataOptions.watch || []), input] : asyncDataOptions.watch const isLazy = lastArg === 'useLazyQuery' ? true : (asyncDataOptions.lazy || false) return useAsyncData(queryKey, () => (client as any)[path].query(toValue(input), { diff --git a/src/client/types.ts b/src/client/types.ts index df3a30f..b97883e 100644 --- a/src/client/types.ts +++ b/src/client/types.ts @@ -63,13 +63,14 @@ export type DecorateProcedure< DefaultT = null, >( input: MaybeRefOrGetter>, - opts?: AsyncDataOptions & { + opts?: Omit, 'watch'> & { trpc?: TRPCRequestOptions /** * The custom unique key to use. * @see https://nuxt.com/docs/api/composables/use-async-data#params */ - queryKey?: string + queryKey?: string, + watch?: AsyncDataOptions['watch'] | false }, ) => AsyncData | DefaultT, DataE>, useLazyQuery: < @@ -80,13 +81,14 @@ export type DecorateProcedure< DefaultT = null, >( input: MaybeRefOrGetter>, - opts?: Omit, 'lazy'> & { + opts?: Omit, 'lazy' | 'watch'> & { trpc?: TRPCRequestOptions /** * The custom unique key to use. * @see https://nuxt.com/docs/api/composables/use-async-data#params */ - queryKey?: string + queryKey?: string, + watch?: AsyncDataOptions['watch'] | false }, ) => AsyncData | DefaultT, DataE>, query: Resolver