Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nested Sorting: interface by non-derived child entity #4058

Merged
merged 1 commit into from
Jul 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 38 additions & 13 deletions graphql/src/store/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -562,22 +562,47 @@ fn build_order_by(
})
}
OrderByValue::Child(parent_field_name, child_field_name) => {
if entity.is_interface() {
return Err(QueryExecutionError::OrderByNotSupportedError(
entity.name().to_owned(),
parent_field_name,
));
}
// Finds the field that connects the parent entity with the child entity.
// In the case of an interface, we need to find the field on one of the types that implement the interface,
// as the `@derivedFrom` directive is only allowed on object types.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The crazy thing here is that AFAIK it's possible for different object types that implement the same interface to store that attribute directly or derived. I have no idea how well that actually works in practice, but I don't think we enforce anything there.

I don't think we should hold this PR up any longer because of that, but it's likely that this will lead to issues if anybody uses that somewhat crazy mix of derived and direct storage. I have no idea if anybody does that, and we should have a look at the specific subgraph if that ever leads to issues. It might be a good idea though to require that all implementers of the interface use the same storage and return an error otherwise just to make sure we don't inadvertently return incorrect data.

let field = match entity {
ObjectOrInterface::Object(_) => {
sast::get_field(entity, parent_field_name.as_str()).ok_or_else(|| {
QueryExecutionError::EntityFieldError(
entity.name().to_owned(),
parent_field_name.clone(),
)
})?
}
ObjectOrInterface::Interface(_) => {
let object_types = schema
.types_for_interface()
.get(&EntityType::new(entity.name().to_string()))
.ok_or(QueryExecutionError::EntityFieldError(
entity.name().to_owned(),
parent_field_name.clone(),
))?;

let field =
sast::get_field(entity, parent_field_name.as_str()).ok_or_else(|| {
QueryExecutionError::EntityFieldError(
entity.name().to_owned(),
parent_field_name.clone(),
)
})?;
if let Some(first_entity) = object_types.first() {
sast::get_field(first_entity, parent_field_name.as_str()).ok_or_else(
|| {
QueryExecutionError::EntityFieldError(
entity.name().to_owned(),
parent_field_name.clone(),
)
},
)?
} else {
Err(QueryExecutionError::EntityFieldError(
entity.name().to_owned(),
parent_field_name.clone(),
))?
}
}
};
let derived = field.is_derived();
let base_type = field.field_type.get_base_type();

let child_entity = schema
.object_or_interface(base_type)
.ok_or_else(|| QueryExecutionError::NamedTypeError(base_type.into()))?;
Expand Down
Loading