Rework Failure 3 #671

This commit is contained in:
Sunli 2021-11-07 19:11:17 +08:00
parent 4d65f9c739
commit dbc0862894
13 changed files with 106 additions and 106 deletions

View File

@ -10,7 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Implement `From<Option<Option<T>>>` for `MaybeUndefined<T>`.
- Add `MaybeUndefined::as_opt_ref`, `MaybeUndefined::as_opt_deref`, `MaybeUndefined::map`, `MaybeUndefined::map_value`, `MaybeUndefined::contains`, `MaybeUndefined::contains_value`, and `MaybeUndefined::transpose` methods.
- Made `MaybeUndefined::is_undefined`, `MaybeUndefined::is_null`, `MaybeUndefined::is_value`, `MaybeUndefined::value` and `MaybeUndefined::as_opt_ref` const.
- Add `Failure` type. [#671](https://github.com/async-graphql/async-graphql/issues/671)
- Add `ResolverError` type. [#671](https://github.com/async-graphql/async-graphql/issues/671)
- [async-graphql-axum] Bump axum from `0.2.5` to `0.3`.
- [async-graphql-poem] Export the HTTP headers in the `Context`.

View File

@ -27,9 +27,9 @@ impl ErrorExtensionValues {
pub struct ServerError {
/// An explanatory message of the error.
pub message: String,
/// The concrete error type, comes from [`Failure<T>`].
/// The source of the error, comes from [`ResolverError<T>`].
#[serde(skip)]
pub error: Option<Arc<dyn Any + Send + Sync>>,
pub source: Option<Arc<dyn Any + Send + Sync>>,
/// Where the error occurred.
#[serde(skip_serializing_if = "Vec::is_empty", default)]
pub locations: Vec<Pos>,
@ -70,28 +70,28 @@ impl ServerError {
pub fn new(message: impl Into<String>, pos: Option<Pos>) -> Self {
Self {
message: message.into(),
error: None,
source: None,
locations: pos.map(|pos| vec![pos]).unwrap_or_default(),
path: Vec::new(),
extensions: None,
}
}
/// Downcast the error object by reference.
/// Get the source of the error.
///
/// # Examples
///
/// ```rust
/// use std::string::FromUtf8Error;
/// use async_graphql::{Failure, Error, ServerError, Pos};
/// use async_graphql::{ResolverError, Error, ServerError, Pos};
///
/// let bytes = vec![0, 159];
/// let err: Error = String::from_utf8(bytes).map_err(Failure::new).unwrap_err().into();
/// let err: Error = String::from_utf8(bytes).map_err(ResolverError::new).unwrap_err().into();
/// let server_err: ServerError = err.into_server_error(Pos { line: 1, column: 1 });
/// assert!(server_err.concrete_error::<FromUtf8Error>().is_some());
/// assert!(server_err.source::<FromUtf8Error>().is_some());
/// ```
pub fn concrete_error<T: Any + Send + Sync>(&self) -> Option<&T> {
self.error.as_ref().map(|err| err.downcast_ref()).flatten()
pub fn source<T: Any + Send + Sync>(&self) -> Option<&T> {
self.source.as_ref().map(|err| err.downcast_ref()).flatten()
}
#[doc(hidden)]
@ -116,7 +116,7 @@ impl From<parser::Error> for ServerError {
fn from(e: parser::Error) -> Self {
Self {
message: e.to_string(),
error: None,
source: None,
locations: e.positions().collect(),
path: Vec::new(),
extensions: None,
@ -209,9 +209,9 @@ pub type InputValueResult<T> = Result<T, InputValueError<T>>;
pub struct Error {
/// The error message.
pub message: String,
/// The concrete error type, comes from [`Failure<T>`].
/// The source of the error, comes from [`ResolverError<T>`].
#[serde(skip)]
pub error: Option<Arc<dyn Any + Send + Sync>>,
pub source: Option<Arc<dyn Any + Send + Sync>>,
/// Extensions to the error.
#[serde(skip_serializing_if = "error_extensions_is_empty")]
pub extensions: Option<ErrorExtensionValues>,
@ -237,7 +237,7 @@ impl Error {
pub fn new(message: impl Into<String>) -> Self {
Self {
message: message.into(),
error: None,
source: None,
extensions: None,
}
}
@ -247,7 +247,7 @@ impl Error {
pub fn into_server_error(self, pos: Pos) -> ServerError {
ServerError {
message: self.message,
error: self.error,
source: self.source,
locations: vec![pos],
path: Vec::new(),
extensions: self.extensions,
@ -259,17 +259,17 @@ impl<T: Display + Send + Sync + 'static> From<T> for Error {
fn from(e: T) -> Self {
Self {
message: e.to_string(),
error: None,
source: None,
extensions: None,
}
}
}
impl From<Failure> for Error {
fn from(e: Failure) -> Self {
impl From<ResolverError> for Error {
fn from(e: ResolverError) -> Self {
Self {
message: e.message,
error: Some(e.error),
source: Some(e.error),
extensions: None,
}
}
@ -355,7 +355,7 @@ pub trait ErrorExtensions: Sized {
let Error {
message,
error,
source,
extensions,
} = self.extend();
@ -364,7 +364,7 @@ pub trait ErrorExtensions: Sized {
Error {
message,
error,
source,
extensions: Some(extensions),
}
}
@ -382,13 +382,13 @@ impl<E: Display> ErrorExtensions for &E {
fn extend(self) -> Error {
Error {
message: self.to_string(),
error: None,
source: None,
extensions: None,
}
}
}
impl ErrorExtensions for Failure {
impl ErrorExtensions for ResolverError {
#[inline]
fn extend(self) -> Error {
Error::from(self)
@ -430,14 +430,14 @@ where
}
}
/// A wrapper around a dynamic error type.
/// A wrapper around a dynamic error type for resolver.
#[derive(Debug)]
pub struct Failure {
pub struct ResolverError {
message: String,
error: Arc<dyn Any + Send + Sync>,
}
impl<T: StdError + Send + Sync + 'static> From<T> for Failure {
impl<T: StdError + Send + Sync + 'static> From<T> for ResolverError {
fn from(err: T) -> Self {
Self {
message: err.to_string(),
@ -446,7 +446,7 @@ impl<T: StdError + Send + Sync + 'static> From<T> for Failure {
}
}
impl Failure {
impl ResolverError {
/// Create a new failure.
#[inline]
pub fn new<T: StdError + Send + Sync + 'static>(err: T) -> Self {

View File

@ -209,8 +209,8 @@ pub use base::{
Type, UnionType,
};
pub use error::{
Error, ErrorExtensionValues, ErrorExtensions, Failure, InputValueError, InputValueResult,
ParseRequestError, PathSegment, Result, ResultExt, ServerError, ServerResult,
Error, ErrorExtensionValues, ErrorExtensions, InputValueError, InputValueResult,
ParseRequestError, PathSegment, ResolverError, Result, ResultExt, ServerError, ServerResult,
};
pub use look_ahead::Lookahead;
pub use registry::CacheControl;

View File

@ -851,7 +851,7 @@ impl From<RuleError> for ServerError {
fn from(e: RuleError) -> Self {
Self {
message: e.message,
error: None,
source: None,
locations: e.locations,
path: Vec::new(),
extensions: e.extensions,

View File

@ -92,23 +92,23 @@ pub async fn test_failure() {
#[Object]
impl Query {
async fn failure(&self) -> Result<i32> {
Err(Failure::new(MyError::Error1).into())
Err(ResolverError::new(MyError::Error1).into())
}
async fn failure2(&self) -> Result<i32> {
Err(Failure::new(MyError::Error2))?;
Err(ResolverError::new(MyError::Error2))?;
Ok(1)
}
async fn failure3(&self) -> Result<i32> {
Err(Failure::new(MyError::Error1)
Err(ResolverError::new(MyError::Error1)
.extend_with(|_, values| values.set("a", 1))
.extend_with(|_, values| values.set("b", 2)))?;
Ok(1)
}
async fn failure4(&self) -> Result<i32> {
Err(Failure::new(MyError::Error2))
Err(ResolverError::new(MyError::Error2))
.extend_err(|_, values| values.set("a", 1))
.extend_err(|_, values| values.set("b", 2))?;
Ok(1)
@ -122,7 +122,7 @@ pub async fn test_failure() {
.into_result()
.unwrap_err()
.remove(0);
assert_eq!(err.concrete_error::<MyError>().unwrap(), &MyError::Error1);
assert_eq!(err.source::<MyError>().unwrap(), &MyError::Error1);
let err = schema
.execute("{ failure2 }")
@ -130,7 +130,7 @@ pub async fn test_failure() {
.into_result()
.unwrap_err()
.remove(0);
assert_eq!(err.concrete_error::<MyError>().unwrap(), &MyError::Error2);
assert_eq!(err.source::<MyError>().unwrap(), &MyError::Error2);
let err = schema
.execute("{ failure3 }")
@ -138,7 +138,7 @@ pub async fn test_failure() {
.into_result()
.unwrap_err()
.remove(0);
assert_eq!(err.concrete_error::<MyError>().unwrap(), &MyError::Error1);
assert_eq!(err.source::<MyError>().unwrap(), &MyError::Error1);
assert_eq!(
err.extensions,
Some({
@ -155,7 +155,7 @@ pub async fn test_failure() {
.into_result()
.unwrap_err()
.remove(0);
assert_eq!(err.concrete_error::<MyError>().unwrap(), &MyError::Error2);
assert_eq!(err.source::<MyError>().unwrap(), &MyError::Error2);
assert_eq!(
err.extensions,
Some({
@ -179,7 +179,7 @@ pub async fn test_failure2() {
#[Object]
impl Query {
async fn failure(&self) -> Result<i32, Failure> {
async fn failure(&self) -> Result<i32, ResolverError> {
Err(MyError::Error1)?
}
}

View File

@ -242,7 +242,7 @@ pub async fn test_find_entity_with_context() {
schema.execute(query).await.into_result().unwrap_err(),
vec![ServerError {
message: "Not found".to_string(),
error: None,
source: None,
locations: vec![Pos {
line: 2,
column: 13

View File

@ -85,7 +85,7 @@ pub async fn test_field_features() {
vec![ServerError {
message: r#"Unknown field "valueAbc" on type "QueryRoot". Did you mean "value"?"#
.to_owned(),
error: None,
source: None,
locations: vec![Pos { column: 3, line: 1 }],
path: Vec::new(),
extensions: None,
@ -114,7 +114,7 @@ pub async fn test_field_features() {
vec![ServerError {
message: r#"Unknown field "valueAbc" on type "MyObj". Did you mean "value"?"#
.to_owned(),
error: None,
source: None,
locations: vec![Pos { column: 9, line: 1 }],
path: Vec::new(),
extensions: None,
@ -150,7 +150,7 @@ pub async fn test_field_features() {
.errors,
vec![ServerError {
message: r#"Unknown field "valuesAbc" on type "SubscriptionRoot". Did you mean "values", "valuesBson"?"#.to_owned(),
error: None,
source: None,
locations: vec![Pos {
column: 16,
line: 1

View File

@ -99,7 +99,7 @@ pub async fn test_guard_simple_rule() {
.unwrap_err(),
vec![ServerError {
message: "Forbidden".to_string(),
error: None,
source: None,
locations: vec![Pos { line: 1, column: 3 }],
path: vec![PathSegment::Field("value".to_owned())],
extensions: None,
@ -128,7 +128,7 @@ pub async fn test_guard_simple_rule() {
.errors,
vec![ServerError {
message: "Forbidden".to_string(),
error: None,
source: None,
locations: vec![Pos {
line: 1,
column: 16
@ -178,7 +178,7 @@ pub async fn test_guard_and_operator() {
.unwrap_err(),
vec![ServerError {
message: "Forbidden".to_string(),
error: None,
source: None,
locations: vec![Pos { line: 1, column: 3 }],
path: vec![PathSegment::Field("value".to_owned())],
extensions: None,
@ -198,7 +198,7 @@ pub async fn test_guard_and_operator() {
.unwrap_err(),
vec![ServerError {
message: "Forbidden".to_string(),
error: None,
source: None,
locations: vec![Pos { line: 1, column: 3 }],
path: vec![PathSegment::Field("value".to_owned())],
extensions: None,
@ -218,7 +218,7 @@ pub async fn test_guard_and_operator() {
.unwrap_err(),
vec![ServerError {
message: "Forbidden".to_string(),
error: None,
source: None,
locations: vec![Pos { line: 1, column: 3 }],
path: vec![PathSegment::Field("value".to_owned())],
extensions: None,
@ -288,7 +288,7 @@ pub async fn test_guard_or_operator() {
.unwrap_err(),
vec![ServerError {
message: "Forbidden".to_string(),
error: None,
source: None,
locations: vec![Pos { line: 1, column: 3 }],
path: vec![PathSegment::Field("value".to_owned())],
extensions: None,
@ -338,7 +338,7 @@ pub async fn test_guard_chain_operator() {
.unwrap_err(),
vec![ServerError {
message: "Forbidden".to_string(),
error: None,
source: None,
locations: vec![Pos { line: 1, column: 3 }],
path: vec![PathSegment::Field("value".to_owned())],
extensions: None,
@ -359,7 +359,7 @@ pub async fn test_guard_chain_operator() {
.unwrap_err(),
vec![ServerError {
message: "Forbidden".to_string(),
error: None,
source: None,
locations: vec![Pos { line: 1, column: 3 }],
path: vec![PathSegment::Field("value".to_owned())],
extensions: None,
@ -380,7 +380,7 @@ pub async fn test_guard_chain_operator() {
.unwrap_err(),
vec![ServerError {
message: "Forbidden".to_string(),
error: None,
source: None,
locations: vec![Pos { line: 1, column: 3 }],
path: vec![PathSegment::Field("value".to_owned())],
extensions: None,
@ -401,7 +401,7 @@ pub async fn test_guard_chain_operator() {
.unwrap_err(),
vec![ServerError {
message: "Forbidden".to_string(),
error: None,
source: None,
locations: vec![Pos { line: 1, column: 3 }],
path: vec![PathSegment::Field("value".to_owned())],
extensions: None,
@ -493,7 +493,7 @@ pub async fn test_guard_race_operator() {
.unwrap_err(),
vec![ServerError {
message: "Forbidden".to_string(),
error: None,
source: None,
locations: vec![Pos { line: 1, column: 3 }],
path: vec![PathSegment::Field("value".to_owned())],
extensions: None,
@ -549,7 +549,7 @@ pub async fn test_guard_use_params() {
.unwrap_err(),
vec![ServerError {
message: "Forbidden".to_string(),
error: None,
source: None,
locations: vec![Pos { line: 1, column: 3 }],
path: vec![PathSegment::Field("get".to_owned())],
extensions: None,

View File

@ -67,7 +67,7 @@ pub async fn test_input_validator_string_min_length() {
.expect_err(&should_fail_msg),
vec![ServerError {
message: field_error_msg,
error: None,
source: None,
locations: vec!(Pos {
line: 1,
column: 17
@ -85,7 +85,7 @@ pub async fn test_input_validator_string_min_length() {
.expect_err(&should_fail_msg[..]),
vec![ServerError {
message: object_error_msg,
error: None,
source: None,
locations: vec!(Pos {
line: 1,
column: 14
@ -179,7 +179,7 @@ pub async fn test_input_validator_string_max_length() {
.expect_err(&should_fail_msg[..]),
vec![ServerError {
message: field_error_msg,
error: None,
source: None,
locations: vec!(Pos {
line: 1,
column: 17
@ -197,7 +197,7 @@ pub async fn test_input_validator_string_max_length() {
.expect_err(&should_fail_msg[..]),
vec![ServerError {
message: object_error_msg,
error: None,
source: None,
locations: vec!(Pos {
line: 1,
column: 14
@ -290,7 +290,7 @@ pub async fn test_input_validator_chars_min_length() {
.expect_err(&should_fail_msg),
vec![ServerError {
message: field_error_msg,
error: None,
source: None,
locations: vec!(Pos {
line: 1,
column: 17
@ -308,7 +308,7 @@ pub async fn test_input_validator_chars_min_length() {
.expect_err(&should_fail_msg[..]),
vec![ServerError {
message: object_error_msg,
error: None,
source: None,
locations: vec!(Pos {
line: 1,
column: 14
@ -403,7 +403,7 @@ pub async fn test_input_validator_chars_max_length() {
.expect_err(&should_fail_msg[..]),
vec![ServerError {
message: field_error_msg,
error: None,
source: None,
locations: vec!(Pos {
line: 1,
column: 17
@ -421,7 +421,7 @@ pub async fn test_input_validator_chars_max_length() {
.expect_err(&should_fail_msg[..]),
vec![ServerError {
message: object_error_msg,
error: None,
source: None,
locations: vec!(Pos {
line: 1,
column: 14
@ -542,7 +542,7 @@ pub async fn test_input_validator_string_email() {
.expect_err(&should_fail_msg[..]),
vec![ServerError {
message: field_error_msg,
error: None,
source: None,
locations: vec!(Pos {
line: 1,
column: 17
@ -561,7 +561,7 @@ pub async fn test_input_validator_string_email() {
.expect_err(&should_fail_msg[..]),
vec![ServerError {
message: object_error_msg,
error: None,
source: None,
locations: vec!(Pos {
line: 1,
column: 14
@ -692,7 +692,7 @@ pub async fn test_input_validator_string_mac() {
.expect_err(&should_fail_msg[..]),
vec![ServerError {
message: field_error_msg.clone(),
error: None,
source: None,
locations: vec!(Pos {
line: 1,
column: 17
@ -711,7 +711,7 @@ pub async fn test_input_validator_string_mac() {
.expect_err(&should_fail_msg[..]),
vec![ServerError {
message: object_error_msg.clone(),
error: None,
source: None,
locations: vec!(Pos {
line: 1,
column: 14
@ -729,7 +729,7 @@ pub async fn test_input_validator_string_mac() {
.expect_err(&should_fail_msg[..]),
vec![ServerError {
message: field_error_msg,
error: None,
source: None,
locations: vec!(Pos {
line: 1,
column: 17
@ -748,7 +748,7 @@ pub async fn test_input_validator_string_mac() {
.expect_err(&should_fail_msg[..]),
vec![ServerError {
message: object_error_msg,
error: None,
source: None,
locations: vec!(Pos {
line: 1,
column: 14
@ -806,7 +806,7 @@ pub async fn test_input_validator_string_mac() {
.expect_err(&should_fail_msg[..]),
vec![ServerError {
message: field_error_msg,
error: None,
source: None,
locations: vec!(Pos {
line: 1,
column: 17
@ -825,7 +825,7 @@ pub async fn test_input_validator_string_mac() {
.expect_err(&should_fail_msg[..]),
vec![ServerError {
message: object_error_msg,
error: None,
source: None,
locations: vec!(Pos {
line: 1,
column: 14
@ -867,7 +867,7 @@ pub async fn test_input_validator_string_mac() {
.expect_err(&should_fail_msg[..]),
vec![ServerError {
message: field_error_msg,
error: None,
source: None,
locations: vec!(Pos {
line: 1,
column: 17
@ -886,7 +886,7 @@ pub async fn test_input_validator_string_mac() {
.expect_err(&should_fail_msg[..]),
vec![ServerError {
message: object_error_msg,
error: None,
source: None,
locations: vec!(Pos {
line: 1,
column: 14
@ -947,7 +947,7 @@ pub async fn test_input_validator_int_range() {
.expect_err(&should_fail_msg[..]),
vec![ServerError {
message: field_error_msg,
error: None,
source: None,
locations: vec!(Pos {
line: 1,
column: 17
@ -965,7 +965,7 @@ pub async fn test_input_validator_int_range() {
.expect_err(&should_fail_msg[..]),
vec![ServerError {
message: object_error_msg,
error: None,
source: None,
locations: vec!(Pos {
line: 1,
column: 14
@ -1054,7 +1054,7 @@ pub async fn test_input_validator_int_less_than() {
.expect_err(&should_fail_msg[..]),
vec![ServerError {
message: field_error_msg,
error: None,
source: None,
locations: vec!(Pos {
line: 1,
column: 17
@ -1072,7 +1072,7 @@ pub async fn test_input_validator_int_less_than() {
.expect_err(&should_fail_msg[..]),
vec![ServerError {
message: object_error_msg,
error: None,
source: None,
locations: vec!(Pos {
line: 1,
column: 14
@ -1163,7 +1163,7 @@ pub async fn test_input_validator_int_greater_than() {
.expect_err(&should_fail_msg[..]),
vec![ServerError {
message: field_error_msg,
error: None,
source: None,
locations: vec!(Pos {
line: 1,
column: 17
@ -1181,7 +1181,7 @@ pub async fn test_input_validator_int_greater_than() {
.expect_err(&should_fail_msg[..]),
vec![ServerError {
message: object_error_msg,
error: None,
source: None,
locations: vec!(Pos {
line: 1,
column: 14
@ -1265,7 +1265,7 @@ pub async fn test_input_validator_int_nonzero() {
.expect_err(&should_fail_msg[..]),
vec![ServerError {
message: field_error_msg,
error: None,
source: None,
locations: vec!(Pos {
line: 1,
column: 17
@ -1283,7 +1283,7 @@ pub async fn test_input_validator_int_nonzero() {
.expect_err(&should_fail_msg[..]),
vec![ServerError {
message: object_error_msg,
error: None,
source: None,
locations: vec!(Pos {
line: 1,
column: 14
@ -1371,7 +1371,7 @@ pub async fn test_input_validator_int_equal() {
.expect_err(&should_fail_msg[..]),
vec![ServerError {
message: field_error_msg,
error: None,
source: None,
locations: vec!(Pos {
line: 1,
column: 17
@ -1389,7 +1389,7 @@ pub async fn test_input_validator_int_equal() {
.expect_err(&should_fail_msg[..]),
vec![ServerError {
message: object_error_msg,
error: None,
source: None,
locations: vec!(Pos {
line: 1,
column: 14
@ -1489,7 +1489,7 @@ pub async fn test_input_validator_list_max_length() {
.expect_err(&should_fail_msg[..]),
vec![ServerError {
message: field_error_msg,
error: None,
source: None,
locations: vec!(Pos {
line: 1,
column: 17
@ -1507,7 +1507,7 @@ pub async fn test_input_validator_list_max_length() {
.expect_err(&should_fail_msg[..]),
vec![ServerError {
message: object_error_msg,
error: None,
source: None,
locations: vec!(Pos {
line: 1,
column: 14
@ -1607,7 +1607,7 @@ pub async fn test_input_validator_list_min_length() {
.expect_err(&should_fail_msg[..]),
vec![ServerError {
message: field_error_msg,
error: None,
source: None,
locations: vec!(Pos {
line: 1,
column: 17
@ -1625,7 +1625,7 @@ pub async fn test_input_validator_list_min_length() {
.expect_err(&should_fail_msg[..]),
vec![ServerError {
message: object_error_msg,
error: None,
source: None,
locations: vec!(Pos {
line: 1,
column: 14
@ -1733,7 +1733,7 @@ pub async fn test_input_validator_operator_or() {
.expect_err(&should_fail_msg[..]),
vec![ServerError {
message: field_error_msg,
error: None,
source: None,
locations: vec!(Pos {
line: 1,
column: 17
@ -1751,7 +1751,7 @@ pub async fn test_input_validator_operator_or() {
.expect_err(&should_fail_msg[..]),
vec![ServerError {
message: object_error_msg,
error: None,
source: None,
locations: vec!(Pos {
line: 1,
column: 14
@ -1852,7 +1852,7 @@ pub async fn test_input_validator_operator_and() {
.expect_err(&should_fail_msg[..]),
vec![ServerError {
message: field_error_msg,
error: None,
source: None,
locations: vec!(Pos {
line: 1,
column: 17
@ -1870,7 +1870,7 @@ pub async fn test_input_validator_operator_and() {
.expect_err(&should_fail_msg[..]),
vec![ServerError {
message: object_error_msg,
error: None,
source: None,
locations: vec!(Pos {
line: 1,
column: 14
@ -1974,7 +1974,7 @@ pub async fn test_input_validator_variable() {
.expect_err(&should_fail_msg[..]),
vec![ServerError {
message: field_error_msg,
error: None,
source: None,
locations: vec!(Pos {
line: 1,
column: 37
@ -1992,7 +1992,7 @@ pub async fn test_input_validator_variable() {
.expect_err(&should_fail_msg[..]),
vec![ServerError {
message: object_error_msg,
error: None,
source: None,
locations: vec!(Pos {
line: 1,
column: 34
@ -2079,7 +2079,7 @@ pub async fn test_custom_input_validator_with_extensions() {
.expect_err(should_fail_msg),
vec![ServerError {
message: field_error_msg.into(),
error: None,
source: None,
locations: vec!(Pos {
line: 1,
column: 17

View File

@ -18,7 +18,7 @@ pub async fn test_input_value_custom_error() {
vec![ServerError {
message: "Failed to parse \"Int\": Only integers from -128 to 127 are accepted."
.to_owned(),
error: None,
source: None,
locations: vec![Pos {
line: 1,
column: 14,

View File

@ -167,7 +167,7 @@ pub async fn test_array_type() {
vec![ServerError {
message: r#"Failed to parse "[Int!]": Expected input type "[Int; 6]", found [Int; 5]."#
.to_owned(),
error: None,
source: None,
locations: vec![Pos {
line: 1,
column: 22,

View File

@ -34,14 +34,14 @@ pub async fn test_fieldresult() {
errors: vec![
ServerError {
message: "TestError".to_string(),
error: None,
source: None,
locations: vec![Pos { line: 1, column: 3 }],
path: vec![PathSegment::Field("error1".to_owned())],
extensions: None,
},
ServerError {
message: "TestError".to_string(),
error: None,
source: None,
locations: vec![Pos {
line: 1,
column: 19,
@ -62,7 +62,7 @@ pub async fn test_fieldresult() {
.unwrap_err(),
vec![ServerError {
message: "TestError".to_string(),
error: None,
source: None,
locations: vec![Pos { line: 1, column: 3 }],
path: vec![PathSegment::Field("optError".to_owned())],
extensions: None,
@ -77,7 +77,7 @@ pub async fn test_fieldresult() {
.unwrap_err(),
vec![ServerError {
message: "TestError".to_string(),
error: None,
source: None,
locations: vec![Pos { line: 1, column: 3 }],
path: vec![
PathSegment::Field("vecError".to_owned()),
@ -192,7 +192,7 @@ pub async fn test_error_propagation() {
cache_control: Default::default(),
errors: vec![ServerError {
message: "myerror".to_string(),
error: None,
source: None,
locations: vec![Pos {
line: 1,
column: 20,
@ -220,7 +220,7 @@ pub async fn test_error_propagation() {
cache_control: Default::default(),
errors: vec![ServerError {
message: "myerror".to_string(),
error: None,
source: None,
locations: vec![Pos {
line: 1,
column: 23,
@ -244,7 +244,7 @@ pub async fn test_error_propagation() {
cache_control: Default::default(),
errors: vec![ServerError {
message: "myerror".to_string(),
error: None,
source: None,
locations: vec![Pos {
line: 1,
column: 23,
@ -274,7 +274,7 @@ pub async fn test_error_propagation() {
cache_control: Default::default(),
errors: vec![ServerError {
message: "myerror".to_string(),
error: None,
source: None,
locations: vec![Pos {
line: 1,
column: 23,

View File

@ -345,7 +345,7 @@ pub async fn test_subscription_error() {
stream.next().await,
Some(Err(vec![ServerError {
message: "TestError".to_string(),
error: None,
source: None,
locations: vec![Pos {
line: 1,
column: 25
@ -391,7 +391,7 @@ pub async fn test_subscription_fieldresult() {
cache_control: Default::default(),
errors: vec![ServerError {
message: "StreamErr".to_string(),
error: None,
source: None,
locations: vec![Pos {
line: 1,
column: 16