Skip to content

ensureQueryData incorrectly handles throwOnError #172

@alula

Description

@alula

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions