Skip to content

Angular tanstack query #2206

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

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from

Conversation

ScriptType
Copy link

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

Copy link
Contributor

coderabbitai bot commented Aug 4, 2025

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

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 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 d395aa9 and 809a817.

📒 Files selected for processing (1)
  • packages/plugins/tanstack-query/src/generator.ts (8 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/plugins/tanstack-query/src/generator.ts
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 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

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.

1 participant