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

feat(2720): add validations on input types #2724

Closed
Closed
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
9 changes: 5 additions & 4 deletions src/core/blueprint/from_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,12 @@ pub fn to_json_schema_for_field(field: &Field, config: &Config) -> JsonSchema {
to_json_schema(field, config)
}
pub fn to_json_schema_for_args(args: &BTreeMap<String, Arg>, config: &Config) -> JsonSchema {
let mut schema_fields = BTreeMap::new();
for (name, arg) in args.iter() {
schema_fields.insert(name.clone(), to_json_schema(arg, config));
if let Some(arg) = args.values().next() {
// gRPC can only support one input message, so we check for only one argument
// compatibility
return to_json_schema(arg, config);
}
JsonSchema::Obj(schema_fields)
JsonSchema::Empty
}
fn to_json_schema<T>(field: &T, config: &Config) -> JsonSchema
where
Expand Down
11 changes: 6 additions & 5 deletions src/core/blueprint/operators/grpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,18 @@ fn validate_schema(
) -> Valid<(), String> {
let input_type = &operation.input_type;
let output_type = &operation.output_type;

Valid::from(JsonSchema::try_from(input_type))
.zip(Valid::from(JsonSchema::try_from(output_type)))
.and_then(|(_input_schema, sub_type)| {
// TODO: add validation for input schema - should compare result grpc.body to
// schema
.and_then(|(sub_args, sub_type)| {
let super_type = field_schema.field;
let super_args = field_schema.args;

// TODO: all of the fields in protobuf are optional actually
// and if we want to mark some fields as required in GraphQL
// JsonSchema won't match and the validation will fail
sub_type.is_a(&super_type, name)
sub_type
.is_a(&super_type, name)
.and(super_args.is_a(&sub_args, name))
})
}

Expand Down
Loading