-
-
Notifications
You must be signed in to change notification settings - Fork 89
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
refactor(tanstack): merge zenstack query/mutation options into tanstack options #1136
Conversation
WalkthroughWalkthroughThe changes primarily revolve around enhancing the Tanstack Query plugin to support version 5, with significant updates in handling query and mutation hooks. This includes the removal of Changes
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
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 as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
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.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files ignored due to path filters (2)
packages/plugins/tanstack-query/package.json
is excluded by:!**/*.json
pnpm-lock.yaml
is excluded by:!**/*.yaml
Files selected for processing (13)
- packages/plugins/swr/src/generator.ts (1 hunks)
- packages/plugins/tanstack-query/src/generator.ts (8 hunks)
- packages/plugins/tanstack-query/src/runtime-v5/index.ts (1 hunks)
- packages/plugins/tanstack-query/src/runtime-v5/react.ts (8 hunks)
- packages/plugins/tanstack-query/src/runtime-v5/svelte.ts (6 hunks)
- packages/plugins/tanstack-query/src/runtime/common.ts (2 hunks)
- packages/plugins/tanstack-query/src/runtime/index.ts (1 hunks)
- packages/plugins/tanstack-query/src/runtime/react.ts (6 hunks)
- packages/plugins/tanstack-query/src/runtime/svelte.ts (6 hunks)
- packages/plugins/tanstack-query/src/runtime/vue.ts (6 hunks)
- packages/plugins/tanstack-query/tests/plugin.test.ts (6 hunks)
- packages/plugins/tanstack-query/tests/react-hooks-v5.test.tsx (12 hunks)
- packages/plugins/tanstack-query/tests/react-hooks.test.tsx (13 hunks)
Additional comments: 38
packages/plugins/tanstack-query/src/runtime/index.ts (1)
- 1-7: The export reorganization and additions in
index.ts
are correctly implemented, ensuring that the necessary types and functions for query handling are available. This change aligns with the PR's objectives to enhance query and mutation handling capabilities.packages/plugins/tanstack-query/src/runtime-v5/index.ts (1)
- 1-7: The changes in
runtime-v5/index.ts
correctly introduce new exports for enhanced query and mutation handling in version 5 of the library. This ensures consistency and availability of necessary types across different versions.packages/plugins/tanstack-query/tests/plugin.test.ts (3)
- 56-56: The update of the
version
property from 'v5' to 'v4' for thereact
target in the plugin configuration test seems to contradict the PR's aim of adapting to Tanstack v5. Please verify if this change is intentional and aligns with the overall objectives.- 99-99: Similar to the
react
target, updating theversion
property for thevue
target also requires verification to ensure it aligns with the PR's objectives of adapting to Tanstack v5.- 142-142: The update of the
version
property for thesvelte
target, like the previous two, needs verification to confirm its alignment with the PR's objectives regarding Tanstack v5 adaptation.packages/plugins/tanstack-query/src/runtime/react.ts (4)
- 22-23: The addition of
ExtraMutationOptions
andExtraQueryOptions
types is correctly implemented, enhancing the flexibility and customization capabilities of query and mutation hooks.- 63-71: The update to
useModelQuery
to includeExtraQueryOptions
and the modification of thegetQueryKey
call align with the PR's objectives to enhance query handling. Ensure that the default behavior foroptimisticUpdate
is clearly documented for users.- 95-95: The handling of
infinite
andoptimisticUpdate
properties inuseInfiniteModelQuery
is correctly implemented, ensuring consistent and flexible query key generation.- 122-130: > 📝 NOTE
This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [125-148]
The updates to
useModelMutation
to includeExtraMutationOptions
and handleinvalidateQueries
andoptimisticUpdate
based on options are well-implemented. It's important to ensure that these options are clearly documented for users to understand their impact.packages/plugins/tanstack-query/src/runtime/svelte.ts (4)
- 22-23: The addition of
ExtraMutationOptions
andExtraQueryOptions
types for the Svelte runtime is correctly implemented, enhancing the customization capabilities of query and mutation hooks.- 63-71: The update to
useModelQuery
to includeExtraQueryOptions
and the modification of thegetQueryKey
call align with the PR's objectives to enhance query handling in the Svelte runtime. Ensure that the default behavior foroptimisticUpdate
is clearly documented for users.- 95-95: The handling of
infinite
andoptimisticUpdate
properties inuseInfiniteModelQuery
is correctly implemented for the Svelte runtime, ensuring consistent and flexible query key generation.- 121-129: > 📝 NOTE
This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [124-147]
The updates to
useModelMutation
to includeExtraMutationOptions
and handleinvalidateQueries
andoptimisticUpdate
based on options are well-implemented for the Svelte runtime. It's important to ensure that these options are clearly documented for users to understand their impact.packages/plugins/tanstack-query/src/runtime/vue.ts (4)
- 23-24: The addition of
ExtraMutationOptions
andExtraQueryOptions
types for the Vue runtime is correctly implemented, enhancing the customization capabilities of query and mutation hooks.- 65-73: The update to
useModelQuery
to includeExtraQueryOptions
and the modification of thegetQueryKey
call align with the PR's objectives to enhance query handling in the Vue runtime. Ensure that the default behavior foroptimisticUpdate
is clearly documented for users.- 97-97: The handling of
infinite
andoptimisticUpdate
properties inuseInfiniteModelQuery
is correctly implemented for the Vue runtime, ensuring consistent and flexible query key generation.- 125-133: > 📝 NOTE
This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [128-152]
The updates to
useModelMutation
to includeExtraMutationOptions
and handleinvalidateQueries
andoptimisticUpdate
based on options are well-implemented for the Vue runtime. It's important to ensure that these options are clearly documented for users to understand their impact.packages/plugins/tanstack-query/src/runtime-v5/svelte.ts (4)
- 25-26: The addition of
ExtraMutationOptions
andExtraQueryOptions
types for the Svelte runtime in version 5 is correctly implemented, enhancing the customization capabilities of query and mutation hooks.- 66-73: The update to
useModelQuery
to includeExtraQueryOptions
and the modification of thegetQueryKey
call align with the PR's objectives to enhance query handling in the Svelte runtime for version 5. Ensure that the default behavior foroptimisticUpdate
is clearly documented for users.- 113-113: The handling of
infinite
andoptimisticUpdate
properties inuseInfiniteModelQuery
is correctly implemented for the Svelte runtime in version 5, ensuring consistent and flexible query key generation.- 160-168: > 📝 NOTE
This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [163-185]
The updates to
useModelMutation
to includeExtraMutationOptions
and handleinvalidateQueries
andoptimisticUpdate
based on options are well-implemented for the Svelte runtime in version 5. It's important to ensure that these options are clearly documented for users to understand their impact.packages/plugins/tanstack-query/src/runtime-v5/react.ts (4)
- 27-28: The addition of
ExtraMutationOptions
andExtraQueryOptions
types for the React runtime in version 5 is correctly implemented, enhancing the customization capabilities of query and mutation hooks.- 67-75: The update to
useModelQuery
to includeExtraQueryOptions
and the modification of thegetQueryKey
call align with the PR's objectives to enhance query handling in the React runtime for version 5. Ensure that the default behavior foroptimisticUpdate
is clearly documented for users.- 127-127: The handling of
infinite
andoptimisticUpdate
properties inuseInfiniteModelQuery
is correctly implemented for the React runtime in version 5, ensuring consistent and flexible query key generation.- 180-188: > 📝 NOTE
This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [183-205]
The updates to
useModelMutation
to includeExtraMutationOptions
and handleinvalidateQueries
andoptimisticUpdate
based on options are well-implemented for the React runtime in version 5. It's important to ensure that these options are clearly documented for users to understand their impact.packages/plugins/tanstack-query/src/runtime/common.ts (3)
- 46-56: The introduction of
ExtraMutationOptions
withinvalidateQueries
andoptimisticUpdate
properties provides clear, flexible configuration for mutations. This is a positive change that enhances the library's functionality.- 61-66: The
ExtraQueryOptions
type with anoptimisticUpdate
property is a good addition, allowing for more granular control over query behavior. This aligns well with the goal of enhancing customization capabilities for users.- 138-155: The refactoring of
getQueryKey
to accept anoptions
object instead of separate boolean parameters is a significant improvement. It simplifies the function signature and makes the function more extensible for future options. However, ensure that all calls to this function throughout the codebase have been updated to pass anoptions
object.packages/plugins/swr/src/generator.ts (1)
- 69-69: The removal of
useHooksContext
import aligns with the PR's objective to shift away from Zenstack-specific hooks. Ensure that this change does not negatively impact any functionalities that previously relied onuseHooksContext
.Verification successful
The removal of
useHooksContext
import fromgenerator.ts
in theswr
plugin does not negatively impact any functionalities within this file, as the script results indicate no usage ofuseHooksContext
. This aligns with the PR's objective to shift away from Zenstack-specific hooks.Scripts Executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Search for usage of useHooksContext in the current file. Expecting no results. rg --type typescript 'useHooksContext' packages/plugins/swr/src/generator.tsLength of output: 111
Script:
#!/bin/bash # Correcting the previous script to search for usage of useHooksContext in the current file without specifying file type. rg 'useHooksContext' packages/plugins/swr/src/generator.tsLength of output: 58
packages/plugins/tanstack-query/tests/react-hooks.test.tsx (2)
- 17-17: Updating the test suite description to
'Tanstack Query React Hooks V4 Test'
accurately reflects the versioning changes and the scope of the tests. This is a good practice for maintaining clarity in test documentation.- 165-165: Adding
{ optimisticUpdate: true }
touseModelQuery
calls in several tests is a necessary adjustment to align with the newExtraQueryOptions
type and to test the optimistic update feature. This change ensures that the tests cover the new functionality introduced in the PR.Also applies to: 188-189, 221-221, 244-245, 319-319, 342-343, 415-415, 438-439
packages/plugins/tanstack-query/tests/react-hooks-v5.test.tsx (2)
- 223-232: > 📝 NOTE
This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [208-229]
The introduction of
optimisticUpdate
andinvalidateQueries
options inuseModelQuery
anduseModelMutation
calls enhances the flexibility and control over query and mutation behavior. This is a positive change, aligning with the PR objectives to integrate Zenstack options into Tanstack options for improved customization capabilities.
- 238-240: The use of
getQueryKey
with{ infinite: false, optimisticUpdate: true }
options in cache data retrieval is a significant improvement. It streamlines the process of generating and using query keys, making it more consistent and flexible across different runtime environments. This change supports the PR's goal of enhancing query and mutation handling capabilities.packages/plugins/tanstack-query/src/generator.ts (5)
- 20-20: The introduction of
ts-pattern
for pattern matching is a notable improvement. It enhances the flexibility and readability of the options handling logic in the generation of query and mutation hooks. This aligns with the PR's objective to provide more detailed configuration capabilities for query and mutation behaviors.- 41-41: Updating the version check to default to 'v5' and ensuring only 'v4' and 'v5' are supported versions is a necessary change. It reflects the focus of this PR on integrating Zenstack options into Tanstack v5, ensuring that the generator logic is aligned with the supported versions of Tanstack.
- 546-546: The addition of
ExtraQueryOptions
andExtraMutationOptions
to the base imports is a critical update. It ensures that these new types are available for use in the generated query and mutation hooks, supporting the PR's goal of enhancing customization capabilities for users. This change is essential for allowing more detailed configuration of query and mutation behaviors.- 597-628: The use of
ts-pattern
for generating query options based on the target framework, return type, data type, and version is an excellent application of pattern matching. It simplifies the logic for determining the appropriate options type for different scenarios, enhancing the maintainability and readability of the code. This approach aligns with the PR's objectives by providing a more flexible and standardized way to configure query hooks.- 633-643: Similarly, the application of
ts-pattern
for generating mutation options based on the target framework, return type, and arguments type is a valuable improvement. It streamlines the process of determining the correct options type for mutation hooks, contributing to the PR's goal of enhancing the flexibility and customization of mutation handling across different frameworks.
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.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files selected for processing (1)
- tests/integration/tests/cli/plugins.test.ts (1 hunks)
Additional comments: 2
tests/integration/tests/cli/plugins.test.ts (2)
- 74-74: The version of
@tanstack/react-query
has been updated from^4.0.0
to^5.0.0
. This change aligns with the PR's objective to support Tanstack v5. Ensure that all tests and functionalities relying on@tanstack/react-query
are compatible with version 5.0.0, as major version updates can introduce breaking changes.Verification successful
The update of
@tanstack/react-query
to version^5.0.0
in the test file is consistent with the codebase's explicit support for this version, as evidenced by specific tests and runtime logic designed for version 5. This indicates that the change aligns with the project's requirements and compatibility considerations. Therefore, the version update in the PR is verified to be appropriate for the project's current state and objectives.* 71-77: > 📝 **NOTE** > This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [1-1]Scripts Executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Verify if there are specific tests targeting @tanstack/react-query features that might be affected by the version update. rg --type ts "react-query"Length of output: 4478
The file structure and setup for testing plugins, including the updated
@tanstack/react-query
, follow best practices for isolation and environment management. Consider revisiting the commented-out package managers (pnpm
,pnpm-workspace
) and plugin configurations in future work to expand test coverage.
Fixes #835
Summary by CodeRabbit
ExtraQueryOptions
andExtraMutationOptions
for extended control over queries and mutations, including handling of optimistic updates.