-
-
Notifications
You must be signed in to change notification settings - Fork 485
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 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. |
Hi, @mortik Sorry for the long wait, I've retraced the steps so far. First, if you want to customize the query key, you can currently do so by using https://orval.dev/reference/configuration/output#querykey For Other discussions: With this change, when you add an option, the |
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.
@mortik I added a question.
packages/query/src/index.ts
Outdated
? [`'${operationName}'`, ...queryKeyPathParams] | ||
: routeString; |
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.
Should this be common and no separation is necessary?
? [`'${operationName}'`, ...queryKeyPathParams] | |
: routeString; | |
? operationName : routeString; |
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.
@mortik
I still don't understand why this change is necessary so could you explain for me?
Or, incorporate this change.
@mortik looks like conflicts too |
i tried to use the |
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
Co-authored-by: Shodai Suzuki <[email protected]>
544d036
to
4251d09
Compare
i resolved the conflict :) |
Co-authored-by: Shodai Suzuki <[email protected]>
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