Allow useInfiniteQueryParam for POST endpoints without OpenAPI query parameters
Description
What problem does this feature solve?
When generating React Query infinite hooks, Orval currently requires
useInfiniteQueryParam to exist among the operation's OpenAPI query parameters.
This is a limitation for POST endpoints where pagination parameters are provided in the request body rather than as URL query parameters.
For example, our API has the following endpoint:
/element/page/v2:
post:
operationId: searchPageableElementsByFilter
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/ElementFilter'
responses:
'200':
content:
'*/*':
schema:
$ref: '#/components/schemas/CommonPageableResponseElementResponse'The pagination parameter (offset) is a property of ElementFilter, so there is no OpenAPI in: query parameter named offset.
However, we would like to generate an infinite query using:
query: {
useQuery: true,
useInfinite: true,
useInfiniteQueryParam: 'offset',
}Currently Orval resolves the configured infinite query parameter against queryParams. Since the operation has no query parameters, the infinite hook is considered not allowed and is not generated.
Why this seems too restrictive
useInfiniteQueryParam describes the parameter that should receive the pageParam value from TanStack Query. It does not necessarily need to be a URL query parameter.
For example, for a POST endpoint it is perfectly valid for the generated request to conceptually look like:
const queryFn = ({ pageParam }) =>
searchPageableElementsByFilter({
...elementFilter,
offset: pageParam,
});In this case offset is part of the request body rather than the URL.
Therefore, requiring useInfiniteQueryParam to be present in the OpenAPI queryParams seems to couple infinite query generation too tightly to URL query parameters.
Current behavior
We currently have to modify GeneratorVerbOptions.queryParams in a custom PreGen transformer and inject a synthetic query parameter so that Orval considers the infinite hook valid.
This works, but it is effectively a workaround around an internal generator constraint rather than an actual API requirement.
Proposed behavior
I suggest separating these two concepts:
- Whether the configured useInfiniteQueryParam exists in the URL query parameters.
- Whether the configured parameter can be used as the pagination parameter for the generated infinite query.
For example, when:
useInfinite: true,
useInfiniteQueryParam: 'offset',is explicitly configured for an operation, Orval could generate the infinite hook even when offset is not an OpenAPI in: query parameter.
The generated code should then allow the configured parameter to be supplied through the appropriate request input (e.g. request body for POST operations).
An alternative would be to introduce an explicit option indicating that the infinite query parameter is not an URL query parameter.
Example
Given:
searchPageableElementsByFilter: {
query: {
useQuery: true,
useInfinite: true,
useInfiniteQueryParam: 'offset',
},
},and:
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/ElementFilter'where ElementFilter contains:
type ElementFilter = {
// ...
offset?: number;
};I would expect Orval to generate an infinite hook and use:
const queryFn = ({ signal, pageParam }) =>
searchPageableElementsByFilter(
{
...elementFilter,
offset: pageParam,
},
{ signal }
);without requiring offset to also be declared as an OpenAPI query parameter.
Related issues
This appears to be related to the existing handling of useInfiniteQueryParam:
#393 — useInfiniteQueryParam generates invalid code when the parameter does not exist. #3101 — useInfiniteQueryParam should only be added to hooks with that query parameter present.
Those issues make sense for preventing invalid generated code, but they also highlight the underlying assumption that the infinite pagination parameter must be an OpenAPI query parameter.
This proposal is specifically about relaxing that assumption for request bodies, particularly POST endpoints.
Proposed solution
The infinite query generation should not depend on whether useInfiniteQueryParam is declared as an OpenAPI query parameter.
For operations where useInfiniteQueryParam is configured, Orval could:
- Generate the infinite query hook even when the configured parameter is not present in operation.parameters.
- Determine where the parameter belongs:
- query parameter → add it to the URL query;
- request body → add it to the request body.
- For POST endpoints with body-based pagination, generate the pageParam inside the request body:
const queryFn = ({ pageParam }) =>
searchPageableElementsByFilter({
...elementFilter,
offset: pageParam,
});Alternatively, an explicit option could be introduced to indicate that the infinite query parameter is located in the request body, for example:
useInfiniteQueryParam: 'offset',
useInfiniteQueryParamLocation: 'body',This would preserve the current behavior for query parameters while allowing common POST pagination patterns without requiring synthetic OpenAPI query parameters or custom generator transformers.
Source: orval-labs/orval