-
-
Notifications
You must be signed in to change notification settings - Fork 624
Open
Labels
bugSomething isn't workingSomething isn't workingopenapi-react-queryRelevant to openapi-react-queryRelevant to openapi-react-query
Description
openapi-react-query version
0.5.1
Description
When calling $api.useQuery, it's possible to accidentally pass React Query options (retry, refetchInterval, refetchOnMount, etc.) as the 3rd argument (options) instead of the 4th argument (queryOptions). TypeScript does not flag this, and at runtime the options are silently ignored.
This applies to endpoints that don't have options parameters defined in the schema.
Reproduction
// schema
export interface paths {
"/me": {
parameters: {
query?: never;
header?: never;
path?: never;
cookie?: never;
};
get: operations["get_user"];
put: operations["update_user"];
post?: never;
delete?: never;
options?: never;
head?: never;
patch?: never;
trace?: never;
};
}
export interface operations {
get_user: {
parameters: {
query?: never;
header?: never;
path?: never;
cookie?: never;
};
requestBody?: never;
responses: {
// ...
};
};import createClient from "openapi-react-query";
import createFetchClient from "openapi-fetch";
const fetchClient = createFetchClient<paths>({ baseUrl: "https://api.example.com" });
const $api = createClient(fetchClient);
// No type error — but `refetchOnMount` and `retry` are silently swallowed
// by the fetch client and never reach React Query
const query = $api.useQuery("get", "/me", {
retry: false,
refetchOnMount: false,
});
// Correct usage (options in 4th arg):
const query = $api.useQuery("get", "/me", undefined, {
retry: false,
refetchOnMount: false,
});Expected result
Passing queryOptions as the third param should raise a type error
Extra
- I’m willing to open a PR (see CONTRIBUTING.md)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingopenapi-react-queryRelevant to openapi-react-queryRelevant to openapi-react-query