Skip to content

Commit

Permalink
refactor(call): use Valid::from_option instead of if let Some
Browse files Browse the repository at this point in the history
  • Loading branch information
ologbonowiwi committed Jan 3, 2024
1 parent debceee commit 000af1c
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions src/blueprint/from_config/operators/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,17 @@ pub fn update_call(
));
}

let type_and_field = if let Some(query) = &call.query {
Valid::succeed(("Query", query.as_str()))
} else {
Valid::fail("call must have query".to_string())
};

type_and_field
.and_then(|(type_name, field_name)| {
Valid::from_option(call.query.clone(), "call must have query".to_string())
.and_then(|field_name| {
Valid::from_option(
config.find_type(type_name),
format!("{} type not found on config", type_name),
config.find_type("Query"),
format!("Query type not found on config"),
)
.zip(Valid::succeed(field_name))
})
.and_then(|(query_type, field_name)| {
Valid::from_option(
query_type.fields.get(field_name),
query_type.fields.get(&field_name),
format!("{} field not found", field_name),
)
.and_then(|field| {
Expand Down

0 comments on commit 000af1c

Please sign in to comment.