orval
orval copied to clipboard
Extra axios options are not generated for react-query
Hi, I need to pass additional options to axios, but can't find a way to do this with react-query client (haven't tested with other clients).
I have this config:
import { defineConfig } from 'orval';
export default defineConfig({
server: {
input: 'http://server:8000/api/v1/schema.json',
output: {
target: './src/restTypes.ts',
client: 'react-query',
override: {
mutator: {
path: './src/hooks/useServer.ts',
name: 'useServer',
default: true,
},
},
}
},
});
And a hook for axios:
import { useContext } from 'react';
import { AxiosRequestConfig } from 'axios';
import { AxiosContext } from '../components/AxiosProvider';
const useServer = <T>(): ((
config: AxiosRequestConfig,
options?: AxiosRequestConfig,
) => Promise<T>) => {
const { axios } = useContext(AxiosContext);
return (config: AxiosRequestConfig, options?: AxiosRequestConfig) => {
return axios({
...config,
...options,
}).then(({ data }) => data);
};
};
export default useServer;
However, when I generate the code using orval, looks like it doesn't add the second parameter:
Maybe I'm doing something wrong. Let me know if I'm missing something.
Thanks.
Hello @denisorehovsky, It's not possible for the moment with the hook. I will need to take a look at it
@anymaniax When will have time to take a look? If not soon, maybe I will take a look myself.
If you have the time go ahead. It's always a pleasure to receive some help 🥹
@anymaniax Hi. I'm looking at the examples again, and I see this:
This is react query example and it looks like it provides extra axios options. However, when I generate types locally, I don't see this option in the code:
What am I doing wrong?
The problem is the hook that returns a function. Behind the implementation is not the same.
@anymaniax I really don't have a lot of free time right now for contributing and understanding the codebase. But I would love to see this improvement merged. Is it possible to increase the priority of this issue? Maybe donate some money. Let me know what you think. Thanks.
@denisorehovsky I will try to take a look at it but I am doing that during my free time so it's not always easy to find time so I prioritize bugs first. And for the support, I want to invest more time to open source in a long term and it can help for sure but I prefer that you do it because you like the project and want to support it.
should be fixed with 6.9.5
can you verify, please?
@anymaniax Works perfectly. Thank you.
Great! Also thanks for the support 😊