Skip to content

Commit

Permalink
feat: allow watch: false in useQuery
Browse files Browse the repository at this point in the history
warflash committed Apr 4, 2024
1 parent e2bd26f commit fbff0da
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/client/decorationProxy.ts
Original file line number Diff line number Diff line change
@@ -50,7 +50,7 @@ export function createNuxtProxyDecoration<TRouter extends AnyRouter> (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), {
10 changes: 6 additions & 4 deletions src/client/types.ts
Original file line number Diff line number Diff line change
@@ -63,13 +63,14 @@ export type DecorateProcedure<
DefaultT = null,
>(
input: MaybeRefOrGetter<inferProcedureInput<TProcedure>>,
opts?: AsyncDataOptions<ResT, DataT, PickKeys, DefaultT> & {
opts?: Omit<AsyncDataOptions<ResT, DataT, PickKeys, DefaultT>, '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<ResT, DataT, PickKeys, DefaultT>['watch'] | false
},
) => AsyncData<PickFrom<DataT, PickKeys> | DefaultT, DataE>,
useLazyQuery: <
@@ -80,13 +81,14 @@ export type DecorateProcedure<
DefaultT = null,
>(
input: MaybeRefOrGetter<inferProcedureInput<TProcedure>>,
opts?: Omit<AsyncDataOptions<ResT, DataT, PickKeys, DefaultT>, 'lazy'> & {
opts?: Omit<AsyncDataOptions<ResT, DataT, PickKeys, DefaultT>, '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<ResT, DataT, PickKeys, DefaultT>['watch'] | false
},
) => AsyncData<PickFrom<DataT, PickKeys> | DefaultT, DataE>,
query: Resolver<TProcedure>

0 comments on commit fbff0da

Please sign in to comment.