Skip to content

Generates incorrect queryKeys for Infinite queries #140

Description

@AnderssonPeter

Describe the bug
Generates incorrect queryKeys for Infinite queries, the page is expected to be sent into the KeyFn.

To Reproduce
Steps to reproduce the behavior:

  • Generate client using openapi-rq --pageParam page --input https://localhost:44353/swagger/v1/swagger.json --output src/openapi/.
  • Compile code 💥

Expected behavior
I think you need 2 sets for KeyFn functions one for Infinite queries and one for the normal request.
Where the Infinite version excludes the page.

Screenshots
image

  • OS: Windows 11
  • Version v1.6.0

Activity

  1. changed the title [-]generates incorrect queryKeys for Infinite queries[/-] [+]Generates incorrect queryKeys for Infinite queries[/+] on Aug 19, 2024
  2. hanahem commented on Aug 20, 2024

    @hanahem

    Oh thanks for raising this one, I think it causes the issue I raised here:
    #139

  3. self-assigned this
    on Sep 16, 2024
  4. 7nohe commented on Aug 11, 2026

    @7nohe
    Owner

    Fixed in v3.0.0.

    Infinite queries now get their own key constant and key function, separate from the plain query ones, and the page parameter is excluded from the infinite key at the type level:

    export type FindPaginatedPetsInfiniteClientOptions = Omit<Options<FindPaginatedPetsData, true>, "query"> & { query?: Omit<NonNullable<FindPaginatedPetsData["query"]>, "page"> };
    
    export const useFindPaginatedPetsInfiniteKey = [useFindPaginatedPetsKey, "infinite"] as const;
    export const UseFindPaginatedPetsInfiniteKeyFn = (clientOptions: FindPaginatedPetsInfiniteClientOptions = {}, queryKey?: Array<unknown>) => [...useFindPaginatedPetsInfiniteKey, ...(queryKey ?? [clientOptions])];

    The page value is threaded into the request only (query: { ...clientOptions.query, page: pageParam }), never into the key — so the key stays stable across pages, which is the behaviour TanStack Query expects.

    Note the infinite key nests the plain key as its first segment. That means invalidateQueries({ queryKey: [useFindPaginatedPetsKey] }) still matches both caches, while the "infinite" segment keeps cached InfiniteData from colliding with plain query data.

    A custom page-param name (--pageParam) is respected in the Omit. Available on latest (npm i @7nohe/openapi-react-query-codegen@3). Thanks for the clear report — the two-key-set design is exactly what you proposed.

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

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions