diff --git a/compiler/crates/relay-compiler/tests/compile_relay_artifacts/fixtures/provided-variable-in-fragment.expected b/compiler/crates/relay-compiler/tests/compile_relay_artifacts/fixtures/provided-variable-in-fragment.expected index 32211772de6c0..76df37dbc82a3 100644 --- a/compiler/crates/relay-compiler/tests/compile_relay_artifacts/fixtures/provided-variable-in-fragment.expected +++ b/compiler/crates/relay-compiler/tests/compile_relay_artifacts/fixtures/provided-variable-in-fragment.expected @@ -7,9 +7,12 @@ query providedVariableInFragment_Query($id: ID!) { } fragment providedVariableInFragment_Fragment1 on User - @argumentDefinitions(foo_gk: {type: "Boolean!", provider: "foo_gk_module.js"}) + @argumentDefinitions( + foo_gk: {type: "Boolean!", provider: "foo_gk_module.js"} + foobar_gk: {type: "Boolean!", provider: "foobar_gk_module.js"}) { name @include(if: $foo_gk) + alternate_name @include(if: $foobar_gk) } fragment providedVariableInFragment_Fragment2 on User @@ -75,6 +78,11 @@ fragment providedVariableInFragment_Fragment2 on User "kind": "LocalArgument", "name": "__providedVariableInFragment_Fragment1__foo_gk" }, + { + "defaultValue": null, + "kind": "LocalArgument", + "name": "__providedVariableInFragment_Fragment1__foobar_gk" + }, { "defaultValue": null, "kind": "LocalArgument", @@ -122,6 +130,20 @@ fragment providedVariableInFragment_Fragment2 on User } ] }, + { + "condition": "__providedVariableInFragment_Fragment1__foobar_gk", + "kind": "Condition", + "passingValue": true, + "selections": [ + { + "alias": null, + "args": null, + "kind": "ScalarField", + "name": "alternate_name", + "storageKey": null + } + ] + }, { "condition": "__providedVariableInFragment_Fragment2__bar_gk", "kind": "Condition", @@ -166,6 +188,7 @@ QUERY: query providedVariableInFragment_Query( $id: ID! $__providedVariableInFragment_Fragment1__foo_gk: Boolean! + $__providedVariableInFragment_Fragment1__foobar_gk: Boolean! $__providedVariableInFragment_Fragment2__bar_gk: Boolean! ) { node(id: $id) { @@ -178,6 +201,7 @@ query providedVariableInFragment_Query( fragment providedVariableInFragment_Fragment1 on User { name @include(if: $__providedVariableInFragment_Fragment1__foo_gk) + alternate_name @include(if: $__providedVariableInFragment_Fragment1__foobar_gk) } fragment providedVariableInFragment_Fragment2 on User { @@ -190,6 +214,10 @@ fragment providedVariableInFragment_Fragment2 on User { { "kind": "RootArgument", "name": "__providedVariableInFragment_Fragment1__foo_gk" + }, + { + "kind": "RootArgument", + "name": "__providedVariableInFragment_Fragment1__foobar_gk" } ], "kind": "Fragment", @@ -209,6 +237,20 @@ fragment providedVariableInFragment_Fragment2 on User { "storageKey": null } ] + }, + { + "condition": "__providedVariableInFragment_Fragment1__foobar_gk", + "kind": "Condition", + "passingValue": true, + "selections": [ + { + "alias": null, + "args": null, + "kind": "ScalarField", + "name": "alternate_name", + "storageKey": null + } + ] } ], "type": "User", diff --git a/compiler/crates/relay-compiler/tests/compile_relay_artifacts/fixtures/provided-variable-in-fragment.graphql b/compiler/crates/relay-compiler/tests/compile_relay_artifacts/fixtures/provided-variable-in-fragment.graphql index 62252269476f1..6e7f655e813b0 100644 --- a/compiler/crates/relay-compiler/tests/compile_relay_artifacts/fixtures/provided-variable-in-fragment.graphql +++ b/compiler/crates/relay-compiler/tests/compile_relay_artifacts/fixtures/provided-variable-in-fragment.graphql @@ -6,9 +6,12 @@ query providedVariableInFragment_Query($id: ID!) { } fragment providedVariableInFragment_Fragment1 on User - @argumentDefinitions(foo_gk: {type: "Boolean!", provider: "foo_gk_module.js"}) + @argumentDefinitions( + foo_gk: {type: "Boolean!", provider: "foo_gk_module.js"} + foobar_gk: {type: "Boolean!", provider: "foobar_gk_module.js"}) { name @include(if: $foo_gk) + alternate_name @include(if: $foobar_gk) } fragment providedVariableInFragment_Fragment2 on User diff --git a/compiler/crates/relay-transforms/src/apply_fragment_arguments/mod.rs b/compiler/crates/relay-transforms/src/apply_fragment_arguments/mod.rs index f251faad9ba78..2e148dcde08e8 100644 --- a/compiler/crates/relay-transforms/src/apply_fragment_arguments/mod.rs +++ b/compiler/crates/relay-transforms/src/apply_fragment_arguments/mod.rs @@ -392,7 +392,7 @@ impl ApplyFragmentArgumentsTransform<'_, '_, '_> { }); for definition in provided_arguments { self.provided_variables - .insert(fragment.name.item, definition.clone()); + .insert(definition.name.item, definition.clone()); } } diff --git a/compiler/crates/relay-transforms/src/provided_variable_fragment_transform.rs b/compiler/crates/relay-transforms/src/provided_variable_fragment_transform.rs index 71b7153c3512e..5eec205cfb669 100644 --- a/compiler/crates/relay-transforms/src/provided_variable_fragment_transform.rs +++ b/compiler/crates/relay-transforms/src/provided_variable_fragment_transform.rs @@ -20,6 +20,7 @@ use itertools::Itertools; /// [provided_variable_name] --> __[fragment_name]__[provided_variable_name] /// - Remove provided variables from (local) argument definitions /// - Add provided variables to list of used global variables +/// apply_fragment_arguments depends on provide_variable_fragment_transform pub fn provided_variable_fragment_transform(program: &Program) -> Program { let mut transform = ProvidedVariableFragmentTransform::new(); transform