Skip to content

Conversation

minchodang
Copy link

Changes

This PR adds the infiniteQueryOptions helper method to openapi-react-query, resolving #2462.

What's Added:

  • New infiniteQueryOptions method in the client API
  • Type-safe support for TanStack Query's Infinite Query Options
  • Comprehensive documentation at docs/openapi-react-query/infinite-query-options.md
  • Unit tests covering pagination scenarios

Implementation Details:

  • Added InfiniteQueryOptionsFunction type with full type inference for pageParam, InfiniteData, and select return types
  • infiniteQueryOptions returns ready-to-use options for useInfiniteQuery, usePrefetchInfiniteQuery, QueryClient.fetchInfiniteQuery, and other infinite query APIs
  • Supports customizable page parameter name via pageParamName option (defaults to "cursor")
  • Reuses the library's existing queryKey convention for consistency

Why This Matters:

Previously, openapi-react-query provided excellent ergonomics for standard queries through queryOptions and useQuery, but lacked first-class support for infinite queries. Users had to hand-roll option objects and type definitions for cursor/offset pagination use cases.

This addition:

  • Brings feature parity with TanStack Query v5's options helpers
  • Reduces boilerplate and type-casting for paginated endpoints
  • Improves type-safety around pageParam and InfiniteData
  • Enables users to leverage any TanStack Query infinite query API not explicitly wrapped by this library
  • Aligns with existing DX patterns established by queryOptions

How to Review

  1. Implementation: Review the infiniteQueryOptions function and type definitions in packages/openapi-react-query/src/index.ts:

    • Type inference for pageParam via InferPageParamType
    • Pagination logic that merges pageParam into query params
    • Consistency with existing queryOptions implementation
  2. Tests: Check test coverage in packages/openapi-react-query/test/ for:

    • Type inference validation
    • getNextPageParam/getPreviousPageParam behavior
    • Integration with useInfiniteQuery
  3. Documentation: Review docs/openapi-react-query/infinite-query-options.md for:

    • Clear API explanation and usage examples
    • Consistency with other documentation (compare with query-options.md)
    • Practical examples showing usage with useInfiniteQuery and usePrefetchInfiniteQuery
  4. Navigation: Verify the new page is properly integrated in .vitepress/en.ts

Checklist

  • Unit tests updated
  • docs/ updated
  • pnpm run update:examples run (N/A - only applicable for openapi-typescript)

Closes #2462

@minchodang minchodang requested a review from a team as a code owner October 4, 2025 04:50
@minchodang minchodang requested a review from htunnicliff October 4, 2025 04:50
Copy link

netlify bot commented Oct 4, 2025

👷 Deploy request for openapi-ts pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit a87698b

Copy link

changeset-bot bot commented Oct 4, 2025

⚠️ No Changeset found

Latest commit: a87698b

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@minchodang minchodang force-pushed the feature/infinite-query-options branch from ddc3d33 to 07aea3a Compare October 4, 2025 05:02
…eQueryOptions

- Add initialPageParam to UseInfiniteQueryMethod options
- Use InferPageParamType<Options> instead of unknown for TPageParam
- Clean up unused variables in tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add infiniteQueryOptions function
1 participant