-
-
Notifications
You must be signed in to change notification settings - Fork 466
feat: Add useOperationIdAsQueryKey option for query key generation #2314
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
base: master
Are you sure you want to change the base?
feat: Add useOperationIdAsQueryKey option for query key generation #2314
Conversation
This commit adds a new configuration option useOperationIdAsQueryKey to the query options that allows users to generate query keys using the OpenAPI operation ID instead of the route string. Changes Made: - Added useOperationIdAsQueryKey option to QueryOptions and NormalizedQueryOptions interfaces - Modified query key generation logic to use operation ID when enabled - Added support for the new option in normalizeQueryOptions function - Added comprehensive tests for the new functionality Benefits: - Stable keys that dont change when route paths are modified - Cleaner, more semantic query keys - Consistent naming across applications - Backward compatible (defaults to false) Fixes orval-labs#2096
- Added comprehensive documentation for the useOperationIdAsQueryKey option in the existing output configuration docs - Removed accidental .tool-versions file that's not part of the project structure - Added code examples showing the difference between default and new behavior - Integrated documentation into the existing project structure
This should resolve #2096 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
I realized that this approach still needs an update to include the path params like id etc. i will update the pr to include that in the querykey function |
Please give me a little time to salvage past discussions about cases where you might want to use arbitrary strings for query keys. And once a policy has been decided, it will need to be documented in the documentation to avoid any confusion. |
Summary
Fix #2096
This PR adds a new configuration option
useOperationIdAsQueryKey
that allows users to generate query keys using the OpenAPI operation ID instead of the route string for TanStack Query implementations.Changes
useOperationIdAsQueryKey?: boolean
toQueryOptions
andNormalizedQueryOptions
typespackages/query/src/index.ts
to use operation ID when enablednormalizeQueryOptions
function to handle the new optionpackages/query/src/utils.test.ts
/docs/src/pages/reference/configuration/output.md
Configuration Example