Skip to content

feat(composition): support @provides on fields returning a Union type#3026

Merged
Aenimus merged 5 commits into
mainfrom
david/eng-5628-support-provides-on-union
Jul 2, 2026
Merged

feat(composition): support @provides on fields returning a Union type#3026
Aenimus merged 5 commits into
mainfrom
david/eng-5628-support-provides-on-union

Conversation

@Aenimus

@Aenimus Aenimus commented Jun 27, 2026

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • Bug Fixes
    • Improved @provides validation by returning Error objects with more precise messaging for incompatible types and invalid inline-fragment type conditions.
    • Broadened accepted @provides parent type scenarios, including union-returning fields, while still enforcing incompatible base-scalar cases.
  • New Features
    • Added a warning for @provides on union-returning fields when router support may be limited.
  • Tests
    • Expanded federation tests for union-related @provides, including invalid @external, unknown/invalid inline fragment conditions, and non-member union fragment cases.

Checklist

Open Source AI Manifesto

This project follows the principles of the Open Source AI Manifesto. Please ensure your contribution aligns with its principles.

@Aenimus Aenimus requested a review from a team as a code owner June 27, 2026 00:49
@coderabbitai

coderabbitai Bot commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a67095ff-9d23-40d3-91ae-004fe0c71233

📥 Commits

Reviewing files that changed from the base of the PR and between 5c422ce and 6e66340.

📒 Files selected for processing (1)
  • composition/src/v1/warnings/warnings.ts
💤 Files with no reviewable changes (1)
  • composition/src/v1/warnings/warnings.ts

Walkthrough

This PR adds union support to @provides validation, introduces shared parent/result helpers, adds a union warning path, and expands normalization and federation test coverage.

Changes

Provides validation update

Layer / File(s) Summary
Provides contracts and helpers
composition/src/utils/string-constants.ts, composition/src/schema-building/types/types.ts, composition/src/ast/utils.ts, composition/src/errors/errors.ts, composition/src/v1/normalization/types/results.ts, composition/src/v1/normalization/types/types.ts, composition/src/v1/utils/utils.ts, composition/src/v1/warnings/params.ts, composition/src/v1/warnings/warnings.ts
VALID_PROVIDES_PARENT_KINDS, ValidProvidesParentData, isValidProvidesParentData, the @provides error helper, union parent result types, the union type guard, and the union warning helper are added or renamed.
Normalization parent resolution
composition/src/v1/normalization/types/params.ts, composition/src/v1/normalization/normalization-factory.ts
getFieldSetParent() now returns a { success, data, error } result, accepts the new parameter object, and routes union-capable @provides parents through the updated validation flow.
Provides directive tests
composition/tests/v1/directives/provides.test.ts, composition/tests/v1/directives/fieldset-directives.test.ts
Tests switch to the new error helper and inline-fragment message builder, update constant-based type-name expectations, and add union-returning @provides cases for success and fragment/type-condition failures.

Estimated code review effort: 4 (Complex) | ~45 minutes

Possibly related PRs

  • wundergraph/cosmo#2348: Touches the same composition/src/errors/errors.ts @provides incompatibility helper that this PR renames and changes to return an Error.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and accurately summarizes the main change: composition support for @provides on Union-returning fields.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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

@codecov

codecov Bot commented Jun 27, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 73.52941% with 45 lines in your changes missing coverage. Please review.
✅ Project coverage is 43.34%. Comparing base (285ab20) to head (6e66340).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
composition/src/errors/errors.ts 57.14% 24 Missing ⚠️
...tion/src/v1/normalization/normalization-factory.ts 77.38% 19 Missing ⚠️
composition/src/v1/utils/utils.ts 66.66% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main    #3026       +/-   ##
===========================================
- Coverage   61.44%   43.34%   -18.10%     
===========================================
  Files         259      867      +608     
  Lines       30137   125298    +95161     
  Branches        0    10192    +10192     
===========================================
+ Hits        18517    54312    +35795     
- Misses      10131    70640    +60509     
+ Partials     1489      346     -1143     
Files with missing lines Coverage Δ
composition/src/ast/utils.ts 87.92% <100.00%> (ø)
composition/src/schema-building/types/types.ts 100.00% <ø> (ø)
composition/src/utils/string-constants.ts 100.00% <100.00%> (ø)
composition/src/v1/normalization/types/params.ts 100.00% <100.00%> (ø)
composition/src/v1/normalization/types/results.ts 100.00% <ø> (ø)
composition/src/v1/warnings/params.ts 100.00% <ø> (ø)
composition/src/v1/warnings/warnings.ts 89.47% <100.00%> (ø)
composition/src/v1/utils/utils.ts 81.28% <66.66%> (ø)
...tion/src/v1/normalization/normalization-factory.ts 90.59% <77.38%> (ø)
composition/src/errors/errors.ts 81.55% <57.14%> (ø)

... and 1116 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
composition/src/v1/normalization/normalization-factory.ts (1)

2061-2122: 🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift

Validate inline fragments by possible-type overlap

composition/src/v1/normalization/normalization-factory.ts:2061-2122

The kind-based checks here miss GraphQL’s overlap rule: interface fragments on a union parent are rejected even when they share concrete members, and union type conditions are accepted unconditionally even when they are disjoint. Replace the shortcut logic with a possible-type intersection check for the parent and fragment type condition.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@composition/src/v1/normalization/normalization-factory.ts` around lines 2061
- 2122, The inline fragment validation in normalization-factory is using
kind-specific shortcuts instead of GraphQL possible-type overlap, so update the
logic around the fragmentNamedTypeData switch to compare the parent and
typeCondition by intersecting their possible concrete types. In the fragment
handling path near the existing parentDatas/shouldDefineSelectionSet flow, keep
the existing error helpers but replace the interface/union/object acceptance
rules with a shared overlap check for parentData and fragmentNamedTypeData, and
only allow the fragment when their possible types intersect; otherwise fall
through to invalidInlineFragmentTypeConditionErrorMessage.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@composition/src/errors/errors.ts`:
- Around line 779-781: Update the incompatible `@provides` error message in the
error helper that builds the response-type validation error so it includes Union
as a valid kind alongside Object and Interface, matching the new
VALID_PROVIDES_PARENT_KINDS behavior. While touching that return in errors.ts,
collapse the message construction into a single template literal instead of
concatenating strings, keeping the same fieldCoords, subgraphName, and
responseType placeholders.

In `@composition/tests/v1/directives/provides.test.ts`:
- Around line 1242-1268: The union-returning `@provides` tests only verify that
warnings are empty, so they do not prove the directive is preserved in the
composed result. Update the relevant tests around the
createSubgraph/federateSubgraphsSuccess flow to assert the composed output for
the union parent path, especially subgraphConfigBySubgraphName and the
conditional-field data produced for the `@provides` selection. Keep the existing
no-warning check, but add assertions that the composed config still contains the
union-field `@provides` behavior for the valid union cases.

---

Outside diff comments:
In `@composition/src/v1/normalization/normalization-factory.ts`:
- Around line 2061-2122: The inline fragment validation in normalization-factory
is using kind-specific shortcuts instead of GraphQL possible-type overlap, so
update the logic around the fragmentNamedTypeData switch to compare the parent
and typeCondition by intersecting their possible concrete types. In the fragment
handling path near the existing parentDatas/shouldDefineSelectionSet flow, keep
the existing error helpers but replace the interface/union/object acceptance
rules with a shared overlap check for parentData and fragmentNamedTypeData, and
only allow the fragment when their possible types intersect; otherwise fall
through to invalidInlineFragmentTypeConditionErrorMessage.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 73b11a7c-85b6-4368-8689-78f7025b2741

📥 Commits

Reviewing files that changed from the base of the PR and between 6e88b50 and 76b9195.

📒 Files selected for processing (8)
  • composition/src/ast/utils.ts
  • composition/src/errors/errors.ts
  • composition/src/schema-building/types/types.ts
  • composition/src/utils/string-constants.ts
  • composition/src/v1/normalization/normalization-factory.ts
  • composition/src/v1/normalization/types/results.ts
  • composition/src/v1/normalization/types/types.ts
  • composition/tests/v1/directives/provides.test.ts

Comment thread composition/src/errors/errors.ts Outdated
Comment thread composition/tests/v1/directives/provides.test.ts Outdated
Comment thread composition/src/v1/normalization/types/types.ts Outdated
@Aenimus Aenimus enabled auto-merge (squash) July 2, 2026 23:20
@Aenimus Aenimus merged commit 8fd5a7c into main Jul 2, 2026
27 of 28 checks passed
@Aenimus Aenimus deleted the david/eng-5628-support-provides-on-union branch July 2, 2026 23:50
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