Skip to content

refactor: relax prisma type safety to decrease type count #1019

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

Merged
merged 2 commits into from
May 30, 2025

Conversation

Yohe-Am
Copy link
Contributor

@Yohe-Am Yohe-Am commented May 28, 2025

  • Improves the type count of the prisma type generators by relaxing type safety. Namely:
    • Create/update types have all related types as optional even when required
    • Where filters will always have all the relationships present even when netsted in another where type

Migration notes


  • The change comes with new or modified tests
  • Hard-to-understand functions have explanatory comments
  • End-user documentation is updated to reflect the change

Summary by CodeRabbit

  • New Features

    • Added an optional selection flag property to multiple TypeScript selection types, enabling enhanced selection capabilities in generated client code.
  • Bug Fixes

    • Updated version checks in initialization routines to expect version "0.5.1-rc.3".
  • Refactor

    • Simplified and streamlined type generation logic by disabling selective relationship and model skipping in generated types.
    • Reorganized and clarified struct and type alias declarations for improved code structure and maintainability.
    • Adjusted internal variant ordering for RPC calls to improve internal consistency.
  • Tests

    • Updated test output to provide more concise and relevant debugging information.

Copy link
Contributor

coderabbitai bot commented May 28, 2025

📝 Walkthrough

Walkthrough

This set of changes primarily comments out and disables all logic related to skipping relationships, models, or properties during Prisma type generation in Rust. Several fields and methods managing such skips are commented out across multiple files, simplifying type generation to always include all relationships and models. Additionally, the order of variants in the RpcCall enum is changed, version constants are updated in test files, TypeScript selection types gain an optional selection flag, and type declarations in a Rust test are reorganized and clarified.

Changes

File(s) Change Summary
src/meta-cli/src/typegraph/rpc/mod.rs Reordered variants in the RpcCall enum.
src/typegraph/core/src/runtimes/prisma/errors.rs Commented out the unregistered_relationship error function.
src/typegraph/core/src/runtimes/prisma/type_generation/input_type.rs
src/typegraph/core/src/runtimes/prisma/type_generation/order_by.rs
src/typegraph/core/src/runtimes/prisma/type_generation/out_type.rs
src/typegraph/core/src/runtimes/prisma/type_generation/where_.rs
src/typegraph/core/src/runtimes/prisma/type_generation/with_nested_count.rs
Commented out all fields, methods, and logic related to skipping relationships/models in type generation. Naming and recursion-avoidance logic based on skips is disabled.
tests/metagen/typegraphs/identities/rs/fdk.rs
tests/runtimes/wasm_wire/rust/fdk.rs
Updated static version string from "0.5.1-rc.2" to "0.5.1-rc.3". In wasm_wire/rust/fdk.rs, reorganized and clarified type declarations for Entity and Profile.
tests/metagen/typegraphs/identities/ts/fdk.ts
tests/metagen/typegraphs/sample/ts/client.ts
Added optional property _?: SelectionFlags to multiple exported TypeScript selection types.
tests/runtimes/prisma/type_duplication_test.ts Replaced raw serialized data logging with a concise summary of serialized size and type array length.

Sequence Diagram(s)

sequenceDiagram
    participant PrismaTypeGen
    participant Model
    participant Property

    PrismaTypeGen->>Model: Get all relationships/properties
    loop For each property
        PrismaTypeGen->>Property: Generate type (no skipping logic)
    end
    PrismaTypeGen-->>Model: Complete type generation (all relationships included)
Loading

Possibly related PRs

  • metatypedev/metatype#982: Also modifies the order of variants in the RpcCall enum in the same file.
  • metatypedev/metatype#977: Refactors and changes imports and the RpcCall enum variants in the same file, directly related to enum variant ordering.

Suggested reviewers

  • michael-0acf4

📜 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 1da0f15 and 8b0d125.

⛔ Files ignored due to path filters (3)
  • Cargo.lock is excluded by !**/*.lock
  • tests/runtimes/typegate/__snapshots__/typegate_prisma_test.ts.snap is excluded by !**/*.snap
  • tests/runtimes/typegate/__snapshots__/typegate_runtime_test.ts.snap is excluded by !**/*.snap
📒 Files selected for processing (1)
  • src/typegraph/core/Cargo.toml (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • src/typegraph/core/Cargo.toml
⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: lint-compat (macos-14, aarch64-apple-darwin, false)
  • GitHub Check: lint-compat (macos-13, x86_64-apple-darwin, false)
  • GitHub Check: test-full
  • GitHub Check: build-docker (linux/arm64, ubuntu-22.04-arm)
  • GitHub Check: build-docker (linux/amd64, custom-ubuntu-large)
  • GitHub Check: pre-commit

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.
    • Explain this complex logic.
    • 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. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • 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.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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)

  • @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 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: 6

🧹 Nitpick comments (4)
src/typegraph/core/src/runtimes/prisma/type_generation/where_.rs (1)

33-41: Remove commented code instead of keeping it.

The entire nested method is commented out rather than removed. Consider removing dead code to improve maintainability.

-    // fn nested(&self, name: &str, model_id: TypeId) -> Self {
-    //     // let mut skip_models = self.skip_models.clone();
-    //     // skip_models.insert(self.model_id.name().unwrap().unwrap(), name.to_string());
-    //     Self {
-    //         model_id,
-    //         // skip_models,
-    //         aggregates: self.aggregates,
-    //     }
-    // }
src/typegraph/core/src/runtimes/prisma/type_generation/order_by.rs (2)

6-6: Clean up commented import.

The commented import should be removed if it's no longer needed.

-// use crate::runtimes::prisma::errors;

29-32: Remove commented public method.

The commented skip method should be removed rather than kept as commented code.

-    // pub fn skip(mut self, rel_names: Vec<String>) -> Self {
-    //     self.skip_rel = rel_names;
-    //     self
-    // }
src/typegraph/core/src/runtimes/prisma/type_generation/input_type.rs (1)

54-63: Remove extensive commented relationship handling code.

Large blocks of commented code should be removed for better maintainability.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 38df9d0 and 1da0f15.

⛔ Files ignored due to path filters (29)
  • deno.lock is excluded by !**/*.lock
  • src/typegraph/core/src/runtimes/prisma/type_generation/snapshots/typegraph_core__runtimes__prisma__type_generation__query_where_expr__tests__Post__QueryWhereExpr.snap is excluded by !**/*.snap
  • src/typegraph/core/src/runtimes/prisma/type_generation/snapshots/typegraph_core__runtimes__prisma__type_generation__query_where_expr__tests__User__QueryWhereExpr.snap is excluded by !**/*.snap
  • src/typegraph/core/src/runtimes/prisma/type_generation/snapshots/typegraph_core__runtimes__prisma__type_generation__test__create_many Post inp.snap is excluded by !**/*.snap
  • src/typegraph/core/src/runtimes/prisma/type_generation/snapshots/typegraph_core__runtimes__prisma__type_generation__test__create_many Post out.snap is excluded by !**/*.snap
  • src/typegraph/core/src/runtimes/prisma/type_generation/snapshots/typegraph_core__runtimes__prisma__type_generation__test__create_many User inp.snap is excluded by !**/*.snap
  • src/typegraph/core/src/runtimes/prisma/type_generation/snapshots/typegraph_core__runtimes__prisma__type_generation__test__create_many User out.snap is excluded by !**/*.snap
  • src/typegraph/core/src/runtimes/prisma/type_generation/snapshots/typegraph_core__runtimes__prisma__type_generation__test__create_one Post inp.snap is excluded by !**/*.snap
  • src/typegraph/core/src/runtimes/prisma/type_generation/snapshots/typegraph_core__runtimes__prisma__type_generation__test__create_one User inp.snap is excluded by !**/*.snap
  • src/typegraph/core/src/runtimes/prisma/type_generation/snapshots/typegraph_core__runtimes__prisma__type_generation__test__find_first Post out.snap is excluded by !**/*.snap
  • src/typegraph/core/src/runtimes/prisma/type_generation/snapshots/typegraph_core__runtimes__prisma__type_generation__test__find_first User out.snap is excluded by !**/*.snap
  • src/typegraph/core/src/runtimes/prisma/type_generation/snapshots/typegraph_core__runtimes__prisma__type_generation__test__find_many Post inp.snap is excluded by !**/*.snap
  • src/typegraph/core/src/runtimes/prisma/type_generation/snapshots/typegraph_core__runtimes__prisma__type_generation__test__find_many Post out.snap is excluded by !**/*.snap
  • src/typegraph/core/src/runtimes/prisma/type_generation/snapshots/typegraph_core__runtimes__prisma__type_generation__test__find_many User inp.snap is excluded by !**/*.snap
  • src/typegraph/core/src/runtimes/prisma/type_generation/snapshots/typegraph_core__runtimes__prisma__type_generation__test__find_many User out.snap is excluded by !**/*.snap
  • src/typegraph/core/src/runtimes/prisma/type_generation/snapshots/typegraph_core__runtimes__prisma__type_generation__test__find_unique Post inp.snap is excluded by !**/*.snap
  • src/typegraph/core/src/runtimes/prisma/type_generation/snapshots/typegraph_core__runtimes__prisma__type_generation__test__find_unique Post out.snap is excluded by !**/*.snap
  • src/typegraph/core/src/runtimes/prisma/type_generation/snapshots/typegraph_core__runtimes__prisma__type_generation__test__find_unique User inp.snap is excluded by !**/*.snap
  • src/typegraph/core/src/runtimes/prisma/type_generation/snapshots/typegraph_core__runtimes__prisma__type_generation__test__find_unique User out.snap is excluded by !**/*.snap
  • src/typegraph/core/src/runtimes/prisma/type_generation/snapshots/typegraph_core__runtimes__prisma__type_generation__test__group_by Post inp.snap is excluded by !**/*.snap
  • src/typegraph/core/src/runtimes/prisma/type_generation/snapshots/typegraph_core__runtimes__prisma__type_generation__test__group_by Post out.snap is excluded by !**/*.snap
  • src/typegraph/core/src/runtimes/prisma/type_generation/snapshots/typegraph_core__runtimes__prisma__type_generation__test__group_by User inp.snap is excluded by !**/*.snap
  • src/typegraph/core/src/runtimes/prisma/type_generation/snapshots/typegraph_core__runtimes__prisma__type_generation__test__group_by User out.snap is excluded by !**/*.snap
  • src/typegraph/core/src/runtimes/prisma/type_generation/snapshots/typegraph_core__runtimes__prisma__type_generation__test__update_many Post inp.snap is excluded by !**/*.snap
  • src/typegraph/core/src/runtimes/prisma/type_generation/snapshots/typegraph_core__runtimes__prisma__type_generation__test__update_many User inp.snap is excluded by !**/*.snap
  • src/typegraph/core/src/runtimes/prisma/type_generation/snapshots/typegraph_core__runtimes__prisma__type_generation__test__update_one Post inp.snap is excluded by !**/*.snap
  • src/typegraph/core/src/runtimes/prisma/type_generation/snapshots/typegraph_core__runtimes__prisma__type_generation__test__update_one User inp.snap is excluded by !**/*.snap
  • src/typegraph/core/src/runtimes/prisma/type_generation/snapshots/typegraph_core__runtimes__prisma__type_generation__where___test__where Post.snap is excluded by !**/*.snap
  • src/typegraph/core/src/runtimes/prisma/type_generation/snapshots/typegraph_core__runtimes__prisma__type_generation__where___test__where User.snap is excluded by !**/*.snap
📒 Files selected for processing (12)
  • src/meta-cli/src/typegraph/rpc/mod.rs (1 hunks)
  • src/typegraph/core/src/runtimes/prisma/errors.rs (1 hunks)
  • src/typegraph/core/src/runtimes/prisma/type_generation/input_type.rs (5 hunks)
  • src/typegraph/core/src/runtimes/prisma/type_generation/order_by.rs (4 hunks)
  • src/typegraph/core/src/runtimes/prisma/type_generation/out_type.rs (4 hunks)
  • src/typegraph/core/src/runtimes/prisma/type_generation/where_.rs (3 hunks)
  • src/typegraph/core/src/runtimes/prisma/type_generation/with_nested_count.rs (4 hunks)
  • tests/metagen/typegraphs/identities/rs/fdk.rs (1 hunks)
  • tests/metagen/typegraphs/identities/ts/fdk.ts (4 hunks)
  • tests/metagen/typegraphs/sample/ts/client.ts (2 hunks)
  • tests/runtimes/prisma/type_duplication_test.ts (1 hunks)
  • tests/runtimes/wasm_wire/rust/fdk.rs (2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (4)
tests/runtimes/prisma/type_duplication_test.ts (1)
tests/runtimes/prisma/type_duplication.ts (1)
  • tg (7-80)
tests/metagen/typegraphs/identities/ts/fdk.ts (3)
tests/metagen/typegraphs/identities/py/fdk.py (1)
  • SelectionFlags (433-434)
src/metagen/src/client_py/static/client.py (1)
  • SelectionFlags (421-422)
tests/metagen/typegraphs/sample/py/client.py (1)
  • SelectionFlags (420-421)
src/typegraph/core/src/runtimes/prisma/type_generation/input_type.rs (2)
src/typegraph/core/src/runtimes/prisma/context.rs (1)
  • model_id (36-38)
src/typegraph/core/src/t.rs (2)
  • prop (404-407)
  • optionalx (261-263)
tests/metagen/typegraphs/sample/ts/client.ts (1)
tests/metagen/typegraphs/sample/py/client.py (1)
  • SelectionFlags (420-421)
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: test-full
  • GitHub Check: lint-compat (macos-13, x86_64-apple-darwin, false)
  • GitHub Check: lint-compat (macos-14, aarch64-apple-darwin, false)
  • GitHub Check: pre-commit
🔇 Additional comments (17)
tests/runtimes/prisma/type_duplication_test.ts (1)

19-19: Improved debugging output for type count monitoring.

This change replaces logging of raw serialized data with a concise summary containing the serialized size and type count. This is much more useful for debugging type count issues and monitoring the impact of the PR's changes to reduce type count.

tests/metagen/typegraphs/identities/ts/fdk.ts (1)

1320-1320: LGTM! Consistent addition of selection flags support.

The optional _?: SelectionFlags property is being consistently added to all selection types to support the "select all" functionality. This aligns well with the existing runtime logic in _selectionToNodeSet that already handles the selectAll flag (line 10: const selectAll = selection._ == "selectAll").

Also applies to: 1335-1335, 1346-1346, 1350-1350, 1364-1364, 1369-1369, 1374-1374, 1379-1379, 1384-1384

tests/metagen/typegraphs/sample/ts/client.ts (1)

1111-1111: LGTM! Consistent implementation across different typegraph clients.

The addition of _?: SelectionFlags to all selection types maintains consistency with the identities client and ensures the "select all" functionality is uniformly available. The existing runtime infrastructure properly supports this feature.

Also applies to: 1117-1117, 1131-1131, 1137-1137, 1142-1142, 1146-1146, 1150-1150

tests/metagen/typegraphs/identities/rs/fdk.rs (1)

119-119: LGTM: Version update maintains consistency.

The version bump from "0.5.1-rc.2" to "0.5.1-rc.3" aligns with similar updates in other test files and maintains version consistency across the codebase.

tests/runtimes/wasm_wire/rust/fdk.rs (2)

119-119: LGTM: Consistent version update.

The version bump to "0.5.1-rc.3" maintains consistency with other test files in the codebase.


393-418: LGTM: Improved type organization.

The reorganization of Entity and Profile structs and their related type aliases improves code readability by grouping related types together. The types are now positioned more logically after RecordCreationInput rather than at the end of the module.

src/meta-cli/src/typegraph/rpc/mod.rs (1)

23-26:

❓ Verification inconclusive

Verify that enum reordering doesn't affect serialization.

Moving Runtimes to the first position makes logical sense given the PR's focus on runtime changes. However, ensure that this reordering doesn't break existing serialization/deserialization behavior.


🏁 Script executed:

#!/bin/bash
# Description: Check if RpcCall enum has untagged serde attribute and verify usage patterns
# Expected: Confirm that reordering is safe for existing serialization

# Look for RpcCall enum usage and serialization patterns
rg -A 10 -B 5 "RpcCall" --type rust | head -50

# Check for any tests that might depend on enum order
fd "test" --type f --extension rs --exec rg -l "RpcCall" {} \;

Length of output: 3491


Validate untagged RpcCall variant order

The RpcCall enum in src/meta-cli/src/typegraph/rpc/mod.rs is annotated with #[serde(untagged)], which means Serde will attempt to deserialize into each variant in declaration order. Reordering these variants can change how incoming payloads are matched and may break existing (de)serialization.

• Ensure that moving Runtimes to the first position doesn’t inadvertently shadow the other variants.
• Add or update unit tests that round-trip serialize/deserialize a representative payload for each variant.
• If any payload now deserializes to the wrong variant, either revert the order or switch to an explicitly tagged representation (#[serde(tag = "...", content = "...")]).

src/typegraph/core/src/runtimes/prisma/type_generation/where_.rs (2)

124-147: Simplification of naming logic is consistent with changes.

The removal of suffix generation based on skip_models aligns with the overall simplification approach.


20-20:

✅ Verification successful

Critical: Removal of skip_models may cause infinite recursion.

The skip_models field that prevented infinite recursion in self-referencing models has been commented out. This could lead to stack overflow errors during type generation for models with circular relationships.

Please verify that this change doesn't introduce infinite recursion by running the following script to check for self-referencing models:

Also applies to: 28-28


🏁 Script executed:

#!/bin/bash
# Description: Search for self-referencing model definitions that could cause infinite recursion
# Expected: Find models that reference themselves directly or through cycles

echo "Searching for potential self-referencing models..."
rg -A 10 -B 5 'model.*\{' --type rust | rg -A 15 'Property::Model.*model_type'

Length of output: 1364


🏁 Script executed:

#!/bin/bash
set -e
echo "Displaying skip_models occurrences and nested/generate methods in where_.rs"
# List skip_models mentions
rg -n skip_models src/typegraph/core/src/runtimes/prisma/type_generation/where_.rs || echo "No skip_models found"
# Show nested method context
rg -n "fn nested" -C5 src/typegraph/core/src/runtimes/prisma/type_generation/where_.rs || echo "No nested method found"
# Show generate method implementation
rg -n "fn generate" -A20 src/typegraph/core/src/runtimes/prisma/type_generation/where_.rs || echo "Generate method not found"
# Display the file header to inspect overall context
sed -n '1,200p' src/typegraph/core/src/runtimes/prisma/type_generation/where_.rs

Length of output: 8823


🏁 Script executed:

#!/bin/bash
set -e
echo "=== PrismaContext struct definition ==="
rg -n "struct PrismaContext" -A20 -B5 src/typegraph/core/src/runtimes/prisma/context.rs || echo "PrismaContext struct not found"

echo
echo "=== impl PrismaContext and generate methods ==="
rg -n "impl PrismaContext" -A200 src/typegraph/core/src/runtimes/prisma/context.rs || echo "impl PrismaContext not found"
echo
rg -n "fn generate" -A50 src/typegraph/core/src/runtimes/prisma/context.rs || echo "generate method not found"

Length of output: 9413


🏁 Script executed:

#!/bin/bash
set -e
echo "Inspecting typegen_cache usage and generate method in PrismaContext"
rg -n "typegen_cache" -C10 src/typegraph/core/src/runtimes/prisma/context.rs || echo "typegen_cache not found"
rg -n "fn generate<" -C5 src/typegraph/core/src/runtimes/prisma/context.rs || echo "Generic generate method not found"
rg -n "get_or_init" -C5 src/typegraph/core/src/runtimes/prisma/context.rs || echo "No get_or_init usage found"

Length of output: 1287


🏁 Script executed:

#!/bin/bash
set -e
echo "Searching for TypeGen trait definition"
rg -n "trait TypeGen" -A5 src/typegraph/core/src/runtimes/prisma || echo "TypeGen trait not found"

Length of output: 729


🏁 Script executed:

#!/bin/bash
set -e
echo "=== type_generation/mod.rs (first 200 lines) ==="
sed -n '1,200p' src/typegraph/core/src/runtimes/prisma/type_generation/mod.rs

Length of output: 6438


No infinite recursion risk: PrismaContext’s typegen_cache prevents it

The skip_models logic has been removed, but recursion is still guarded by the cache in PrismaContext::generate. It pre-inserts a reference placeholder for each type_name before recursing, so nested calls for the same or cyclic models immediately hit the cache and return a ref_, rather than recursing further.

No changes required here.

src/typegraph/core/src/runtimes/prisma/type_generation/order_by.rs (2)

16-16: Consistent removal of skip mechanism across type generators.

The skip_rel field removal is consistent with similar changes in other type generation modules.

Also applies to: 24-24


56-62:

❓ Verification inconclusive

Risk of infinite recursion in OrderBy generation.

Similar to the Where type, removing the skip logic could cause infinite recursion when generating OrderBy types for self-referencing models.

The same recursion risks apply here as in the Where type. Please ensure this change has been tested with circular model relationships.

Also applies to: 70-73


🏁 Script executed:

#!/bin/bash
# Search for skip_rel references in order_by.rs
rg 'skip_rel' -n src/typegraph/core/src/runtimes/prisma/type_generation/order_by.rs || echo "no skip_rel found in order_by.rs"
# Show context around the commented-out skip_rel logic removal
sed -n '50,80p' src/typegraph/core/src/runtimes/prisma/type_generation/order_by.rs

echo ""
echo "=== Comparing Where generation for skip_rel ==="
rg 'skip_rel' -n src/typegraph/core/src/runtimes/prisma/type_generation/where.rs || echo "no skip_rel found in where.rs"
# Show context around skip_rel usage in where.rs
sed -n '50,80p' src/typegraph/core/src/runtimes/prisma/type_generation/where.rs

Length of output: 2666


Verify infinite recursion risk in OrderBy generator

The skip_rel checks were removed from your OrderBy generator in
src/typegraph/core/src/runtimes/prisma/type_generation/order_by.rs
– specifically around lines 56–62 and 70–73. Without these guards, self-referencing models can trigger infinite recursion when building OrderBy types.

• Please add tests covering circular relationships
• Or re-introduce the skip_rel logic (as used in other generators) to break cycles

src/typegraph/core/src/runtimes/prisma/type_generation/with_nested_count.rs (2)

16-16: Consistent with skip removal pattern.

The removal of the skip field follows the same pattern as other type generation modules.

Also applies to: 23-23


38-48:

❓ Verification inconclusive

Comprehensive removal of relationship skip logic.

The commented code shows extensive logic for handling relationship skipping and self-referencing models. This was likely important for preventing infinite recursion.

Please verify that models with self-references (where rel.left.model_type == rel.right.model_type) don't cause infinite loops in the simplified implementation.


🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

# Locate with_nested_count.rs
file=$(fd --full-path "with_nested_count.rs" | head -n1)
echo "Inspecting file: $file"

# Print the first 200 lines to understand the current logic
sed -n '1,200p' "$file"

Length of output: 4346


🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

# Locate PrismaContext file
file=$(fd --full-path "context.rs" | grep "src/typegraph/core/src/runtimes/prisma/context.rs" | head -n1)
echo "Inspecting context file: $file"

# Show implementation of PrismaContext including generate method
sed -n '1,200p' "$file"

# Search for generate method definition
rg -n "fn generate" -C5 "$file"

Length of output: 7047


🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

# Search for generate method in PrismaContext
rg -n "fn generate" -C2 src/typegraph/core/src/runtimes/prisma/context.rs || true

# Search for impl TypegraphContext in Prisma runtime
rg -n "impl.*TypegraphContext" -C3 src/typegraph/core/src/runtimes/prisma

Length of output: 178


🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

# Search for TypegraphContext trait definition and its implementations
rg -n "trait TypegraphContext" -C3 .
rg -n "impl .*TypegraphContext" -C3 .

Length of output: 58


Verify prevention of infinite recursion for self-referential models

I wasn’t able to locate how context.generate short-circuits on previously built types (e.g. via the typegen_cache) to confirm that a model referencing itself won’t endlessly recurse. Please ensure that either:

  • The TypegraphContext::generate implementation checks the type’s name cache (so repeated calls for Model_with_nested_count return the cached TypeId rather than rebuild), or
  • Add back the self-reference skip logic (i.e. when rel.left.model_type == rel.right.model_type) to prevent infinite nesting.
src/typegraph/core/src/runtimes/prisma/type_generation/input_type.rs (3)

23-23: Consistent removal of skip_rel mechanism.

The removal of skip_rel field and initialization is consistent with other type generation modules.

Also applies to: 31-31, 39-39


218-230: Simplified naming removes complexity tracking.

The naming logic has been simplified to remove skip-based suffixes, which is consistent with the overall approach.


145-150:

❓ Verification inconclusive

Breaking change: All relationships now optional in create operations.

This is a significant behavioral change where relationships that were previously required in create operations are now always optional. This aligns with the PR objective but represents a breaking change.

Please verify that making all relationships optional doesn't break existing functionality. Run the following script to check for tests that might be affected:


🏁 Script executed:

#!/bin/bash
# Description: Find tests that might be affected by making relationships optional
# Expected: Find test cases that rely on required relationships

echo "Searching for tests that might assume required relationships..."
rg -A 5 -B 5 'create.*input|InputType.*create' --type rust tests/
rg -A 10 'required.*relation|relation.*required' --type rust tests/

Length of output: 274


Verify impact of making relationships optional in create operations

The change unconditionally wraps all relationship fields in t::optionalx(inner), removing the prior special-case for (Operation::Create, Cardinality::One). This is a breaking behavioral change: fields that were once required on create are now optional.

I couldn’t find any tests explicitly assuming required relationships (no matches in tests/), but that absence isn’t proof there are none. Please manually verify:

• Review your integration and unit tests (both in tests/ and src/**/mod.rs or *_test.rs) for any create-mutation scenarios that depended on non-optional relations.
• Confirm generated GraphQL input types still match your schema expectations for create operations.
• Run end-to-end or schema-introspection tests to catch any consumption errors.

File to inspect:

  • src/typegraph/core/src/runtimes/prisma/type_generation/input_type.rs (around lines 145–150)
src/typegraph/core/src/runtimes/prisma/type_generation/out_type.rs (1)

79-95:

❓ Verification inconclusive

Potential type name conflicts without unique suffixes.

Removing the suffix generation means all output types for a model will have the same name regardless of which relationships are included. If the system previously generated multiple type variations with different relationships, this could lead to naming conflicts.

Run the following script to check if the codebase relies on generating multiple type variations:


🏁 Script executed:

#!/bin/bash
# Description: Check for patterns that might indicate reliance on multiple type variations

# Search for places where OutType is instantiated with different skip_rel sets
ast-grep --pattern 'OutType { $$$, skip_rel: $_ }'

# Search for references to output type names with suffixes
rg -A 2 '_output_excluding_' 

Length of output: 81


Confirm skip_rel usage to avoid naming collisions

Our search didn’t find any instantiations of OutType with non-empty skip_rel or any references to the old _excluding_ suffix. However, absence of evidence isn’t evidence of absence. Please manually verify whether anywhere in the Prisma type-generation pipeline multiple OutType values are created with differing skip_rel sets. If they are, you’ll need to restore unique suffix logic to prevent GraphQL type name conflicts.

@Yohe-Am Yohe-Am requested a review from Natoandro May 28, 2025 13:56
@Yohe-Am Yohe-Am merged commit fd66345 into main May 30, 2025
10 of 11 checks passed
@Yohe-Am Yohe-Am deleted the fix/prisma-type-safety-count-tradeoff branch May 30, 2025 08:55
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