Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: added missing request params in to the queryKeyFn #169

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading