queryKey not recognized or failing when using addInfiniteQuery: true #10586
-
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
@synasapmob this is a known operator precedence bug in the codegen plugin. when your query has optional variables, the generated infinite query hook produces: queryKey: optionsQueryKey ?? variables === undefined ? ['Query.infinite'] : ['Query.infinite', variables]due to JS precedence, this parses as regular queries aren't affected because they use a different codegen path that doesn't destructure there's an open fix PR #1092 that adds the missing parentheses (single character change in workaround: patch the package to add the parentheses yourself: # if using pnpm
pnpm patch @graphql-codegen/typescript-react-query
# in the patched file, find generateInfiniteQueryFormattedParameters in fetcher.js
# change: queryKey: optionsQueryKey ?? ${queryKey},
# to: queryKey: optionsQueryKey ?? (${queryKey}),
pnpm patch-commit @graphql-codegen/typescript-react-queryor just use ref: issue #786 | fix PR #1092 | MDN nullish coalescing precedence |
Beta Was this translation helpful? Give feedback.


@synasapmob this is a known operator precedence bug in the codegen plugin. when your query has optional variables, the generated infinite query hook produces:
due to JS precedence, this parses as
(optionsQueryKey ?? (variables === undefined)) ? [...] : [...]instead ofoptionsQueryKey ?? (variables === undefined ? [...] : [...]). your customqueryKeygets swallowed because the??resolves to a truthy value before the ternary evaluates.regular queries aren't affected because they use a different codegen path that doesn't destructure
queryKeyfrom options.queryKeyHashFnstill works be…