Allow top-level spreads of @updatable fragments#5204
Open
captbaritone wants to merge 7 commits intofacebook:mainfrom
Open
Allow top-level spreads of @updatable fragments#5204captbaritone wants to merge 7 commits intofacebook:mainfrom
captbaritone wants to merge 7 commits intofacebook:mainfrom
Conversation
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.
14f4731 to
41e7ce2
Compare
41e7ce2 to
0073faa
Compare
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).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
@updatablefragments at the top level of an operation or fragment definitionfragment Foo on Node { ...Updatable_user })Test plan
cargo test -p relay-transforms -- updatable_fragment_spread— all 26 tests passupdatable_fragment_spread_top_leveltest now passes as validupdatable_fragment_spread_top_level_abstract_in_concrete— abstract updatable fragment at top level of concrete-typed fragmentupdatable_fragment_spread_top_level_wrong_type— concrete updatable fragment at top level of abstract-typed fragmentupdatable_fragment_spread_top_level_in_inline_fragment— updatable fragment in inline fragment at top level