orval
orval copied to clipboard
Feature Request: Add operationId to queryKey for better React Query hook identification
Is your feature request related to a problem? Please describe.
Currently, when generating React Query hooks using Orval, the queryKey returned from the ...QueryKey functions only includes the API path, for example:
return [`/some/path`] as const;
This makes it difficult to uniquely identify or cache queries in larger projects where many paths may be dynamic or similar.
Describe the solution you’d like
I’d like to request an option in Orval’s config to include the operationId alongside the API path in the queryKey, like:
return ['getSomeData', `/some/path`] as const;
Describe alternatives you’ve considered
We are currently using a custom post-generation script to parse the generated api-docs.ts and inject the operationId manually, but this approach is brittle and could break with future Orval updates.
Additional context
It would be great if this could be implemented as an opt-in configuration flag, for example:
reactQuery:
includeOperationIdInQueryKey: true
Thanks for the great tool and all your hard work!
I feel like this has been asked before and solved maybe with a mutator function?
I've retraced the steps so far.
First, if you want to customize the query key, you can currently do so by using override.query.querykey.
https://orval.dev/reference/configuration/output#querykey
For mutator, starting with #1730, the operationId defined in the OpenAPI is now used as the query key by default.
- https://github.com/orval-labs/orval/pull/1730
Other discussions:
- https://github.com/orval-labs/orval/issues/243
With this change, when you add an option, the OpenAPI operationId will be used as the query key by default. This makes sense to me, as it's the same behavior as the default for mutator 👍