Skip to content

@kubb/plugin-react-query: Support nextParam and previousParam in Infinite query with nested field support #1815

@davidsonalencar

Description

@davidsonalencar

Feature Request

In the current Infinite type under @kubb/plugin-react-query, we only have queryParam and (optionally) a cursorParam. It would be helpful to support both nextParam and previousParam separately for more flexible pagination handling, especially in APIs that provide both directions.

Proposed enhancement

Extend the Infinite type to include:

export type Infinite = {
  queryParam: string
  nextParam?: string | string[]
  previousParam?: string | string[]
  initialPageParam: unknown
}
  • nextParam: used to extract the cursor for the next page.
  • previousParam: used to extract the cursor for the previous page, useful for bidirectional pagination.
  • Both could support dot notation or an array path to access nested fields, e.g. 'data.next.id' or ['data', 'next', 'id'].

Why this matters

Many paginated APIs return both next and previous cursors, and being able to access them independently — especially when they’re nested — would improve the usability and adaptability of the useInfiniteQuery config generation.

Example use case:

{
  "data": [...],
  "pagination": {
    "next": { "id": "abc123" },
    "prev": { "id": "xyz789" }
  }
}

With:

nextParam: ['pagination', 'next', 'id']
previousParam: ['pagination', 'prev', 'id']

This would allow codegen to correctly extract the right cursor depending on direction and aligns with how getNextPageParam and getPreviousPageParam are used in TanStack Query.

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions