Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 28ed68e

Browse files
graphql: handle empty lists in list_values to avoid panic (#6100)
* graphql: handle empty lists in list_values to avoid panic * graphql: add unit test for empty IN filter
1 parent 2252f6d commit 28ed68e

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

‎graphql/src/store/query.rs‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,9 @@ fn build_child_filter_from_object(
417417
fn list_values(value: Value, filter_type: &str) -> Result<Vec<Value>, QueryExecutionError> {
418418
match value {
419419
Value::List(values) => {
420+
if values.is_empty() {
421+
return Ok(values);
422+
}
420423
// Check that all values in list are of the same type
421424
let root_discriminant = discriminant(&values[0]);
422425
for value in &values {
@@ -968,6 +971,26 @@ mod tests {
968971
)
969972
}
970973

974+
#[test]
975+
fn build_query_handles_empty_in_list() {
976+
let query_field = default_field_with(
977+
"where",
978+
r::Value::Object(Object::from_iter(vec![(
979+
"id_in".into(),
980+
r::Value::List(vec![]),
981+
)])),
982+
);
983+
984+
let result = query(&query_field);
985+
assert_eq!(
986+
result.filter,
987+
Some(EntityFilter::And(vec![EntityFilter::In(
988+
"id".to_string(),
989+
Vec::<Value>::new(),
990+
)]))
991+
);
992+
}
993+
971994
#[test]
972995
fn build_query_yields_block_change_gte_filter() {
973996
let query_field = default_field_with(

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /