Skip to content

feat: use nested list element to handle nullability properly#2086

Merged
Noroth merged 2 commits into
mainfrom
ludwig/eng-7679-protographic-use-nested-list-element-for-single-list
Jul 28, 2025
Merged

feat: use nested list element to handle nullability properly#2086
Noroth merged 2 commits into
mainfrom
ludwig/eng-7679-protographic-use-nested-list-element-for-single-list

Conversation

@Noroth

@Noroth Noroth commented Jul 28, 2025

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • Refactor

    • Updated the structure of list wrapper messages in generated protobuf definitions to consistently use a nested message pattern, where each wrapper now contains an inner message with repeated items and a single field referencing this inner message.
  • Tests

    • Updated test snapshots and assertions to reflect the new nested message structure for list wrappers.
    • Enhanced test coverage to verify field numbers and structure for both outer wrapper messages and their nested inner messages.

Checklist

  • I have discussed my proposed changes in an issue and have received approval to proceed.
  • I have followed the coding standards of the project.
  • Tests or benchmarks have been added or updated.
  • Documentation has been updated on https://github.com/wundergraph/cosmo-docs.
  • I have read the Contributors Guide.

@Noroth Noroth requested a review from StarpTech as a code owner July 28, 2025 07:12
@coderabbitai

coderabbitai Bot commented Jul 28, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

This change refactors the logic for generating list wrapper messages in the SDL-to-Proto conversion process. The buildWrapperMessage method now always generates a nested List message within each wrapper, standardizing the structure for all list nesting levels. Corresponding test snapshots and assertions are updated to reflect this new message structure.

Changes

Cohort / File(s) Change Summary
Wrapper Message Refactor
protographic/src/sdl-to-proto-visitor.ts
Refactored the buildWrapperMessage method to always generate a nested List message inside list wrapper messages, removing conditional branching and unifying the structure for all list nesting levels.
Test Snapshots: Basic and Scalar Types
protographic/tests/sdl-to-proto/01-basic-types.test.ts
protographic/tests/sdl-to-proto/11-lists.test.ts
Updated test snapshots to reflect the new nested List message structure in wrapper messages for scalar, object, enum, interface, union, input, and recursive types, as well as complex and nested lists.
Test Snapshots: Complex Types
protographic/tests/sdl-to-proto/02-complex-types.test.ts
Updated test snapshots for complex types to use the new nested List message structure in all list wrapper messages.
Test Snapshots: Edge Cases
protographic/tests/sdl-to-proto/05-edge-cases.test.ts
Updated test snapshots for edge cases to apply the nested List message structure in all relevant list wrapper messages.
Test Logic: Field Numbering and Structure
protographic/tests/sdl-to-proto/06-field-ordering.test.ts
Enhanced test logic to separately verify field numbers for both the outer wrapper message's list field and the nested List message's items field, reflecting the new message structure.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~15–25 minutes

Possibly related PRs

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 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 c80b2bb and 1fcdbb0.

📒 Files selected for processing (6)
  • protographic/src/sdl-to-proto-visitor.ts (1 hunks)
  • protographic/tests/sdl-to-proto/01-basic-types.test.ts (4 hunks)
  • protographic/tests/sdl-to-proto/02-complex-types.test.ts (3 hunks)
  • protographic/tests/sdl-to-proto/05-edge-cases.test.ts (1 hunks)
  • protographic/tests/sdl-to-proto/06-field-ordering.test.ts (6 hunks)
  • protographic/tests/sdl-to-proto/11-lists.test.ts (16 hunks)
⏰ 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). (1)
  • GitHub Check: Analyze (go)
🔇 Additional comments (25)
protographic/src/sdl-to-proto-visitor.ts (1)

596-612: LGTM! Excellent refactoring to standardize wrapper message structure.

This refactoring simplifies and unifies the wrapper message generation logic by always creating a consistent nested structure with an inner List message. The benefits include:

  • Eliminates conditional logic complexity for different nesting levels
  • Provides a standardized, predictable message structure
  • Improves code maintainability and readability

The new uniform structure where all wrapper messages contain a nested List message with repeated items and an outer list field is much cleaner than the previous conditional approach.

protographic/tests/sdl-to-proto/01-basic-types.test.ts (1)

145-148: LGTM! Test snapshots correctly updated for new wrapper structure.

The test snapshots have been properly updated to reflect the refactored wrapper message structure. All ListOf* messages now consistently use the nested List message pattern with:

  • Inner List message containing repeated items
  • Outer wrapper message containing list field

This provides comprehensive test coverage validating that the implementation change produces the expected protobuf output format across various data types (String, User, Float, Int, Point, TreeNode, etc.).

Also applies to: 252-255, 485-488, 492-495, 520-523, 527-530, 715-718, 722-725

protographic/tests/sdl-to-proto/05-edge-cases.test.ts (1)

369-372: LGTM! Edge case test snapshots properly updated.

The edge case test snapshots have been consistently updated to use the new nested List message structure for ListOfComment, ListOfPost, and ListOfString wrapper messages. This ensures the refactoring works correctly across complex scenarios including:

  • Federation entity types with @key directives
  • Union and interface types
  • Complex schema structures with various GraphQL constructs

The consistent application of the nested structure pattern across all test scenarios validates the comprehensive nature of the implementation change.

Also applies to: 376-379, 383-386

protographic/tests/sdl-to-proto/11-lists.test.ts (16)

69-107: LGTM! Consistent nested list wrapper structure implemented.

The test snapshots correctly reflect the new standardized list wrapper message structure. The nested List message pattern provides consistent nullability handling across all list types.


150-162: LGTM! Proper nested structure for basic list wrappers.

The ListOfString and ListOfUser wrapper messages now consistently use the nested List message pattern, which standardizes nullability handling.


220-231: LGTM! Nested structure maintained for complex list scenarios.

The deeply nested list scenarios correctly implement the standardized wrapper message structure with the inner List message containing the repeated items.


292-303: LGTM! Consistent pattern applied to all list wrapper types.

The changes maintain consistency across different list wrapper scenarios, ensuring uniform nullability handling regardless of the contained type (String, User, etc.).


365-369: LGTM! Enum list wrappers follow the same pattern.

The ListOfStatus wrapper correctly implements the nested structure, demonstrating that the standardization applies to all types including enums.


444-448: LGTM! Interface list wrappers maintain consistency.

The ListOfNode wrapper for interface types follows the same nested structure pattern, ensuring uniform behavior across different GraphQL type categories.


530-534: LGTM! Union list wrappers use standardized structure.

The ListOfSearchResult wrapper for union types correctly implements the nested List message pattern, maintaining consistency across all GraphQL type kinds.


608-648: LGTM! Scalar and custom scalar list wrappers are consistent.

All scalar type list wrappers (ListOfDateTime, ListOfFloat, ListOfInt, ListOfJSON, ListOfString) properly implement the nested structure, ensuring uniform nullability handling for all scalar types.


756-768: LGTM! Deep nesting maintains the standardized pattern.

Even with deeply nested list structures, the wrapper messages consistently use the nested List message pattern, proving the robustness of the new approach.


850-862: LGTM! Input type list wrappers follow the pattern.

The ListOfString and ListOfUpdateUserInput wrappers for input types correctly implement the nested structure, ensuring consistency across output and input type scenarios.


1001-1076: LGTM! Complex mixed scenarios maintain consistency.

The comprehensive test with mixed types (enums, interfaces, unions, nested lists) shows that all wrapper messages consistently use the nested List structure, demonstrating the thoroughness of the refactoring.


1204-1216: LGTM! Edge cases properly handle the new structure.

The edge case scenarios with various nullable combinations correctly implement the nested wrapper pattern, ensuring robust nullability handling in all scenarios.


1304-1343: LGTM! Recursive types work correctly with nested wrappers.

The recursive type scenarios (ListOfCategory, ListOfComment, ListOfUser) properly implement the nested structure, showing that the pattern works well with self-referencing types.


1473-1533: LGTM! Complex input scenarios maintain standardization.

All input type list wrappers in complex scenarios consistently use the nested List message structure, ensuring uniform behavior across simple and complex input type scenarios.


1690-1977: LGTM! Recursive input types handle nesting correctly.

The recursive input type scenarios properly implement the nested wrapper structure, demonstrating that the pattern works effectively with complex recursive input types and deep nesting.


1944-1977: LGTM! Most complex scenarios maintain consistency.

The most complex mixed recursive and non-recursive scenarios with deep nesting all use the standardized nested List message pattern, proving the robustness and consistency of the refactoring approach.

protographic/tests/sdl-to-proto/02-complex-types.test.ts (3)

40-45: LGTM! Enum-related list wrapper uses standardized structure.

The ListOfUser wrapper message correctly implements the nested List message pattern, ensuring consistent nullability handling for enum-related scenarios.


235-240: LGTM! Circular reference list wrapper maintains consistency.

The ListOfTreeNode wrapper for circular/recursive types properly implements the nested structure, demonstrating that the standardization works well with self-referencing types.


311-323: LGTM! Input type list wrappers follow the standardized pattern.

Both ListOfAddressInput and ListOfUser wrapper messages correctly implement the nested List message structure, ensuring consistent nullability handling for input type scenarios.

protographic/tests/sdl-to-proto/06-field-ordering.test.ts (3)

1157-1189: LGTM! Correctly implements nested List structure verification.

The test now properly verifies both the outer wrapper message (with list field) and the nested List message (with items field), aligning with the refactored structure where all list wrappers contain a nested List message.


1228-1256: LGTM! Consistent field preservation verification.

The field number preservation logic correctly verifies both existing wrapper types maintain their field numbers and new wrapper types receive the expected field numbers. The implementation is consistent with the nested structure pattern.


1286-1514: LGTM! Comprehensive nested and mixed wrapper type verification.

This segment excellently handles complex scenarios including:

  • Nested wrapper types (ListOfListOfString, ListOfListOfInt, etc.)
  • Mixed simple and nested wrapper combinations
  • Field number preservation across schema modifications
  • Proper verification of wrapper type removal

The implementation consistently follows the nested structure pattern and provides thorough test coverage for the refactored list wrapper message generation logic.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch ludwig/eng-7679-protographic-use-nested-list-element-for-single-list

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 generate unit tests to generate unit tests for 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.

Comment thread protographic/tests/sdl-to-proto/11-lists.test.ts
Comment thread protographic/src/sdl-to-proto-visitor.ts

@StarpTech StarpTech left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Noroth Noroth merged commit 7445cb5 into main Jul 28, 2025
9 checks passed
@Noroth Noroth deleted the ludwig/eng-7679-protographic-use-nested-list-element-for-single-list branch July 28, 2025 09:37
@Noroth Noroth mentioned this pull request Sep 30, 2025
5 tasks
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