graphql-code-generator-community
graphql-code-generator-community copied to clipboard
Unexpected Result with Nullish Coalescing and Ternary Operators in React Query's infinite query key
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.
Your Example Website or App
https://github.com/nanopang/graphql-code-generator-community/commit/95c2a728a3d23278c821d5e5734cec0b23a8c1e2
Steps to Reproduce the Bug or Issue
- 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
graphqlversion:16.8.1@graphql-codegen/typescript-react-queryversion(s): 6.1.0
Codegen Config File
No response
Additional context
No response
+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.