Skip to content

Conversation

@ymc9
Copy link
Member

@ymc9 ymc9 commented Sep 9, 2025

fixes #2226

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 9, 2025

📝 Walkthrough

Walkthrough

Adjusts Zod transformer’s delegate input type resolution to pick from candidate names based on existing DMMF input types (handles certain Prisma naming variants). Adds an inheritance-aware field comparison in SDK backlink detection. Adds a regression test validating delegated subtype update input schema for a self-relation.

Changes

Cohort / File(s) Summary
Zod transformer: delegate input type name resolution
packages/schema/src/plugins/zod/transformer.ts
Replace direct mapped input-type name with candidate-based lookup: build candidates (start with mapped name, also try variants like replacing UpdateOneUpdate and NestedInputInput) and choose an existing DMMF inputObjectTypes name if found; otherwise fall back to original mapped name. No signature changes.
SDK relation backlink handling
packages/sdk/src/utils.ts
Add local helper sameField comparing DataModelField by name and base ($inheritedFrom or $container) and use it in getRelationBackLink to treat inherited/delegated fields as the same when skipping backlink candidates. No public API changes.
Regression test for delegated subtype with self-relation
tests/regression/tests/issue-2226.test.ts
New test using loadSchema(..., fullZod: true) that ensures RegistrationFrameworkUpdateInputObjectSchema exists and safely parses an object with replacedRegistrationId: '123', covering delegated subtype + base-model self-relation scenario.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant T as Zod Transformer
  participant D as DMMF.inputObjectTypes
  participant R as Result

  T->>T: Derive mappedInputTypeName
  T->>T: Build candidate list (mapped, UpdateOne→Update, NestedInput→Input)
  T->>D: Search for first matching input type name among candidates
  alt Match found
    D-->>T: MatchedName
    T->>R: Use MatchedName for processedInputType
  else No match
    D-->>T: None
    T->>R: Use original mappedInputTypeName
  end
Loading
sequenceDiagram
  autonumber
  participant U as getRelationBackLink
  participant F as Field
  participant O as OtherField

  U->>U: sameField(O, F) compares name + base ($inheritedFrom | $container)
  alt same field
    U-->>U: Skip backlink candidate
  else different field
    U-->>U: Consider as backlink
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Pre-merge checks (3 passed, 1 warning, 1 inconclusive)

❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Linked Issues Check ⚠️ Warning Although the PR adds candidate-based mapping and a regression test for the delegated self-relation case, it does not implement explicit opposite-side field detection using @relation names or cardinality, nor does it cover the full range of Prisma input naming variants or include tests for field-order and naming permutations as required by issue #2226. Extend the mapping logic to detect and prefer the opposite-side relation field based on @relation metadata, include additional Prisma input variants like Unchecked and UpdateToOneWithWhereWithout, and add tests for field-order and naming permutations to fully satisfy the linked issue’s requirements.
Description Check ❓ Inconclusive The description merely references the issue number without summarizing the key changes or their impact, making it too vague to inform reviewers about what the PR actually does. Please expand the description to include a brief summary of the main modifications, such as the candidate-based name resolution in mapDelegateInputType, the introduction of the sameField helper, and the new regression test for the delegated self-relation scenario.
✅ Passed checks (3 passed)
Check name Status Explanation
Title Check ✅ Passed The title clearly indicates that the primary change addresses a Zod generation issue for self-relations in delegated types, directly reflecting the core problem the PR resolves.
Out of Scope Changes Check ✅ Passed All code changes, including updates to transformer.ts, the sameField helper in utils.ts, and the new regression test, directly support fixing Zod generation for delegated self-relations and do not introduce unrelated features.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

Tip

👮 Agentic pre-merge checks are now available in preview!

Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.

  • Built-in checks – Quickly apply ready-made checks to enforce title conventions, require pull request descriptions that follow templates, validate linked issues for compliance, and more.
  • Custom agentic checks – Define your own rules using CodeRabbit’s advanced agentic capabilities to enforce organization-specific policies and workflows. For example, you can instruct CodeRabbit’s agent to verify that API documentation is updated whenever API schema files are modified in a PR. Note: Upto 5 custom checks are currently allowed during the preview period. Pricing for this feature will be announced in a few weeks.

Example:

reviews:
  pre_merge_checks:
    custom_checks:
      - name: "Undocumented Breaking Changes"
        mode: "warning"
        instructions: |
          Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).

Please share your feedback with us on this Discord post.


📜 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 f51424a and be6eabc.

📒 Files selected for processing (1)
  • packages/schema/src/plugins/zod/transformer.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/schema/src/plugins/zod/transformer.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: build-test (20.x)
  • GitHub Check: build-test (20.x)
  • GitHub Check: build-test (20.x)
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/issue-2226

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

Comment @coderabbitai help to get the list of available commands and usage tips.

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

🧹 Nitpick comments (2)
packages/sdk/src/utils.ts (1)

662-669: Correctly skipping self/clone in backlink detection for delegated inheritance.

Replacing strict identity with a structural "same field" check fixes the self-relation case where inherited fields are cloned. This is the right place to apply it and the comparison logic (name + base model via $inheritedFrom ?? $container) is sound.

Minor: consider extracting sameField as a shared utility if other places compare fields across inheritance.

Also applies to: 671-672

tests/regression/tests/issue-2226.test.ts (1)

24-31: Solid regression; consider one more assertion to harden failures.

Add an explicit check that zodSchemas and the target object schema both exist before parsing, so failures surface with clearer messages.

-        const schema = zodSchemas.objects.RegistrationFrameworkUpdateInputObjectSchema;
-        expect(schema).toBeDefined();
+        expect(zodSchemas).toBeDefined();
+        const schema = zodSchemas.objects?.RegistrationFrameworkUpdateInputObjectSchema;
+        expect(schema).toBeDefined();

Optional follow-ups (future PR): add a second case where the to-many side appears before the to-one side in the model to cover ordering permutations requested in the issue.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 25da0c7 and f51424a.

📒 Files selected for processing (3)
  • packages/schema/src/plugins/zod/transformer.ts (1 hunks)
  • packages/sdk/src/utils.ts (1 hunks)
  • tests/regression/tests/issue-2226.test.ts (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
tests/regression/tests/issue-2226.test.ts (1)
packages/testtools/src/schema.ts (1)
  • loadSchema (172-248)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
  • GitHub Check: build-test (20.x)
  • GitHub Check: build-test (20.x)
  • GitHub Check: OSSAR-Scan
  • GitHub Check: dependency-review
  • GitHub Check: build-test (20.x)
🔇 Additional comments (1)
packages/schema/src/plugins/zod/transformer.ts (1)

260-268: Import safety still OK after remapping.

Good call to only add schema import when the mapped type differs from the current object’s originalName, avoiding self-import cycles.

@ymc9 ymc9 merged commit 8962ad9 into dev Sep 9, 2025
12 checks passed
@ymc9 ymc9 deleted the fix/issue-2226 branch September 9, 2025 18:30
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