Shaddix / react-query-swagger

Generates react-query hooks based on Swagger API definitions
MIT License
122 stars 4 forks source link

Unable to override axios config for individual query #38

Closed schwer closed 7 months ago

schwer commented 7 months ago

I am using the following arguments to build a client:

react-query-swagger /tanstack /input:swagger.yaml /template:Axios /serviceHost:. /use-recommended-configuration /output:lib/openapi.ts

And when using the generated client, I want to be able to override the axios behavarior for a specific useQuery usage:

import { Query } from './lib/openapi';

export function useMyQuery(axiosInstance: AxiosInstance) {
  return client.useMyQuery({
     onSuccess() {
       console.log("success");
     }
  }, {
    baseURL: "https://some-other-domain.com",
  });
}

When I look at the generated sources, the config is not being passed into the client method that runs the request. It therefore only uses the query configuration based on the setAxiosFactory or set...AxiosConfig call.

The generated client method looks like this:

function __getMyQuery() {
   return Client.getMyQuery();
}

The call stack indicates that the __getMyQuery function is being called with the attached meta/config passed into the original useQuery call. I suspect a fix here would require a slight modification because it's just adding an additional argument to an existing call flow.

Shaddix commented 7 months ago

Thanks for the report, plan to have this fixed today

Shaddix commented 7 months ago

@schwer the latest version should contain the fix. Could you please check if it's ok or not now? :)

Shaddix commented 7 months ago

I'm closing this one, feel free to reopen if something goes wrong