Skip to content

Feature Request - [react-query] Add config to disable unique query keys for suspense queries #1105

@altaudio

Description

@altaudio

Is your feature request related to a problem? Please describe.

The @graphql-codegen/typescript-react-query plugin currently generates different query keys for suspense and standard query hooks (e.g. ['Posts'] vs ['PostsSuspense']). This means that the same underlying query will be treated as different by React Query depending on the fetching mechanism.

This isn't aligned with React Query's design: suspense is just a different rendering strategy, not a different query. There's no indication in the React Query docs — including the Advanced SSR guide — that query keys should differ.

This causes issues when working with cache invalidation, prefetching, or reusing data across query variants. You often have to invalidate or prefetch both variants manually, which becomes messy and error-prone.

Describe the solution you'd like

I’ve submitted a PR that adds a uniqueSuspenseQueryKeys config option (default true to preserve current behavior). When set to false, it ensures that suspense and standard query variants share the same query key.

Describe alternatives you've considered

  • Manually overriding the query key via options.queryKey, but that’s verbose and easy to forget.
  • Writing a custom plugin — not ideal for such a small config tweak.

Additional context

The PR with the proposed solution is already open here: #1104

Apologies for opening the PR before raising this issue — happy to make modifications or adjustments based on discussion.

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