Skip to content

Allow top-level spreads of @updatable fragments#5204

Open
captbaritone wants to merge 7 commits intofacebook:mainfrom
captbaritone:allow-top-level-updatable-fragment-spreads
Open

Allow top-level spreads of @updatable fragments#5204
captbaritone wants to merge 7 commits intofacebook:mainfrom
captbaritone:allow-top-level-updatable-fragment-spreads

Conversation

@captbaritone
Copy link
Copy Markdown
Contributor

Summary

  • Remove restriction DefaultNetworkLayer isn't exported #15 that forbade spreading @updatable fragments at the top level of an operation or fragment definition
  • Instead of unconditionally rejecting top-level spreads, perform the same supertype check used for linked fields against the containing operation/fragment type
  • Two cases remain correctly rejected:
    • Type mismatch: spreading a concrete-typed updatable fragment in an abstract-typed container (e.g. fragment Foo on Node { ...Updatable_user })
    • Inline fragment at top level: no linked field exists for discriminated union validation

Test plan

  • cargo test -p relay-transforms -- updatable_fragment_spread — all 26 tests pass
  • Previously-invalid updatable_fragment_spread_top_level test now passes as valid
  • New valid test: updatable_fragment_spread_top_level_abstract_in_concrete — abstract updatable fragment at top level of concrete-typed fragment
  • New invalid test: updatable_fragment_spread_top_level_wrong_type — concrete updatable fragment at top level of abstract-typed fragment
  • New invalid test: updatable_fragment_spread_top_level_in_inline_fragment — updatable fragment in inline fragment at top level

@meta-cla meta-cla bot added the CLA Signed label Mar 6, 2026
Remove restriction facebook#15 that forbade spreading @updatable fragments at the
top level of an operation or fragment definition. Instead of unconditionally
rejecting top-level spreads, perform the same supertype check used for
linked fields against the containing operation/fragment type.

Two cases remain errors:
- Type mismatch: spreading a concrete-typed updatable fragment in an
  abstract-typed container (e.g. fragment Foo on Node { ...Updatable_user })
- Inline fragment at top level: no linked field exists to validate for
  discriminated union creation
…allowed

Remove the "known type hole" bullet point from the website docs that stated
updatable fragments cannot be spread at the top level. Also update the code
comment in the validator to remove the outdated restriction.
An @alias'd inline fragment acts as a type boundary (like a linked
field), so we can relax the restrictions that require a discriminated
union or disallow top-level inline fragments. This adds an
AliasedInlineFragment path item that performs the supertype check
without requiring discriminated union validation, and updates error
messages to suggest @alias as a fix.
@captbaritone captbaritone force-pushed the allow-top-level-updatable-fragment-spreads branch from 14f4731 to 41e7ce2 Compare March 6, 2026 20:31
@captbaritone captbaritone force-pushed the allow-top-level-updatable-fragment-spreads branch from 41e7ce2 to 0073faa Compare March 6, 2026 20:34
When an updatable fragment's type doesn't match the containing type,
users previously had to wrap in an aliased inline fragment. Now @alias
can be placed directly on the fragment spread itself, which is simpler
since the fragment already carries the type condition.
Replace three separate error variants (SubtypeOrEqualContainingType,
SubtypeOrEqualLinkedField, SubtypeOrEqualAliasedInlineFragment) with a
single UpdatableFragmentSpreadTypeMismatch variant. All three cases
represent the same conceptual problem and suggest the same fix (@alias).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant