Skip to content

Add infiniteQueryOptions function #2462

@minchodang

Description

@minchodang

Description

I frequently use TanStack Query’s infiniteQueryOptions for cursor/offset pagination, and I love how openapi-typescript models REST interfaces. In openapi-react-query, we currently have great ergonomics for standard queries, but there’s no first-class helper for infinite queries. This forces consumers to hand-roll option objects and typings repeatedly.

Adding an infiniteQueryOptions helper would:
• Bring feature parity with TanStack Query v5’s options helpers
• Reduce boilerplate and copy-paste across paginated endpoints
• Improve type-safety, especially around pageParam and InfiniteData
• Align with the existing queryOptions ergonomics and DX in this library

I’m opening this issue to propose the API and contribute an implementation with tests and docs.

Proposal

API

Introduce a typed helper that mirrors TanStack Query v5 semantics while leveraging this library’s path/method typing:

client.infiniteQueryOptions<
  Method extends HttpMethod,
  Path extends PathsWithMethod<Paths, Method>,
  Init extends RequestInitLike = RequestInitLike,
  Options extends Omit<
    UseInfiniteQueryOptions<
      Response["data"],
      Response["error"],
      InferSelectReturnType<InfiniteData<Response["data"]>, Options["select"]>,
      Response["data"],
      QueryKey<Paths, Method, Path>,
      InferPageParamType<Options>
    >,
    "queryKey" | "queryFn"
  >
>(
  method: Method,
  path: Path,
  init?: Init,
  options?: Options
): UseInfiniteQueryOptions<
  Response["data"],
  Response["error"],
  InferSelectReturnType<InfiniteData<Response["data"]>, Options["select"]>,
  Response["data"],
  QueryKey<Paths, Method, Path>,
  InferPageParamType<Options>
>;

Key points:
• Returns a ready-to-pass options object for useInfiniteQuery.
• Infers pageParam from options.initialPageParam via InferPageParamType.
• Supports getNextPageParam, getPreviousPageParam, select, retry, staleTime, etc.
• Reuses the library’s queryKey convention for stable keys.

Example

const options = client.infiniteQueryOptions(
  "get",
  "/v1/items",
  { headers: { Authorization: token } },
  {
    initialPageParam: undefined as string | undefined,
    queryFn: ({ pageParam }) =>
      client.GET("/v1/items", { params: { query: { cursor: pageParam } } })
        .then(r => r.data),
    getNextPageParam: lastPage => lastPage.nextCursor,
    select: data => data, // optional
  }
);

// usage
const result = useInfiniteQuery(options);

Prior art
• TanStack Query v5 infiniteQueryOptions: https://tanstack.com/query/latest/docs/framework/react/reference/infiniteQueryOptions

Compatibility
• Additive, no breaking changes.
• Mirrors existing queryOptions patterns.

Testing & Docs
• Type tests to verify inference of pageParam, InfiniteData, and select result types.
• Runtime tests for getNextPageParam/getPreviousPageParam.
• README updates with a quickstart and example.

Extra

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions