mirror of
https://github.com/ArthurDanjou/trpc-nuxt.git
synced 2026-01-14 12:14:40 +01:00
feat: add custom query key option
This commit is contained in:
@@ -41,7 +41,7 @@ export function createNuxtProxyDecoration<TRouter extends AnyRouter> (name: stri
|
|||||||
const [input, otherOptions] = args
|
const [input, otherOptions] = args
|
||||||
|
|
||||||
if (lastArg === 'useQuery') {
|
if (lastArg === 'useQuery') {
|
||||||
const { trpc, ...asyncDataOptions } = otherOptions || {} as any
|
const { trpc, queryKey: customQueryKey, ...asyncDataOptions } = otherOptions || {} as any
|
||||||
|
|
||||||
let controller: AbortController
|
let controller: AbortController
|
||||||
|
|
||||||
@@ -54,7 +54,7 @@ export function createNuxtProxyDecoration<TRouter extends AnyRouter> (name: stri
|
|||||||
controller = typeof AbortController !== 'undefined' ? new AbortController() : {} as AbortController
|
controller = typeof AbortController !== 'undefined' ? new AbortController() : {} as AbortController
|
||||||
}
|
}
|
||||||
|
|
||||||
const queryKey = getQueryKey(path, unref(input))
|
const queryKey = customQueryKey || getQueryKey(path, unref(input))
|
||||||
return useAsyncData(queryKey, () => (client as any)[path].query(unref(input), {
|
return useAsyncData(queryKey, () => (client as any)[path].query(unref(input), {
|
||||||
signal: controller?.signal,
|
signal: controller?.signal,
|
||||||
...trpc
|
...trpc
|
||||||
|
|||||||
@@ -59,7 +59,14 @@ type DecorateProcedure<
|
|||||||
PickKeys extends KeysOf<DataT> = KeysOf<DataT>,
|
PickKeys extends KeysOf<DataT> = KeysOf<DataT>,
|
||||||
>(
|
>(
|
||||||
input: MaybeRef<inferProcedureInput<TProcedure>>,
|
input: MaybeRef<inferProcedureInput<TProcedure>>,
|
||||||
opts?: AsyncDataOptions<ResT, DataT, PickKeys> & { trpc?: TRPCRequestOptions },
|
opts?: AsyncDataOptions<ResT, DataT, PickKeys> & {
|
||||||
|
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>,
|
) => AsyncData<PickFrom<DataT, PickKeys> | null, DataE>,
|
||||||
query: Resolver<TProcedure>
|
query: Resolver<TProcedure>
|
||||||
} : TProcedure extends AnyMutationProcedure ? {
|
} : TProcedure extends AnyMutationProcedure ? {
|
||||||
|
|||||||
Reference in New Issue
Block a user