Provide the queryKey in error message #4042
Replies: 2 comments 1 reply
-
I've tried, but the problem is the overloads of useQuery and how we parse arguments: So if it's neither an array, nor a function, it will be spread, and spreading a string results in the queryKey being However, now that I'm thinking about it, maybe you want to contribute to add an additional dev-only runtime check similar to this one: query/packages/query-core/src/query.ts Lines 353 to 359 in 357ec04 to
if we throw in useQuery, it will go to error state and retry. I wanted to avoid that because it hides the issue. The uncaught type error seems to be a natural follow-up bug because we have no overloads for this function, thus we don't use |
Beta Was this translation helpful? Give feedback.
-
I was having the same error, and problem was TYPO, where i write gueryKey instead a queryKey. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi! 👋🏽
As one of the breaking changes on v4, the
queryKey
needs to be an Array. I want to report to our internal services when a non-arrayqueryKey
is provided so our microfrontends can migrate accordingly - we have 30+ of projects to update.There's an error logged when a non-array queryKey is provided (reference) but it doesn't contain the provided queryKey. Is it possible to add it to the message?
My current solution is to override the
useQuery
export to check thequeryKey
, but I think doing it through the logger would be a cleaner solution.Related question:
useQuery
doesn't throw, only logs, when a non-arrayqueryKey
is provided and it works fine, data is loaded, but other APIs such asgetQueryData
fail when receiving a string asqueryKey
, e.g.:index.js:1341 Uncaught TypeError: Cannot create property 'exact' on string 'someQueryKey'
(reference) -arg1
is the string, not falsy, therefore returned, which fails here.Are there plans to throw an error in
useQuery
OR support strings in other APIs?Beta Was this translation helpful? Give feedback.
All reactions