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

Unexpected Result with Nullish Coalescing and Ternary Operators in React Query's infinite query key

Open nanopang opened this issue 1 year ago • 1 comments

Which packages are impacted by your issue?

@graphql-codegen/typescript-react-query

Describe the bug

While using the generated infinite query function and providing the queryKey option, it uses the [XXX.infinite] instead of the provided queryKey.

  • CleanShot 2024-07-19 at 16 51 55

Your Example Website or App

https://github.com/nanopang/graphql-code-generator-community/commit/95c2a728a3d23278c821d5e5734cec0b23a8c1e2

Steps to Reproduce the Bug or Issue

  1. Codegen typescript-react-query with addInfiniteQuery 2.Pass the queryKey value to the generated Infinite query 3.It will ignore the queryKey

Expected behavior

use the provided optionsQueryKey instead of the [XXX.infinite]

Screenshots or Videos

No response

Platform

  • OS: MacOS
  • NodeJS: 20.12.2
  • graphql version:16.8.1
  • @graphql-codegen/typescript-react-query version(s): 6.1.0

Codegen Config File

No response

Additional context

No response

nanopang avatar Jul 19 '24 09:07 nanopang

+1 Facing the same issue.

The solution is to wrap the ternaries in a bracket.

before: queryKey: optionsQueryKey ?? variables === undefined ? ['Modules.infinite'] : ['Modules.infinite', variables],

after: queryKey: optionsQueryKey ?? (variables === undefined ? ['Modules.infinite'] : ['Modules.infinite', variables]),

This should be a proposed PR.

MR-AMDEV avatar May 07 '25 10:05 MR-AMDEV