Pass an additional option object in fetcher function when using custom axios instance
See original GitHub issueWhat are the steps to reproduce this issue?
- The fetchcer function in generated code is correct with default config
orval.config.ts:
import { defineConfig } from 'orval'
export default defineConfig({
test: {
output: {
mode: 'split',
target: './swag.ts',
client: 'react-query',
},
input: {
target: './swagger.json',
}
}
})
result:
export const auth = (
options?: AxiosRequestConfig // here we have an options here
): Promise<AxiosResponse<X>> => {
return axios.get(
`/api/v1/auth`,options
);
}
- But with custom axios instance config:
export default defineConfig({
test: {
output: {
mode: 'split',
target: './swag.ts',
client: 'react-query',
+ override: {
+ mutator: {
+ path: './custom-instance.ts',
+ name: 'customInstance',
+ },
},
},
input: {
target: './swagger.json',
}
}
})
The options param no longer remains…
export const auth = ( // here no options can be passed in
) => {
return customInstance<X>(
{url: `/api/v1/auth`, method: 'get'
},
);
}
What were you expecting to happen?
I want to pass some different option to some request, for example a longer timeout for certain requests. But with custom axios instance it behaves different than default one, it’ll need to make custom axios instance also have fetcher function accept an options object as param.
What versions are you using?
Package Version: v6.7.1
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Create custom fetch hook for multiple Axios instances - ITNEXT
Customize how to fetch data with React hooks.
Read more >Passing custom props via axios config · Issue #2295 - GitHub
Describe the bug We use some custom parameters via axios configuration. They are used in the response interceptor.
Read more >How to pass dynamic parameters to axios instance
To pass headers dynamically, you could export a function that takes options as an argument and returns a new instance of axios :...
Read more >Axios vs. fetch(): Which is best for making HTTP requests?
Axios is not always an ideal solution; depending on your needs, there are sometimes better options for making HTTP requests.
Read more >Arguments - SWR
In some scenarios, it's useful to pass multiple arguments (can be any value or object) to the fetcher function. For example an authorized...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Damn you are right !!! 😂😂
Maybe we should add this to the doc.
After some probing, I found out this is already supported from https://github.com/anymaniax/orval/issues/282. 🙂
The solution was maybe not the most obvious one but I was able to get this working by adding a second parameter to the custom client definition then regenerating the code, e.g.: