-
-
Couldn't load subscription status.
- Fork 126
fix(zod): delegate aux fields appearing in WhereUniqueInput schemas #2029
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
Conversation
📝 WalkthroughWalkthroughThe changes update the filtering conditions in schema generator methods by replacing the use of Changes
Sequence Diagram(s)Filtering Logic FlowsequenceDiagram
participant Caller as Generator Caller
participant Generator as Schema Generator
participant Filter as Filtering Logic
Caller->>Generator: Invoke schema generation (transformInterface/generateObjectSchemas)
Generator->>Filter: Evaluate field/method names using "includes" check
Filter-->>Generator: Return filtered list of fields/methods
Generator-->>Caller: Return processed schema data
Regression Test FlowsequenceDiagram
participant Test as Regression Test
participant DB as Database
participant Schema as Schema Loader
participant Parser as Zod Parser
Test->>DB: Create and connect to database
Test->>Schema: Load schema with models and relationships
Test->>Parser: Parse schema using updated filtering logic
Parser-->>Test: Return validation results (success/failure)
Test->>Test: Assert expected behavior and failure on delegate fields
Possibly related PRs
Suggested reviewers
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (3)
⏰ Context from checks skipped due to timeout of 90000ms (6)
🪧 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 using PR comments)
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)
tests/regression/tests/issue-2028.test.ts (1)
5-5: Minor naming inconsistency in database name.The database name 'issue-1955-1' doesn't match the issue number being tested (2028). This won't affect functionality but could be confusing.
-const dbUrl = await createPostgresDb('issue-1955-1'); +const dbUrl = await createPostgresDb('issue-2028');
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
packages/schema/src/plugins/enhancer/enhance/index.ts(2 hunks)packages/schema/src/plugins/zod/generator.ts(1 hunks)tests/regression/tests/issue-2028.test.ts(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (6)
- GitHub Check: Analyze (javascript-typescript)
- GitHub Check: build-test (20.x)
- GitHub Check: dependency-review
- GitHub Check: build-test (20.x)
- GitHub Check: build-test (20.x)
- GitHub Check: OSSAR-Scan
🔇 Additional comments (6)
packages/schema/src/plugins/zod/generator.ts (1)
247-247: Good fix to correctly handle delegate auxiliary fields.This change from using
startsWithtoincludesensures that fields with theDELEGATE_AUX_RELATION_PREFIXanywhere in their name are properly filtered out, not just at the beginning of the name. This aligns with the PR objective to fix delegate auxiliary fields appearing in WhereUniqueInput schemas.packages/schema/src/plugins/enhancer/enhance/index.ts (3)
568-568: Consistent filtering of delegate auxiliary fields in properties.This change from
startsWithtoincludesprovides more comprehensive filtering of auxiliary fields, ensuring that properties withDELEGATE_AUX_RELATION_PREFIXanywhere in their name are excluded.
571-571: Consistent filtering of delegate auxiliary fields in methods.Similarly to property filtering, this change ensures methods with
DELEGATE_AUX_RELATION_PREFIXanywhere in their name are properly excluded.
853-853: Updated auxiliary field detection logic.Changed the filtering of auxiliary declarations to use
includesinstead ofstartsWith, maintaining consistency with the other changes and ensuring more comprehensive filtering.tests/regression/tests/issue-2028.test.ts (2)
1-116: Well-structured regression test for issue #2028.This test effectively validates that:
- The Zod schemas correctly exclude delegate fields from the
UserFolderWhereUniqueInputObjectSchema- The compound unique query functionality works as expected for both delegate model types
The test creates a comprehensive scenario with inheritance relationships (Foo, Bar, Baz) and many-to-many relationships (User-UserFolder-Foo), which thoroughly validates the fix.
56-73: Good negative testing for delegate auxiliary fields.The test properly verifies that parsing attempts with delegate fields like
userId_delegate_aux_UserFolder_fooId_BaranduserId_delegate_aux_UserFolder_fooId_Bazreturn failure, confirming that these fields are correctly excluded from the schema.
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.
Hey @diesal11 , good catch and many thanks for making the fix! Code looks great to me. I'll merge and release a patch.
Fixes #2028
This also silently fixes the enhanced PrismaClient types by updating that code to use
.includes(DELEGATE_AUX_RELATION_PREFIX)over.startsWith(DELEGATE_AUX_RELATION_PREFIX)to search for delegate aux fields.Unfortunately I couldn't find an easy way to test the PrismaClient types within the existing test infrastructure, so that regression is untested.