Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Global useQuery Configuration does not apply to POST requests #1723

Open
vitminakov opened this issue Nov 29, 2024 · 6 comments
Open

Global useQuery Configuration does not apply to POST requests #1723

vitminakov opened this issue Nov 29, 2024 · 6 comments
Labels
bug Something isn't working

Comments

@vitminakov
Copy link

vitminakov commented Nov 29, 2024

What are the steps to reproduce this issue?

  1. In the orval.config.js, configure the operations as follows:
operations: {
  query: {
    useQuery: true,
  },
};
  1. Use this configuration on a POST request in the OpenAPI schema.
  2. Generate the API using orval

What happens?

Even though useQuery: true is configured globally, the POST request generates a useMutation instead of a useQuery.

What were you expecting to happen?

I expected the POST request to generate useQuery based on the global configuration.

Any logs, error output, etc?

Any other comments?

When specifying the operationId explicitly in the orval.config.js:

operations: {
  getSideMenu: {
    query: {
      useQuery: true,
    },
  },
};

I have found this #515
Is it related?

What versions are you using?

  System:
    OS: macOS 12.1
    CPU: (10) arm64 Apple M1 Pro
    Memory: 107.91 MB / 16.00 GB
    Shell: 5.8 - /bin/zsh
  npmPackages:
    @tanstack/react-query: 5.61.5 => 5.61.5 
    axios: 1.7.8 => 1.7.8 
    orval: 7.3.0 => 7.3.0 
    react: 18.3.1 => 18.3.1 
@melloware
Copy link
Collaborator

See this ticket: #1162

did you try..

query: {
        useQuery: true,
        useMutation: false,
      }

@vitminakov
Copy link
Author

vitminakov commented Nov 29, 2024

there is my config

/* eslint-disable no-undef */
function header(info) {
  return [
    'eslint-disable',
    'Generated by orval 🍺',
    'Do not edit manually.',
    ...(info.title ? [info.title] : []),
    ...(info.description ? [info.description] : []),
    ...(info.version ? [`OpenAPI spec version: ${info.version}`] : [])
  ];
}

module.exports = {
  bff: {
    output: {
      mode: 'single',
      target: './src/api/bff/index.ts',
      schemas: './src/api/bff/model',
      client: 'react-query',
      clean: true,
      prettier: true,
      headers: true,
      override: {
        header,
        mutator: {
          path: './src/shared/config/axios/instance.ts',
          name: 'customInstance'
        },
        query: {
          useQuery: true,
          useMutation: false,
          usePrefetch: true
        }
      }
    },
    input: {
      target: './merged.yaml'
    }
  }
};

The useMutation: false setting does not generate hooks or prefetch for POST requests at all. The point is to enable POST requests to be made using useQuery as well.

@melloware
Copy link
Collaborator

@thulstrup can you help here?

@vitminakov
Copy link
Author

vitminakov commented Nov 29, 2024

To clarify the situation a bit, I want to know: is it possible to generate useQuery hooks for POST requests instead of useMutation? I assume that the current options act as a filter.

@thulstrup
Copy link

My code from back then looked something like this, but the override doesn’t appear to be functioning properly.

module.exports = {
  example: {
    output: {
      mode: "single",
      clean: true,
      target: "api/index.ts",
      schemas: "api/models",
      client: "react-query",
      override: {
        operations: {
          postExample: {
            query: {
              useQuery: true,
              useMutation: false,
            },
          },
        },
      },
    },
    input: {
      target:
        "https://example.com/swagger/v1/swagger.yaml",
    },
  },
};

@melloware
Copy link
Collaborator

OK so this is a regression bug.

@melloware melloware added the bug Something isn't working label Nov 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants