Skip to content

Commit

Permalink
fix(query): fix pageParam for useInfiniteQuery (#947)
Browse files Browse the repository at this point in the history
* fix(query): fix pageParam

* fix(query): fix pageParam

* fix(query): fix pageParam

* fix(query): fix pageParam

* fix(query): fix pageParam

* fix(query): fix pageParam

* fix(query): fix pageParam
  • Loading branch information
georgiev-anton authored Nov 17, 2023
1 parent 5b29452 commit 685edcd
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 14 deletions.
6 changes: 5 additions & 1 deletion packages/query/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -849,7 +849,11 @@ const generateQueryImplementation = ({
)
return param.destructured;
return param.name === 'params'
? `{ ${queryParam}: pageParam, ...params }`
? `{...params, ${queryParam}: pageParam || ${
isVue(outputClient)
? `unref(params)?.['${queryParam}']`
: `params?.['${queryParam}']`
}}`
: param.name;
})
.join(',')
Expand Down
20 changes: 12 additions & 8 deletions samples/nx-fastify-react/apps/app/src/api/endpoints/petstoreAPI.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
/**
* Generated by orval v6.17.0 🍺
* Generated by orval v6.19.1 🍺
* Do not edit manually.
* Petstore API
* Petstore API
* OpenAPI spec version: 1.0.0
*/
import { useQuery } from 'react-query';
import type {
UseQueryOptions,
QueryFunction,
UseQueryResult,
QueryKey,
UseQueryOptions,
UseQueryResult,
} from 'react-query';
import type { GetPets201Item } from '../schemas';
import { customInstance } from '../mutator/custom-instance';
Expand All @@ -27,16 +27,16 @@ export const getPets = (signal?: AbortSignal) => {
});
};

export const getGetPetsQueryKey = () => [`/pets`] as const;
export const getGetPetsQueryKey = () => {
return [`/pets`] as const;
};

export const getGetPetsQueryOptions = <
TData = Awaited<ReturnType<typeof getPets>>,
TError = unknown
>(options?: {
query?: UseQueryOptions<Awaited<ReturnType<typeof getPets>>, TError, TData>;
}): UseQueryOptions<Awaited<ReturnType<typeof getPets>>, TError, TData> & {
queryKey: QueryKey;
} => {
}) => {
const { query: queryOptions } = options ?? {};

const queryKey = queryOptions?.queryKey ?? getGetPetsQueryKey();
Expand All @@ -45,7 +45,11 @@ export const getGetPetsQueryOptions = <
signal,
}) => getPets(signal);

return { queryKey, queryFn, ...queryOptions };
return { queryKey, queryFn, ...queryOptions } as UseQueryOptions<
Awaited<ReturnType<typeof getPets>>,
TError,
TData
> & { queryKey: QueryKey };
};

export type GetPetsQueryResult = NonNullable<
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Generated by orval v6.17.0 🍺
* Generated by orval v6.19.1 🍺
* Do not edit manually.
* Petstore API
* Petstore API
Expand Down
2 changes: 1 addition & 1 deletion samples/nx-fastify-react/apps/app/src/api/schemas/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Generated by orval v6.17.0 🍺
* Generated by orval v6.19.1 🍺
* Do not edit manually.
* Petstore API
* Petstore API
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ export const getListPetsInfiniteQueryOptions = <
Awaited<ReturnType<typeof listPets>>,
QueryKey,
ListPetsParams['limit']
> = ({ pageParam }) => listPets({ limit: pageParam, ...params }, version);
> = ({ pageParam }) =>
listPets({ ...params, limit: pageParam || params?.['limit'] }, version);

return {
queryKey,
Expand Down Expand Up @@ -348,7 +349,8 @@ export const getListPetsSuspenseInfiniteQueryOptions = <
Awaited<ReturnType<typeof listPets>>,
QueryKey,
ListPetsParams['limit']
> = ({ pageParam }) => listPets({ limit: pageParam, ...params }, version);
> = ({ pageParam }) =>
listPets({ ...params, limit: pageParam || params?.['limit'] }, version);

return {
queryKey,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,12 @@ export const getListPetsInfiniteQueryOptions = <
const queryFn: QueryFunction<Awaited<ReturnType<typeof listPets>>> = ({
signal,
pageParam,
}) => listPets({ limit: pageParam, ...params }, version, signal);
}) =>
listPets(
{ ...params, limit: pageParam || params?.['limit'] },
version,
signal,
);

return {
queryKey,
Expand Down

0 comments on commit 685edcd

Please sign in to comment.