thegraph-graphql-utils: Implement Error trait for APISchemaError
use graphql_parser::Pos;
use graphql_parser::schema::*;
use inflector::Inflector;
+use std::error::Error;
+use std::fmt;
use std::iter::IntoIterator;
use ast::schema as ast;
@@ -10,6 +12,26 @@ pub enum APISchemaError {
TypeExists(String),
}
+impl Error for APISchemaError {
+ fn description(&self) -> &str {
+ "API schema error"
+ }
+
+ fn cause(&self) -> Option<&Error> {
+ None
+ }
+}
+
+impl fmt::Display for APISchemaError {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ match self {
+ APISchemaError::TypeExists(s) => {
+ write!(f, "Type \"{}\" already exists in the input schema", s)
+ }
+ }
+ }
+}
+
/// Derives a full-fledged GraphQL API schema from an input schema.
///
/// The input schema should only have type/enum/interface/union definitions
