2020-05-10 10:27:46 +00:00
|
|
|
use async_graphql::*;
|
|
|
|
|
|
|
|
#[async_std::test]
|
|
|
|
pub async fn test_input_value_custom_error() {
|
|
|
|
struct Query;
|
|
|
|
|
2020-09-18 00:52:13 +00:00
|
|
|
#[Object]
|
2020-05-10 10:27:46 +00:00
|
|
|
impl Query {
|
2020-07-28 14:13:07 +00:00
|
|
|
async fn parse_int(&self, _n: i8) -> bool {
|
2020-05-10 10:27:46 +00:00
|
|
|
true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let schema = Schema::new(Query, EmptyMutation, EmptySubscription);
|
2020-07-28 14:13:07 +00:00
|
|
|
let query = r#"{ parseInt(n:289) }"#;
|
2020-05-10 10:27:46 +00:00
|
|
|
assert_eq!(
|
2020-09-10 23:58:02 +00:00
|
|
|
schema.execute(query).await.into_result().unwrap_err(),
|
2020-05-10 10:27:46 +00:00
|
|
|
Error::Query {
|
|
|
|
pos: Pos {
|
|
|
|
line: 1,
|
|
|
|
column: 14
|
|
|
|
},
|
|
|
|
path: None,
|
|
|
|
err: QueryError::ParseInputValue {
|
2020-07-28 14:13:07 +00:00
|
|
|
reason: "Only integers from -128 to 127 are accepted.".to_string()
|
2020-05-10 10:27:46 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|