Skip to content

Conversation

@ScriptType
Copy link
Contributor

Second try (before I did not branch from dev ...)

Heyho, pretty new to the open-source world.
As I use Angular and NestJS in my tech stack and found this interesting library I was pretty sad that the plugin does not work with Angular, so I created an implementation.
Sadly, I can't get the test running on my system. (even without any changes to the code) (It searches the package.json in a very wrong directory. I don't know why, and I didn't want to change anything on the setup/config files.)

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 4, 2025

Important

Review skipped

Review was skipped due to path filters

⛔ Files ignored due to path filters (2)
  • packages/plugins/tanstack-query/package.json is excluded by !**/*.json
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml, !**/*.yaml

CodeRabbit blocks several paths by default. You can override this behavior by explicitly including those paths in the path filters. For example, including **/dist/** will override the default block on the dist directory, by removing the pattern from both the lists.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

📝 Walkthrough

Walkthrough

Angular framework support was integrated into the TanStack Query plugin. This includes a new Angular runtime module, generator logic for Angular-specific hooks and context, updated build scripts and configuration, and new tests for Angular. The post-build script was also updated to handle Angular-related package aliasing.

Changes

Cohort / File(s) Change Summary
Angular Runtime Integration
packages/plugins/tanstack-query/src/runtime-v5/angular.ts
Introduced a new Angular runtime module for TanStack Query v5, providing Angular-specific hooks (useModelQuery, useInfiniteModelQuery, useModelMutation), context management, and exports for integration with Angular's dependency injection and TanStack Query client.
Generator Angular Support
packages/plugins/tanstack-query/src/generator.ts
Extended the plugin generator to support Angular as a target. Added target validation, Angular-specific hook/mutation generation, context handling, type imports, and index exports. Ensured Angular is only supported for v5, with appropriate type and import handling throughout the codebase.
Angular Test Case
packages/plugins/tanstack-query/tests/plugin.test.ts
Added a new test case and Angular component source to validate plugin output for Angular integration, mirroring existing tests for other frameworks and ensuring correct hook usage and output for Angular.
Build Entry Update
packages/plugins/tanstack-query/tsup-v5.config.ts
Added the Angular runtime module as a new entry point in the build configuration for runtime-v5, ensuring the Angular runtime is built alongside other framework runtimes.
Postbuild Alias Replacement
packages/plugins/tanstack-query/scripts/postbuild.js
Updated the postbuild script to replace @tanstack/angular-query-v5 with @tanstack/angular-query-experimental in built Angular runtime files, aligning with aliasing for other TanStack Query packages.

Sequence Diagram(s)

sequenceDiagram
    participant AngularApp as Angular App
    participant AngularRuntime as angular.ts
    participant QueryClient as TanStack Query Client
    participant API as API Server

    AngularApp->>AngularRuntime: useModelQuery(model, url, args, options)
    AngularRuntime->>QueryClient: createQuery({ queryKey, queryFn, ...options })
    QueryClient->>API: fetch data (via fetcher)
    API-->>QueryClient: returns data
    QueryClient-->>AngularRuntime: provides query result
    AngularRuntime-->>AngularApp: returns query result

    AngularApp->>AngularRuntime: useInfiniteModelQuery(model, url, args, options)
    AngularRuntime->>QueryClient: createInfiniteQuery({ queryKey, queryFn, ...options })
    QueryClient->>API: fetch paged data (via fetcher)
    API-->>QueryClient: returns paged data
    QueryClient-->>AngularRuntime: provides infinite query result
    AngularRuntime-->>AngularApp: returns infinite query result

    AngularApp->>AngularRuntime: useModelMutation(model, method, url, ...)
    AngularRuntime->>QueryClient: createMutation({ mutationFn, ...options })
    AngularApp->>QueryClient: mutate(args)
    QueryClient->>API: send mutation request
    API-->>QueryClient: returns result
    QueryClient-->>AngularRuntime: provides mutation result
    AngularRuntime-->>AngularApp: returns mutation result
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~40 minutes

✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

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

Support

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

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 generate unit tests to generate unit tests for 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
Contributor

@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)
packages/plugins/tanstack-query/src/generator.ts (1)

281-304: Consider reducing code duplication

The Angular case is identical to the React case above. Consider combining them to reduce duplication:

         case 'react':
-        case 'vue':
-            // override the mutateAsync function to return the correct type
-            func.addVariableStatement({
-                declarationKind: VariableDeclarationKind.Const,
-                declarations: [
-                    {
-                        name: 'mutation',
-                        initializer: `{
-                    ..._mutation,
-                    mutateAsync: async <T extends ${argsType}>(
-                        args: Prisma.SelectSubset<T, ${argsType}>,
-                        options?: ${optionsType}
-                      ) => {
-                        return (await _mutation.mutateAsync(
-                          args,
-                          options as any
-                        )) as ${returnType};
-                    },
-                }`,
-                    },
-                ],
-            });
-            break;
-
-        case 'svelte':
-            // svelte-query returns a store for mutations
-            // here we override the mutateAsync function to return the correct type
-            // and call `derived` to return a new reactive store
-            func.addVariableStatement({
-                declarationKind: VariableDeclarationKind.Const,
-                declarations: [
-                    {
-                        name: 'mutation',
-                        initializer: `derived(_mutation, value => ({
-                    ...value,
-                    mutateAsync: async <T extends ${argsType}>(
-                        args: Prisma.SelectSubset<T, ${argsType}>,
-                        options?: ${optionsType}
-                      ) => {
-                        return (await value.mutateAsync(
-                          args,
-                          options as any
-                        )) as ${returnType};
-                    },
-                }))`,
-                    },
-                ],
-            });
-            break;
-
         case 'angular':
-            // Angular uses injectMutation which returns the mutation object directly
-            // override the mutateAsync function to return the correct type
+        case 'vue':
+            // override the mutateAsync function to return the correct type
             func.addVariableStatement({
                 declarationKind: VariableDeclarationKind.Const,
                 declarations: [
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 6d11737 and d395aa9.

⛔ Files ignored due to path filters (2)
  • packages/plugins/tanstack-query/package.json is excluded by !**/*.json
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml, !**/*.yaml
📒 Files selected for processing (5)
  • packages/plugins/tanstack-query/scripts/postbuild.js (1 hunks)
  • packages/plugins/tanstack-query/src/generator.ts (8 hunks)
  • packages/plugins/tanstack-query/src/runtime-v5/angular.ts (1 hunks)
  • packages/plugins/tanstack-query/tests/plugin.test.ts (1 hunks)
  • packages/plugins/tanstack-query/tsup-v5.config.ts (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (3)
packages/plugins/tanstack-query/src/generator.ts (7)
packages/sdk/src/types.ts (1)
  • PluginError (115-119)
packages/schema/src/plugins/zod/index.ts (1)
  • name (5-5)
packages/schema/src/plugins/prisma/index.ts (1)
  • name (19-19)
packages/schema/src/plugins/enhancer/index.ts (1)
  • name (15-15)
packages/plugins/openapi/src/index.ts (1)
  • name (5-5)
packages/plugins/trpc/src/index.ts (1)
  • name (4-4)
packages/plugins/tanstack-query/src/index.ts (1)
  • name (4-4)
packages/plugins/tanstack-query/tests/plugin.test.ts (1)
packages/testtools/src/schema.ts (2)
  • loadSchema (173-249)
  • normalizePath (73-75)
packages/plugins/tanstack-query/src/runtime-v5/angular.ts (1)
packages/plugins/tanstack-query/src/runtime/common.ts (4)
  • DEFAULT_QUERY_ENDPOINT (15-15)
  • marshal (213-220)
  • setupInvalidation (254-275)
  • setupOptimisticUpdate (333-377)
🔇 Additional comments (10)
packages/plugins/tanstack-query/tsup-v5.config.ts (1)

4-4: LGTM!

The Angular runtime entry point is correctly added following the same pattern as other frameworks.

packages/plugins/tanstack-query/scripts/postbuild.js (1)

49-54: Angular package uses experimental version

The implementation correctly follows the established pattern. Note that Angular replaces with @tanstack/angular-query-experimental while other frameworks use stable package names, indicating Angular support may be experimental.

packages/plugins/tanstack-query/tests/plugin.test.ts (1)

346-346: Angular version is up-to-date and valid

The test’s '^20.0.0' constraint aligns with the current stable Angular release (v20.1.3 as of July 23, 2025). No changes are needed.

packages/plugins/tanstack-query/src/generator.ts (2)

44-47: Good validation for Angular version constraint

The check ensures Angular is only supported with v5, which aligns with the fact that Angular support appears to be experimental and only available in TanStack Query v5.


630-632: LGTM!

Angular context exports follow the established pattern for other frameworks.

packages/plugins/tanstack-query/src/runtime-v5/angular.ts (5)

1-1: LGTM!

Appropriate ESLint directive for a runtime module that handles dynamic types.


32-58: Well-implemented Angular context management

The implementation correctly uses Angular's dependency injection with:

  • Proper InjectionToken declaration
  • Provider function following Angular patterns
  • Safe optional injection with sensible defaults
  • Correct context destructuring and spreading

70-90: LGTM!

The query hook correctly integrates Angular's injectQuery with the common query logic.


102-124: LGTM!

The infinite query hook properly handles pagination and follows the established pattern.


138-207: Comprehensive mutation implementation

The mutation hook is well-implemented with:

  • Proper request method handling
  • Correct use of Angular's QueryClient injection
  • Support for both query invalidation and optimistic updates
  • Appropriate cancellation of in-flight queries to prevent race conditions

Copy link
Member

@ymc9 ymc9 left a comment

Choose a reason for hiding this comment

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

Hi @ScriptType ,

Thanks for making this PR! I've never used Angular or tanstack-angular-query, but the change looks very good to me. Please check the one comment I added when you have time.

I'll merge it with the dev branch where I made a few fixes related to the observed test failures. If the issues are resolved, I'll approve the PR and get it merged.

Will you be interested in adding documentation for it too?

@ScriptType
Copy link
Contributor Author

ScriptType commented Aug 9, 2025

Removed the Peer-Dependencie.
The Documentation would be a separate PR in the other Repo ? Sure i can do it.
But my English is not the best, so I would let me AI help correct the text and stuff if this is ok.

Is there anything else I can help you with inside the project?

@ymc9
Copy link
Member

ymc9 commented Aug 9, 2025

Removed the Peer-Dependencie. The Documentation would be a separate PR in the other Repo ? Sure i can do it. But my English is not the best, so I would let me AI help correct the text and stuff if this is ok.

Is there anything else I can help you with inside the project?

Awesome! Yes, docs are in a separate repo here:

https://github.com/zenstackhq/zenstack-docs/blob/main/docs/reference/plugins/tanstack-query.mdx

I think simply mirroring current content about react/vue would be sufficient. I can help with some touchup if needed. Thanks! @ScriptType

ymc9
ymc9 previously approved these changes Aug 9, 2025
Copy link
Member

@ymc9 ymc9 left a comment

Choose a reason for hiding this comment

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

I'll merge this PR once the CI passes.

@ymc9 ymc9 merged commit b5b9efe into zenstackhq:dev Aug 9, 2025
12 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.

2 participants