Skip to content

Commit

Permalink
fix: add missing useLazyQuery type
Browse files Browse the repository at this point in the history
  • Loading branch information
wobsoriano committed Aug 22, 2023
1 parent f7eeb10 commit 299ae55
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
2 changes: 1 addition & 1 deletion playground/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const addTodo = async () => {
}
}
const { data: todos, pending, error, refresh } = await $client.todo.getTodos.useQuery()
const { data: todos, pending, error, refresh } = await $client.todo.getTodos.useLazyQuery()
</script>

<template>
Expand Down
10 changes: 5 additions & 5 deletions src/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,17 @@ 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))
const watch = isRef(input) ? [...(asyncDataOptions.watch || []), input] : asyncDataOptions.watch
const isLazy = lastArg === 'useLazyQuery' ? true : (asyncDataOptions.lazy || false)

return useAsyncData(queryKey, () => (client as any)[path].query(unref(input), {
signal: controller?.signal,
...trpc
}), {
...asyncDataOptions,
watch: isRef(input) ? [...(asyncDataOptions.watch || []), input] : asyncDataOptions.watch
watch,
lazy: isLazy
})
}

Expand Down
24 changes: 20 additions & 4 deletions src/client/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ type DecorateProcedure<
> = TProcedure extends AnyQueryProcedure
? {
useQuery: <
ResT = inferTransformedProcedureOutput<TProcedure>,
DataE = TRPCClientErrorLike<TProcedure>,
DataT = ResT,
PickKeys extends KeysOf<DataT> = KeysOf<DataT>,
ResT = inferTransformedProcedureOutput<TProcedure>,
DataE = TRPCClientErrorLike<TProcedure>,
DataT = ResT,
PickKeys extends KeysOf<DataT> = KeysOf<DataT>,
>(
input: MaybeRef<inferProcedureInput<TProcedure>>,
opts?: AsyncDataOptions<ResT, DataT, PickKeys> & {
Expand All @@ -68,6 +68,22 @@ type DecorateProcedure<
queryKey?: string
},
) => AsyncData<PickFrom<DataT, PickKeys> | null, DataE>,
useLazyQuery: <
ResT = inferTransformedProcedureOutput<TProcedure>,
DataE = TRPCClientErrorLike<TProcedure>,
DataT = ResT,
PickKeys extends KeysOf<DataT> = KeysOf<DataT>,
>(
input: MaybeRef<inferProcedureInput<TProcedure>>,
opts?: Omit<AsyncDataOptions<ResT, DataT, PickKeys>, 'lazy'> & {
trpc?: TRPCRequestOptions
/**
* The custom unique key to use.
* @see https://nuxt.com/docs/api/composables/use-async-data#params
*/
queryKey?: string
},
) => AsyncData<PickFrom<DataT, PickKeys> | null, DataE>,
query: Resolver<TProcedure>
} : TProcedure extends AnyMutationProcedure ? {
mutate: Resolver<TProcedure>
Expand Down

1 comment on commit 299ae55

@vercel
Copy link

@vercel vercel bot commented on 299ae55 Aug 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

trpc-nuxt – ./

trpc-nuxt-wobsoriano.vercel.app
trpc-nuxt.vercel.app
trpc-nuxt-git-main-wobsoriano.vercel.app

Please sign in to comment.