Skip to content

Conversation

ZenSoftware
Copy link

@ZenSoftware ZenSoftware commented Sep 4, 2025

Hi @AhmedElywa,

There is a problem with the new UpdateManyAndReturn feature Prisma introduced as of Prisma v6.2.0. Similar to issue #335, @paljs/generator is not producing the correct types for the file resolversTypes.ts.

It is generating Client.Prisma.UpdateManyUserAndReturnOutputType which does not exist. Instead of ReturnType<Client.Prisma.UserDelegate['updateManyAndReturn']> which does.

This pull request remedies the issue. Cheers 🥂

Summary by CodeRabbit

  • New Features
    • Improved type generation to support UpdateMany…AndReturn outputs, providing accurate return types for updateManyAndReturn operations.
    • Aligns behavior with existing CreateMany…AndReturn support for a consistent developer experience.
    • Enhances TypeScript autocomplete and type safety when working with update-many-and-return flows.
  • Chores
    • Internal type-generation logic extended without changing public APIs or altering existing code paths.

Copy link

coderabbitai bot commented Sep 4, 2025

Walkthrough

Extends type-generation logic to recognize UpdateMany...AndReturnOutputType names. Adds branches in getParentType and getOutputType to derive the inner model and return ReturnType<Client.Prisma.Delegate["updateManyAndReturn"]>, mirroring existing CreateMany...AndReturnOutputType handling. No exported API signatures were changed.

Changes

Cohort / File(s) Summary
SDL type-generation: AndReturn handling
packages/generator/src/sdl/GenerateTypes.ts
Adds recognition and return-type resolution for UpdateMany...AndReturnOutputType in getParentType and getOutputType, mapping to ReturnType<Client.Prisma.Delegate["updateManyAndReturn"]>. Mirrors existing CreateMany...AndReturnOutputType logic; no other code paths altered.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant GT as GenerateTypes
  participant Name as Type Name
  participant Prisma as Client.Prisma.<Model>Delegate

  Note over GT,Name: Type resolution flow (updated)
  GT->>Name: Inspect options.type / name
  alt CreateMany...AndReturnOutputType
    GT->>Prisma: Resolve ReturnType[createManyAndReturn]
    Prisma-->>GT: Output type
  else UpdateMany...AndReturnOutputType (new)
    GT->>Prisma: Resolve ReturnType[updateManyAndReturn]
    Prisma-->>GT: Output type
  else Other types
    GT-->>GT: Existing resolution paths
  end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

I twitch my ears at types that turn,
From updates many, outputs return.
Hop, skip, compile—no path askew,
Create had friends, now Update too.
In fields of Prisma, carrots bright,
I nibble types that fit just right.

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

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • 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.
  • 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 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/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit 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

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • 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

@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/generator/src/sdl/GenerateTypes.ts (1)

56-63: DRY up AndReturn handling for CreateMany/UpdateMany

Minor duplication in extracting the inner model and composing the delegate ReturnType for both CreateMany/UpdateMany. A tiny helper keeps this consistent and eases future extensions.

Apply within these ranges:

-    if (name.startsWith('CreateMany') && name.endsWith('AndReturnOutputType')) {
-      const innerType = name.replace(/^CreateMany|AndReturnOutputType$/g, '');
-      return `ReturnType<Client.Prisma.${innerType}Delegate["createManyAndReturn"]>`;
-    }
+    if (name.startsWith('CreateMany') && name.endsWith('AndReturnOutputType')) {
+      return this.getAndReturnDelegateReturnType(name, 'CreateMany');
+    }
@@
-    if (name.startsWith('UpdateMany') && name.endsWith('AndReturnOutputType')) {
-      const innerType = name.replace(/^UpdateMany|AndReturnOutputType$/g, '');
-      return `ReturnType<Client.Prisma.${innerType}Delegate["updateManyAndReturn"]>`;
-    }
+    if (name.startsWith('UpdateMany') && name.endsWith('AndReturnOutputType')) {
+      return this.getAndReturnDelegateReturnType(name, 'UpdateMany');
+    }
@@
-        if (options.type.startsWith('CreateMany') && options.type.endsWith('AndReturnOutputType')) {
-          const innerType = options.type.replace(/^CreateMany|AndReturnOutputType$/g, '');
-          return `ReturnType<Client.Prisma.${innerType}Delegate["createManyAndReturn"]>`;
-        }
+        if (options.type.startsWith('CreateMany') && options.type.endsWith('AndReturnOutputType')) {
+          return this.getAndReturnDelegateReturnType(options.type as string, 'CreateMany');
+        }
@@
-        if (options.type.startsWith('UpdateMany') && options.type.endsWith('AndReturnOutputType')) {
-          const innerType = options.type.replace(/^UpdateMany|AndReturnOutputType$/g, '');
-          return `ReturnType<Client.Prisma.${innerType}Delegate["updateManyAndReturn"]>`;
-        }
+        if (options.type.startsWith('UpdateMany') && options.type.endsWith('AndReturnOutputType')) {
+          return this.getAndReturnDelegateReturnType(options.type as string, 'UpdateMany');
+        }

Add this helper inside the class:

private getAndReturnDelegateReturnType(name: string, op: 'CreateMany' | 'UpdateMany') {
  const inner = name.replace(new RegExp(`^${op}|AndReturnOutputType$`, 'g'), '')
  const method = `${op.charAt(0).toLowerCase()}${op.slice(1)}AndReturn` as
    | 'createManyAndReturn'
    | 'updateManyAndReturn'
  return `ReturnType<Client.Prisma.${inner}Delegate["${method}"]>`
}

Also applies to: 81-88

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between d1f0440 and c04b26c.

⛔ Files ignored due to path filters (1)
  • packages/generator/tests/SDL/__snapshots__/generateSDLTypescript.test.ts.snap is excluded by !**/*.snap
📒 Files selected for processing (1)
  • packages/generator/src/sdl/GenerateTypes.ts (2 hunks)
🔇 Additional comments (2)
packages/generator/src/sdl/GenerateTypes.ts (2)

60-63: LGTM: Correct mapping for UpdateMany...AndReturnOutputType

This fixes the incorrect Client.Prisma.UpdateManyAndReturnOutputType by emitting ReturnType<Client.Prisma.Delegate['updateManyAndReturn']> for parent types. Matches Prisma v6.2+ semantics.


85-88: LGTM: Output type resolution mirrors CreateMany case

Accurately returns ReturnType<Client.Prisma.Delegate['updateManyAndReturn']> for resolver return types. This aligns with the existing CreateMany...AndReturnOutputType handling.

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