graph: Address feedback on collecting errors
@@ -452,15 +452,13 @@ impl Schema {
.unwrap_or_else(|err| errors.push(err));
self.validate_derived_from()
.unwrap_or_else(|err| errors.push(err));
- self.validate_fields()
- .unwrap_or_else(|mut errs| errors.append(&mut errs));
self.validate_schema_type_has_no_fields()
.unwrap_or_else(|err| errors.push(err));
self.validate_only_import_directives_on_schema_type()
.unwrap_or_else(|err| errors.push(err));
+ errors.append(&mut self.validate_fields());
errors.append(&mut self.validate_import_directives());
- self.validate_imported_types(schemas)
- .unwrap_or_else(|mut errs| errors.append(&mut errs));
+ errors.append(&mut self.validate_imported_types(schemas));
if errors.is_empty() {
Ok(())
} else {
@@ -621,8 +619,7 @@ impl Schema {
fn validate_imported_types(
&self,
schemas: &HashMap<SchemaReference, Arc<Schema>>,
- ) -> Result<(), Vec<SchemaValidationError>> {
- let errors =
+ ) -> Vec<SchemaValidationError> {
self.imported_types()
.iter()
.fold(vec![], |mut errors, (imported_type, schema_ref)| {
@@ -646,8 +643,7 @@ impl Schema {
};
let is_native = native_types.iter().any(|object| object.name.eq(name));
- let is_imported =
- imported_types.iter().any(|(import, _)| match import {
+ let is_imported = imported_types.iter().any(|(import, _)| match import {
ImportedType::Name(n) => name.eq(n),
ImportedType::NameAs(_, az) => name.eq(az),
});
@@ -663,18 +659,13 @@ impl Schema {
.into_iter()
.for_each(|err| errors.push(err));
errors
- });
-
- match errors.is_empty() {
- true => Ok(()),
- false => Err(errors),
- }
+ })
}
- fn validate_fields(&self) -> Result<(), Vec<SchemaValidationError>> {
+ fn validate_fields(&self) -> Vec<SchemaValidationError> {
let native_types = self.document.get_object_and_interface_type_fields();
let imported_types = self.imported_types();
- let errors = native_types
+ native_types
.iter()
.fold(vec![], |errors, (type_name, fields)| {
fields.iter().fold(errors, |mut errors, field| {
@@ -702,11 +693,7 @@ impl Schema {
));
errors
})
- });
- match errors.is_empty() {
- false => Err(errors),
- true => Ok(()),
- }
+ })
}
fn validate_schema_types(&self) -> Result<(), SchemaValidationError> {
