graph: Add QueryExecutionError variants for failed enum/scalar value coercion
-use crate::data::subgraph::*;
-use graphql_parser::{query as q, Pos};
-
use failure;
+use graphql_parser::{query as q, Pos};
use hex::FromHexError;
use num_bigint;
use serde::ser::*;
@@ -10,6 +8,8 @@ use std::error::Error;
use std::fmt;
use std::string::FromUtf8Error;
+use crate::data::subgraph::*;
+
/// Error caused while executing a [Query](struct.Query.html).
#[derive(Debug)]
pub enum QueryExecutionError {
@@ -47,6 +47,8 @@ pub enum QueryExecutionError {
Timeout,
EmptySelectionSet(String),
Unimplemented(String),
+ EnumCoercionError(Pos, String, q::Value, String, Vec<String>),
+ ScalarCoercionError(Pos, String, q::Value, String),
}
impl Error for QueryExecutionError {
@@ -168,6 +170,12 @@ impl fmt::Display for QueryExecutionError {
Unimplemented(feature) => {
write!(f, "Feature `{}` is not yet implemented", feature)
}
+ EnumCoercionError(_, field, value, enum_type, values) => {
+ write!(f, "Failed to coerce value `{}` of field `{}` to enum type `{}`. Possible values are: {}", value, field, enum_type, values.join(", "))
+ }
+ ScalarCoercionError(_, field, value, scalar_type) => {
+ write!(f, "Failed to coerce value `{}` of field `{}` to scalar type `{}`", value, field, scalar_type)
+ }
}
}
}
@@ -292,7 +300,9 @@ impl Serialize for QueryError {
| QueryError::ExecutionError(InvalidArgumentError(pos, _, _))
| QueryError::ExecutionError(MissingArgumentError(pos, _))
| QueryError::ExecutionError(InvalidVariableTypeError(pos, _))
- | QueryError::ExecutionError(MissingVariableError(pos, _)) => {
+ | QueryError::ExecutionError(MissingVariableError(pos, _))
+ | QueryError::ExecutionError(EnumCoercionError(pos, _, _, _, _))
+ | QueryError::ExecutionError(ScalarCoercionError(pos, _, _, _)) => {
let mut location = HashMap::new();
location.insert("line", pos.line);
location.insert("column", pos.column);
