From f2bcf9b68b109a8579ba17b2f643759116e736af Mon Sep 17 00:00:00 2001 From: wobsoriano Date: Sun, 20 Aug 2023 22:50:48 -0700 Subject: [PATCH] feat: add custom query key option --- src/client/index.ts | 4 ++-- src/client/types.ts | 9 ++++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/client/index.ts b/src/client/index.ts index 870e6dd..476e4ec 100644 --- a/src/client/index.ts +++ b/src/client/index.ts @@ -41,7 +41,7 @@ export function createNuxtProxyDecoration (name: stri const [input, otherOptions] = args if (lastArg === 'useQuery') { - const { trpc, ...asyncDataOptions } = otherOptions || {} as any + const { trpc, queryKey: customQueryKey, ...asyncDataOptions } = otherOptions || {} as any let controller: AbortController @@ -54,7 +54,7 @@ export function createNuxtProxyDecoration (name: stri 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), { signal: controller?.signal, ...trpc diff --git a/src/client/types.ts b/src/client/types.ts index 5657f66..fdbb0b7 100644 --- a/src/client/types.ts +++ b/src/client/types.ts @@ -59,7 +59,14 @@ type DecorateProcedure< PickKeys extends KeysOf = KeysOf, >( input: MaybeRef>, - opts?: AsyncDataOptions & { trpc?: TRPCRequestOptions }, + opts?: AsyncDataOptions & { + trpc?: TRPCRequestOptions + /** + * The custom unique key to use. + * @see https://nuxt.com/docs/api/composables/use-async-data#params + */ + queryKey?: string + }, ) => AsyncData | null, DataE>, query: Resolver } : TProcedure extends AnyMutationProcedure ? {