Skip to content

Conversation

@devsergiy
Copy link
Member

@devsergiy devsergiy commented Aug 7, 2025

Summary by CodeRabbit

  • Bug Fixes

    • Improved handling of interface objects in federated graph schemas to ensure correct expansion into their concrete types.
  • Tests

    • Added a new test case to verify correct rewriting of queries involving interface objects and their concrete implementations.

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.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 7, 2025

Walkthrough

The changes update the logic for resolving allowed interface member type names in a federated GraphQL schema, ensuring interface objects are expanded into their concrete types based on federation configuration. Additionally, a new test case is introduced to verify this behavior, covering scenarios involving interface objects and their concrete implementations.

Changes

Cohort / File(s) Change Summary
Interface member type resolution logic
v2/pkg/engine/plan/abstract_selection_rewriter_helpers.go
Enhanced logic in getAllowedInterfaceMemberTypeNames to expand interface objects into their concrete types using federation config, deduplicate, and sort results. Minor comment improvements for clarity.
Test coverage for interface object expansion
v2/pkg/engine/plan/abstract_selection_rewriter_test.go
Added a test case to TestInterfaceSelectionRewriter_RewriteOperation to validate correct expansion of interface objects into concrete types during rewriting, using a schema with interfaces, interface objects, and concrete types.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

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 a490fad and 77d4424.

📒 Files selected for processing (2)
  • v2/pkg/engine/plan/abstract_selection_rewriter_helpers.go (2 hunks)
  • v2/pkg/engine/plan/abstract_selection_rewriter_test.go (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: in the graphql-go-tools grpc datasource, only non-null lists use protobuf's repeated field syntax di...
Learnt from: Noroth
PR: wundergraph/graphql-go-tools#1246
File: v2/pkg/engine/datasource/grpc_datasource/execution_plan_visitor.go:457-457
Timestamp: 2025-07-28T12:44:56.405Z
Learning: In the graphql-go-tools gRPC datasource, only non-null lists use protobuf's repeated field syntax directly. For nullable or nested lists, wrapper types are used because protobuf repeated fields cannot be nullable. The TypeIsNonNullList check ensures only appropriate list types are marked as repeated in the protobuf message structure.

Applied to files:

  • v2/pkg/engine/plan/abstract_selection_rewriter_helpers.go
⏰ 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). (4)
  • GitHub Check: Build and test (go 1.23 / windows-latest)
  • GitHub Check: Build and test (go 1.23 / windows-latest)
  • GitHub Check: Build and test (go 1.23 / ubuntu-latest)
  • GitHub Check: Build and test (go 1.23 / ubuntu-latest)
🔇 Additional comments (4)
v2/pkg/engine/plan/abstract_selection_rewriter_helpers.go (3)

547-556: LGTM - Comment improvements

Good grammatical fixes in the comments, particularly fixing "if it is doesn't" to "if it doesn't" on line 554.


563-594: LGTM - Well-implemented interface object expansion

The logic correctly handles interface objects by:

  1. Collecting implementing types from the upstream schema
  2. Checking if each type is configured as an interface object in the federation configuration
  3. Expanding interface objects into their concrete types while preserving non-interface-object types
  4. Properly sorting and deduplicating the final result with slices.Compact()

The implementation is clear, well-commented, and aligns with the PR objective to fix interface object rewriting.


537-605: Well-structured enhancement with clear logic flow

The function enhancement maintains backward compatibility while adding interface object support. The logic flow is clear and error handling is consistent.

Minor performance note: The nested loop for interface object lookup (lines 575-581) has O(n*m) complexity. For typical schema sizes this is fine, but could be optimized with a map lookup if needed in the future.

v2/pkg/engine/plan/abstract_selection_rewriter_test.go (1)

3730-3816: Excellent test case for interface object rewriting

This test case effectively validates the core functionality with:

Comprehensive setup: Properly defines the schema with Named interface, Account interface object, and concrete types
Realistic scenario: Tests nested fragments where an interface object contains concrete type fragments
Correct configuration: Interface object metadata properly maps Account to Admin and User concrete types
Expected behavior: The rewritten operation correctly expands the Account interface object into separate Admin and User fragments
Proper assertions: Expects shouldRewrite: true and validates the complete transformation

The test directly exercises the enhanced getAllowedInterfaceMemberTypeNames logic and confirms interface objects are properly expanded during rewriting.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch sergiy/eng-7751-fix-rewriting-abstract-selection-for-interface-object

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

@devsergiy devsergiy merged commit 8c8c9de into master Aug 7, 2025
9 checks passed
@devsergiy devsergiy deleted the sergiy/eng-7751-fix-rewriting-abstract-selection-for-interface-object branch August 7, 2025 15:02
devsergiy pushed a commit that referenced this pull request Aug 7, 2025
🤖 I have created a release *beep* *boop*
---


##
[2.0.0-rc.218](v2.0.0-rc.217...v2.0.0-rc.218)
(2025-08-07)


### Bug Fixes

* fix rewriting an interface object implementing interface
([#1265](#1265))
([8c8c9de](8c8c9de))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **Bug Fixes**
* Resolved an issue where an interface object that implements another
interface was incorrectly rewritten.

* **Documentation**
* Added a changelog entry for version 2.0.0-rc.218 documenting the above
bug fix.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
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