Skip to content

fix: allow multiple aliases#1231

Merged
Noroth merged 1 commit intomasterfrom
ludwig/eng-7597-allow-multiple-aliased-fields
Jul 15, 2025
Merged

fix: allow multiple aliases#1231
Noroth merged 1 commit intomasterfrom
ludwig/eng-7597-allow-multiple-aliased-fields

Conversation

@Noroth
Copy link
Copy Markdown
Contributor

@Noroth Noroth commented Jul 14, 2025

Summary by CodeRabbit

  • New Features

    • Improved support for multiple aliases of the same field in GraphQL queries, ensuring correct handling in nested objects, interface fragments, and union fragments.
  • Bug Fixes

    • Enhanced field uniqueness and existence checks to account for both field names and aliases, preventing duplicate or missing fields when aliases are used.
  • Tests

    • Added comprehensive test cases to verify correct alias handling in various complex query scenarios.

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

coderabbitai Bot commented Jul 14, 2025

Walkthrough

This change refines alias handling for fields in the gRPC datasource execution plan. It updates deduplication and existence checks to consider both field names and aliases, modifies related method signatures, and extends test coverage to validate multiple alias scenarios in queries, including nested, interface, and union contexts.

Changes

Files/Paths Change Summary
v2/pkg/engine/datasource/grpc_datasource/execution_plan.go Changed field deduplication and existence logic to use both name and alias; updated Exists method signature.
v2/pkg/engine/datasource/grpc_datasource/execution_plan_visitor.go Updated duplicate field checks and RPCField construction to consider both field name and alias.
v2/pkg/engine/datasource/grpc_datasource/execution_plan_test.go Added multiple test cases to cover execution plan generation with multiple aliases in various query scenarios.
v2/pkg/engine/datasource/grpc_datasource/grpc_datasource_test.go Added and modified tests to validate correct alias handling in loading data, including nested and fragment cases.

Possibly related PRs

  • feat: add support for aliases #1209: Modifies field alias handling in the grpc_datasource package, including changes to RPCField, execution plan logic, visitor code, and tests, directly related to implementing alias support.

📜 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 9b917c6 and dfdf337.

📒 Files selected for processing (4)
  • v2/pkg/engine/datasource/grpc_datasource/execution_plan.go (2 hunks)
  • v2/pkg/engine/datasource/grpc_datasource/execution_plan_test.go (1 hunks)
  • v2/pkg/engine/datasource/grpc_datasource/execution_plan_visitor.go (2 hunks)
  • v2/pkg/engine/datasource/grpc_datasource/grpc_datasource_test.go (2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (3)
v2/pkg/engine/datasource/grpc_datasource/execution_plan_visitor.go (1)
pkg/ast/ast_field_alias.go (1)
  • Alias (8-12)
v2/pkg/engine/datasource/grpc_datasource/execution_plan.go (1)
pkg/ast/ast_field_alias.go (1)
  • Alias (8-12)
v2/pkg/engine/datasource/grpc_datasource/execution_plan_test.go (1)
v2/pkg/engine/datasource/grpc_datasource/execution_plan.go (9)
  • RPCExecutionPlan (49-54)
  • RPCCall (58-71)
  • RPCMessage (75-89)
  • RPCFields (209-209)
  • RPCField (150-174)
  • OneOfType (21-21)
  • OneOfTypeInterface (28-28)
  • RPCFieldSelectionSet (112-112)
  • OneOfTypeUnion (30-30)
🔇 Additional comments (16)
v2/pkg/engine/datasource/grpc_datasource/execution_plan_visitor.go (2)

314-317: LGTM! Proper alias-aware duplicate field detection.

The changes correctly implement alias-aware duplicate field detection by:

  1. Extracting the field alias using FieldAliasString()
  2. Checking existence using both field name and alias
  3. Preventing duplicates only when both name and alias match

This allows multiple aliases of the same field (e.g., field1: someField, field2: someField) to coexist while preventing exact duplicates.


337-337: LGTM! Alias information properly stored in field.

The alias is correctly stored in the RPCField struct, ensuring that alias information is preserved throughout the execution plan construction.

v2/pkg/engine/datasource/grpc_datasource/execution_plan.go (2)

135-141: LGTM! Intelligent alias-aware field deduplication.

The change from using field.Name to field.AliasOrPath() for deduplication is well-designed:

  • Fields with aliases are deduplicated by their alias
  • Fields without aliases are deduplicated by their JSONPath
  • This allows multiple aliases of the same field to coexist correctly

The AliasOrPath() method provides a clean abstraction for this logic.


223-231: LGTM! Consistent alias-aware existence checking.

The updated Exists method signature and logic properly support alias handling:

  • Method now accepts both name and alias parameters
  • Checks both field name and alias for exact matches
  • Prevents duplicates only when both name and alias match exactly
  • Maintains backward compatibility for fields without aliases

This change aligns perfectly with the caller's expectations in the visitor file.

v2/pkg/engine/datasource/grpc_datasource/execution_plan_test.go (5)

3110-3163: LGTM: Comprehensive test for multiple aliases on the same field

This test case effectively validates that multiple aliases for the same field (name aliased as name1, name2, name3) are correctly handled in the execution plan by creating separate RPCField entries with appropriate alias assignments.


3164-3295: LGTM: Well-structured test for multiple aliases with different arguments

This test case properly validates that fields with the same name but different arguments create separate RPC calls, and that aliases are correctly applied to each call. The test covers an important edge case where user(id: "123") is called twice with different aliases (user1 and sameUser), ensuring proper deduplication handling.


3296-3397: LGTM: Thorough test for nested object aliases

This test case comprehensively validates multiple aliases at different nesting levels within nested objects. The expected execution plan correctly shows aliases applied at each level (name1/name2 at root, title1/title2 at level B, label1/label2 at level C), demonstrating proper recursive handling of aliases in nested structures.


3398-3484: LGTM: Excellent coverage for interface fragment aliases

This test case effectively validates alias handling in interface fragments, covering both common fields (name1, name2) and fragment-specific fields (volume1, volume2 for both Cat and Dog fragments). The expected execution plan correctly separates aliases in both the common fields and the fragment-specific selection sets.


3485-3604: LGTM: Comprehensive test for union fragment aliases

This test case provides thorough coverage of alias handling in union fragments, testing multiple aliases across different union member types (Product, User, Category). The expected execution plan correctly shows aliases applied within each union fragment's field selection set, ensuring proper handling of union-specific field aliases.

v2/pkg/engine/datasource/grpc_datasource/grpc_datasource_test.go (7)

1320-1341: LGTM: Enhanced test case properly validates multiple aliases functionality.

The modification to use multiple aliases (userId1, userId2, userName1, userName2) and the corresponding validation logic correctly ensures that:

  • All aliases for the same field return identical values
  • Original field names are not present when aliases are used
  • The test validates the core functionality of multiple aliases support

1494-1517: LGTM: Comprehensive test case for basic multiple aliases scenario.

This test case properly validates that multiple aliases (name1, name2, name3) for the same field return identical values and that the original field name is not present in the response. The test structure is clear and follows established patterns.


1518-1550: LGTM: Well-structured test for multiple aliases with arguments.

This test case effectively validates that multiple aliases work correctly with parameterized queries, ensuring that:

  • Different user IDs return different data
  • Same user ID with different alias names return identical data
  • The validation logic properly checks for expected values

1551-1588: LGTM: Thorough test coverage for nested object aliases.

This test case comprehensively validates multiple aliases behavior in nested GraphQL objects, ensuring the functionality works correctly at multiple levels of nesting. The validation properly checks that aliases return identical values across all nesting levels.


1589-1619: LGTM: Excellent coverage for interface fragment aliases.

This test case properly validates multiple aliases within interface fragments, ensuring that type-specific aliases work correctly for both Cat and Dog types while maintaining the interface contract. The validation logic correctly handles the conditional presence of type-specific fields.


1620-1659: LGTM: Comprehensive test for identical function calls with multiple aliases.

This test case effectively validates that multiple aliases work correctly when the same function is called with identical arguments, ensuring that:

  • Both function calls return the same underlying data
  • Aliases within each call return identical values
  • The response structure is consistent across different alias naming strategies

1660-1696: LGTM: Thorough test coverage for union fragment aliases.

This test case comprehensively validates multiple aliases within union fragments, ensuring that type-specific aliases work correctly across different union members (Product, User, Category). The validation logic properly handles the conditional presence of type-specific fields and ensures aliases return identical values.

✨ Finishing Touches
  • 📝 Generate Docstrings

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.

@Noroth Noroth merged commit 01d91e2 into master Jul 15, 2025
11 checks passed
@Noroth Noroth deleted the ludwig/eng-7597-allow-multiple-aliased-fields branch July 15, 2025 08:09
Noroth pushed a commit that referenced this pull request Jul 15, 2025
🤖 I have created a release *beep* *boop*
---


##
[2.0.0-rc.206](v2.0.0-rc.205...v2.0.0-rc.206)
(2025-07-15)


### Bug Fixes

* allow multiple aliases
([#1231](#1231))
([01d91e2](01d91e2))

---
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 to enable support for multiple aliases.

* **Documentation**
* Added a changelog entry for version 2.0.0-rc.206, detailing the latest
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