Skip to content

Commit

Permalink
feat: add custom query key option
Browse files Browse the repository at this point in the history
  • Loading branch information
wobsoriano committed Aug 21, 2023
1 parent 4289dcb commit f2bcf9b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export function createNuxtProxyDecoration<TRouter extends AnyRouter> (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

Expand All @@ -54,7 +54,7 @@ export function createNuxtProxyDecoration<TRouter extends AnyRouter> (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
Expand Down
9 changes: 8 additions & 1 deletion src/client/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,14 @@ type DecorateProcedure<
PickKeys extends KeysOf<DataT> = KeysOf<DataT>,
>(
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>,
query: Resolver<TProcedure>
} : TProcedure extends AnyMutationProcedure ? {
Expand Down

0 comments on commit f2bcf9b

Please sign in to comment.