Skip to content

Conversation

mortik
Copy link

@mortik mortik commented Aug 18, 2025

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

  • Added useOperationIdAsQueryKey?: boolean to QueryOptions and NormalizedQueryOptions types
  • Modified query key generation logic in packages/query/src/index.ts to use operation ID when enabled
  • Updated normalizeQueryOptions function to handle the new option
  • Added comprehensive tests in packages/query/src/utils.test.ts
  • Added documentation in /docs/src/pages/reference/configuration/output.md

Configuration Example

module.exports = {
  petstore: {
    output: {
      client: 'react-query',
      override: {
        query: {
          useOperationIdAsQueryKey: true,
        },
      },
    },
    input: './petstore.yaml',
  },
};

mortik added 2 commits August 18, 2025 15:19
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
@mortik
Copy link
Author

mortik commented Aug 18, 2025

This should resolve #2096

@melloware melloware added the tanstack-query TanStack Query related issue label Aug 18, 2025
AllieJonsson
AllieJonsson previously approved these changes Aug 19, 2025
Copy link
Contributor

@AllieJonsson AllieJonsson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@mortik
Copy link
Author

mortik commented Aug 19, 2025

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

@soartec-lab
Copy link
Member

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.

@soartec-lab soartec-lab self-assigned this Aug 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tanstack-query TanStack Query related issue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature Request: Add operationId to queryKey for better React Query hook identification
4 participants