diff --git a/graphql/src/store/query.rs b/graphql/src/store/query.rs index 3270279e30c..add79d0d14d 100644 --- a/graphql/src/store/query.rs +++ b/graphql/src/store/query.rs @@ -206,22 +206,23 @@ fn build_list_filter_from_value( schema: &ApiSchema, value: &r::Value, ) -> Result, QueryExecutionError> { + // We have object like this + // { or: [{ name: \"John\", id: \"m1\" }, { mainBand: \"b2\" }] } return match value { r::Value::List(list) => Ok(list .iter() .map(|item| { + // It is each filter in the object + // { name: \"John\", id: \"m1\" } + // the fields within the object are ANDed together return match item { - r::Value::Object(object) => { - Ok(build_filter_from_object(entity, object, schema)?) - } + r::Value::Object(object) => Ok(EntityFilter::And(build_filter_from_object( + entity, object, schema, + )?)), _ => Err(QueryExecutionError::InvalidFilterError), }; }) - .collect::>, QueryExecutionError>>()? - // Flatten all different EntityFilters into one list - .into_iter() - .flatten() - .collect::>()), + .collect::, QueryExecutionError>>()?), _ => Err(QueryExecutionError::InvalidFilterError), }; } diff --git a/graphql/tests/query.rs b/graphql/tests/query.rs index 42a1da112c8..e5833fa6284 100644 --- a/graphql/tests/query.rs +++ b/graphql/tests/query.rs @@ -2128,7 +2128,7 @@ fn deterministic_error() { fn can_query_with_or_filter() { const QUERY: &str = " query { - musicians(where: { or: [{ name: \"John\", id: \"m2\" }] }) { + musicians(where: { or: [{ name: \"John\" }, { id: \"m2\" }] }) { name id } @@ -2147,6 +2147,26 @@ fn can_query_with_or_filter() { }) } +#[test] +fn can_query_with_or_filter_fields_always_and() { + const QUERY: &str = " + query { + musicians(where: { or: [{ name: \"John\", id: \"m2\" }] }) { + name + id + } + } + "; + + run_query(QUERY, |result, _| { + let exp = object! { + musicians: r::Value::List(vec![]), + }; + let data = extract_data!(result).unwrap(); + assert_eq!(data, exp); + }) +} + #[test] fn can_query_with_and_filter() { const QUERY: &str = "