fix(query): improve compatibility with useQueries and useSuspenseQueries#521
fix(query): improve compatibility with useQueries and useSuspenseQueries#521
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
WalkthroughThe changes update type interfaces across multiple packages to replace the Changes
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
Assessment against linked issues
Poem
Note ⚡️ AI Code Reviews for VS Code, Cursor, WindsurfCodeRabbit 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. Note ⚡️ Faster reviews with cachingCodeRabbit 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 ✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed 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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Codecov ReportAll modified and coverable lines are covered by tests ✅ 📢 Thoughts on this report? Let us know! |
More templates
@orpc/arktype
@orpc/client
@orpc/nest
@orpc/contract
@orpc/openapi
@orpc/openapi-client
@orpc/react
@orpc/react-query
@orpc/server
@orpc/shared
@orpc/solid-query
@orpc/standard-server
@orpc/standard-server-fetch
@orpc/standard-server-node
@orpc/standard-server-peer
@orpc/svelte-query
@orpc/valibot
@orpc/vue-colada
@orpc/vue-query
@orpc/zod
commit: |
There was a problem hiding this comment.
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
📒 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 inferenceThe introduction of
throwOnErrormethod in place of what was likely aretrymethod 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 queriesThe same
throwOnErrormethod 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 handlingThis 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 queriesSimilar 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 queriesThe 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
useQuerieshook.
🏁 Script executed:
#!/bin/bash # Check for any remaining issues with the useQueries hook fd --type file --extension ts useQueriesLength of output: 42
The
fdcommand you ran only searches filenames, not file contents, so it won’t find usages of the hook. Let’s search inside all.tsfiles for calls touseQueries:
🏁 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
useQueriesType Inference Across All PackagesThe
useQuerieshook is used in multiple packages beyondsolid-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.datawith the correct inferred type.packages/vue-query/tests/e2e.test-d.ts (2)
77-78: Activated error type checking for Vue batch queriesThis 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 queriesThis 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 checksThese assertions validate that error types are correctly inferred in batch query operations, which is crucial for the goal of improving compatibility between
useQueriesanduseSuspenseQueries.
208-226: Good addition of test coverage for streamed queries in batchThis new test case properly validates that
useQueriesworks withexperimental_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 throwOnErrorReplacing
retrywiththrowOnErroris a cleaner approach for error handling and type inference. This change removes the unnecessaryfailureCountparameter, 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 queriesApplying the same error handling pattern to
InfiniteOptionsBaseensures consistent behavior across different query types, which is a good practice.packages/svelte-query/src/types.ts (2)
21-21: Consistent cross-adapter implementationGood 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 typesThe consistent implementation of
throwOnErroracross 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 behaviorThis 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 createQueriesThese 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 createQueriesGood 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 useSuspenseQueriesCorrectly added the import for
useSuspenseQueriesto support the new test cases.
113-115: Updated error type assertion in useQueries testChanged 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 testSimilar 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 streamedOptionsExcellent addition of test coverage for
useSuspenseQuerieswith 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 QueryOptionsBaseThis is a key change that simplifies the error handling API by:
- Renaming the method to better describe its purpose
- Removing the
failureCountparameter- 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 InfiniteOptionsBaseConsistent with the previous change, updated the infinite query options to use
throwOnErrorinstead ofretry. 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 useSuspenseQueriesCorrectly added the import for
useSuspenseQueriesto support the new test cases.
131-133: Added error type assertions for useQueriesThese 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 queryOptionsGood addition that tests
useSuspenseQuerieswith 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 streamedOptionsExcellent addition of test coverage for both
useQueriesanduseSuspenseQuerieswith streamed options. These tests complement the standard query options tests and ensure proper type inference for all batch query scenarios, including streamed data.
Fixed: https://github.com/unnoq/orpc/issues/519
Summary by CodeRabbit
New Features
Bug Fixes
Refactor
retrymethod withthrowOnErrorin query option interfaces to improve error type inference and consistency.Tests