Skip to content

Commit b3d4487

Browse files
committed
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 20fda1c commit b3d4487

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
@@ -389,6 +389,9 @@ fn build_child_filter_from_object(
389389
fn list_values(value: Value, filter_type: &str) -> Result<Vec<Value>, QueryExecutionError> {
390390
match value {
391391
Value::List(values) => {
392+
if values.is_empty() {
393+
return Ok(values);
394+
}
392395
// Check that all values in list are of the same type
393396
let root_discriminant = discriminant(&values[0]);
394397
for value in &values {
@@ -940,6 +943,26 @@ mod tests {
940943
)
941944
}
942945

946+
#[test]
947+
fn build_query_handles_empty_in_list() {
948+
let query_field = default_field_with(
949+
"where",
950+
r::Value::Object(Object::from_iter(vec![(
951+
"id_in".into(),
952+
r::Value::List(vec![]),
953+
)])),
954+
);
955+
956+
let result = query(&query_field);
957+
assert_eq!(
958+
result.filter,
959+
Some(EntityFilter::And(vec![EntityFilter::In(
960+
"id".to_string(),
961+
Vec::<Value>::new(),
962+
)]))
963+
);
964+
}
965+
943966
#[test]
944967
fn build_query_yields_block_change_gte_filter() {
945968
let query_field = default_field_with(

0 commit comments

Comments
 (0)