Skip to content

Commit

Permalink
Merge pull request #167 from warflash/disable_watch
Browse files Browse the repository at this point in the history
feat: allow `watch: false` in useQuery
  • Loading branch information
wobsoriano authored Jun 9, 2024
2 parents b6c5668 + fbff0da commit 8de066b
Show file tree
Hide file tree
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
Expand Up @@ -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), {
Expand Down
10 changes: 6 additions & 4 deletions src/client/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: <
Expand All @@ -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>
Expand Down

0 comments on commit 8de066b

Please sign in to comment.