question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Extra axios options are not generated for react-query

See original GitHub issue

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:

image

Maybe I’m doing something wrong. Let me know if I’m missing something.

Thanks.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
anymaniaxcommented, Aug 29, 2022

Great! Also thanks for the support 😊

1reaction
denisorehovskycommented, Aug 29, 2022

@anymaniax Works perfectly. Thank you.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Request not responding, Why an OPTIONS method is sent ...
I've been having a problem i don't really have using jQuery Ajax methods, when i use axios, my request sends one Request Method:OPTIONS...
Read more >
Data Fetching with React Query & Axios | by Alex Streza
Axios is a solid library don't get me wrong but react-query brings a caching mechanism under the hood and its API is incredibly...
Read more >
Axios get in url works but with second parameter as object it ...
axios.get accepts a request config as the second parameter (not query string params). You can use the params config option to set query...
Read more >
react-query-swagger - npm
Generates react -query hooks for your API based on Swagger/OpenAPI ... There are no other projects in the npm registry using react-query-swagger.
Read more >
React Query 3: A Guide to Fetching and Managing Data
Need to fetch data in React? Learn about React Query, an excellent server state management library for simplifying your data-fetching needs.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found