Skip to content

fix(query): improve compatibility with useQueries and useSuspenseQueries#521

Merged
dinwwwh merged 4 commits intomainfrom
unnoq/issue519
May 20, 2025
Merged

fix(query): improve compatibility with useQueries and useSuspenseQueries#521
dinwwwh merged 4 commits intomainfrom
unnoq/issue519

Conversation

@dinwwwh
Copy link
Copy Markdown
Member

@dinwwwh dinwwwh commented May 20, 2025

Fixed: https://github.com/unnoq/orpc/issues/519

Summary by CodeRabbit

  • New Features

    • Improved type inference and error handling for multi-query hooks across React, Solid, Svelte, and Vue integrations.
    • Added new test cases to verify correct error and data type inference for multi-query and streamed query scenarios.
  • Bug Fixes

    • Enhanced error type assertions in tests for multi-query hooks, ensuring accurate type checks.
  • Refactor

    • Replaced the optional retry method with throwOnError in query option interfaces to improve error type inference and consistency.
  • Tests

    • Expanded and updated test coverage for error and data types in multi-query and streamed query scenarios.
    • Simplified tests by removing redundant error handling callbacks in certain cases.

@vercel
Copy link
Copy Markdown

vercel Bot commented May 20, 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 May 20, 2025 6:53am

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 20, 2025

Walkthrough

The changes update type interfaces across multiple packages to replace the retry method with a new throwOnError method for error type inference. Test suites are revised to remove or adjust error handling callbacks, add new test cases for batch query hooks (notably useSuspenseQueries), and improve error type assertions, especially for batch and streamed query scenarios.

Changes

File(s) Change Summary
packages/react-query/src/types.ts,
packages/solid-query/src/types.ts,
packages/svelte-query/src/types.ts,
packages/vue-query/src/types.ts
Replaced the retry?(failureCount: number, error: TError): boolean method with throwOnError?(error: TError): boolean in QueryOptionsBase and InfiniteOptionsBase interfaces. Updated comments to reflect the new method's purpose for error type inference.
packages/react-query/src/procedure-utils.test-d.ts,
packages/solid-query/src/procedure-utils.test-d.ts,
packages/svelte-query/src/procedure-utils.test-d.ts,
packages/vue-query/src/procedure-utils.test-d.ts
Removed or simplified throwOnError callbacks in query tests, uncommented and enabled error type assertions in batch query tests, and added/expanded test cases for batch/streamed queries to verify correct type inference for data and errors.
packages/react-query/tests/e2e.test-d.ts,
packages/solid-query/tests/e2e.test-d.ts,
packages/svelte-query/tests/e2e.test-d.ts,
packages/vue-query/tests/e2e.test-d.ts
Updated error code checks in test assertions from 'OVERRIDE' to 'BASE', changed expected error data types from unknown to { output: string }, enabled previously commented-out assertions, and added a new test for useSuspenseQueries in React Query tests.

Sequence Diagram(s)

sequenceDiagram
    participant Dev as Developer
    participant BatchHook as useSuspenseQueries / useQueries
    participant QueryOptions as queryOptions
    participant TanStack as TanStack Query

    Dev->>QueryOptions: Create query options (no retry, with throwOnError)
    Dev->>BatchHook: Pass query options to batch hook
    BatchHook->>TanStack: Execute queries using options
    TanStack->>BatchHook: Return results with correct error type inference
    BatchHook->>Dev: Provide data and error with correct types
Loading

Assessment against linked issues

Objective Addressed Explanation
Ensure useSuspenseQueries is compatible with queryOptions and does not error on retry (#519)

Poem

A hop, a skip, a change in the air—
No more retry, just errors to spare!
Batch queries now dance, type checks in tow,
With throwOnError, the tests all glow.
From React to Svelte, Vue to Solid too,
The codebase is happy—thank you, dev crew!
🐇✨

Note

⚡️ AI Code Reviews for VS Code, Cursor, Windsurf

CodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback.
Learn more here.


Note

⚡️ Faster reviews with caching

CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.
Enjoy the performance boost—your workflow just got faster.

✨ 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.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 20, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

📢 Thoughts on this report? Let us know!

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 20, 2025

More templates

@orpc/arktype

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

@orpc/client

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

@orpc/nest

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

@orpc/contract

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

@orpc/openapi

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

@orpc/openapi-client

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

@orpc/react

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

@orpc/react-query

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

@orpc/server

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

@orpc/shared

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

@orpc/solid-query

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

@orpc/standard-server

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

@orpc/standard-server-fetch

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

@orpc/standard-server-node

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

@orpc/standard-server-peer

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

@orpc/svelte-query

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

@orpc/valibot

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

@orpc/vue-colada

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

@orpc/vue-query

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

@orpc/zod

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

commit: 8aed0dc

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: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between a9447ff and 8aed0dc.

📒 Files selected for processing (12)
  • packages/react-query/src/procedure-utils.test-d.ts (3 hunks)
  • packages/react-query/src/types.ts (2 hunks)
  • packages/react-query/tests/e2e.test-d.ts (4 hunks)
  • packages/solid-query/src/procedure-utils.test-d.ts (2 hunks)
  • packages/solid-query/src/types.ts (2 hunks)
  • packages/solid-query/tests/e2e.test-d.ts (2 hunks)
  • packages/svelte-query/src/procedure-utils.test-d.ts (3 hunks)
  • packages/svelte-query/src/types.ts (2 hunks)
  • packages/svelte-query/tests/e2e.test-d.ts (2 hunks)
  • packages/vue-query/src/procedure-utils.test-d.ts (1 hunks)
  • packages/vue-query/src/types.ts (2 hunks)
  • packages/vue-query/tests/e2e.test-d.ts (2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (4)
packages/solid-query/src/procedure-utils.test-d.ts (2)
packages/contract/src/error.ts (1)
  • ErrorFromErrorMap (49-49)
packages/contract/tests/shared.ts (1)
  • baseErrorMap (12-17)
packages/svelte-query/src/procedure-utils.test-d.ts (2)
packages/contract/src/error.ts (1)
  • ErrorFromErrorMap (49-49)
packages/contract/tests/shared.ts (1)
  • baseErrorMap (12-17)
packages/vue-query/src/procedure-utils.test-d.ts (2)
packages/contract/src/error.ts (1)
  • ErrorFromErrorMap (49-49)
packages/contract/tests/shared.ts (1)
  • baseErrorMap (12-17)
packages/react-query/src/procedure-utils.test-d.ts (2)
packages/contract/src/error.ts (1)
  • ErrorFromErrorMap (49-49)
packages/contract/tests/shared.ts (1)
  • baseErrorMap (12-17)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: publish-commit
  • GitHub Check: lint
🔇 Additional comments (27)
packages/solid-query/src/types.ts (2)

21-21: API update improves error type inference

The introduction of throwOnError method in place of what was likely a retry method significantly improves TypeScript's ability to infer error types in TanStack Query. This change focuses solely on error handling rather than retry logic.


44-44: Consistent API update for infinite queries

The same throwOnError method has been properly applied to the infinite query options interface, maintaining consistency across the API.

packages/svelte-query/tests/e2e.test-d.ts (2)

84-86: Type assertions now validate correct error handling

This test case has been activated to properly check error type inference in batch queries. The check now validates that errors with code 'BASE' have the correct data type structure.


177-179: Improved type safety for streamed batch queries

Similar to the previous case, this test now verifies that error type inference works correctly in streamed batch queries, providing more complete type coverage for all query variants.

packages/solid-query/tests/e2e.test-d.ts (2)

168-170: Completed error type assertions for streamed queries

The test now properly verifies error type inference for streamed batch queries, ensuring consistent behavior across all query variants.


79-81:

Details

❓ Verification inconclusive

Fixed type inference for useQueries hook

This test activation resolves the original issue mentioned in the PR, ensuring that error types are correctly inferred when using the useQueries hook.


🏁 Script executed:

#!/bin/bash
# Check for any remaining issues with the useQueries hook
fd --type file --extension ts useQueries

Length of output: 42


The fd command you ran only searches filenames, not file contents, so it won’t find usages of the hook. Let’s search inside all .ts files for calls to useQueries:


🏁 Script executed:

#!/bin/bash
# Search for all occurrences of useQueries( in TS files
rg --with-filename --line-number 'useQueries\(' -g '*.ts'

Length of output: 1084


Verify useQueries Type Inference Across All Packages

The useQueries hook is used in multiple packages beyond solid-query. Please confirm that error types are correctly inferred and tested in each instance:

  • packages/vue-query/tests/e2e.test-d.ts
  • packages/vue-query/src/procedure-utils.test-d.ts
  • packages/solid-query/tests/e2e.test-d.ts (already updated)
  • packages/solid-query/src/procedure-utils.test-d.ts
  • packages/react-query/tests/e2e.test-d.ts
  • packages/react-query/src/procedure-utils.test-d.ts

Ensure that each test that checks for an error status also verifies error.data with the correct inferred type.

packages/vue-query/tests/e2e.test-d.ts (2)

77-78: Activated error type checking for Vue batch queries

This change enables proper error type validation for the Vue implementation of batch queries, ensuring consistent behavior with other framework implementations.


164-166: Complete error handling coverage for Vue streamed queries

This test case ensures that error types are properly inferred in Vue's implementation of streamed batch queries, completing the full coverage of error handling scenarios.

packages/solid-query/src/procedure-utils.test-d.ts (2)

118-119: Enhancing error type inference checks

These assertions validate that error types are correctly inferred in batch query operations, which is crucial for the goal of improving compatibility between useQueries and useSuspenseQueries.


208-226: Good addition of test coverage for streamed queries in batch

This new test case properly validates that useQueries works with experimental_streamedOptions, ensuring consistent type inference for both data and error types in batch streamed query scenarios. This is essential for the PR's objective of improving compatibility between batch query hooks.

packages/react-query/src/types.ts (2)

13-13: Improved error type inference with throwOnError

Replacing retry with throwOnError is a cleaner approach for error handling and type inference. This change removes the unnecessary failureCount parameter, focusing solely on the error object which makes it easier for TanStack Query to correctly infer error types.


36-36: Consistent implementation of throwOnError for infinite queries

Applying the same error handling pattern to InfiniteOptionsBase ensures consistent behavior across different query types, which is a good practice.

packages/svelte-query/src/types.ts (2)

21-21: Consistent cross-adapter implementation

Good to see the same error handling approach being applied across all adapter packages. This ensures that the behavior is consistent regardless of which framework is being used.


44-44: Maintaining API consistency across query types

The consistent implementation of throwOnError across both regular and infinite query options maintains API coherence, which is important for developer experience.

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

427-439: Uncommented test with workaround for Vue-specific behavior

This test properly verifies error type inference with initial data for Vue Query. The FIXME comment correctly documents a known discrepancy in how Vue Query handles initial data compared to React Query, which is important for any developers working on this in the future.

It might be worth opening an issue to track the Vue-specific initialData handling difference. Is this discrepancy something that should be addressed in a future PR?

packages/svelte-query/src/procedure-utils.test-d.ts (2)

119-120: Added error type assertions for createQueries

These assertions correctly verify that error types for both queries match the expected ErrorFromErrorMap<typeof baseErrorMap> type, improving test coverage for batch queries.


209-227: Added test for experimental_streamedOptions with createQueries

Good addition of test coverage for batch queries with streamed options. This test ensures proper type inference for both data and error types in streamed batch query scenarios.

packages/react-query/tests/e2e.test-d.ts (4)

3-3: Added import for useSuspenseQueries

Correctly added the import for useSuspenseQueries to support the new test cases.


113-115: Updated error type assertion in useQueries test

Changed the error code check from 'OVERRIDE' to 'BASE' with appropriate data type assertion. This ensures more accurate error type inference testing since the 'BASE' error type has a defined structure with { output: string }.


230-232: Updated error type assertion in useQueries with streamedOptions test

Similar to the previous change, updated to check for 'BASE' error code with proper type assertion. This standardizes error type testing across query variants.


247-278: Added test for useSuspenseQueries with streamedOptions

Excellent addition of test coverage for useSuspenseQueries with streamed options. This directly addresses the PR objective of improving compatibility with batch query hooks, particularly for suspense-enabled queries.

packages/vue-query/src/types.ts (2)

34-34: Replaced retry with throwOnError in QueryOptionsBase

This is a key change that simplifies the error handling API by:

  1. Renaming the method to better describe its purpose
  2. Removing the failureCount parameter
  3. Focusing solely on error type inference

This change will improve type inference for error objects, especially in batch query scenarios.


65-65: Replaced retry with throwOnError in InfiniteOptionsBase

Consistent with the previous change, updated the infinite query options to use throwOnError instead of retry. This ensures a uniform API for error handling across query types.

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

6-6: Added import for useSuspenseQueries

Correctly added the import for useSuspenseQueries to support the new test cases.


131-133: Added error type assertions for useQueries

These assertions correctly verify that error types for both queries match the expected ErrorFromErrorMap<typeof baseErrorMap> type, improving test coverage for batch queries.


135-153: Added test for useSuspenseQueries with queryOptions

Good addition that tests useSuspenseQueries with the standard query options. The assertions properly verify both data and error types, ensuring type safety when using suspense-enabled batch queries.


241-279: Added tests for useQueries and useSuspenseQueries with streamedOptions

Excellent addition of test coverage for both useQueries and useSuspenseQueries with streamed options. These tests complement the standard query options tests and ensure proper type inference for all batch query scenarios, including streamed data.

Comment thread packages/svelte-query/src/procedure-utils.test-d.ts
@dinwwwh dinwwwh merged commit ba44cb8 into main May 20, 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.

useSuspenseQueries incompatible with queryOptions

1 participant