Skip to content

feat(tanstack-query): .queryKey, .streamedKey, .infiniteKey, .mutationKey#625

Merged
dinwwwh merged 3 commits intomainfrom
unnoq/issue620
Jun 10, 2025
Merged

feat(tanstack-query): .queryKey, .streamedKey, .infiniteKey, .mutationKey#625
dinwwwh merged 3 commits intomainfrom
unnoq/issue620

Conversation

@dinwwwh
Copy link
Copy Markdown
Member

@dinwwwh dinwwwh commented Jun 9, 2025

Fixes #620, #517

Summary by CodeRabbit

  • New Features

    • Introduced dedicated methods for generating query, streamed query, infinite query, and mutation keys within the procedure utilities, making key management more flexible and explicit.
  • Documentation

    • Updated the Tanstack Query integration guide to clarify key generation methods and provide detailed usage examples.
    • Enhanced documentation comments to better distinguish partial matching keys from full matching keys.
  • Tests

    • Added comprehensive unit and type-checking tests for the new key generation utilities and their integration with query state retrieval.
    • Extended end-to-end tests to verify type correctness of query state accessors for various key types.
    • Updated test usage to adopt new key-generating methods for improved clarity.
  • Refactor

    • Centralized and streamlined key generation logic for improved consistency and maintainability.

@vercel
Copy link
Copy Markdown

vercel Bot commented Jun 9, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
orpc ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 10, 2025 1:04pm

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 9, 2025

Walkthrough

This change introduces explicit key generation methods to the Tanstack Query integration, including .queryKey, .streamedKey, .infiniteKey, and .mutationKey. It updates type definitions, refactors utility implementations to use these methods, and adds comprehensive unit and type tests. Documentation is updated to reflect the new key generation approach and improve type inference for query keys.

Changes

File(s) Change Summary
apps/content/docs/integrations/tanstack-query.md Updated documentation to explain new key generation methods and provide usage examples for exact key matching and data updates.
packages/tanstack-query/src/procedure-utils.ts Added .queryKey, .streamedKey, .infiniteKey, .mutationKey methods to ProcedureUtils; refactored options to use them.
packages/tanstack-query/src/types.ts Introduced QueryKeyOptions, experimental_StreamedKeyOptions types; refactored related option types for clarity and reuse.
packages/tanstack-query/src/procedure-utils.test-d.ts Added type-level tests for new key generation and option methods, including error and inference checks.
packages/tanstack-query/src/procedure-utils.test.ts Added unit tests to verify correct delegation and return values of new key generation methods.
packages/tanstack-query/tests/e2e.test-d.ts Added type tests for query state retrieval using new key methods for standard, streamed, and infinite queries.
packages/tanstack-query/tests/e2e.test.tsx Updated test usages to utilize new key methods in query client data retrieval.
packages/tanstack-query/src/general-utils.ts Updated JSDoc for key method to clarify partial matching key usage and updated documentation URL.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant ProcedureUtils
    participant QueryClient

    User->>ProcedureUtils: .queryKey(options)
    ProcedureUtils->>ProcedureUtils: generateOperationKey(path, input)
    ProcedureUtils-->>User: DataTag (query key)

    User->>QueryClient: getQueryData(DataTag)
    QueryClient-->>User: Output (typed result)
Loading

Assessment against linked issues

Objective Addressed Explanation
Infer router output/query key automatically during setQueryData (#620)

Assessment against linked issues: Out-of-scope changes

No out-of-scope changes detected.

Poem

In the garden where queries grow,
Rabbits hop and data flows.
Keys now bloom in tidy rows,
.queryKey, .streamedKey—everyone knows!
With types inferred and bugs kept low,
Our code hops forward—watch it go!
🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between dea342e and fd014a3.

📒 Files selected for processing (2)
  • packages/tanstack-query/src/procedure-utils.test-d.ts (5 hunks)
  • packages/tanstack-query/src/types.ts (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/tanstack-query/src/types.ts
🧰 Additional context used
🧬 Code Graph Analysis (1)
packages/tanstack-query/src/procedure-utils.test-d.ts (3)
packages/contract/src/error.ts (1)
  • ErrorFromErrorMap (49-49)
packages/contract/tests/shared.ts (1)
  • baseErrorMap (12-17)
packages/tanstack-query/tests/shared.tsx (1)
  • queryClient (8-14)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: publish-commit
  • GitHub Check: lint
  • GitHub Check: test
🔇 Additional comments (9)
packages/tanstack-query/src/procedure-utils.test-d.ts (9)

6-6: Imports look correct for the new functionality.

The addition of QueryClient and skipToken imports is necessary for testing the new key generation methods and their integration with QueryClient.


13-13: QueryClient instance creation is appropriate.

Creating a QueryClient instance for testing getQueryState functionality is a good approach to verify that the generated keys work correctly with existing TanStack Query APIs.


44-92: Comprehensive type testing for .queryKey method.

The test suite covers all essential scenarios:

  • Optional vs required input handling
  • Type inference validation
  • skipToken support for conditional queries
  • Query key override capability
  • Return type validation
  • QueryClient integration

The use of @ts-expect-error annotations correctly validates type errors for invalid inputs.


161-166: Good addition of QueryClient integration test.

Testing that getQueryState returns correctly typed data and error states ensures the generated query keys work seamlessly with existing TanStack Query functionality.


168-222: Thorough testing of experimental streamed key functionality.

The .streamedKey tests follow the same comprehensive pattern as .queryKey tests, which is appropriate. The experimental nature is clearly indicated with the experimental_streamedKey method name. The additional queryFnOptions parameter testing (lines 208-214) is a good addition specific to streamed queries.


294-299: Consistent QueryClient integration testing.

The pattern of testing getQueryState with the generated keys is consistently applied across different key types, ensuring all key generation methods integrate properly with QueryClient.


301-397: Sophisticated testing for infinite query keys.

The .infiniteKey tests appropriately handle the complexity of infinite queries:

  • Input function type inference with pageParam
  • PageParam type checking and conflicts
  • Conditional skipToken usage with pageParam functions
  • InfiniteData type validation for getQueryState

The pageParam type conflict testing (lines 348-365) is particularly valuable for catching type mismatches.


548-558: Proper infinite query state type validation.

The test correctly validates that getQueryState returns InfiniteData<UtilsOutput, number> for infinite queries, which is the expected wrapped type for paginated data.


560-578: Appropriate testing for mutation keys.

The .mutationKey tests are appropriately simpler than query key tests since mutations don't typically have input parameters. The tests cover the essential scenarios of optional arguments and key overrides while maintaining consistency with other key generation methods.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Hello @unnoq, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

Summary of Changes

Hello! gemini-code-assist here, providing a summary of this pull request. This PR introduces dedicated helper methods for generating TanStack Query keys within the oRPC TanStack Query integration. Previously, only a generic .key method existed, which was primarily intended for partial matching scenarios like invalidation. This change adds .queryKey, .streamedKey, .infiniteKey, and .mutationKey to provide type-safe, full-matching keys specifically tailored for each query/mutation type, addressing issues #620 and #517. The changes include updates to the core utility function, comprehensive type definition tests, runtime tests, and documentation.

Highlights

  • New Key Generation Methods: Introduced .queryKey, .streamedKey, .infiniteKey, and .mutationKey helpers on the procedure utils for generating type-safe, full-matching keys for their respective TanStack Query operations.
  • Documentation Update: The documentation for the TanStack Query integration has been updated to explain the difference between the existing .key (partial matching) and the new specific key methods (full matching) and provides an example using .queryKey.
  • Improved Type Safety: Extensive TypeScript definition tests (.test-d.ts) have been added to ensure the new key methods correctly handle optional/required inputs, infer types, support skipToken, allow key overrides, and provide correct typing for getQueryState.
  • Internal Usage Update: The existing .queryOptions, .streamedOptions, .infiniteOptions, and .mutationOptions methods have been updated internally to utilize these new dedicated key generation helpers.

Changelog

Click here to see the changelog
  • apps/content/docs/integrations/tanstack-query.md
    • Updated documentation to differentiate between .key (partial matching) and the new specific key methods (.queryKey, etc.) for full matching (lines 140-146).
    • Added an example demonstrating the use of .queryKey with queryClient.setQueryData (lines 165-169).
  • packages/tanstack-query/src/procedure-utils.test-d.ts
    • Added QueryClient import and instantiation for testing getQueryState (lines 6, 13).
    • Added comprehensive type definition tests for .queryKey covering input handling, type inference, skipToken, key override, and getQueryState typing (lines 44-91).
    • Added comprehensive type definition tests for .experimental_streamedKey covering input handling, type inference, skipToken, key override, and getQueryState typing (lines 162-215).
    • Added comprehensive type definition tests for .infiniteKey covering input handling, type inference, skipToken, pageParam inference/conflicts, key override, and getQueryState typing (lines 289-384).
    • Added type definition tests for .mutationKey covering optional arguments, key override, and return type (lines 537-554).
  • packages/tanstack-query/src/procedure-utils.test.ts
    • Added runtime tests for .queryKey verifying generateOperationKey calls and key override (lines 33-39).
    • Added runtime tests for .experimental_streamedKey verifying generateOperationKey calls and key override (lines 78-84).
    • Added runtime tests for .infiniteKey verifying generateOperationKey calls and key override (lines 166-172).
    • Added runtime tests for .mutationKey verifying generateOperationKey calls and key override (lines 237-243).
  • packages/tanstack-query/src/procedure-utils.ts
    • Imported DataTag and QueryKey types (line 3).
    • Imported new key options types experimental_StreamedKeyOptions and QueryKeyOptions (lines 5, 12).
    • Added queryKey method implementation, calling generateOperationKey with type 'query' (lines 126-130).
    • Updated queryOptions to use the new utils.queryKey method (line 133).
    • Added experimental_streamedKey method implementation, calling generateOperationKey with type 'streamed' (lines 158-161).
    • Updated experimental_streamedOptions to use the new utils.experimental_streamedKey method (line 165).
    • Added infiniteKey method implementation, calling generateOperationKey with type 'infinite' (lines 199-205).
    • Updated infiniteOptions to use the new utils.infiniteKey method (line 209).
    • Added mutationKey method implementation, calling generateOperationKey with type 'mutation' (lines 234-238).
    • Updated mutationOptions to use the new utils.mutationKey method (line 241).
    • Assigned the created utils object to a variable before returning (lines 123, 259).
  • packages/tanstack-query/src/types.ts
    • Defined new type QueryKeyOptions for options accepted by key generation methods (lines 37-40).
    • Updated QueryOptionsIn to extend QueryKeyOptions and use Omit for queryKey (lines 41-44).
    • Defined new type experimental_StreamedKeyOptions extending QueryKeyOptions (lines 54-56).
  • packages/tanstack-query/tests/e2e.test-d.ts
    • Added type tests for .queryKey checking getQueryState data and error types (lines 22-29).
    • Added type tests for .streamedKey checking getQueryState data and error types (lines 182-189).
    • Added type tests for .infiniteKey checking getQueryState data and error types (lines 342-349).
  • packages/tanstack-query/tests/e2e.test.tsx
    • Updated getQueryData call in the useQuery test to use .queryKey instead of .key (line 37).
    • Updated getQueryData call in the streamed/useQuery test to use .experimental_streamedKey instead of .key (line 90).
    • Updated getQueryData call in the useInfiniteQuery test to use .infiniteKey instead of .key (line 153).
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 9, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

📢 Thoughts on this report? Let us know!

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces dedicated helper methods (.queryKey, .streamedKey, .infiniteKey, .mutationKey) for generating full matching keys in the TanStack Query integration. This is a valuable addition that improves clarity over the existing .key method (now designated for partial matching) and directly addresses the need for exact key matching for operations like setQueryData.

The changes are well-implemented across documentation, type definitions, and tests. The new methods are clearly defined, and the existing options methods (.queryOptions, etc.) have been refactored to use these new key generation utilities, which is a nice touch for consistency.

Overall, this is a solid enhancement. I have one suggestion regarding a type assertion that could be more precise.

Summary of Findings

  • Type Assertion Precision: In packages/tanstack-query/src/procedure-utils.ts, the infiniteKey method uses as any for its return value. While functionally likely correct due to the interface definition, a more precise cast to the expected DataTag type would improve type safety and explicitness within the implementation.
  • Documentation Update: The documentation in apps/content/docs/integrations/tanstack-query.md has been effectively updated to reflect the new key generation methods and clarify the distinction between partial and full matching keys. The examples are clear.
  • Test Coverage: Comprehensive type definition tests (.test-d.ts) and runtime tests (.test.ts, .test.tsx) have been added for the new key methods, covering various scenarios including input handling, skipToken, and type inference. This ensures the reliability of the new features.
  • Code Refactoring: The existing *Options methods (e.g., queryOptions) have been refactored to use the new dedicated key generation methods (e.g., queryKey). This improves internal consistency and maintainability.

Merge Readiness

This pull request significantly improves the TanStack Query integration by providing clearer and more explicit ways to generate query keys. The code is well-structured, thoroughly tested, and the documentation is updated accordingly.

There is one medium-severity suggestion regarding a type assertion in procedure-utils.ts. Addressing this would enhance the internal type precision.

I am unable to approve pull requests directly. However, once the suggested change is considered or addressed, I believe this PR will be in excellent shape for merging after review and approval from authorized maintainers.

Comment thread packages/tanstack-query/src/procedure-utils.ts
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Jun 9, 2025

More templates

@orpc/arktype

npm i https://pkg.pr.new/@orpc/arktype@625

@orpc/client

npm i https://pkg.pr.new/@orpc/client@625

@orpc/contract

npm i https://pkg.pr.new/@orpc/contract@625

@orpc/hey-api

npm i https://pkg.pr.new/@orpc/hey-api@625

@orpc/nest

npm i https://pkg.pr.new/@orpc/nest@625

@orpc/openapi

npm i https://pkg.pr.new/@orpc/openapi@625

@orpc/openapi-client

npm i https://pkg.pr.new/@orpc/openapi-client@625

@orpc/react

npm i https://pkg.pr.new/@orpc/react@625

@orpc/react-query

npm i https://pkg.pr.new/@orpc/react-query@625

@orpc/server

npm i https://pkg.pr.new/@orpc/server@625

@orpc/shared

npm i https://pkg.pr.new/@orpc/shared@625

@orpc/solid-query

npm i https://pkg.pr.new/@orpc/solid-query@625

@orpc/standard-server

npm i https://pkg.pr.new/@orpc/standard-server@625

@orpc/standard-server-aws-lambda

npm i https://pkg.pr.new/@orpc/standard-server-aws-lambda@625

@orpc/standard-server-fetch

npm i https://pkg.pr.new/@orpc/standard-server-fetch@625

@orpc/standard-server-node

npm i https://pkg.pr.new/@orpc/standard-server-node@625

@orpc/standard-server-peer

npm i https://pkg.pr.new/@orpc/standard-server-peer@625

@orpc/svelte-query

npm i https://pkg.pr.new/@orpc/svelte-query@625

@orpc/tanstack-query

npm i https://pkg.pr.new/@orpc/tanstack-query@625

@orpc/valibot

npm i https://pkg.pr.new/@orpc/valibot@625

@orpc/vue-colada

npm i https://pkg.pr.new/@orpc/vue-colada@625

@orpc/vue-query

npm i https://pkg.pr.new/@orpc/vue-query@625

@orpc/zod

npm i https://pkg.pr.new/@orpc/zod@625

commit: fd014a3

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (6)
apps/content/docs/integrations/tanstack-query.md (1)

142-142: Fix grammatical issue in documentation.

The word "action" should be plural "actions" to match the context.

-- `.key`: Generate a **partial matching** key for action like revalidating queries, checking mutation status, etc.
+- `.key`: Generate a **partial matching** key for actions like revalidating queries, checking mutation status, etc.
🧰 Tools
🪛 LanguageTool

[uncategorized] ~142-~142: Loose punctuation mark.
Context: ...eys for queries and mutations: - .key: Generate a partial matching key for...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~142-~142: The grammatical number of this noun doesn’t look right. Consider replacing it.
Context: ...Generate a partial matching key for action like revalidating queries, checking mut...

(AI_EN_LECTOR_REPLACEMENT_NOUN_NUMBER)

packages/tanstack-query/src/procedure-utils.test-d.ts (1)

289-385: Comprehensive infinite key tests with minor improvement opportunity.

The tests excellently cover pageParam type inference and initial page parameter typing. However, consider removing the unnecessary type cast on line 378.

-      const state = queryClient.getQueryState(optionalUtils.infiniteKey({
-        input: () => ({}),
-        initialPageParam,
-      }))
+      const infiniteKey = optionalUtils.infiniteKey({
+        input: () => ({}),
+        initialPageParam,
+      })
+      const state = queryClient.getQueryState(infiniteKey)
packages/tanstack-query/src/procedure-utils.ts (4)

34-41: Add documentation link for .queryKey method.

The JSDoc comment is missing the documentation link that other methods have. Consider adding it for consistency.

   /**
    * Generate the key used for query options
+   *
+   * @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query#query-key Tanstack Query Key Docs}
    */

54-61: Add documentation link for experimental streamed key method.

   /**
    * Generate the key used for streamed options
+   *
+   * @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query#streamed-key Tanstack Streamed Key Docs}
    */

75-83: Add documentation link for infinite key method.

   /**
    * Generate the key used for infinite options
+   *
+   * @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query#infinite-key Tanstack Infinite Key Docs}
    */

94-102: Add documentation link for mutation key method.

   /**
    * Generate the key used for mutation options
+   *
+   * @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query#mutation-key Tanstack Mutation Key Docs}
    */
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 343cede and 4051fef.

📒 Files selected for processing (7)
  • apps/content/docs/integrations/tanstack-query.md (2 hunks)
  • packages/tanstack-query/src/procedure-utils.test-d.ts (5 hunks)
  • packages/tanstack-query/src/procedure-utils.test.ts (4 hunks)
  • packages/tanstack-query/src/procedure-utils.ts (7 hunks)
  • packages/tanstack-query/src/types.ts (2 hunks)
  • packages/tanstack-query/tests/e2e.test-d.ts (3 hunks)
  • packages/tanstack-query/tests/e2e.test.tsx (3 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (4)
packages/tanstack-query/tests/e2e.test.tsx (1)
packages/tanstack-query/tests/shared.tsx (3)
  • queryClient (8-14)
  • orpc (5-5)
  • streamedOrpc (6-6)
packages/tanstack-query/tests/e2e.test-d.ts (1)
packages/tanstack-query/tests/shared.tsx (3)
  • queryClient (8-14)
  • orpc (5-5)
  • streamedOrpc (6-6)
packages/tanstack-query/src/types.ts (4)
packages/react-query/src/types.ts (1)
  • QueryOptionsIn (5-8)
packages/solid-query/src/types.ts (1)
  • QueryOptionsIn (13-16)
packages/svelte-query/src/types.ts (1)
  • QueryOptionsIn (13-16)
packages/vue-query/src/types.ts (1)
  • QueryOptionsIn (18-29)
packages/tanstack-query/src/procedure-utils.test-d.ts (3)
packages/contract/src/error.ts (1)
  • ErrorFromErrorMap (49-49)
packages/contract/tests/shared.ts (1)
  • baseErrorMap (12-17)
packages/tanstack-query/tests/shared.tsx (1)
  • queryClient (8-14)
🪛 LanguageTool
apps/content/docs/integrations/tanstack-query.md

[uncategorized] ~142-~142: Loose punctuation mark.
Context: ...eys for queries and mutations: - .key: Generate a partial matching key for...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~142-~142: The grammatical number of this noun doesn’t look right. Consider replacing it.
Context: ...Generate a partial matching key for action like revalidating queries, checking mut...

(AI_EN_LECTOR_REPLACEMENT_NOUN_NUMBER)


[uncategorized] ~144-~144: Loose punctuation mark.
Context: ...tions](#query-options). - .streamedKey: Generate a full matching key for [S...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~145-~145: Loose punctuation mark.
Context: ...treamed-query-options). - .infiniteKey: Generate a full matching key for [I...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~146-~146: Loose punctuation mark.
Context: ...nfinite-query-options). - .mutationKey: Generate a full matching key for [M...

(UNLIKELY_OPENING_PUNCTUATION)

⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: publish-commit
  • GitHub Check: lint
🔇 Additional comments (20)
packages/tanstack-query/tests/e2e.test.tsx (3)

37-37: LGTM! Correct usage of the new .queryKey() method.

The migration from .key({ input: { input: 123 }, type: 'query' }) to .queryKey({ input: { input: 123 } }) correctly uses the new specific key generation method, eliminating the need for the type parameter.


90-90: LGTM! Proper migration to .experimental_streamedKey() with updated parameter name.

The change correctly:

  • Uses the new .experimental_streamedKey() method instead of generic .key()
  • Renames fnOptions to queryFnOptions to match the new API signature
  • Removes the type: 'streamed' parameter as it's now implicit in the method name

153-153: LGTM! Correct migration to .infiniteKey() with proper parameter transformation.

The change correctly:

  • Uses the new .infiniteKey() method instead of generic .key()
  • Transforms the input parameter from a static object to a function (input => ({ input }))
  • Adds the required initialPageParam parameter
  • Removes the type: 'infinite' parameter as it's now implicit
apps/content/docs/integrations/tanstack-query.md (2)

140-146: Excellent documentation update explaining the new key generation methods.

The updated documentation clearly explains:

  • The distinction between partial and full matching keys
  • The specific use cases for each method
  • The corresponding option types for each method

This provides developers with clear guidance on when to use each key generation method.

🧰 Tools
🪛 LanguageTool

[uncategorized] ~142-~142: Loose punctuation mark.
Context: ...eys for queries and mutations: - .key: Generate a partial matching key for...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~142-~142: The grammatical number of this noun doesn’t look right. Consider replacing it.
Context: ...Generate a partial matching key for action like revalidating queries, checking mut...

(AI_EN_LECTOR_REPLACEMENT_NOUN_NUMBER)


[uncategorized] ~144-~144: Loose punctuation mark.
Context: ...tions](#query-options). - .streamedKey: Generate a full matching key for [S...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~145-~145: Loose punctuation mark.
Context: ...treamed-query-options). - .infiniteKey: Generate a full matching key for [I...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~146-~146: Loose punctuation mark.
Context: ...nfinite-query-options). - .mutationKey: Generate a full matching key for [M...

(UNLIKELY_OPENING_PUNCTUATION)


166-169: Great addition showing practical usage of .queryKey() for data updates.

The new example demonstrates a common use case where developers need the exact key to update query data, highlighting the value of the full matching key methods.

packages/tanstack-query/src/procedure-utils.test.ts (4)

33-40: Excellent test coverage for .queryKey() method.

The test correctly verifies:

  • Delegation to generateOperationKey with the correct operation type ('query')
  • Proper parameter passing including input
  • Handling of explicit queryKey override
  • Call count validation to ensure no extra calls when key is provided

78-85: Comprehensive test for .experimental_streamedKey() method.

The test properly validates:

  • Delegation with 'streamed' operation type
  • Correct parameter forwarding
  • Key override functionality
  • Appropriate mock call counting

166-173: Well-structured test for .infiniteKey() method.

The test effectively covers:

  • Delegation with 'infinite' operation type
  • Complex input parameter transformation (function to initial page param)
  • Key override behavior
  • Mock call verification

237-244: Complete test coverage for .mutationKey() method.

The test correctly verifies:

  • Delegation with 'mutation' operation type
  • Handling of no parameters (mutation keys typically don't need input)
  • Key override functionality
  • Proper call count management
packages/tanstack-query/tests/e2e.test-d.ts (3)

22-30: Excellent type safety validation for .queryKey() method.

The test properly verifies:

  • Correct data type for standard queries ({ output: string } | undefined)
  • Type-safe error handling with isDefinedError
  • Proper integration with queryClient.getQueryState

182-190: Comprehensive type checking for .experimental_streamedKey() method.

The test correctly validates:

  • Array return type for streamed queries ({ output: string }[] | undefined)
  • Error type safety for streamed operations
  • Proper QueryClient integration

342-350: Well-designed type test for .infiniteKey() method.

The test effectively verifies:

  • Correct InfiniteData generic type with proper page and page param types
  • Error handling type safety
  • Complex input function parameter handling
  • Integration with QueryClient state management
packages/tanstack-query/src/procedure-utils.test-d.ts (4)

6-6: LGTM! Good test setup for key generation methods.

The addition of QueryClient and its instantiation enables proper testing of getQueryState type inference with the new key methods.

Also applies to: 13-14


44-92: Excellent type test coverage for .queryKey method!

The tests thoroughly validate:

  • Optional vs required input handling
  • Type inference and error checking
  • skipToken compatibility
  • Query key overrides
  • Return type conformance to QueryKey
  • Integration with QueryClient.getQueryState

This provides strong type safety guarantees for the new key generation method.


162-216: Well-structured tests for experimental streamed key generation!

The tests mirror the .queryKey test structure while appropriately handling the additional queryFnOptions parameter specific to streamed queries. Good consistency in using the experimental prefix.


537-555: Clean and appropriate tests for mutation key generation.

The simpler test structure correctly reflects that mutation keys don't require input parameters. All essential scenarios are covered.

packages/tanstack-query/src/types.ts (3)

37-40: Well-designed type extraction for key options.

The QueryKeyOptions<TInput> type nicely consolidates the common pattern of conditional input handling and optional query key override, improving code reusability across the new key generation methods.


41-44: Improved type semantics with Omit.

Using Omit<QueryObserverOptions<...>, 'queryKey'> is more semantically correct than SetOptional<..., 'queryKey'> since the query key is now handled separately through QueryKeyOptions. This makes the type intention clearer.


54-57: Consistent type extension for streamed queries.

The experimental_StreamedKeyOptions appropriately extends QueryKeyOptions while adding the streamed-specific queryFnOptions parameter.

packages/tanstack-query/src/procedure-utils.ts (1)

126-156: Excellent refactoring to centralize key generation!

The implementation successfully modularizes key generation by:

  1. Extracting key generation into dedicated methods
  2. Having options methods delegate to their corresponding key methods
  3. Maintaining backward compatibility
  4. Ensuring consistent key generation across all operation types

This architectural improvement enhances maintainability and reduces code duplication.

Also applies to: 158-197, 199-232, 234-256

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
apps/content/docs/integrations/tanstack-query.md (1)

165-169: Usage example of .queryKey is correct
The setQueryData snippet correctly demonstrates updating cached data with .queryKey. Consider including parallel examples for .streamedKey and .infiniteKey (and even .mutationKey) to fully illustrate each helper’s usage.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4051fef and dea342e.

📒 Files selected for processing (3)
  • apps/content/docs/integrations/tanstack-query.md (2 hunks)
  • packages/tanstack-query/src/general-utils.ts (1 hunks)
  • packages/tanstack-query/src/procedure-utils.ts (7 hunks)
✅ Files skipped from review due to trivial changes (1)
  • packages/tanstack-query/src/general-utils.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/tanstack-query/src/procedure-utils.ts
🧰 Additional context used
🪛 LanguageTool
apps/content/docs/integrations/tanstack-query.md

[uncategorized] ~142-~142: Loose punctuation mark.
Context: ...eys for queries and mutations: - .key: Generate a partial matching key for...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~144-~144: Loose punctuation mark.
Context: ...tions](#query-options). - .streamedKey: Generate a full matching key for [S...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~145-~145: Loose punctuation mark.
Context: ...treamed-query-options). - .infiniteKey: Generate a full matching key for [I...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~146-~146: Loose punctuation mark.
Context: ...nfinite-query-options). - .mutationKey: Generate a full matching key for [M...

(UNLIKELY_OPENING_PUNCTUATION)

⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: publish-commit
  • GitHub Check: lint
🔇 Additional comments (1)
apps/content/docs/integrations/tanstack-query.md (1)

140-147: Comprehensive key helper enumeration
The addition of .key, .queryKey, .streamedKey, .infiniteKey, and .mutationKey accurately reflects the new API surface and aligns with implementation.

🧰 Tools
🪛 LanguageTool

[uncategorized] ~142-~142: Loose punctuation mark.
Context: ...eys for queries and mutations: - .key: Generate a partial matching key for...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~144-~144: Loose punctuation mark.
Context: ...tions](#query-options). - .streamedKey: Generate a full matching key for [S...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~145-~145: Loose punctuation mark.
Context: ...treamed-query-options). - .infiniteKey: Generate a full matching key for [I...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~146-~146: Loose punctuation mark.
Context: ...nfinite-query-options). - .mutationKey: Generate a full matching key for [M...

(UNLIKELY_OPENING_PUNCTUATION)

Comment thread packages/tanstack-query/src/procedure-utils.ts
@dinwwwh dinwwwh merged commit 9f1bc8b into main Jun 10, 2025
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Infer router output/query key automatically during setQueryData

2 participants