Skip to content

Commit

Permalink
add regression test for fragment spreads with undefined global variab…
Browse files Browse the repository at this point in the history
…les as arguments

Summary:
Don't think we have a similar test for this where we are passing an undefined global variable as an argument to a fragment spread, so added one while working on T160746170

Add regression test for fragment spreads with undefined global variables as arguments

Reviewed By: alunyov

Differential Revision: D50573429

fbshipit-source-id: b16bb3e2fecb32f1c642f912808e1b81a991bfe5
  • Loading branch information
monicatang authored and facebook-github-bot committed Oct 24, 2023
1 parent 8011e22 commit f90edc4
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
==================================== INPUT ====================================
#expected-to-throw
query QueryWithUndefinedArgument {
node {
...UserFragment @arguments(age: $age)
}
}

fragment UserFragment on User
@argumentDefinitions(age: {type: "Int", defaultValue: null}) {
name
}
==================================== ERROR ====================================
✖︎ Expected variable `$age` to be defined on the operation

fragment-spread-with-undefined-argument.invalid.graphql:4:37
3 │ node {
4 │ ...UserFragment @arguments(age: $age)
│ ^^^^
5 │ }
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#expected-to-throw
query QueryWithUndefinedArgument {
node {
...UserFragment @arguments(age: $age)
}
}

fragment UserFragment on User
@argumentDefinitions(age: {type: "Int", defaultValue: null}) {
name
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<2727cdaebb7d446fd26bcade2da67b8f>>
* @generated SignedSource<<7435d162790438e443e6e90825864a09>>
*/

mod validate_global_variables;
Expand All @@ -19,6 +19,13 @@ async fn fragment_include_with_provided_argument() {
test_fixture(transform_fixture, "fragment-include-with-provided-argument.graphql", "validate_global_variables/fixtures/fragment-include-with-provided-argument.expected", input, expected).await;
}

#[tokio::test]
async fn fragment_spread_with_undefined_argument_invalid() {
let input = include_str!("validate_global_variables/fixtures/fragment-spread-with-undefined-argument.invalid.graphql");
let expected = include_str!("validate_global_variables/fixtures/fragment-spread-with-undefined-argument.invalid.expected");
test_fixture(transform_fixture, "fragment-spread-with-undefined-argument.invalid.graphql", "validate_global_variables/fixtures/fragment-spread-with-undefined-argument.invalid.expected", input, expected).await;
}

#[tokio::test]
async fn fragment_with_undefined_variable_invalid() {
let input = include_str!("validate_global_variables/fixtures/fragment-with-undefined-variable.invalid.graphql");
Expand Down

0 comments on commit f90edc4

Please sign in to comment.