diff --git a/juniper/CHANGELOG.md b/juniper/CHANGELOG.md index 20e78044..510a25ce 100644 --- a/juniper/CHANGELOG.md +++ b/juniper/CHANGELOG.md @@ -73,6 +73,7 @@ All user visible changes to `juniper` crate will be documented in this file. Thi - Incorrect GraphQL list coercion rules: `null` cannot be coerced to an `[Int!]!` or `[Int]!`. ([#1004]) - All procedural macros expansion inside `macro_rules!`. ([#1054], [#1051]) - Incorrect input value coercion with defaults. ([#1080], [#1073]) +- Incorrect error when explicit `null` provided for `null`able list input parameter. ([#1086], [#1085]) [#503]: /../../issues/503 [#528]: /../../issues/528 @@ -106,6 +107,8 @@ All user visible changes to `juniper` crate will be documented in this file. Thi [#1073]: /../../issues/1073 [#1080]: /../../pull/1080 [#1081]: /../../pull/1081 +[#1085]: /../../issues/1085 +[#1086]: /../../pull/1086 [ba1ed85b]: /../../commit/ba1ed85b3c3dd77fbae7baf6bc4e693321a94083 diff --git a/juniper/src/types/utilities.rs b/juniper/src/types/utilities.rs index 2781418a..f1be0792 100644 --- a/juniper/src/types/utilities.rs +++ b/juniper/src/types/utilities.rs @@ -25,6 +25,7 @@ where } } TypeType::List(ref inner, expected_size) => match *arg_value { + InputValue::Null | InputValue::Variable(_) => true, InputValue::List(ref items) => { if let Some(expected) = expected_size { if items.len() != expected { diff --git a/juniper/src/validation/rules/arguments_of_correct_type.rs b/juniper/src/validation/rules/arguments_of_correct_type.rs index 8230267d..2c7aadbe 100644 --- a/juniper/src/validation/rules/arguments_of_correct_type.rs +++ b/juniper/src/validation/rules/arguments_of_correct_type.rs @@ -83,7 +83,7 @@ mod tests { }; #[test] - fn good_null_value() { + fn null_into_nullable_int() { expect_passes_rule::<_, _, DefaultScalarValue>( factory, r#" @@ -96,6 +96,20 @@ mod tests { ); } + #[test] + fn null_into_nullable_list() { + expect_passes_rule::<_, _, DefaultScalarValue>( + factory, + r#" + { + complicatedArgs { + stringListArgField(stringListArg: null) + } + } + "#, + ); + } + #[test] fn null_into_int() { expect_fails_rule::<_, _, DefaultScalarValue>( @@ -114,6 +128,24 @@ mod tests { ); } + #[test] + fn null_into_list() { + expect_fails_rule::<_, _, DefaultScalarValue>( + factory, + r#" + { + complicatedArgs { + nonNullStringListArgField(nonNullStringListArg: null) + } + } + "#, + &[RuleError::new( + &error_message("nonNullStringListArg", "[String!]!"), + &[SourcePosition::new(111, 3, 64)], + )], + ); + } + #[test] fn good_int_value() { expect_passes_rule::<_, _, DefaultScalarValue>( diff --git a/juniper/src/validation/test_harness.rs b/juniper/src/validation/test_harness.rs index 492e4564..c2f5ddac 100644 --- a/juniper/src/validation/test_harness.rs +++ b/juniper/src/validation/test_harness.rs @@ -724,6 +724,9 @@ where registry .field::>("stringListArgField", i) .argument(registry.arg::>>>("stringListArg", i)), + registry + .field::>("nonNullStringListArgField", i) + .argument(registry.arg::>("nonNullStringListArg", i)), registry .field::>("complexArgField", i) .argument(registry.arg::>("complexArg", i)),