Skip to content

fix(postprocess): merge ParentOnTypeNames when combining sibling object fields#1392

Open
jensneuse wants to merge 2 commits intomasterfrom
jensneuse/investigate-2346
Open

fix(postprocess): merge ParentOnTypeNames when combining sibling object fields#1392
jensneuse wants to merge 2 commits intomasterfrom
jensneuse/investigate-2346

Conversation

@jensneuse
Copy link
Member

@jensneuse jensneuse commented Feb 18, 2026

Summary by CodeRabbit

  • Bug Fixes

    • Improved field merging logic to correctly consolidate parent-type context across interface fragments, ensuring accurate data resolution in complex GraphQL queries.
  • Tests

    • Added regression test for merging concrete types within interface fragments in federation scenarios.
    • Added test coverage for field merging with parent-type context consolidation across multiple nesting levels.

Fixes a bug where deeply nested fields go missing from responses when a named fragment on an interface contains inline fragments for multiple concrete types and the non-matching type's fragment is defined first (cosmo#2346).

Root cause: In merge_fields.go step 4, when merging sibling object fields from different concrete type fragments, ParentOnTypeNames was not merged — only the first-processed type's conditions were kept. At resolve time, skipFieldOnParentTypeNames then silently dropped the field for all other types.

Fix: Extract the ParentOnTypeNames merge logic (already present for scalars in step 5) into a shared mergeParentOnTypeNames method and call it in step 4 after mergeValues.

Tests added:

  • 2 post-processor unit tests (merge_fields_test.go) confirming order-independent ParentOnTypeNames merging
  • End-to-end federation integration test reproducing the exact query pattern from the issue, including new ProductA/ProductB/Base types in the accounts subgraph

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.

…ct fields

When merging sibling object fields from different concrete type inline
fragments (step 4 of merge_fields.go), ParentOnTypeNames was not merged —
only the first type's conditions were kept, causing the field to be
silently skipped at resolve time for all other types.

Fix: extract ParentOnTypeNames merge logic into mergeParentOnTypeNames and
call it in step 4 after mergeValues, mirroring what step 5 already does
for scalar fields.

Fixes wundergraph/cosmo#2346

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 18, 2026

No actionable comments were generated in the recent review. 🎉


📝 Walkthrough

Walkthrough

This PR adds a regression test for merging concrete types in root field and interface fragments. It introduces GraphQL schema definitions, Go model types, resolvers, and test queries to replicate the scenario, while enhancing the engine's field merging logic to properly propagate and merge ParentOnTypeNames during sibling field deduplication.

Changes

Cohort / File(s) Summary
Federation Test Setup
execution/federationtesting/accounts/graph/model/models_gen.go, execution/federationtesting/accounts/graph/schema.graphqls, execution/federationtesting/accounts/graph/schema.resolvers.go
Introduces Base interface and Category, Owner, ProductA, ProductB types in GraphQL schema and Go models with corresponding resolver returning concrete test data.
Test Files
execution/engine/federation_integration_test.go, execution/federationtesting/testdata/queries/merge_concrete_type_in_root_field_and_interface_fragment.graphql
Adds regression test case and GraphQL query that exercises merging concrete types (ProductA/ProductB) through interface fragments on the Base interface.
Engine Field Merging Logic
v2/pkg/engine/postprocess/merge_fields.go
Introduces ParentOnTypeNames propagation during sibling field merging via a new helper method, ensuring depth-aware type-name consolidation when deduplicating fields.
Engine Tests
v2/pkg/engine/postprocess/merge_fields_test.go
Adds regression test cases verifying that ParentOnTypeNames from multiple concrete type fragments are correctly merged and included in the result.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix(postprocess): merge ParentOnTypeNames when combining sibling object fields' accurately and specifically describes the main code change—fixing a bug in merge_fields.go by merging ParentOnTypeNames during field combination.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch jensneuse/investigate-2346

Comment @coderabbitai help to get the list of available commands and usage tips.

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.

1 participant