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

bug?: react-query implementation when POST is used it always transforms into useMutation while for some cases its a useQuery for us! #515

Closed
maapteh opened this issue Jul 28, 2022 · 5 comments
Labels
enhancement New feature or request

Comments

@maapteh
Copy link

maapteh commented Jul 28, 2022

Hi, i noticed when my endpoint is POST the tooling generates a useMutation implementation, while for us it's really a useQuery.

Since we can't dictate how the api's should be setup (POST has been chosen as a security measurement for this particular case), I was wondering if there is a way to tell the tooling which implementation to use for specific endpoints/methods?

@maapteh maapteh changed the title docs: influence on react-query implementation bug?: influence on react-query implementation Jul 29, 2022
@maapteh maapteh changed the title bug?: influence on react-query implementation bug?: react-query implementation when POST is used it always transforms into useMutation while for some cases its a useQuery for us! Jul 29, 2022
@maapteh maapteh changed the title bug?: react-query implementation when POST is used it always transforms into useMutation while for some cases its a useQuery for us! bug?: react-query implementation when POST is used it always transforms into useMutation while for some cases its a useQuery for us! Jul 29, 2022
@anymaniax
Copy link
Collaborator

anymaniax commented Jul 30, 2022

Hey @maapteh it's not possible for now. I would it to add an option for it. But you can use the function generate and use it in a useMutation at the moment

@anymaniax anymaniax added the enhancement New feature or request label Jul 30, 2022
@reichhartd
Copy link
Contributor

I think you can also use override to create a useQuery for a specific operationId (in this case FindUsers).
We have a similar case and solve it like this:

import { defineConfig } from 'orval';

import openApiSpec from './apiSpecs/swagger.json';

export default defineConfig({
    [openApiSpec.info.title]: {
        output: {
            clean: true,
            client: 'react-query',
            headers: true,
            mode: 'tags-split',
            override: {
                operations: {
                    FindUsers: {
                        query: {
                            useQuery: true,
                        },
                    },
                },
            },
            target: 'src/services/generated/api.ts',
            tsconfig: 'tsconfig.json',
        },
        input: {
            target: 'apiSpecs/swagger.json',
        },
    },
});

@anymaniax
Copy link
Collaborator

Thanks, @reichhartd. Completely forgot that I did that 😅

@landtee
Copy link

landtee commented Jul 24, 2024

sorry if I poke everyone watching this thread but I wonder if there is a way to generate both useQuery, useMutation with custom name as right now overriding with both useMutation and useQuery are true give out hook with same name

@melloware
Copy link
Collaborator

@landtee i suggest opening a Discussion in the Discussion area and provide your example config and what its generating and what you would like it to generate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants