Skip to content

Commit ba5f12f

Browse files
authored
Sorting an interface by child-level entity (#4058)
1 parent 05e838a commit ba5f12f

File tree

3 files changed

+227
-76
lines changed

3 files changed

+227
-76
lines changed

graphql/src/store/query.rs

+38-13
Original file line numberDiff line numberDiff line change
@@ -562,22 +562,47 @@ fn build_order_by(
562562
})
563563
}
564564
OrderByValue::Child(parent_field_name, child_field_name) => {
565-
if entity.is_interface() {
566-
return Err(QueryExecutionError::OrderByNotSupportedError(
567-
entity.name().to_owned(),
568-
parent_field_name,
569-
));
570-
}
565+
// Finds the field that connects the parent entity with the child entity.
566+
// In the case of an interface, we need to find the field on one of the types that implement the interface,
567+
// as the `@derivedFrom` directive is only allowed on object types.
568+
let field = match entity {
569+
ObjectOrInterface::Object(_) => {
570+
sast::get_field(entity, parent_field_name.as_str()).ok_or_else(|| {
571+
QueryExecutionError::EntityFieldError(
572+
entity.name().to_owned(),
573+
parent_field_name.clone(),
574+
)
575+
})?
576+
}
577+
ObjectOrInterface::Interface(_) => {
578+
let object_types = schema
579+
.types_for_interface()
580+
.get(&EntityType::new(entity.name().to_string()))
581+
.ok_or(QueryExecutionError::EntityFieldError(
582+
entity.name().to_owned(),
583+
parent_field_name.clone(),
584+
))?;
571585

572-
let field =
573-
sast::get_field(entity, parent_field_name.as_str()).ok_or_else(|| {
574-
QueryExecutionError::EntityFieldError(
575-
entity.name().to_owned(),
576-
parent_field_name.clone(),
577-
)
578-
})?;
586+
if let Some(first_entity) = object_types.first() {
587+
sast::get_field(first_entity, parent_field_name.as_str()).ok_or_else(
588+
|| {
589+
QueryExecutionError::EntityFieldError(
590+
entity.name().to_owned(),
591+
parent_field_name.clone(),
592+
)
593+
},
594+
)?
595+
} else {
596+
Err(QueryExecutionError::EntityFieldError(
597+
entity.name().to_owned(),
598+
parent_field_name.clone(),
599+
))?
600+
}
601+
}
602+
};
579603
let derived = field.is_derived();
580604
let base_type = field.field_type.get_base_type();
605+
581606
let child_entity = schema
582607
.object_or_interface(base_type)
583608
.ok_or_else(|| QueryExecutionError::NamedTypeError(base_type.into()))?;

0 commit comments

Comments
 (0)