Skip to content

Commit

Permalink
Support all cases
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilkisiela committed Sep 13, 2022
1 parent 05fff42 commit e057635
Show file tree
Hide file tree
Showing 3 changed files with 291 additions and 41 deletions.
20 changes: 4 additions & 16 deletions graphql/src/schema/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,24 +354,12 @@ fn field_list_filter_input_values(
// derived, we allow ID strings to be passed on.
// Adds child filter only to object types.
let (input_field_type, parent_type_name) = match typedef {
TypeDefinition::Object(parent) => {
TypeDefinition::Object(ObjectType { name, .. })
| TypeDefinition::Interface(InterfaceType { name, .. }) => {
if ast::get_derived_from_directive(field).is_some() {
(None, Some(parent.name.clone()))
(None, Some(name.clone()))
} else {
(
Some(Type::NamedType("String".into())),
Some(parent.name.clone()),
)
}
}
TypeDefinition::Interface(parent) => {
if ast::get_derived_from_directive(field).is_some() {
(None, Some(parent.name.clone()))
} else {
(
Some(Type::NamedType("String".into())),
Some(parent.name.clone()),
)
(Some(Type::NamedType("String".into())), Some(name.clone()))
}
}
TypeDefinition::Scalar(ref t) => (Some(Type::NamedType(t.name.to_owned())), None),
Expand Down
39 changes: 37 additions & 2 deletions graphql/src/store/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,14 +268,16 @@ fn build_child_filter_from_object(
.ok_or(QueryExecutionError::InvalidFilterError)?
.name
.to_string(),
false => field_name,
false => field_name.clone(),
};

if child_entity.is_interface() {
Ok(EntityFilter::Or(
child_entity
.object_types(schema.schema())
.expect("Interface is not implemented by any types")
.ok_or(QueryExecutionError::AbstractTypeError(
"Interface is not implemented by any types".to_string(),
))?
.iter()
.map(|object_type| {
EntityFilter::Child(Child {
Expand All @@ -287,6 +289,39 @@ fn build_child_filter_from_object(
})
.collect(),
))
} else if entity.is_interface() {
Ok(EntityFilter::Or(
entity
.object_types(schema.schema())
.ok_or(QueryExecutionError::AbstractTypeError(
"Interface is not implemented by any types".to_string(),
))?
.iter()
.map(|object_type| {
let field = object_type
.fields
.iter()
.find(|f| f.name == field_name.clone())
.ok_or(QueryExecutionError::InvalidFilterError)?;
let derived = field.is_derived();

let attr = match derived {
true => sast::get_derived_from_field(child_entity, field)
.ok_or(QueryExecutionError::InvalidFilterError)?
.name
.to_string(),
false => field_name.clone(),
};

Ok(EntityFilter::Child(Child {
attr: attr.clone(),
entity_type: EntityType::new(child_entity.name().to_string()),
filter: filter.clone(),
derived,
}))
})
.collect::<Result<Vec<EntityFilter>, QueryExecutionError>>()?,
))
} else {
Ok(EntityFilter::Child(Child {
attr,
Expand Down
Loading

0 comments on commit e057635

Please sign in to comment.