Skip to content

feat: adds uniqueSuspenseQueryKeys option #1104

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

altaudio
Copy link

@altaudio altaudio commented May 19, 2025

🚨 IMPORTANT: Please do not create a Pull Request without creating an issue first.

Any change needs to be discussed before proceeding. Failure to do so may result in the rejection of the pull request.

Description

This PR introduces a new configuration option, uniqueSuspenseQueryKeys, to the @graphql-codegen/typescript-react-query plugin.

Currently, suspense and standard query hooks are generated with different query keys, which leads to duplicated cache entries and complicates cache invalidation, prefetching, and general React Query usage. However, React Query treats suspense as a rendering strategy rather than a unique query variant, and its documentation does not suggest different keys are necessary.

This change allows users to opt-in to reusing the same query key between suspense and standard hooks, streamlining the developer experience.

Related #1105

Type of change

  • New feature (non-breaking change which adds functionality)

How Has This Been Tested?

  • Added a new test case in react-query.spec.ts under config: uniqueSuspenseQueryKeys that ensures shared keys between suspense and non-suspense hooks
  • Verified generated output via snapshot
  • Tested the package locally against our app - the query keys are successfully generated

Test Environment:

  • OS: macOS 13.7.5
  • @graphql-codegen: 5.0.5
  • NodeJS: 22.14.0

Checklist:

  • I have followed the CONTRIBUTING doc and the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

Copy link

changeset-bot bot commented May 19, 2025

🦋 Changeset detected

Latest commit: 4820b24

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@graphql-codegen/typescript-react-query Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@altaudio altaudio force-pushed the as/adds-unique-suspense-query-keys-option branch from 669e4f2 to 4820b24 Compare May 19, 2025 14:50
@altaudio altaudio marked this pull request as ready for review May 19, 2025 14:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant