graphql-code-generator-community icon indicating copy to clipboard operation
graphql-code-generator-community copied to clipboard

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

Open altaudio opened this issue 6 months ago • 1 comments

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: https://github.com/dotansimha/graphql-code-generator-community/pull/1104

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

altaudio avatar May 19 '25 14:05 altaudio

would love to see this implemented. @dotansimha any thoughts on how we can get this in?

djstein avatar May 19 '25 15:05 djstein