diff --git a/src/createUseQuery.mts b/src/createUseQuery.mts index ea91907..8eb919e 100644 --- a/src/createUseQuery.mts +++ b/src/createUseQuery.mts @@ -347,7 +347,7 @@ export function createQueryHook({ ), ts.factory.createIdentifier("queryKey"), ] - : [], + : [ts.factory.createIdentifier("queryKey")], ), ), ts.factory.createPropertyAssignment( @@ -490,7 +490,7 @@ function createQueryKeyFnExport(queryKey: string, method: MethodDeclaration) { ts.factory.createArrowFunction( undefined, undefined, - params ? [params, overrideKey] : [], + params ? [params, overrideKey] : [overrideKey], undefined, EqualsOrGreaterThanToken, queryKeyFn(queryKey, method), @@ -506,14 +506,6 @@ function queryKeyFn( queryKey: string, method: MethodDeclaration, ): ts.Expression { - const params = getRequestParamFromMethod(method); - - if (!params) { - return ts.factory.createArrayLiteralExpression([ - ts.factory.createIdentifier(queryKey), - ]); - } - return ts.factory.createArrayLiteralExpression( [ ts.factory.createIdentifier(queryKey), diff --git a/tests/__snapshots__/createSource.test.ts.snap b/tests/__snapshots__/createSource.test.ts.snap index ff7385b..dd528b0 100644 --- a/tests/__snapshots__/createSource.test.ts.snap +++ b/tests/__snapshots__/createSource.test.ts.snap @@ -24,7 +24,7 @@ export const UseDefaultServiceFindPetsKeyFn = ({ limit, tags }: { export type DefaultServiceGetNotDefinedDefaultResponse = Awaited>; export type DefaultServiceGetNotDefinedQueryResult = UseQueryResult; export const useDefaultServiceGetNotDefinedKey = "DefaultServiceGetNotDefined"; -export const UseDefaultServiceGetNotDefinedKeyFn = () => [useDefaultServiceGetNotDefinedKey]; +export const UseDefaultServiceGetNotDefinedKeyFn = (queryKey?: Array) => [useDefaultServiceGetNotDefinedKey, ...(queryKey ?? [])]; export type DefaultServiceFindPetByIdDefaultResponse = Awaited>; export type DefaultServiceFindPetByIdQueryResult = UseQueryResult; export const useDefaultServiceFindPetByIdKey = "DefaultServiceFindPetById"; @@ -67,7 +67,7 @@ export const useDefaultServiceFindPets = = unknown[]>(queryKey?: TQueryKey, options?: Omit, "queryKey" | "queryFn">) => useQuery({ queryKey: Common.UseDefaultServiceGetNotDefinedKeyFn(), queryFn: () => DefaultService.getNotDefined() as TData, ...options }); +export const useDefaultServiceGetNotDefined = = unknown[]>(queryKey?: TQueryKey, options?: Omit, "queryKey" | "queryFn">) => useQuery({ queryKey: Common.UseDefaultServiceGetNotDefinedKeyFn(queryKey), queryFn: () => DefaultService.getNotDefined() as TData, ...options }); /** * Returns a user based on a single ID, if the user does not have access to the pet * @param data The data for the request. @@ -145,7 +145,7 @@ export const useDefaultServiceFindPetsSuspense = = unknown[]>(queryKey?: TQueryKey, options?: Omit, "queryKey" | "queryFn">) => useSuspenseQuery({ queryKey: Common.UseDefaultServiceGetNotDefinedKeyFn(), queryFn: () => DefaultService.getNotDefined() as TData, ...options }); +export const useDefaultServiceGetNotDefinedSuspense = = unknown[]>(queryKey?: TQueryKey, options?: Omit, "queryKey" | "queryFn">) => useSuspenseQuery({ queryKey: Common.UseDefaultServiceGetNotDefinedKeyFn(queryKey), queryFn: () => DefaultService.getNotDefined() as TData, ...options }); /** * Returns a user based on a single ID, if the user does not have access to the pet * @param data The data for the request. diff --git a/tests/__snapshots__/generate.test.ts.snap b/tests/__snapshots__/generate.test.ts.snap index 7b7c14d..4aed6c0 100644 --- a/tests/__snapshots__/generate.test.ts.snap +++ b/tests/__snapshots__/generate.test.ts.snap @@ -15,7 +15,7 @@ export const UseDefaultServiceFindPetsKeyFn = ({ limit, tags }: { export type DefaultServiceGetNotDefinedDefaultResponse = Awaited>; export type DefaultServiceGetNotDefinedQueryResult = UseQueryResult; export const useDefaultServiceGetNotDefinedKey = "DefaultServiceGetNotDefined"; -export const UseDefaultServiceGetNotDefinedKeyFn = () => [useDefaultServiceGetNotDefinedKey]; +export const UseDefaultServiceGetNotDefinedKeyFn = (queryKey?: Array) => [useDefaultServiceGetNotDefinedKey, ...(queryKey ?? [])]; export type DefaultServiceFindPetByIdDefaultResponse = Awaited>; export type DefaultServiceFindPetByIdQueryResult = UseQueryResult; export const useDefaultServiceFindPetByIdKey = "DefaultServiceFindPetById"; @@ -110,7 +110,7 @@ export const useDefaultServiceFindPets = = unknown[]>(queryKey?: TQueryKey, options?: Omit, "queryKey" | "queryFn">) => useQuery({ queryKey: Common.UseDefaultServiceGetNotDefinedKeyFn(), queryFn: () => DefaultService.getNotDefined() as TData, ...options }); +export const useDefaultServiceGetNotDefined = = unknown[]>(queryKey?: TQueryKey, options?: Omit, "queryKey" | "queryFn">) => useQuery({ queryKey: Common.UseDefaultServiceGetNotDefinedKeyFn(queryKey), queryFn: () => DefaultService.getNotDefined() as TData, ...options }); /** * Returns a user based on a single ID, if the user does not have access to the pet * @param data The data for the request. @@ -187,7 +187,7 @@ export const useDefaultServiceFindPetsSuspense = = unknown[]>(queryKey?: TQueryKey, options?: Omit, "queryKey" | "queryFn">) => useSuspenseQuery({ queryKey: Common.UseDefaultServiceGetNotDefinedKeyFn(), queryFn: () => DefaultService.getNotDefined() as TData, ...options }); +export const useDefaultServiceGetNotDefinedSuspense = = unknown[]>(queryKey?: TQueryKey, options?: Omit, "queryKey" | "queryFn">) => useSuspenseQuery({ queryKey: Common.UseDefaultServiceGetNotDefinedKeyFn(queryKey), queryFn: () => DefaultService.getNotDefined() as TData, ...options }); /** * Returns a user based on a single ID, if the user does not have access to the pet * @param data The data for the request.