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

feat: adds uniqueSuspenseQueryKeys option

Open altaudio opened this issue 6 months ago • 1 comments

🚨 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 https://github.com/dotansimha/graphql-code-generator-community/issues/1105

Type of change

  • [x] 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:

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

altaudio avatar May 19 '25 14:05 altaudio

🦋 Changeset detected

Latest commit: 4820b24fd2c0babfc6a0cf365e2738b5ce041da1

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

changeset-bot[bot] avatar May 19 '25 14:05 changeset-bot[bot]