dotansimha / dotansimha/graphql-code-generator-community

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

Open
#1,105 1 comment 2 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
137
Forks
195
Avg merge
6h 20m
Merged PRs (30d)
16

Description

**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](https://tanstack.com/query/latest/docs/framework/react/guides/advanced-ssr#streaming-with-server-components) — 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.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.