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

RFC: feat(query): add shouldExportMutatorHooks option #1105

Merged
merged 1 commit into from
Jan 31, 2024

Conversation

ezequiel
Copy link
Contributor

@ezequiel ezequiel commented Dec 8, 2023

Status

HOLD

Description

When client is set as react-query, 3 different functions are generated for each query/mutation. For example:

export const useCreateUserHook = () => {
  ... 
};

export const useCreateUserMutationOptions = <TError = ErrorType<unknown>, TContext = unknown>(...): ... => {
  ...
};


export const useCreateUser = <TError = ErrorType<unknown>, TContext = unknown>(...) => {
  ....
};

GOAL: I don't want to export useCreateUserHook. This causes confusion for my team and I on which function to use: useCreateUserHook, or useCreateUser? Ideally we always use the react-query version (useCreateUser), but it's easier if we just don't export it at all, so no one can make the mistake

(I arguably don't want useCreateUserMutationOptions exported either, but that one is less problematic)

I made this an option to preserve backwards compatibility, but let me know your thoughts

Steps to Test or Reproduce

orval.config.js

module.exports = {
  api: {
    input: {
      target: '../docs/swagger.json',
      override: {
        transformer,
      },
    },
    validation: true,
    output: {
      target: 'api.generated.ts',
      client: 'react-query',
      workspace: 'src/api',
      override: {
        query: {
          useQuery: false,
          useSuspenseQuery: true,
          shouldExportMutatorHooks: false,
        },
      },
    },
  },
};

Verified the mutator hook is no longer exported

@ezequiel
Copy link
Contributor Author

ezequiel commented Dec 8, 2023

Do we think this is an actual problem, and worth adding an option for?

Thinking a little more here, it'd be nice if there was a granular export configuration capability to control exactly how much gets exported (e.g. in my case, I don't want the mutator hook or MutationOptions exported), though that seems a little difficult here given all the different clients. Adding a one-off option for now might complicate things in the future, if we ever decide to go down that route

@ezequiel ezequiel changed the title feat(query): add shouldExportMutatorHooks option RFC: feat(query): add shouldExportMutatorHooks option Dec 8, 2023
@melloware
Copy link
Collaborator

I like the idea can you add a matching Issue ticket so I can link this PR to a ticket please.

@melloware melloware added this to the 6.24.0 milestone Dec 19, 2023
@melloware melloware added the enhancement New feature or request label Dec 19, 2023
@melloware melloware merged commit e602232 into orval-labs:master Jan 31, 2024
2 checks passed
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

Successfully merging this pull request may close these issues.

3 participants