Skip to content

Commit c650713

Browse files
committed
Backport accepting explicit null argument for nullable list input parameter (#1086, #1085)
1 parent 8276173 commit c650713

File tree

4 files changed

+38
-2
lines changed

4 files changed

+38
-2
lines changed

juniper/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# master
22

3-
- No changes yet
3+
- Fix incorrect error when explicit `null` provided for `null`able list input parameter. ([#1086](https://github.com/graphql-rust/juniper/pull/1086))
44

55
# [[0.15.9] 2022-02-02](https://github.com/graphql-rust/juniper/releases/tag/juniper-v0.15.9)
66

juniper/src/types/utilities.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ where
2525
}
2626
}
2727
TypeType::List(ref inner) => match *arg_value {
28+
InputValue::Null | InputValue::Variable(_) => true,
2829
InputValue::List(ref items) => items
2930
.iter()
3031
.all(|i| is_valid_literal_value(schema, inner, &i.item)),

juniper/src/validation/rules/arguments_of_correct_type.rs

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ mod tests {
8585
};
8686

8787
#[test]
88-
fn good_null_value() {
88+
fn null_into_nullable_int() {
8989
expect_passes_rule::<_, _, DefaultScalarValue>(
9090
factory,
9191
r#"
@@ -98,6 +98,20 @@ mod tests {
9898
);
9999
}
100100

101+
#[test]
102+
fn null_into_nullable_list() {
103+
expect_passes_rule::<_, _, DefaultScalarValue>(
104+
factory,
105+
r#"
106+
{
107+
complicatedArgs {
108+
stringListArgField(stringListArg: null)
109+
}
110+
}
111+
"#,
112+
);
113+
}
114+
101115
#[test]
102116
fn null_into_int() {
103117
expect_fails_rule::<_, _, DefaultScalarValue>(
@@ -116,6 +130,24 @@ mod tests {
116130
);
117131
}
118132

133+
#[test]
134+
fn null_into_list() {
135+
expect_fails_rule::<_, _, DefaultScalarValue>(
136+
factory,
137+
r#"
138+
{
139+
complicatedArgs {
140+
nonNullStringListArgField(nonNullStringListArg: null)
141+
}
142+
}
143+
"#,
144+
&[RuleError::new(
145+
&error_message("nonNullStringListArg", "[String!]!"),
146+
&[SourcePosition::new(111, 3, 64)],
147+
)],
148+
);
149+
}
150+
119151
#[test]
120152
fn good_int_value() {
121153
expect_passes_rule::<_, _, DefaultScalarValue>(

juniper/src/validation/test_harness.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,9 @@ where
666666
registry
667667
.field::<Option<String>>("stringListArgField", i)
668668
.argument(registry.arg::<Option<Vec<Option<String>>>>("stringListArg", i)),
669+
registry
670+
.field::<Option<String>>("nonNullStringListArgField", i)
671+
.argument(registry.arg::<Vec<String>>("nonNullStringListArg", i)),
669672
registry
670673
.field::<Option<String>>("complexArgField", i)
671674
.argument(registry.arg::<Option<ComplexInput>>("complexArg", i)),

0 commit comments

Comments
 (0)