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

POST operation not treated as query despite tag override #730

Closed
dawsonbooth opened this issue Jan 11, 2023 · 5 comments · Fixed by #1212
Closed

POST operation not treated as query despite tag override #730

dawsonbooth opened this issue Jan 11, 2023 · 5 comments · Fixed by #1212
Assignees
Labels
bug Something isn't working workaround A workaround has been provided
Milestone

Comments

@dawsonbooth
Copy link
Contributor

dawsonbooth commented Jan 11, 2023

What are the steps to reproduce this issue?

  1. Add tag override to treat POST with "search" tag as a query
    output: {
      target: 'src/api/generated.ts',
      mode: 'single',
      client: 'react-query',
      override: {
        tags: {
          search: {
            query: {
              useQuery: true,
            },
          },
        },
      },
    },

What happens?

Hooks are still generated as mutations, just moved to a different part of the file.

What were you expecting to happen?

Hooks would be generated as queries.

Any other comments?

#515 has a working example using operations. However, since we have no operation IDs on the paths, using a tag is ideal.

@dawsonbooth dawsonbooth changed the title POST operation not treated as query with tag override POST operation not treated as query despite tag override Jan 11, 2023
@mattiasnordqvist
Copy link

Not working for us either. Did you find a solution?

@dawsonbooth
Copy link
Contributor Author

Not exactly. We're instead wrapping the mutation with a custom hook that mimics the query API, which isn't really ideal but works for now for our purposes.

@mattiasnordqvist

This comment was marked as outdated.

@mattiasnordqvist
Copy link

mattiasnordqvist commented Nov 10, 2023

This worked for us:

  override: {
        query: {
          useQuery: false,
          useMutation: false,
        },
        transformer: (verbOptions) => {
          verbOptions.override.operations[verbOptions.operationId] = {
            ...verbOptions.override.operations[verbOptions.operationId],
            query: {
              ...verbOptions.override.operations[verbOptions.operationId]?.query,
              useMutation: verbOptions.verb == 'post' && verbOptions.tags.includes('Command'),
              useQuery: verbOptions.verb == 'get' || verbOptions.tags.includes('Query'),
            },
          };
          return verbOptions;
        },

@melloware melloware added bug Something isn't working workaround A workaround has been provided labels Nov 10, 2023
@melloware melloware self-assigned this Feb 9, 2024
@melloware melloware added this to the 6.25.0 milestone Feb 9, 2024
@melloware
Copy link
Collaborator

Submitted a bug fix for 6.25.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working workaround A workaround has been provided
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants