Skip to content

Add support for query options api #173

Closed

Description

@bryanjtc

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
Currently I can't get type safety when using the generated query key in query client utilities.
Describe the solution you'd like
A clear and concise description of what you want to happen.
The query options solves this problem by centralizing the query function and the query key and other custom options in one function.

https://tkdodo.eu/blog/the-query-options-api

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

Activity

  1. 7nohe commented on Aug 11, 2026

    @7nohe
    Owner

    Implemented in v3.0.0.

    Generated output now includes a `queries/queryOptions.ts` module built on TanStack Query's `queryOptions()` / `infiniteQueryOptions()` helpers, so the query key and query function are colocated in one type-safe object:

    import { useQuery } from "@tanstack/react-query";
    import { findPetByIdOptions } from "./openapi/queries/queryOptions";
    
    const { data } = useQuery(findPetByIdOptions({ path: { id: 1 } }));

    The same factories work with the query client utilities you mentioned — `queryClient.setQueryData`, `getQueryData`, `ensureQueryData`, etc. — with the key inferred rather than hand-written.

    Available now on `latest` (`npm i @7nohe/openapi-react-query-codegen@3`). See the migration guide for the full v3 changes. Thanks for the suggestion and for linking the TkDodo post — it shaped the design.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions