Skip to content

Commit

Permalink
fix: added missing request params in to the queryFn
Browse files Browse the repository at this point in the history
  • Loading branch information
yusufbkr committed Nov 9, 2024
1 parent 2385221 commit 5915332
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
3 changes: 2 additions & 1 deletion src/common.mts
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,10 @@ export function createQueryKeyFnExport(
queryKey: string,
method: VariableDeclaration,
type: "query" | "mutation" = "query",
modelNames: string[] = [],
) {
// Mutation keys don't require clientOptions
const params = type === "query" ? getRequestParamFromMethod(method) : null;
const params = type === "query" ? getRequestParamFromMethod(method, undefined, modelNames) : null;

// override key is used to allow the user to override the the queryKey values
const overrideKey = ts.factory.createParameterDeclaration(
Expand Down
2 changes: 1 addition & 1 deletion src/createUseQuery.mts
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ export const createUseQuery = ({
queryKey,
});

const queryKeyFn = createQueryKeyFnExport(queryKey, method);
const queryKeyFn = createQueryKeyFnExport(queryKey, method, "query", modelNames);

return {
apiResponse: defaultApiResponse,
Expand Down
12 changes: 6 additions & 6 deletions tests/__snapshots__/createSource.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@ import { AxiosError } from "axios";
export type FindPetsDefaultResponse = Awaited<ReturnType<typeof findPets>>["data"];
export type FindPetsQueryResult<TData = FindPetsDefaultResponse, TError = unknown> = UseQueryResult<TData, TError>;
export const useFindPetsKey = "FindPets";
export const UseFindPetsKeyFn = (clientOptions: Options<unknown, true> = {}, queryKey?: Array<unknown>) => [useFindPetsKey, ...(queryKey ?? [clientOptions])];
export const UseFindPetsKeyFn = (clientOptions: Options<FindPetsData, true> = {}, queryKey?: Array<unknown>) => [useFindPetsKey, ...(queryKey ?? [clientOptions])];
export type GetNotDefinedDefaultResponse = Awaited<ReturnType<typeof getNotDefined>>["data"];
export type GetNotDefinedQueryResult<TData = GetNotDefinedDefaultResponse, TError = unknown> = UseQueryResult<TData, TError>;
export const useGetNotDefinedKey = "GetNotDefined";
export const UseGetNotDefinedKeyFn = (clientOptions: Options<unknown, true> = {}, queryKey?: Array<unknown>) => [useGetNotDefinedKey, ...(queryKey ?? [clientOptions])];
export type FindPetByIdDefaultResponse = Awaited<ReturnType<typeof findPetById>>["data"];
export type FindPetByIdQueryResult<TData = FindPetByIdDefaultResponse, TError = unknown> = UseQueryResult<TData, TError>;
export const useFindPetByIdKey = "FindPetById";
export const UseFindPetByIdKeyFn = (clientOptions: Options<unknown, true>, queryKey?: Array<unknown>) => [useFindPetByIdKey, ...(queryKey ?? [clientOptions])];
export const UseFindPetByIdKeyFn = (clientOptions: Options<FindPetByIdData, true>, queryKey?: Array<unknown>) => [useFindPetByIdKey, ...(queryKey ?? [clientOptions])];
export type FindPaginatedPetsDefaultResponse = Awaited<ReturnType<typeof findPaginatedPets>>["data"];
export type FindPaginatedPetsQueryResult<TData = FindPaginatedPetsDefaultResponse, TError = unknown> = UseQueryResult<TData, TError>;
export const useFindPaginatedPetsKey = "FindPaginatedPets";
export const UseFindPaginatedPetsKeyFn = (clientOptions: Options<unknown, true> = {}, queryKey?: Array<unknown>) => [useFindPaginatedPetsKey, ...(queryKey ?? [clientOptions])];
export const UseFindPaginatedPetsKeyFn = (clientOptions: Options<FindPaginatedPetsData, true> = {}, queryKey?: Array<unknown>) => [useFindPaginatedPetsKey, ...(queryKey ?? [clientOptions])];
export type AddPetMutationResult = Awaited<ReturnType<typeof addPet>>;
export const useAddPetKey = "AddPet";
export const UseAddPetKeyFn = (mutationKey?: Array<unknown>) => [useAddPetKey, ...(mutationKey ?? [])];
Expand Down Expand Up @@ -113,19 +113,19 @@ import { Pet, NewPet, Error, FindPetsData, FindPetsResponse, FindPetsError, AddP
export type FindPetsDefaultResponse = Awaited<ReturnType<typeof findPets>>["data"];
export type FindPetsQueryResult<TData = FindPetsDefaultResponse, TError = unknown> = UseQueryResult<TData, TError>;
export const useFindPetsKey = "FindPets";
export const UseFindPetsKeyFn = (clientOptions: Options<unknown, true> = {}, queryKey?: Array<unknown>) => [useFindPetsKey, ...(queryKey ?? [clientOptions])];
export const UseFindPetsKeyFn = (clientOptions: Options<FindPetsData, true> = {}, queryKey?: Array<unknown>) => [useFindPetsKey, ...(queryKey ?? [clientOptions])];
export type GetNotDefinedDefaultResponse = Awaited<ReturnType<typeof getNotDefined>>["data"];
export type GetNotDefinedQueryResult<TData = GetNotDefinedDefaultResponse, TError = unknown> = UseQueryResult<TData, TError>;
export const useGetNotDefinedKey = "GetNotDefined";
export const UseGetNotDefinedKeyFn = (clientOptions: Options<unknown, true> = {}, queryKey?: Array<unknown>) => [useGetNotDefinedKey, ...(queryKey ?? [clientOptions])];
export type FindPetByIdDefaultResponse = Awaited<ReturnType<typeof findPetById>>["data"];
export type FindPetByIdQueryResult<TData = FindPetByIdDefaultResponse, TError = unknown> = UseQueryResult<TData, TError>;
export const useFindPetByIdKey = "FindPetById";
export const UseFindPetByIdKeyFn = (clientOptions: Options<unknown, true>, queryKey?: Array<unknown>) => [useFindPetByIdKey, ...(queryKey ?? [clientOptions])];
export const UseFindPetByIdKeyFn = (clientOptions: Options<FindPetByIdData, true>, queryKey?: Array<unknown>) => [useFindPetByIdKey, ...(queryKey ?? [clientOptions])];
export type FindPaginatedPetsDefaultResponse = Awaited<ReturnType<typeof findPaginatedPets>>["data"];
export type FindPaginatedPetsQueryResult<TData = FindPaginatedPetsDefaultResponse, TError = unknown> = UseQueryResult<TData, TError>;
export const useFindPaginatedPetsKey = "FindPaginatedPets";
export const UseFindPaginatedPetsKeyFn = (clientOptions: Options<unknown, true> = {}, queryKey?: Array<unknown>) => [useFindPaginatedPetsKey, ...(queryKey ?? [clientOptions])];
export const UseFindPaginatedPetsKeyFn = (clientOptions: Options<FindPaginatedPetsData, true> = {}, queryKey?: Array<unknown>) => [useFindPaginatedPetsKey, ...(queryKey ?? [clientOptions])];
export type AddPetMutationResult = Awaited<ReturnType<typeof addPet>>;
export const useAddPetKey = "AddPet";
export const UseAddPetKeyFn = (mutationKey?: Array<unknown>) => [useAddPetKey, ...(mutationKey ?? [])];
Expand Down
11 changes: 8 additions & 3 deletions tests/__snapshots__/generate.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ import type {
getNotDefined,
postNotDefined,
} from "../requests/services.gen";
import type {
FindPaginatedPetsData,
FindPetByIdData,
FindPetsData,
} from "../requests/types.gen";
export type FindPetsDefaultResponse = Awaited<
ReturnType<typeof findPets>
>["data"];
Expand All @@ -23,7 +28,7 @@ export type FindPetsQueryResult<
> = UseQueryResult<TData, TError>;
export const useFindPetsKey = "FindPets";
export const UseFindPetsKeyFn = (
clientOptions: Options<unknown, true> = {},
clientOptions: Options<FindPetsData, true> = {},
queryKey?: Array<unknown>,
) => [useFindPetsKey, ...(queryKey ?? [clientOptions])];
export type GetNotDefinedDefaultResponse = Awaited<
Expand All @@ -47,7 +52,7 @@ export type FindPetByIdQueryResult<
> = UseQueryResult<TData, TError>;
export const useFindPetByIdKey = "FindPetById";
export const UseFindPetByIdKeyFn = (
clientOptions: Options<unknown, true>,
clientOptions: Options<FindPetByIdData, true>,
queryKey?: Array<unknown>,
) => [useFindPetByIdKey, ...(queryKey ?? [clientOptions])];
export type FindPaginatedPetsDefaultResponse = Awaited<
Expand All @@ -59,7 +64,7 @@ export type FindPaginatedPetsQueryResult<
> = UseQueryResult<TData, TError>;
export const useFindPaginatedPetsKey = "FindPaginatedPets";
export const UseFindPaginatedPetsKeyFn = (
clientOptions: Options<unknown, true> = {},
clientOptions: Options<FindPaginatedPetsData, true> = {},
queryKey?: Array<unknown>,
) => [useFindPaginatedPetsKey, ...(queryKey ?? [clientOptions])];
export type AddPetMutationResult = Awaited<ReturnType<typeof addPet>>;
Expand Down

0 comments on commit 5915332

Please sign in to comment.