Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ensureQueryData incorrectly handles throwOnError #172

Open
alula opened this issue Nov 17, 2024 · 0 comments
Open

ensureQueryData incorrectly handles throwOnError #172

alula opened this issue Nov 17, 2024 · 0 comments

Comments

@alula
Copy link

alula commented Nov 17, 2024

Describe the bug
The generated ensureQueryData.ts specifies Options<T, true>, which restricts the value of throwOnError to true or undefined and assumes that the query never fails.

However the default value of throwOnError is false, so in code currently generated by this tool, if it's not explicitly set by the user, causes both type (the function returns undefined while it's not meant to) and runtime (Query data cannot be undefined. Please make sure to return a value other than undefined from your query function) issues.

Potentially related to #148

To Reproduce
Generate the query code from any API schema and try to use any of the ensure* functions.

"dependencies": {
    "@hey-api/client-fetch": "^0.4.3",
    "@tanstack/react-query": "^5.60.2",
    "@7nohe/openapi-react-query-codegen": "2.0.0-beta.3",
}

Expected behavior
I think that ensure* functions should always throw an error.

Returning undefined is not supported by react-query and does not let you properly handle the failed query.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant