Skip to content

Commit

Permalink
Ensure we strip alias metadata from selections within inline fragments
Browse files Browse the repository at this point in the history
Reviewed By: josephsavona

Differential Revision: D59662483

fbshipit-source-id: dcbeb109b05d174cd13b28ffa30bcfc0ac208e99
  • Loading branch information
captbaritone authored and facebook-github-bot committed Jul 12, 2024
1 parent 768a7ce commit 294cb83
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,22 +57,11 @@ fragment aliasedFragmentInInlineFragmentInner on User {
"plural": false,
"selections": [
{
"fragment": {
"kind": "InlineFragment",
"selections": [
{
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "name",
"storageKey": null
}
],
"type": "User",
"abstractKey": null
},
"kind": "AliasedInlineFragmentSpread",
"name": "aliasedFragmentInInlineFragmentInner"
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "name",
"storageKey": null
},
{
"alias": null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ module.exports = ((node/*: any*/)/*: Fragment<

//- __generated__/fooQuery.graphql.js
/**
* <auto-generated> SignedSource<<8480be3df692c8fedc9ff4e7bc331f0b>>
* <auto-generated> SignedSource<<ad44025e03ede3c075fa44c87694f3fd>>
* @flow
* @lightSyntaxTransform
* @nogrep
Expand Down Expand Up @@ -220,22 +220,11 @@ var node/*: ConcreteRequest*/ = {
"plural": false,
"selections": [
{
"fragment": {
"kind": "InlineFragment",
"selections": [
{
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "name",
"storageKey": null
}
],
"type": "User",
"abstractKey": null
},
"kind": "AliasedInlineFragmentSpread",
"name": "fooInner"
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "name",
"storageKey": null
}
],
"storageKey": null
Expand Down
11 changes: 7 additions & 4 deletions compiler/crates/relay-transforms/src/fragment_alias_directive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,16 @@ impl Transformer for AliasedInlineFragmentRemovalTransform {

fn transform_inline_fragment(&mut self, fragment: &InlineFragment) -> Transformed<Selection> {
if let Some(metadata) = FragmentAliasMetadata::find(&fragment.directives) {
let selections = self
.transform_selections(&fragment.selections)
.replace_or_else(|| fragment.selections.clone());
if metadata.wraps_spread {
if fragment.selections.len() != 1 {
if selections.len() != 1 {
panic!(
"Expected exactly one selection in an aliased inline fragment wrapping a spread. This is a bug in Relay."
);
}
Transformed::Replace(fragment.selections[0].clone())
Transformed::Replace(selections[0].clone())
} else {
let directives = fragment
.directives
Expand All @@ -105,12 +108,12 @@ impl Transformer for AliasedInlineFragmentRemovalTransform {
Transformed::Replace(Selection::InlineFragment(Arc::new(InlineFragment {
directives,
type_condition: fragment.type_condition,
selections: fragment.selections.clone(),
selections,
spread_location: fragment.spread_location,
})))
}
} else {
Transformed::Keep
self.default_transform_inline_fragment(fragment)
}
}
}
Expand Down

0 comments on commit 294cb83

Please sign in to comment.