Accept explicit null argument for nullable list input parameter (#1086, #1085)

This commit is contained in:
ajawalker 2022-07-21 11:49:45 -05:00 committed by GitHub
parent bea94398e8
commit 98412a937e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 40 additions and 1 deletions

View file

@ -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

View file

@ -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 {

View file

@ -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>(

View file

@ -724,6 +724,9 @@ where
registry
.field::<Option<String>>("stringListArgField", i)
.argument(registry.arg::<Option<Vec<Option<String>>>>("stringListArg", i)),
registry
.field::<Option<String>>("nonNullStringListArgField", i)
.argument(registry.arg::<Vec<String>>("nonNullStringListArg", i)),
registry
.field::<Option<String>>("complexArgField", i)
.argument(registry.arg::<Option<ComplexInput>>("complexArg", i)),