Skip to content

fix: interface object implementing entity interface#2117

Merged
Aenimus merged 3 commits intomainfrom
david/eng-7749-fix-interface-object-implementing-entity-interface
Aug 6, 2025
Merged

fix: interface object implementing entity interface#2117
Aenimus merged 3 commits intomainfrom
david/eng-7749-fix-interface-object-implementing-entity-interface

Conversation

@Aenimus
Copy link
Copy Markdown
Member

@Aenimus Aenimus commented Aug 6, 2025

Summary by CodeRabbit

  • New Features

    • Expanded test coverage for @interfaceObject directives, including scenarios involving interface inheritance, field propagation, and shareability constraints.
  • Bug Fixes

    • Corrected error message pluralization for entities in error reporting.
  • Refactor

    • Improved type safety and clarity by introducing and applying domain-specific type aliases throughout the codebase.
    • Enhanced error reporting by updating function signatures and error message construction.
    • Refined federation and normalization logic for clearer handling of interface implementations and field shareability.
  • Tests

    • Added comprehensive tests for interface object behaviors, field propagation, and shareability.
    • Updated test schemas to include @shareable directives where appropriate.
    • Improved test utility functions to provide detailed error logging on failure.

Checklist

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Aug 6, 2025

Walkthrough

The changes introduce new type aliases for key domain concepts and systematically replace plain string types with these aliases across the codebase to enhance type safety and clarity. Several functions and data structures are updated to use these types. Additional logic ensures correct handling of interface objects and shareability in federation, and new tests are added to validate interface object behaviors and error scenarios. Minor fixes and enhancements are applied to error messages and test schemas.

Changes

Cohort / File(s) Change Summary
Type Aliases Introduction
composition/src/types/types.ts
Adds type aliases: FieldName, FieldCoords, SubgraphName, TypeName, NodeType (all as string) to provide semantic clarity and improve type safety.
Type Usage Updates
composition/src/schema-building/types.ts, composition/src/schema-building/utils.ts, composition/src/v1/federation/federation-factory.ts
Replaces generic string types with new type aliases in type definitions, function signatures, and variable declarations for fields, subgraph names, and type names. Updates logic in federation factory for clarity, type safety, and correct copying of shareability flags.
Error Handling Enhancements
composition/src/errors/errors.ts
Updates function signatures and internal logic to use new type aliases for error reporting, and corrects pluralization in error messages.
Interface Object Handling
composition/src/v1/normalization/normalization-factory.ts
Adds logic to skip adding concrete type names for implemented interfaces if the @interfaceObject directive is present, and exports the INTERFACE_OBJECT constant.
Testing: Interface Object Coverage
composition/tests/v1/directives/interface-object.test.ts
Adds comprehensive tests for interface objects, including field propagation, shareability, and error scenarios. Introduces new subgraph definitions for various test cases.
Testing: Shareability Annotation Updates
composition/tests/v1/entity-interface.test.ts, composition/tests/v1/resolvability.test.ts
Updates test subgraph schemas to add @shareable directives to relevant fields, ensuring correct testing of shareability logic.
Testing: Error Logging Utility
composition/tests/utils/utils.ts
Enhances the federation result assertion utility to log errors with full inspection if federation fails, aiding test debugging.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~40 minutes

  • Complexity: High, due to the introduction and propagation of new type aliases across core logic, updates to federation and normalization behavior, and the addition of comprehensive new test scenarios.
  • Estimated time: Reviewers will need to validate type changes, check for correctness in federation logic, and ensure new and updated tests cover intended behaviors.

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 e21a009 and 365c58d.

📒 Files selected for processing (1)
  • composition/tests/v1/directives/interface-object.test.ts (3 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). (13)
  • GitHub Check: build_push_image (nonroot)
  • GitHub Check: build_push_image
  • GitHub Check: image_scan
  • GitHub Check: integration_test (./telemetry)
  • GitHub Check: integration_test (./events)
  • GitHub Check: build_test
  • GitHub Check: integration_test (./. ./fuzzquery ./lifecycle ./modules)
  • GitHub Check: build_test
  • GitHub Check: build_push_image
  • GitHub Check: build_test
  • GitHub Check: build_push_image
  • GitHub Check: build_test
  • GitHub Check: Analyze (go)
🔇 Additional comments (8)
composition/tests/v1/directives/interface-object.test.ts (8)

4-16: LGTM - Well-organized imports for new functionality.

The new imports are appropriately added to support the enhanced test scenarios for interface object implementations. All imported types and functions are utilized in the new test cases.


534-571: Comprehensive test for Interface Object implementing entity Interface.

This test effectively validates that an Interface Object can implement another entity Interface, producing the correct federated schema with proper interface inheritance relationships. The assertion checks all the expected types and their interface implementations.


573-591: Solid negative test for field propagation restrictions.

This test correctly validates that Interface Objects cannot propagate fields to other entity Interfaces, expecting the appropriate invalidInterfaceImplementationError with unimplemented fields. The error assertion structure is comprehensive and type-safe.


593-636: Thorough test for @Shareable validation errors.

This test comprehensively validates that propagating Interface Object fields through multiple Interface Objects without proper @shareable annotations triggers the expected shareability errors. The detailed error assertions with field data maps and subgraph tracking demonstrate robust error handling.


638-677: Excellent test for successful @Shareable field propagation.

This test validates the positive scenario where @shareable Interface Object fields can be successfully propagated through multiple Interface Objects. The expected federated schema correctly shows all entities and interfaces with the propagated name field.


809-837: Well-structured base subgraph for interface inheritance.

The fca subgraph provides a solid foundation for testing interface inheritance scenarios with proper GraphQL syntax and logical type relationships.


839-856: Appropriate subgraph for interface object testing.

The fcb subgraph correctly demonstrates the use of @interfaceObject directive and field extension scenarios. The schema structure supports the interface inheritance test cases.


858-900: Excellent subgraph pairs for shareability testing.

The remaining subgraphs (fcc, fcd, fce, fcf) are strategically designed as pairs to test shareability scenarios. The identical structures with and without @shareable annotations provide clear isolation for testing shareability validation 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 david/eng-7749-fix-interface-object-implementing-entity-interface

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.
  • 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.

Support

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

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.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Aug 6, 2025

Router image scan passed

✅ No security vulnerabilities found in image:

ghcr.io/wundergraph/cosmo/router:sha-7fdff6de45f2d9a668b24ce83e5583fb36ec97cc

Copy link
Copy Markdown
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

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between b1fbfea and e21a009.

📒 Files selected for processing (10)
  • composition/src/errors/errors.ts (4 hunks)
  • composition/src/schema-building/types.ts (4 hunks)
  • composition/src/schema-building/utils.ts (2 hunks)
  • composition/src/types/types.ts (1 hunks)
  • composition/src/v1/federation/federation-factory.ts (8 hunks)
  • composition/src/v1/normalization/normalization-factory.ts (2 hunks)
  • composition/tests/utils/utils.ts (2 hunks)
  • composition/tests/v1/directives/interface-object.test.ts (3 hunks)
  • composition/tests/v1/entity-interface.test.ts (1 hunks)
  • composition/tests/v1/resolvability.test.ts (1 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). (15)
  • GitHub Check: build_push_image
  • GitHub Check: build_test
  • GitHub Check: integration_test (./events)
  • GitHub Check: image_scan (nonroot)
  • GitHub Check: image_scan
  • GitHub Check: integration_test (./telemetry)
  • GitHub Check: build_test
  • GitHub Check: integration_test (./. ./fuzzquery ./lifecycle ./modules)
  • GitHub Check: build_push_image
  • GitHub Check: build_push_image
  • GitHub Check: build_push_image (nonroot)
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: build_test
  • GitHub Check: build_test
  • GitHub Check: Analyze (go)
🔇 Additional comments (28)
composition/src/types/types.ts (1)

3-11: LGTM! Excellent type safety enhancement.

The introduction of semantic type aliases (FieldName, FieldCoords, SubgraphName, TypeName, NodeType) is a great improvement over generic string types. This enhances:

  • Code readability and self-documentation
  • Type safety by preventing accidental mixing of different string contexts
  • Future maintainability and refactoring capabilities

The aliases are appropriately simple and will provide clear semantic meaning throughout the codebase.

composition/tests/v1/entity-interface.test.ts (1)

366-367: LGTM! Test schema correctly updated for shareability validation.

The addition of @shareable directives to the name and age fields in the subgraphD interface object aligns with the broader enhancements to interface object shareability handling. This test schema change supports proper validation of field propagation rules in interface types.

composition/tests/v1/resolvability.test.ts (1)

2179-2179: LGTM! Consistent test schema update for shareability validation.

The addition of @shareable to the age field in subgraphAW is consistent with similar updates across test files to support enhanced interface object shareability validation.

composition/tests/utils/utils.ts (1)

65-69: Excellent debugging enhancement!

Adding detailed error logging before the success assertion will greatly help with troubleshooting when federation unexpectedly fails in tests. Using console.dir with depth: null ensures full object inspection, providing comprehensive debugging information.

composition/src/schema-building/utils.ts (1)

576-576: LGTM! Consistent type safety improvement.

The refinement from Array<string> to Array<SubgraphName> aligns with the broader effort to replace generic string types with semantic type aliases. This enhances type safety and code clarity while maintaining the same functionality.

composition/src/schema-building/types.ts (4)

28-28: LGTM! Enhanced type safety with semantic aliases.

Adding imports for FieldName and SubgraphName type aliases improves type clarity and safety over generic strings.


105-105: LGTM! Improved type safety for subgraph name keys.

Replacing generic string with SubgraphName for map keys provides better semantic meaning and type safety.


114-114: LGTM! Consistent typing for subgraph names.

Using Set<SubgraphName> instead of Set<string> maintains consistency with the enhanced typing approach.


176-176: LGTM! Enhanced field name typing.

Replacing generic string with FieldName for map keys provides better semantic clarity and type safety for field references.

composition/src/errors/errors.ts (4)

33-33: LGTM! Enhanced type safety for error handling.

Adding imports for NodeType and TypeName semantic types improves type clarity in error message generation.


428-430: LGTM! Improved function signature with semantic types.

Replacing generic string parameters with TypeName and NodeType provides better type safety and semantic meaning for error generation.


490-490: LGTM! Consistent usage of semantic type parameter.

Using the parentNodeType parameter directly in the error message maintains consistency with the enhanced typing approach.


860-861: LGTM! Fixed pluralization in error message.

The correction from "entit" + conditional "ies"/"y" to proper pluralization improves error message readability.

composition/src/v1/normalization/normalization-factory.ts (2)

292-292: LGTM!

The import addition is necessary for the conditional checks implemented in the method below.


1271-1273: Correctly implements interface object handling logic.

The conditional checks appropriately prevent treating interface objects as concrete implementations of interfaces. This is crucial for proper federation behavior since interface objects with the @interfaceObject directive represent interfaces in subgraphs that don't actually implement them as concrete types.

The logic is consistently applied in both the existing parent data update path and the new parent data creation path, ensuring uniform behavior.

Also applies to: 1277-1279

composition/tests/v1/directives/interface-object.test.ts (6)

4-10: Imports look appropriate for the new test scenarios.

The new type imports and error handling functions align well with the interface object implementation and shareability tests being added.

Also applies to: 15-15


534-571: Test correctly validates interface object implementing entity interface.

The test appropriately verifies that interface objects can implement entity interfaces and the resulting federated schema correctly reflects the interface hierarchy.


573-591: Test properly validates field propagation constraints.

The test correctly verifies that interface objects cannot propagate fields to entity interfaces, producing the expected invalid interface implementation error.


594-636: Test assertions correctly validate shareability errors.

The test properly checks for shareability errors on both EntityB and EntityC when non-shareable fields are propagated through multiple interface objects.


638-677: Test correctly validates @Shareable field propagation.

The test appropriately verifies that fields marked with @Shareable can be successfully propagated through multiple interface objects, with the federated schema correctly reflecting this propagation.


809-900: Test data subgraphs are well-structured for interface object scenarios.

The new subgraph definitions (fca through fcf) appropriately model various interface inheritance, extension, and field propagation scenarios needed for the test cases.

composition/src/v1/federation/federation-factory.ts (7)

233-233: LGTM! Good use of semantic type aliases.

The introduction of ContractName, FieldCoords, and TypeName type aliases improves type safety and code clarity throughout the file.


247-247: Type safety improvement.

Good refactoring to use TypeName and FieldCoords types instead of generic strings, making the Map's purpose clearer.


427-431: Good defensive programming practice.

The change from getOrThrowError to .get() with a guard clause properly handles the case where configuration data might be absent when all fields are overridden. The explanatory comment is helpful.


1576-1581: Clear variable naming improvement.

Renaming entityInterface to entityInterfaceFederationData better reflects the variable's content and improves code readability.


1606-1608: Proper type conversion for entity interface concrete type names.

Creating a new Set<TypeName> ensures type safety when assigning concrete type names to the configuration.


1651-1686: Excellent implementation of interface object field handling.

The changes properly handle:

  1. Direct iteration over subgraph parent definition field data instead of set operations
  2. Type-safe field coordinates mapping using FieldCoords type
  3. Proper propagation of shareability flags from subgraph field data (replacing the previous TODO)
  4. Correct handling of field data copying with inaccessibility checks

This implementation is cleaner and more maintainable than the previous approach.


3063-3063: Minor style improvement.

Simplified array instantiation without explicit type annotation - TypeScript correctly infers the type.

Comment thread composition/tests/v1/directives/interface-object.test.ts Outdated
@wilsonrivera
Copy link
Copy Markdown
Contributor

LGTM

@Aenimus Aenimus merged commit e999a8c into main Aug 6, 2025
34 checks passed
@Aenimus Aenimus deleted the david/eng-7749-fix-interface-object-implementing-entity-interface branch August 6, 2025 21:27
@Noroth Noroth mentioned this pull request Sep 30, 2025
5 tasks
@coderabbitai coderabbitai Bot mentioned this pull request Mar 6, 2026
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.

3 participants