-
Notifications
You must be signed in to change notification settings - Fork 58
Fix UpdateManyAndReturn type #354
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
base: main
Are you sure you want to change the base?
Conversation
WalkthroughExtends 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
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
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
✨ Finishing Touches
🧪 Generate unit tests
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. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration 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.
Actionable comments posted: 0
🧹 Nitpick comments (1)
packages/generator/src/sdl/GenerateTypes.ts (1)
56-63
: DRY up AndReturn handling for CreateMany/UpdateManyMinor 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.
⛔ 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...AndReturnOutputTypeThis 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 caseAccurately returns ReturnType<Client.Prisma.Delegate['updateManyAndReturn']> for resolver return types. This aligns with the existing CreateMany...AndReturnOutputType handling.
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 fileresolversTypes.ts
.It is generating
Client.Prisma.UpdateManyUserAndReturnOutputType
which does not exist. Instead ofReturnType<Client.Prisma.UserDelegate['updateManyAndReturn']>
which does.This pull request remedies the issue. Cheers 🥂
Summary by CodeRabbit