Skip to content

Commit

Permalink
feat: add useLazyQuery composable
Browse files Browse the repository at this point in the history
  • Loading branch information
wobsoriano committed Aug 21, 2023
1 parent ede7494 commit 93cb442
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export function createNuxtProxyDecoration<TRouter extends AnyRouter> (name: stri

const [input, otherOptions] = args

if (lastArg === 'useQuery') {
if (['useQuery', 'useLazyQuery'].includes(lastArg)) {
const { trpc, queryKey: customQueryKey, ...asyncDataOptions } = otherOptions || {} as any

let controller: AbortController
Expand All @@ -54,6 +54,10 @@ export function createNuxtProxyDecoration<TRouter extends AnyRouter> (name: stri
controller = typeof AbortController !== 'undefined' ? new AbortController() : {} as AbortController
}

if (lastArg === 'useLazyQuery') {
asyncDataOptions.lazy = true;
}

const queryKey = customQueryKey || getQueryKey(path, unref(input))
return useAsyncData(queryKey, () => (client as any)[path].query(unref(input), {
signal: controller?.signal,
Expand Down

0 comments on commit 93cb442

Please sign in to comment.