Skip to content

Commit

Permalink
refactor: revert change on validator return
Browse files Browse the repository at this point in the history
  • Loading branch information
ologbonowiwi committed Feb 29, 2024
1 parent 4372297 commit 110ef3a
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 16 deletions.
5 changes: 2 additions & 3 deletions src/blueprint/mustache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,14 @@ impl<'a> MustachePartsValidator<'a> {
}

impl FieldDefinition {
pub fn validate_field(self, type_of: &config::Type, config: &Config) -> Valid<Self, String> {
pub fn validate_field(&self, type_of: &config::Type, config: &Config) -> Valid<(), String> {
// XXX we could use `Mustache`'s `render` method with a mock
// struct implementing the `PathString` trait encapsulating `validation_map`
// but `render` simply falls back to the default value for a given
// type if it doesn't exist, so we wouldn't be able to get enough
// context from that method alone
// So we must duplicate some of that logic here :(
let parts_validator = MustachePartsValidator::new(type_of, config, &self);
let parts_validator = MustachePartsValidator::new(type_of, config, self);

match &self.resolver {
Some(Expression::IO(IO::Http { req_template, .. })) => {
Expand Down Expand Up @@ -168,6 +168,5 @@ impl FieldDefinition {
}
_ => Valid::succeed(()),
}
.map_to(self)
}
}
14 changes: 8 additions & 6 deletions src/blueprint/operators/graphql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,18 @@ pub fn update_graphql<'a>(
) -> TryFold<'a, (&'a ConfigModule, &'a Field, &'a config::Type, &'a str), FieldDefinition, String>
{
TryFold::<(&ConfigModule, &Field, &config::Type, &'a str), FieldDefinition, String>::new(
|(config, field, type_of, _), b_field| {
|(config_module, field, type_of, _), b_field| {
let Some(graphql) = &field.graphql else {
return Valid::succeed(b_field);
};

compile_graphql(config, operation_type, graphql).and_then(|resolver| {
b_field
.resolver(Some(resolver))
.validate_field(type_of, config)
})
compile_graphql(config_module, operation_type, graphql)
.map(|resolver| b_field.resolver(Some(resolver)))
.and_then(|b_field| {
b_field
.validate_field(type_of, &config_module.config)
.map_to(b_field)
})
},
)
}
5 changes: 3 additions & 2 deletions src/blueprint/operators/grpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,10 +215,11 @@ pub fn update_grpc<'a>(
grpc,
validate_with_schema: true,
})
.and_then(|resolver| {
.map(|resolver| b_field.resolver(Some(resolver)))
.and_then(|b_field| {
b_field
.resolver(Some(resolver))
.validate_field(type_of, &config_module.config)
.map_to(b_field)
})
},
)
Expand Down
12 changes: 7 additions & 5 deletions src/blueprint/operators/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,13 @@ pub fn update_http<'a>(
return Valid::succeed(b_field);
};

compile_http(config_module, field, http).and_then(|resolver| {
b_field
.resolver(Some(resolver))
.validate_field(type_of, &config_module.config)
})
compile_http(config_module, field, http)
.map(|resolver| b_field.resolver(Some(resolver)))
.and_then(|b_field| {
b_field
.validate_field(type_of, &config_module.config)
.map_to(b_field)
})
},
)
}

0 comments on commit 110ef3a

Please sign in to comment.