Skip to content

Commit

Permalink
store: avoid expect
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilkisiela committed Nov 4, 2022
1 parent 8042010 commit 4f1adae
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions graphql/src/store/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -401,15 +401,20 @@ enum OrderByValue {
Child(String, String),
}

fn parse_order_by(enum_value: &String) -> OrderByValue {
fn parse_order_by(enum_value: &String) -> Result<OrderByValue, QueryExecutionError> {
let mut parts = enum_value.split("__");
let first = parts.next().expect("some dark magic happened");
let first = parts.next().ok_or_else(|| {
QueryExecutionError::ValueParseError(
"Invalid order value".to_string(),
enum_value.to_string(),
)
})?;
let second = parts.next();

match second {
Ok(match second {
Some(second) => OrderByValue::Child(first.to_string(), second.to_string()),
None => OrderByValue::Direct(first.to_string()),
}
})
}

struct ObjectOrderDetails {
Expand All @@ -436,7 +441,7 @@ fn build_order_by(
schema: &ApiSchema,
) -> Result<Option<(String, ValueType, Option<OrderByChild>)>, QueryExecutionError> {
match field.argument_value("orderBy") {
Some(r::Value::Enum(name)) => match parse_order_by(name) {
Some(r::Value::Enum(name)) => match parse_order_by(name)? {
OrderByValue::Direct(name) => {
let field = sast::get_field(entity, name.as_str()).ok_or_else(|| {
QueryExecutionError::EntityFieldError(entity.name().to_owned(), name.clone())
Expand Down

0 comments on commit 4f1adae

Please sign in to comment.