Remove unnecessary Result on Schema::execute_stream function.

This commit is contained in:
Sunli 2020-09-11 07:58:02 +08:00
parent 91c75ced2a
commit 35f17a389c
24 changed files with 252 additions and 225 deletions

View File

@ -20,7 +20,7 @@ default = ["bson", "url", "chrono-tz"]
async-graphql-derive = { path = "derive", version = "1.18.0" } async-graphql-derive = { path = "derive", version = "1.18.0" }
async-graphql-parser = { path = "parser", version = "1.18.0" } async-graphql-parser = { path = "parser", version = "1.18.0" }
async-stream = "0.2.1" async-stream = "0.3"
async-trait = "0.1.30" async-trait = "0.1.30"
bytes = "0.5.4" bytes = "0.5.4"
chrono = "0.4.10" chrono = "0.4.10"

View File

@ -98,11 +98,6 @@
#![recursion_limit = "256"] #![recursion_limit = "256"]
#![forbid(unsafe_code)] #![forbid(unsafe_code)]
// Do not try to modify the location of this line of code, it must be
// the first mod defined, otherwise there will be a danger of failing to compile.
#[macro_use]
mod macros;
mod base; mod base;
mod context; mod context;
mod error; mod error;
@ -280,7 +275,7 @@ pub use types::{EnumItem, EnumType};
/// valueWithError /// valueWithError
/// valueWithArg1: valueWithArg /// valueWithArg1: valueWithArg
/// valueWithArg2: valueWithArg(a: 99) /// valueWithArg2: valueWithArg(a: 99)
/// }"#).await.unwrap().data; /// }"#).await.into_result().unwrap().data;
/// assert_eq!(res, serde_json::json!({ /// assert_eq!(res, serde_json::json!({
/// "value": 10, /// "value": 10,
/// "valueRef": 10, /// "valueRef": 10,
@ -335,7 +330,7 @@ pub use async_graphql_derive::Object;
/// ///
/// async_std::task::block_on(async move { /// async_std::task::block_on(async move {
/// let schema = Schema::new(QueryRoot{ value: 10 }, EmptyMutation, EmptySubscription); /// let schema = Schema::new(QueryRoot{ value: 10 }, EmptyMutation, EmptySubscription);
/// let res = schema.execute("{ value }").await.unwrap().data; /// let res = schema.execute("{ value }").await.into_result().unwrap().data;
/// assert_eq!(res, serde_json::json!({ /// assert_eq!(res, serde_json::json!({
/// "value": 10, /// "value": 10,
/// })); /// }));
@ -453,7 +448,7 @@ pub use async_graphql_derive::GQLSimpleObject;
/// ///
/// async_std::task::block_on(async move { /// async_std::task::block_on(async move {
/// let schema = Schema::new(QueryRoot{ value1: MyEnum::A, value2: MyEnum::B }, EmptyMutation, EmptySubscription); /// let schema = Schema::new(QueryRoot{ value1: MyEnum::A, value2: MyEnum::B }, EmptyMutation, EmptySubscription);
/// let res = schema.execute("{ value1 value2 }").await.unwrap().data; /// let res = schema.execute("{ value1 value2 }").await.into_result().unwrap().data;
/// assert_eq!(res, serde_json::json!({ "value1": "A", "value2": "b" })); /// assert_eq!(res, serde_json::json!({ "value1": "A", "value2": "b" }));
/// }); /// });
/// ``` /// ```
@ -461,6 +456,7 @@ pub use async_graphql_derive::Enum;
/// Define a GraphQL input object /// Define a GraphQL input object
/// ///
///
/// You can also [derive this](derive.GQLInputObject.html). /// You can also [derive this](derive.GQLInputObject.html).
/// ///
/// *[See also the Book](https://async-graphql.github.io/async-graphql/en/define_input_object.html).* /// *[See also the Book](https://async-graphql.github.io/async-graphql/en/define_input_object.html).*
@ -512,7 +508,7 @@ pub use async_graphql_derive::Enum;
/// { /// {
/// value1: value(input:{a:9, b:3}) /// value1: value(input:{a:9, b:3})
/// value2: value(input:{a:9}) /// value2: value(input:{a:9})
/// }"#).await.unwrap().data; /// }"#).await.into_result().unwrap().data;
/// assert_eq!(res, serde_json::json!({ "value1": 27, "value2": 90 })); /// assert_eq!(res, serde_json::json!({ "value1": 27, "value2": 90 }));
/// }); /// });
/// ``` /// ```
@ -634,7 +630,7 @@ pub use async_graphql_derive::InputObject;
/// valueC(a: 3, b: 2) /// valueC(a: 3, b: 2)
/// value_d /// value_d
/// } /// }
/// }"#).await.unwrap().data; /// }"#).await.into_result().unwrap().data;
/// assert_eq!(res, serde_json::json!({ /// assert_eq!(res, serde_json::json!({
/// "typeA": { /// "typeA": {
/// "valueA": "hello", /// "valueA": "hello",
@ -711,7 +707,7 @@ pub use async_graphql_derive::GQLInterface;
/// valueB /// valueB
/// } /// }
/// } /// }
/// }"#).await.unwrap().data; /// }"#).await.into_result().unwrap().data;
/// assert_eq!(res, serde_json::json!({ /// assert_eq!(res, serde_json::json!({
/// "allData": [ /// "allData": [
/// { "valueA": 10 }, /// { "valueA": 10 },

View File

@ -1,8 +0,0 @@
macro_rules! try_query_result {
($res:expr) => {
match $res {
Ok(resp) => resp,
Err(err) => return err.into(),
}
};
}

View File

@ -134,9 +134,9 @@ pub struct MetaEnumValue {
/// #[async_std::main] /// #[async_std::main]
/// async fn main() { /// async fn main() {
/// let schema = Schema::new(QueryRoot, EmptyMutation, EmptySubscription); /// let schema = Schema::new(QueryRoot, EmptyMutation, EmptySubscription);
/// assert_eq!(schema.execute("{ value1 }").await.unwrap().cache_control, CacheControl { public: true, max_age: 30 }); /// assert_eq!(schema.execute("{ value1 }").await.into_result().unwrap().cache_control, CacheControl { public: true, max_age: 30 });
/// assert_eq!(schema.execute("{ value2 }").await.unwrap().cache_control, CacheControl { public: false, max_age: 60 }); /// assert_eq!(schema.execute("{ value2 }").await.into_result().unwrap().cache_control, CacheControl { public: false, max_age: 60 });
/// assert_eq!(schema.execute("{ value1 value2 }").await.unwrap().cache_control, CacheControl { public: false, max_age: 30 }); /// assert_eq!(schema.execute("{ value1 value2 }").await.into_result().unwrap().cache_control, CacheControl { public: false, max_age: 30 });
/// } /// }
/// ``` /// ```
#[derive(Clone, Copy, PartialEq, Eq, Debug)] #[derive(Clone, Copy, PartialEq, Eq, Debug)]

View File

@ -29,52 +29,6 @@ impl Response {
self.error.is_some() self.error.is_some()
} }
/// Get self.
///
/// Panics
///
/// It will panic when the response is error.
#[inline]
pub fn unwrap(self) -> Self {
self
}
/// Get the error object.
///
/// Panics
///
/// It will panic when the response is ok.
#[inline]
pub fn unwrap_err(self) -> Error {
self.error.unwrap()
}
/// Returns the contained error, consuming the self value.
///
/// Panics
///
/// Panics if the response is ok, with a panic message including the passed message.
#[inline]
pub fn expect_err(self, msg: &str) -> Error {
match self.error {
Some(err) => err,
None => panic!("{}", msg),
}
}
/// Returns self, consuming the self value.
///
/// Panics
///
/// Panics if the response is errror, with a panic message including the passed message.
#[inline]
pub fn expect(self, msg: &str) -> Self {
match self.error {
Some(_) => panic!("{}", msg),
None => self,
}
}
/// Convert response to `Result<Response>`. /// Convert response to `Result<Response>`.
#[inline] #[inline]
pub fn into_result(self) -> Result<Self> { pub fn into_result(self) -> Result<Self> {

View File

@ -128,7 +128,7 @@ mod test {
let query = r#"{ obj(input: { a: 1, b: 2, c: { a: 11, b: 22 } } ) }"#; let query = r#"{ obj(input: { a: 1, b: 2, c: { a: 11, b: 22 } } ) }"#;
let schema = Schema::new(Query, EmptyMutation, EmptySubscription); let schema = Schema::new(Query, EmptyMutation, EmptySubscription);
assert_eq!( assert_eq!(
schema.execute(query).await.unwrap().data, schema.execute(query).await.into_result().unwrap().data,
serde_json::json!({ serde_json::json!({
"obj": { "obj": {
"a": 1, "a": 1,

View File

@ -12,7 +12,7 @@ use crate::{
do_resolve, CacheControl, ContextBase, Error, ObjectType, Pos, QueryEnv, QueryError, Request, do_resolve, CacheControl, ContextBase, Error, ObjectType, Pos, QueryEnv, QueryError, Request,
Response, Result, SubscriptionType, Type, Variables, ID, Response, Result, SubscriptionType, Type, Variables, ID,
}; };
use futures::Stream; use futures::{Stream, StreamExt};
use indexmap::map::IndexMap; use indexmap::map::IndexMap;
use itertools::Itertools; use itertools::Itertools;
use std::any::Any; use std::any::Any;
@ -20,6 +20,15 @@ use std::ops::Deref;
use std::sync::atomic::AtomicUsize; use std::sync::atomic::AtomicUsize;
use std::sync::Arc; use std::sync::Arc;
macro_rules! try_query_result {
($res:expr) => {
match $res {
Ok(resp) => resp,
Err(err) => return err.into(),
}
};
}
/// Schema builder /// Schema builder
pub struct SchemaBuilder<Query, Mutation, Subscription> { pub struct SchemaBuilder<Query, Mutation, Subscription> {
validation_mode: ValidationMode, validation_mode: ValidationMode,
@ -431,12 +440,17 @@ where
} }
/// Execute an GraphQL subscription. /// Execute an GraphQL subscription.
pub async fn execute_stream( pub fn execute_stream(&self, request: impl Into<Request>) -> impl Stream<Item = Response> {
&self, let schema = self.clone();
request: impl Into<Request>, Box::pin(async_stream::stream! {
) -> Result<impl Stream<Item = Response> + Send> {
let request = request.into(); let request = request.into();
let (document, _, extensions) = self.prepare_query(&request.query, &request.variables)?; let (document, extensions) = match schema.prepare_query(&request.query, &request.variables) {
Ok((document, _, extensions)) => (document, extensions),
Err(err) => {
yield Response::from(err);
return;
}
};
let document = match document.into_data(request.operation_name.as_deref()) { let document = match document.into_data(request.operation_name.as_deref()) {
Some(document) => document, Some(document) => document,
@ -450,14 +464,16 @@ where
QueryError::MissingOperation.into_error(Pos::default()) QueryError::MissingOperation.into_error(Pos::default())
}; };
extensions.lock().error(&err); extensions.lock().error(&err);
return Err(err.into()); yield err.into();
return;
} }
}; };
if document.operation.node.ty != OperationType::Subscription { if document.operation.node.ty != OperationType::Subscription {
let err = QueryError::NotSupported.into_error(Pos::default()); let err = QueryError::NotSupported.into_error(Pos::default());
extensions.lock().error(&err); extensions.lock().error(&err);
return Err(err); yield err.into();
return;
} }
let resolve_id = AtomicUsize::default(); let resolve_id = AtomicUsize::default();
@ -467,19 +483,29 @@ where
document, document,
Arc::new(request.ctx_data), Arc::new(request.ctx_data),
); );
let ctx = env.create_context( let ctx = env.create_context(
&self.env, &schema.env,
None, None,
&env.document.operation.node.selection_set, &env.document.operation.node.selection_set,
&resolve_id, &resolve_id,
); );
let mut streams = Vec::new(); let mut streams = Vec::new();
match create_subscription_stream(self, env.clone(), &ctx, &mut streams).await {
Ok(()) => Ok(futures::stream::select_all(streams)), if let Err(err) = create_subscription_stream(&schema, env.clone(), &ctx, &mut streams).await {
Err(err) => { yield err.into();
env.extensions.lock().error(&err); return;
Err(err) }
let mut stream = futures::stream::select_all(streams);
while let Some(resp) = stream.next().await {
let is_err = resp.is_err();
yield resp;
if is_err {
break;
} }
} }
})
} }
} }

View File

@ -69,7 +69,7 @@ pub struct EmptyFields;
/// async fn main() { /// async fn main() {
/// let schema = Schema::new(QueryRoot, EmptyMutation, EmptySubscription); /// let schema = Schema::new(QueryRoot, EmptyMutation, EmptySubscription);
/// ///
/// assert_eq!(schema.execute("{ numbers(first: 2) { edges { node diff } } }").await.unwrap().data, serde_json::json!({ /// assert_eq!(schema.execute("{ numbers(first: 2) { edges { node diff } } }").await.into_result().unwrap().data, serde_json::json!({
/// "numbers": { /// "numbers": {
/// "edges": [ /// "edges": [
/// {"node": 0, "diff": 10000}, /// {"node": 0, "diff": 10000},
@ -78,7 +78,7 @@ pub struct EmptyFields;
/// }, /// },
/// })); /// }));
/// ///
/// assert_eq!(schema.execute("{ numbers(last: 2) { edges { node diff } } }").await.unwrap().data, serde_json::json!({ /// assert_eq!(schema.execute("{ numbers(last: 2) { edges { node diff } } }").await.into_result().unwrap().data, serde_json::json!({
/// "numbers": { /// "numbers": {
/// "edges": [ /// "edges": [
/// {"node": 9998, "diff": 2}, /// {"node": 9998, "diff": 2},

View File

@ -35,7 +35,7 @@ use std::borrow::Cow;
/// v3:value1 /// v3:value1
/// }"#; /// }"#;
/// assert_eq!( /// assert_eq!(
/// schema.execute(query).await.unwrap().data, /// schema.execute(query).await.into_result().unwrap().data,
/// serde_json::json!({ /// serde_json::json!({
/// "v1": 99, /// "v1": 99,
/// "v2": 1, /// "v2": 1,

View File

@ -37,7 +37,7 @@ pub async fn test_complexity_and_depth() {
.limit_complexity(2) .limit_complexity(2)
.finish(); .finish();
assert_eq!( assert_eq!(
schema.execute(query).await.unwrap_err(), schema.execute(query).await.into_result().unwrap_err(),
Error::Query { Error::Query {
pos: Pos { line: 0, column: 0 }, pos: Pos { line: 0, column: 0 },
path: None, path: None,
@ -62,7 +62,7 @@ pub async fn test_complexity_and_depth() {
.limit_complexity(2) .limit_complexity(2)
.finish(); .finish();
assert_eq!( assert_eq!(
schema.execute(query).await.unwrap_err(), schema.execute(query).await.into_result().unwrap_err(),
Error::Query { Error::Query {
pos: Pos { line: 0, column: 0 }, pos: Pos { line: 0, column: 0 },
path: None, path: None,
@ -95,7 +95,7 @@ pub async fn test_complexity_and_depth() {
.limit_depth(2) .limit_depth(2)
.finish(); .finish();
assert_eq!( assert_eq!(
schema.execute(query).await.unwrap_err(), schema.execute(query).await.into_result().unwrap_err(),
Error::Query { Error::Query {
pos: Pos { line: 0, column: 0 }, pos: Pos { line: 0, column: 0 },
path: None, path: None,

View File

@ -84,7 +84,7 @@ pub async fn test_field_features() {
let query = "{ valueAbc }"; let query = "{ valueAbc }";
assert_eq!( assert_eq!(
schema.execute(query).await.unwrap_err(), schema.execute(query).await.into_result().unwrap_err(),
Error::Query { Error::Query {
pos: Pos { column: 3, line: 1 }, pos: Pos { column: 3, line: 1 },
path: Some(serde_json::json!(["valueAbc"])), path: Some(serde_json::json!(["valueAbc"])),
@ -113,7 +113,7 @@ pub async fn test_field_features() {
let query = "{ obj { valueAbc } }"; let query = "{ obj { valueAbc } }";
assert_eq!( assert_eq!(
schema.execute(query).await.unwrap_err(), schema.execute(query).await.into_result().unwrap_err(),
Error::Query { Error::Query {
pos: Pos { column: 9, line: 1 }, pos: Pos { column: 9, line: 1 },
path: Some(serde_json::json!(["obj", "valueAbc"])), path: Some(serde_json::json!(["obj", "valueAbc"])),
@ -124,10 +124,7 @@ pub async fn test_field_features() {
} }
); );
let mut stream = schema let mut stream = schema.execute_stream("subscription { values }");
.execute_stream("subscription { values }")
.await
.unwrap();
assert_eq!( assert_eq!(
stream.next().await.map(|resp| resp.data), stream.next().await.map(|resp| resp.data),
Some(serde_json::json!({ Some(serde_json::json!({
@ -135,10 +132,7 @@ pub async fn test_field_features() {
})) }))
); );
let mut stream = schema let mut stream = schema.execute_stream("subscription { valuesBson }");
.execute_stream("subscription { valuesBson }")
.await
.unwrap();
assert_eq!( assert_eq!(
stream.next().await.map(|resp| resp.data), stream.next().await.map(|resp| resp.data),
Some(serde_json::json!({ Some(serde_json::json!({
@ -146,13 +140,14 @@ pub async fn test_field_features() {
})) }))
); );
let err = schema
.execute_stream("subscription { valuesAbc }")
.await
.map(|_| ())
.unwrap_err();
assert_eq!( assert_eq!(
err, schema
.execute_stream("subscription { valuesAbc }")
.next()
.await
.unwrap()
.error
.unwrap(),
Error::Query { Error::Query {
pos: Pos { pos: Pos {
column: 16, column: 16,

View File

@ -22,7 +22,7 @@ pub async fn test_fieldresult() {
let schema = Schema::new(Query, EmptyMutation, EmptySubscription); let schema = Schema::new(Query, EmptyMutation, EmptySubscription);
assert_eq!( assert_eq!(
schema.execute("{ error }").await.unwrap_err(), schema.execute("{ error }").await.into_result().unwrap_err(),
Error::Query { Error::Query {
pos: Pos { line: 1, column: 3 }, pos: Pos { line: 1, column: 3 },
path: Some(serde_json::json!(["error"])), path: Some(serde_json::json!(["error"])),
@ -34,7 +34,11 @@ pub async fn test_fieldresult() {
); );
assert_eq!( assert_eq!(
schema.execute("{ optError }").await.unwrap_err(), schema
.execute("{ optError }")
.await
.into_result()
.unwrap_err(),
Error::Query { Error::Query {
pos: Pos { line: 1, column: 3 }, pos: Pos { line: 1, column: 3 },
path: Some(serde_json::json!(["optError"])), path: Some(serde_json::json!(["optError"])),
@ -46,7 +50,11 @@ pub async fn test_fieldresult() {
); );
assert_eq!( assert_eq!(
schema.execute("{ vecError }").await.unwrap_err(), schema
.execute("{ vecError }")
.await
.into_result()
.unwrap_err(),
Error::Query { Error::Query {
pos: Pos { line: 1, column: 3 }, pos: Pos { line: 1, column: 3 },
path: Some(serde_json::json!(["vecError", 1])), path: Some(serde_json::json!(["vecError", 1])),

View File

@ -90,6 +90,7 @@ pub async fn test_guard() {
schema schema
.execute(Request::new(query).data(Role::Guest)) .execute(Request::new(query).data(Role::Guest))
.await .await
.into_result()
.unwrap_err(), .unwrap_err(),
Error::Query { Error::Query {
pos: Pos { line: 1, column: 9 }, pos: Pos { line: 1, column: 9 },
@ -117,6 +118,7 @@ pub async fn test_guard() {
schema schema
.execute(Request::new(query).data(Role::Guest)) .execute(Request::new(query).data(Role::Guest))
.await .await
.into_result()
.unwrap_err(), .unwrap_err(),
Error::Query { Error::Query {
pos: Pos { line: 1, column: 3 }, pos: Pos { line: 1, column: 3 },
@ -131,8 +133,6 @@ pub async fn test_guard() {
assert_eq!( assert_eq!(
schema schema
.execute_stream(Request::new("subscription { values }").data(Role::Admin)) .execute_stream(Request::new("subscription { values }").data(Role::Admin))
.await
.unwrap()
.map(|item| item.data) .map(|item| item.data)
.collect::<Vec<_>>() .collect::<Vec<_>>()
.await, .await,
@ -146,9 +146,11 @@ pub async fn test_guard() {
assert_eq!( assert_eq!(
schema schema
.execute_stream(Request::new("subscription { values }").data(Role::Guest)) .execute_stream(Request::new("subscription { values }").data(Role::Guest))
.next()
.await .await
.map(|_| ()) .unwrap()
.unwrap_err(), .error
.unwrap(),
Error::Query { Error::Query {
pos: Pos { pos: Pos {
line: 1, line: 1,
@ -195,6 +197,7 @@ pub async fn test_multiple_guards() {
.data(Username("test".to_string())) .data(Username("test".to_string()))
) )
.await .await
.into_result()
.unwrap_err(), .unwrap_err(),
Error::Query { Error::Query {
pos: Pos { line: 1, column: 3 }, pos: Pos { line: 1, column: 3 },
@ -215,6 +218,7 @@ pub async fn test_multiple_guards() {
.data(Username("test1".to_string())) .data(Username("test1".to_string()))
) )
.await .await
.into_result()
.unwrap_err(), .unwrap_err(),
Error::Query { Error::Query {
pos: Pos { line: 1, column: 3 }, pos: Pos { line: 1, column: 3 },
@ -235,6 +239,7 @@ pub async fn test_multiple_guards() {
.data(Username("test1".to_string())) .data(Username("test1".to_string()))
) )
.await .await
.into_result()
.unwrap_err(), .unwrap_err(),
Error::Query { Error::Query {
pos: Pos { line: 1, column: 3 }, pos: Pos { line: 1, column: 3 },
@ -290,6 +295,7 @@ pub async fn test_guard_forward_arguments() {
schema schema
.execute(Request::new(query).data(ID::from("aaa"))) .execute(Request::new(query).data(ID::from("aaa")))
.await .await
.into_result()
.unwrap_err(), .unwrap_err(),
Error::Query { Error::Query {
pos: Pos { line: 1, column: 3 }, pos: Pos { line: 1, column: 3 },

View File

@ -194,6 +194,7 @@ pub async fn test_inputobject_flatten_recursive() {
}"# }"#
) )
.await .await
.into_result()
.unwrap() .unwrap()
.data, .data,
serde_json::json!({ serde_json::json!({
@ -209,6 +210,7 @@ pub async fn test_inputobject_flatten_recursive() {
}"# }"#
) )
.await .await
.into_result()
.unwrap() .unwrap()
.data, .data,
serde_json::json!({ serde_json::json!({
@ -224,6 +226,7 @@ pub async fn test_inputobject_flatten_recursive() {
}"# }"#
) )
.await .await
.into_result()
.unwrap() .unwrap()
.data, .data,
serde_json::json!({ serde_json::json!({

View File

@ -63,6 +63,7 @@ pub async fn test_input_validator_string_min_length() {
schema schema
.execute(&field_query) .execute(&field_query)
.await .await
.into_result()
.expect_err(&should_fail_msg), .expect_err(&should_fail_msg),
Error::Rule { Error::Rule {
errors: vec!(RuleError { errors: vec!(RuleError {
@ -79,6 +80,7 @@ pub async fn test_input_validator_string_min_length() {
schema schema
.execute(&object_query) .execute(&object_query)
.await .await
.into_result()
.expect_err(&should_fail_msg[..]), .expect_err(&should_fail_msg[..]),
Error::Rule { Error::Rule {
errors: vec!(RuleError { errors: vec!(RuleError {
@ -96,6 +98,7 @@ pub async fn test_input_validator_string_min_length() {
schema schema
.execute(&field_query) .execute(&field_query)
.await .await
.into_result()
.expect(&error_msg[..]) .expect(&error_msg[..])
.data, .data,
serde_json::json!({"fieldParameter": true}), serde_json::json!({"fieldParameter": true}),
@ -107,6 +110,7 @@ pub async fn test_input_validator_string_min_length() {
schema schema
.execute(&object_query) .execute(&object_query)
.await .await
.into_result()
.expect(&error_msg[..]) .expect(&error_msg[..])
.data, .data,
serde_json::json!({"inputObject": true}), serde_json::json!({"inputObject": true}),
@ -169,6 +173,7 @@ pub async fn test_input_validator_string_max_length() {
schema schema
.execute(&field_query) .execute(&field_query)
.await .await
.into_result()
.expect_err(&should_fail_msg[..]), .expect_err(&should_fail_msg[..]),
Error::Rule { Error::Rule {
errors: vec!(RuleError { errors: vec!(RuleError {
@ -185,6 +190,7 @@ pub async fn test_input_validator_string_max_length() {
schema schema
.execute(&object_query) .execute(&object_query)
.await .await
.into_result()
.expect_err(&should_fail_msg[..]), .expect_err(&should_fail_msg[..]),
Error::Rule { Error::Rule {
errors: vec!(RuleError { errors: vec!(RuleError {
@ -202,6 +208,7 @@ pub async fn test_input_validator_string_max_length() {
schema schema
.execute(&field_query) .execute(&field_query)
.await .await
.into_result()
.expect(&error_msg[..]) .expect(&error_msg[..])
.data, .data,
serde_json::json!({"fieldParameter": true}), serde_json::json!({"fieldParameter": true}),
@ -213,6 +220,7 @@ pub async fn test_input_validator_string_max_length() {
schema schema
.execute(&object_query) .execute(&object_query)
.await .await
.into_result()
.expect(&error_msg[..]) .expect(&error_msg[..])
.data, .data,
serde_json::json!({"inputObject": true}), serde_json::json!({"inputObject": true}),
@ -302,6 +310,7 @@ pub async fn test_input_validator_string_email() {
schema schema
.execute(&field_query) .execute(&field_query)
.await .await
.into_result()
.expect_err(&should_fail_msg[..]), .expect_err(&should_fail_msg[..]),
Error::Rule { Error::Rule {
errors: vec!(RuleError { errors: vec!(RuleError {
@ -319,6 +328,7 @@ pub async fn test_input_validator_string_email() {
schema schema
.execute(&object_query) .execute(&object_query)
.await .await
.into_result()
.expect_err(&should_fail_msg[..]), .expect_err(&should_fail_msg[..]),
Error::Rule { Error::Rule {
errors: vec!(RuleError { errors: vec!(RuleError {
@ -338,6 +348,7 @@ pub async fn test_input_validator_string_email() {
schema schema
.execute(&field_query) .execute(&field_query)
.await .await
.into_result()
.expect(&error_msg[..]) .expect(&error_msg[..])
.data, .data,
serde_json::json!({"fieldParameter": true}), serde_json::json!({"fieldParameter": true}),
@ -349,6 +360,7 @@ pub async fn test_input_validator_string_email() {
schema schema
.execute(&object_query) .execute(&object_query)
.await .await
.into_result()
.expect(&error_msg[..]) .expect(&error_msg[..])
.data, .data,
serde_json::json!({"inputObject": true}), serde_json::json!({"inputObject": true}),
@ -446,6 +458,7 @@ pub async fn test_input_validator_string_mac() {
schema_without_colon schema_without_colon
.execute(&field_query) .execute(&field_query)
.await .await
.into_result()
.expect_err(&should_fail_msg[..]), .expect_err(&should_fail_msg[..]),
Error::Rule { Error::Rule {
errors: vec!(RuleError { errors: vec!(RuleError {
@ -463,6 +476,7 @@ pub async fn test_input_validator_string_mac() {
schema_without_colon schema_without_colon
.execute(&object_query) .execute(&object_query)
.await .await
.into_result()
.expect_err(&should_fail_msg[..]), .expect_err(&should_fail_msg[..]),
Error::Rule { Error::Rule {
errors: vec!(RuleError { errors: vec!(RuleError {
@ -479,6 +493,7 @@ pub async fn test_input_validator_string_mac() {
schema_with_colon schema_with_colon
.execute(&field_query) .execute(&field_query)
.await .await
.into_result()
.expect_err(&should_fail_msg[..]), .expect_err(&should_fail_msg[..]),
Error::Rule { Error::Rule {
errors: vec!(RuleError { errors: vec!(RuleError {
@ -496,6 +511,7 @@ pub async fn test_input_validator_string_mac() {
schema_with_colon schema_with_colon
.execute(&object_query) .execute(&object_query)
.await .await
.into_result()
.expect_err(&should_fail_msg[..]), .expect_err(&should_fail_msg[..]),
Error::Rule { Error::Rule {
errors: vec!(RuleError { errors: vec!(RuleError {
@ -528,6 +544,7 @@ pub async fn test_input_validator_string_mac() {
schema_with_colon schema_with_colon
.execute(&field_query) .execute(&field_query)
.await .await
.into_result()
.expect(&error_msg[..]) .expect(&error_msg[..])
.data, .data,
serde_json::json!({"fieldParameter": true}), serde_json::json!({"fieldParameter": true}),
@ -539,6 +556,7 @@ pub async fn test_input_validator_string_mac() {
schema_with_colon schema_with_colon
.execute(&object_query) .execute(&object_query)
.await .await
.into_result()
.expect(&error_msg[..]) .expect(&error_msg[..])
.data, .data,
serde_json::json!({"inputObject": true}), serde_json::json!({"inputObject": true}),
@ -550,6 +568,7 @@ pub async fn test_input_validator_string_mac() {
schema_without_colon schema_without_colon
.execute(&field_query) .execute(&field_query)
.await .await
.into_result()
.expect_err(&should_fail_msg[..]), .expect_err(&should_fail_msg[..]),
Error::Rule { Error::Rule {
errors: vec!(RuleError { errors: vec!(RuleError {
@ -567,6 +586,7 @@ pub async fn test_input_validator_string_mac() {
schema_without_colon schema_without_colon
.execute(&object_query) .execute(&object_query)
.await .await
.into_result()
.expect_err(&should_fail_msg[..]), .expect_err(&should_fail_msg[..]),
Error::Rule { Error::Rule {
errors: vec!(RuleError { errors: vec!(RuleError {
@ -583,6 +603,7 @@ pub async fn test_input_validator_string_mac() {
schema_without_colon schema_without_colon
.execute(&field_query) .execute(&field_query)
.await .await
.into_result()
.expect(&error_msg[..]) .expect(&error_msg[..])
.data, .data,
serde_json::json!({"fieldParameter": true}), serde_json::json!({"fieldParameter": true}),
@ -594,6 +615,7 @@ pub async fn test_input_validator_string_mac() {
schema_without_colon schema_without_colon
.execute(&object_query) .execute(&object_query)
.await .await
.into_result()
.expect(&error_msg[..]) .expect(&error_msg[..])
.data, .data,
serde_json::json!({"inputObject": true}), serde_json::json!({"inputObject": true}),
@ -605,6 +627,7 @@ pub async fn test_input_validator_string_mac() {
schema_with_colon schema_with_colon
.execute(&field_query) .execute(&field_query)
.await .await
.into_result()
.expect_err(&should_fail_msg[..]), .expect_err(&should_fail_msg[..]),
Error::Rule { Error::Rule {
errors: vec!(RuleError { errors: vec!(RuleError {
@ -622,6 +645,7 @@ pub async fn test_input_validator_string_mac() {
schema_with_colon schema_with_colon
.execute(&object_query) .execute(&object_query)
.await .await
.into_result()
.expect_err(&should_fail_msg[..]), .expect_err(&should_fail_msg[..]),
Error::Rule { Error::Rule {
errors: vec!(RuleError { errors: vec!(RuleError {
@ -681,6 +705,7 @@ pub async fn test_input_validator_int_range() {
schema schema
.execute(&field_query) .execute(&field_query)
.await .await
.into_result()
.expect_err(&should_fail_msg[..]), .expect_err(&should_fail_msg[..]),
Error::Rule { Error::Rule {
errors: vec!(RuleError { errors: vec!(RuleError {
@ -697,6 +722,7 @@ pub async fn test_input_validator_int_range() {
schema schema
.execute(&object_query) .execute(&object_query)
.await .await
.into_result()
.expect_err(&should_fail_msg[..]), .expect_err(&should_fail_msg[..]),
Error::Rule { Error::Rule {
errors: vec!(RuleError { errors: vec!(RuleError {
@ -714,6 +740,7 @@ pub async fn test_input_validator_int_range() {
schema schema
.execute(&field_query) .execute(&field_query)
.await .await
.into_result()
.expect(&error_msg[..]) .expect(&error_msg[..])
.data, .data,
serde_json::json!({"fieldParameter": true}), serde_json::json!({"fieldParameter": true}),
@ -725,6 +752,7 @@ pub async fn test_input_validator_int_range() {
schema schema
.execute(&object_query) .execute(&object_query)
.await .await
.into_result()
.expect(&error_msg[..]) .expect(&error_msg[..])
.data, .data,
serde_json::json!({"inputObject": true}), serde_json::json!({"inputObject": true}),
@ -782,6 +810,7 @@ pub async fn test_input_validator_int_less_than() {
schema schema
.execute(&field_query) .execute(&field_query)
.await .await
.into_result()
.expect_err(&should_fail_msg[..]), .expect_err(&should_fail_msg[..]),
Error::Rule { Error::Rule {
errors: vec!(RuleError { errors: vec!(RuleError {
@ -798,6 +827,7 @@ pub async fn test_input_validator_int_less_than() {
schema schema
.execute(&object_query) .execute(&object_query)
.await .await
.into_result()
.expect_err(&should_fail_msg[..]), .expect_err(&should_fail_msg[..]),
Error::Rule { Error::Rule {
errors: vec!(RuleError { errors: vec!(RuleError {
@ -815,6 +845,7 @@ pub async fn test_input_validator_int_less_than() {
schema schema
.execute(&field_query) .execute(&field_query)
.await .await
.into_result()
.expect(&error_msg[..]) .expect(&error_msg[..])
.data, .data,
serde_json::json!({"fieldParameter": true}), serde_json::json!({"fieldParameter": true}),
@ -826,6 +857,7 @@ pub async fn test_input_validator_int_less_than() {
schema schema
.execute(&object_query) .execute(&object_query)
.await .await
.into_result()
.expect(&error_msg[..]) .expect(&error_msg[..])
.data, .data,
serde_json::json!({"inputObject": true}), serde_json::json!({"inputObject": true}),
@ -885,6 +917,7 @@ pub async fn test_input_validator_int_greater_than() {
schema schema
.execute(&field_query) .execute(&field_query)
.await .await
.into_result()
.expect_err(&should_fail_msg[..]), .expect_err(&should_fail_msg[..]),
Error::Rule { Error::Rule {
errors: vec!(RuleError { errors: vec!(RuleError {
@ -901,6 +934,7 @@ pub async fn test_input_validator_int_greater_than() {
schema schema
.execute(&object_query) .execute(&object_query)
.await .await
.into_result()
.expect_err(&should_fail_msg[..]), .expect_err(&should_fail_msg[..]),
Error::Rule { Error::Rule {
errors: vec!(RuleError { errors: vec!(RuleError {
@ -918,6 +952,7 @@ pub async fn test_input_validator_int_greater_than() {
schema schema
.execute(&field_query) .execute(&field_query)
.await .await
.into_result()
.expect(&error_msg[..]) .expect(&error_msg[..])
.data, .data,
serde_json::json!({"fieldParameter": true}), serde_json::json!({"fieldParameter": true}),
@ -929,6 +964,7 @@ pub async fn test_input_validator_int_greater_than() {
schema schema
.execute(&object_query) .execute(&object_query)
.await .await
.into_result()
.expect(&error_msg[..]) .expect(&error_msg[..])
.data, .data,
serde_json::json!({"inputObject": true}), serde_json::json!({"inputObject": true}),
@ -981,6 +1017,7 @@ pub async fn test_input_validator_int_nonzero() {
schema schema
.execute(&field_query) .execute(&field_query)
.await .await
.into_result()
.expect_err(&should_fail_msg[..]), .expect_err(&should_fail_msg[..]),
Error::Rule { Error::Rule {
errors: vec!(RuleError { errors: vec!(RuleError {
@ -997,6 +1034,7 @@ pub async fn test_input_validator_int_nonzero() {
schema schema
.execute(&object_query) .execute(&object_query)
.await .await
.into_result()
.expect_err(&should_fail_msg[..]), .expect_err(&should_fail_msg[..]),
Error::Rule { Error::Rule {
errors: vec!(RuleError { errors: vec!(RuleError {
@ -1014,6 +1052,7 @@ pub async fn test_input_validator_int_nonzero() {
schema schema
.execute(&field_query) .execute(&field_query)
.await .await
.into_result()
.expect(&error_msg[..]) .expect(&error_msg[..])
.data, .data,
serde_json::json!({"fieldParameter": true}), serde_json::json!({"fieldParameter": true}),
@ -1025,6 +1064,7 @@ pub async fn test_input_validator_int_nonzero() {
schema schema
.execute(&object_query) .execute(&object_query)
.await .await
.into_result()
.expect(&error_msg[..]) .expect(&error_msg[..])
.data, .data,
serde_json::json!({"inputObject": true}), serde_json::json!({"inputObject": true}),
@ -1059,7 +1099,7 @@ pub async fn test_input_validator_int_equal() {
let schema = Schema::new(QueryRoot, EmptyMutation, EmptySubscription); let schema = Schema::new(QueryRoot, EmptyMutation, EmptySubscription);
let equal_to = 5; let equal_to = 5;
for case in -10..10 { for case in -10i32..10 {
let field_query = format!("{{fieldParameter(id: {})}}", case); let field_query = format!("{{fieldParameter(id: {})}}", case);
let object_query = format!("{{inputObject(input: {{id: {}}})}}", case); let object_query = format!("{{inputObject(input: {{id: {}}})}}", case);
if case != equal_to { if case != equal_to {
@ -1078,6 +1118,7 @@ pub async fn test_input_validator_int_equal() {
schema schema
.execute(&field_query) .execute(&field_query)
.await .await
.into_result()
.expect_err(&should_fail_msg[..]), .expect_err(&should_fail_msg[..]),
Error::Rule { Error::Rule {
errors: vec!(RuleError { errors: vec!(RuleError {
@ -1094,6 +1135,7 @@ pub async fn test_input_validator_int_equal() {
schema schema
.execute(&object_query) .execute(&object_query)
.await .await
.into_result()
.expect_err(&should_fail_msg[..]), .expect_err(&should_fail_msg[..]),
Error::Rule { Error::Rule {
errors: vec!(RuleError { errors: vec!(RuleError {
@ -1111,6 +1153,7 @@ pub async fn test_input_validator_int_equal() {
schema schema
.execute(&field_query) .execute(&field_query)
.await .await
.into_result()
.expect(&error_msg[..]) .expect(&error_msg[..])
.data, .data,
serde_json::json!({"fieldParameter": true}), serde_json::json!({"fieldParameter": true}),
@ -1122,6 +1165,7 @@ pub async fn test_input_validator_int_equal() {
schema schema
.execute(&object_query) .execute(&object_query)
.await .await
.into_result()
.expect(&error_msg[..]) .expect(&error_msg[..])
.data, .data,
serde_json::json!({"inputObject": true}), serde_json::json!({"inputObject": true}),
@ -1190,6 +1234,7 @@ pub async fn test_input_validator_list_max_length() {
schema schema
.execute(&field_query) .execute(&field_query)
.await .await
.into_result()
.expect_err(&should_fail_msg[..]), .expect_err(&should_fail_msg[..]),
Error::Rule { Error::Rule {
errors: vec!(RuleError { errors: vec!(RuleError {
@ -1206,6 +1251,7 @@ pub async fn test_input_validator_list_max_length() {
schema schema
.execute(&object_query) .execute(&object_query)
.await .await
.into_result()
.expect_err(&should_fail_msg[..]), .expect_err(&should_fail_msg[..]),
Error::Rule { Error::Rule {
errors: vec!(RuleError { errors: vec!(RuleError {
@ -1223,6 +1269,7 @@ pub async fn test_input_validator_list_max_length() {
schema schema
.execute(&field_query) .execute(&field_query)
.await .await
.into_result()
.expect(&error_msg[..]) .expect(&error_msg[..])
.data, .data,
serde_json::json!({"fieldParameter": true}), serde_json::json!({"fieldParameter": true}),
@ -1234,6 +1281,7 @@ pub async fn test_input_validator_list_max_length() {
schema schema
.execute(&object_query) .execute(&object_query)
.await .await
.into_result()
.expect(&error_msg[..]) .expect(&error_msg[..])
.data, .data,
serde_json::json!({"inputObject": true}), serde_json::json!({"inputObject": true}),
@ -1302,6 +1350,7 @@ pub async fn test_input_validator_list_min_length() {
schema schema
.execute(&field_query) .execute(&field_query)
.await .await
.into_result()
.expect_err(&should_fail_msg[..]), .expect_err(&should_fail_msg[..]),
Error::Rule { Error::Rule {
errors: vec!(RuleError { errors: vec!(RuleError {
@ -1318,6 +1367,7 @@ pub async fn test_input_validator_list_min_length() {
schema schema
.execute(&object_query) .execute(&object_query)
.await .await
.into_result()
.expect_err(&should_fail_msg[..]), .expect_err(&should_fail_msg[..]),
Error::Rule { Error::Rule {
errors: vec!(RuleError { errors: vec!(RuleError {
@ -1335,6 +1385,7 @@ pub async fn test_input_validator_list_min_length() {
schema schema
.execute(&field_query) .execute(&field_query)
.await .await
.into_result()
.expect(&error_msg[..]) .expect(&error_msg[..])
.data, .data,
serde_json::json!({"fieldParameter": true}), serde_json::json!({"fieldParameter": true}),
@ -1346,6 +1397,7 @@ pub async fn test_input_validator_list_min_length() {
schema schema
.execute(&object_query) .execute(&object_query)
.await .await
.into_result()
.expect(&error_msg[..]) .expect(&error_msg[..])
.data, .data,
serde_json::json!({"inputObject": true}), serde_json::json!({"inputObject": true}),
@ -1422,6 +1474,7 @@ pub async fn test_input_validator_operator_or() {
schema schema
.execute(&field_query) .execute(&field_query)
.await .await
.into_result()
.expect_err(&should_fail_msg[..]), .expect_err(&should_fail_msg[..]),
Error::Rule { Error::Rule {
errors: vec!(RuleError { errors: vec!(RuleError {
@ -1438,6 +1491,7 @@ pub async fn test_input_validator_operator_or() {
schema schema
.execute(&object_query) .execute(&object_query)
.await .await
.into_result()
.expect_err(&should_fail_msg[..]), .expect_err(&should_fail_msg[..]),
Error::Rule { Error::Rule {
errors: vec!(RuleError { errors: vec!(RuleError {
@ -1455,6 +1509,7 @@ pub async fn test_input_validator_operator_or() {
schema schema
.execute(&field_query) .execute(&field_query)
.await .await
.into_result()
.expect(&error_msg[..]) .expect(&error_msg[..])
.data, .data,
serde_json::json!({"fieldParameter": true}), serde_json::json!({"fieldParameter": true}),
@ -1466,6 +1521,7 @@ pub async fn test_input_validator_operator_or() {
schema schema
.execute(&object_query) .execute(&object_query)
.await .await
.into_result()
.expect(&error_msg[..]) .expect(&error_msg[..])
.data, .data,
serde_json::json!({"inputObject": true}), serde_json::json!({"inputObject": true}),
@ -1535,6 +1591,7 @@ pub async fn test_input_validator_operator_and() {
schema schema
.execute(&field_query) .execute(&field_query)
.await .await
.into_result()
.expect_err(&should_fail_msg[..]), .expect_err(&should_fail_msg[..]),
Error::Rule { Error::Rule {
errors: vec!(RuleError { errors: vec!(RuleError {
@ -1551,6 +1608,7 @@ pub async fn test_input_validator_operator_and() {
schema schema
.execute(&object_query) .execute(&object_query)
.await .await
.into_result()
.expect_err(&should_fail_msg[..]), .expect_err(&should_fail_msg[..]),
Error::Rule { Error::Rule {
errors: vec!(RuleError { errors: vec!(RuleError {
@ -1568,6 +1626,7 @@ pub async fn test_input_validator_operator_and() {
schema schema
.execute(&field_query) .execute(&field_query)
.await .await
.into_result()
.expect(&error_msg[..]) .expect(&error_msg[..])
.data, .data,
serde_json::json!({"fieldParameter": true}), serde_json::json!({"fieldParameter": true}),
@ -1579,6 +1638,7 @@ pub async fn test_input_validator_operator_and() {
schema schema
.execute(&object_query) .execute(&object_query)
.await .await
.into_result()
.expect(&error_msg[..]) .expect(&error_msg[..])
.data, .data,
serde_json::json!({"inputObject": true}), serde_json::json!({"inputObject": true}),
@ -1654,6 +1714,7 @@ pub async fn test_input_validator_variable() {
schema schema
.execute(Request::new(field_query).variables(variables.clone())) .execute(Request::new(field_query).variables(variables.clone()))
.await .await
.into_result()
.expect_err(&should_fail_msg[..]), .expect_err(&should_fail_msg[..]),
Error::Rule { Error::Rule {
errors: vec!(RuleError { errors: vec!(RuleError {
@ -1670,6 +1731,7 @@ pub async fn test_input_validator_variable() {
schema schema
.execute(Request::new(object_query).variables(variables.clone())) .execute(Request::new(object_query).variables(variables.clone()))
.await .await
.into_result()
.expect_err(&should_fail_msg[..]), .expect_err(&should_fail_msg[..]),
Error::Rule { Error::Rule {
errors: vec!(RuleError { errors: vec!(RuleError {
@ -1687,6 +1749,7 @@ pub async fn test_input_validator_variable() {
schema schema
.execute(Request::new(field_query).variables(variables.clone())) .execute(Request::new(field_query).variables(variables.clone()))
.await .await
.into_result()
.expect(&error_msg[..]) .expect(&error_msg[..])
.data, .data,
serde_json::json!({"fieldParameter": true}), serde_json::json!({"fieldParameter": true}),
@ -1698,6 +1761,7 @@ pub async fn test_input_validator_variable() {
schema schema
.execute(Request::new(object_query).variables(variables.clone())) .execute(Request::new(object_query).variables(variables.clone()))
.await .await
.into_result()
.expect(&error_msg[..]) .expect(&error_msg[..])
.data, .data,
serde_json::json!({"inputObject": true}), serde_json::json!({"inputObject": true}),

View File

@ -14,7 +14,7 @@ pub async fn test_input_value_custom_error() {
let schema = Schema::new(Query, EmptyMutation, EmptySubscription); let schema = Schema::new(Query, EmptyMutation, EmptySubscription);
let query = r#"{ parseInt(n:289) }"#; let query = r#"{ parseInt(n:289) }"#;
assert_eq!( assert_eq!(
schema.execute(query).await.unwrap_err(), schema.execute(query).await.into_result().unwrap_err(),
Error::Query { Error::Query {
pos: Pos { pos: Pos {
line: 1, line: 1,

View File

@ -35,7 +35,7 @@ pub async fn test_interface_simple_object() {
}"#; }"#;
let schema = Schema::new(Query, EmptyMutation, EmptySubscription); let schema = Schema::new(Query, EmptyMutation, EmptySubscription);
assert_eq!( assert_eq!(
schema.execute(query).await.unwrap().data, schema.execute(query).await.into_result().unwrap().data,
serde_json::json!({ serde_json::json!({
"node": { "node": {
"id": 33, "id": 33,
@ -79,7 +79,7 @@ pub async fn test_interface_simple_object2() {
}"#; }"#;
let schema = Schema::new(Query, EmptyMutation, EmptySubscription); let schema = Schema::new(Query, EmptyMutation, EmptySubscription);
assert_eq!( assert_eq!(
schema.execute(query).await.unwrap().data, schema.execute(query).await.into_result().unwrap().data,
serde_json::json!({ serde_json::json!({
"node": { "node": {
"id": 33, "id": 33,
@ -143,7 +143,7 @@ pub async fn test_multiple_interfaces() {
} }
}"#; }"#;
assert_eq!( assert_eq!(
schema.execute(query).await.unwrap().data, schema.execute(query).await.into_result().unwrap().data,
serde_json::json!({ serde_json::json!({
"myObj": { "myObj": {
"valueA": 1, "valueA": 1,
@ -219,7 +219,7 @@ pub async fn test_multiple_objects_in_multiple_interfaces() {
} }
}"#; }"#;
assert_eq!( assert_eq!(
schema.execute(query).await.unwrap().data, schema.execute(query).await.into_result().unwrap().data,
serde_json::json!({ serde_json::json!({
"myObj": [{ "myObj": [{
"valueA": 1, "valueA": 1,
@ -266,7 +266,7 @@ pub async fn test_interface_field_result() {
}"#; }"#;
let schema = Schema::new(Query, EmptyMutation, EmptySubscription); let schema = Schema::new(Query, EmptyMutation, EmptySubscription);
assert_eq!( assert_eq!(
schema.execute(query).await.unwrap().data, schema.execute(query).await.into_result().unwrap().data,
serde_json::json!({ serde_json::json!({
"node": { "node": {
"value": 10, "value": 10,
@ -315,7 +315,7 @@ pub async fn test_interface_field_method() {
let query = "{ test { created_at } }"; let query = "{ test { created_at } }";
let schema = Schema::new(Query, EmptyMutation, EmptySubscription); let schema = Schema::new(Query, EmptyMutation, EmptySubscription);
assert_eq!( assert_eq!(
schema.execute(query).await.unwrap().data, schema.execute(query).await.into_result().unwrap().data,
serde_json::json!({ serde_json::json!({
"test": { "test": {
"created_at": 1, "created_at": 1,

View File

@ -349,7 +349,7 @@ pub async fn test_introspection_deprecation() {
} }
}); });
let mut res = schema.execute(&query).await.unwrap().data; let mut res = schema.execute(&query).await.into_result().unwrap().data;
assert_eq!(res, res_json); assert_eq!(res, res_json);
@ -408,7 +408,7 @@ pub async fn test_introspection_deprecation() {
} }
}); });
res = schema.execute(&query).await.unwrap().data; res = schema.execute(&query).await.into_result().unwrap().data;
assert_eq!(res, res_json); assert_eq!(res, res_json);
@ -427,7 +427,7 @@ pub async fn test_introspection_deprecation() {
} }
}); });
res = schema.execute(&query).await.unwrap().data; res = schema.execute(&query).await.into_result().unwrap().data;
assert_eq!(res, res_json); assert_eq!(res, res_json);
@ -440,7 +440,7 @@ pub async fn test_introspection_deprecation() {
} }
}); });
res = schema.execute(&query).await.unwrap().data; res = schema.execute(&query).await.into_result().unwrap().data;
assert_eq!(res, res_json); assert_eq!(res, res_json);
@ -481,7 +481,7 @@ pub async fn test_introspection_deprecation() {
} }
}); });
res = schema.execute(&query).await.unwrap().data; res = schema.execute(&query).await.into_result().unwrap().data;
assert_eq!(res, res_json); assert_eq!(res, res_json);
@ -500,7 +500,7 @@ pub async fn test_introspection_deprecation() {
} }
}); });
res = schema.execute(&query).await.unwrap().data; res = schema.execute(&query).await.into_result().unwrap().data;
assert_eq!(res, res_json); assert_eq!(res, res_json);
} }
@ -531,7 +531,7 @@ pub async fn test_introspection_type_kind() {
} }
}); });
let mut res = schema.execute(&query).await.unwrap().data; let mut res = schema.execute(&query).await.into_result().unwrap().data;
assert_eq!(res, res_json); assert_eq!(res, res_json);
@ -545,7 +545,7 @@ pub async fn test_introspection_type_kind() {
} }
}); });
res = schema.execute(&query).await.unwrap().data; res = schema.execute(&query).await.into_result().unwrap().data;
assert_eq!(res, res_json); assert_eq!(res, res_json);
@ -559,7 +559,7 @@ pub async fn test_introspection_type_kind() {
} }
}); });
res = schema.execute(&query).await.unwrap().data; res = schema.execute(&query).await.into_result().unwrap().data;
assert_eq!(res, res_json); assert_eq!(res, res_json);
@ -573,7 +573,7 @@ pub async fn test_introspection_type_kind() {
} }
}); });
res = schema.execute(&query).await.unwrap().data; res = schema.execute(&query).await.into_result().unwrap().data;
assert_eq!(res, res_json); assert_eq!(res, res_json);
@ -587,7 +587,7 @@ pub async fn test_introspection_type_kind() {
} }
}); });
res = schema.execute(&query).await.unwrap().data; res = schema.execute(&query).await.into_result().unwrap().data;
assert_eq!(res, res_json); assert_eq!(res, res_json);
@ -626,7 +626,7 @@ pub async fn test_introspection_type_kind() {
} }
}); });
res = schema.execute(&query).await.unwrap().data; res = schema.execute(&query).await.into_result().unwrap().data;
assert_eq!(res, res_json); assert_eq!(res, res_json);
@ -659,7 +659,7 @@ pub async fn test_introspection_type_kind() {
} }
}); });
res = schema.execute(&query).await.unwrap().data; res = schema.execute(&query).await.into_result().unwrap().data;
assert_eq!(res, res_json); assert_eq!(res, res_json);
} }
@ -686,7 +686,7 @@ pub async fn test_introspection_scalar() {
} }
}); });
let res = schema.execute(query).await.unwrap().data; let res = schema.execute(query).await.into_result().unwrap().data;
assert_eq!(res, res_json) assert_eq!(res, res_json)
} }
@ -722,7 +722,7 @@ pub async fn test_introspection_union() {
} }
}); });
let res = schema.execute(query).await.unwrap().data; let res = schema.execute(query).await.into_result().unwrap().data;
assert_eq!(res, res_json) assert_eq!(res, res_json)
} }
@ -765,7 +765,7 @@ pub async fn test_introspection_interface() {
} }
}); });
let mut res = schema.execute(query).await.unwrap().data; let mut res = schema.execute(query).await.into_result().unwrap().data;
assert_eq!(res, res_json); assert_eq!(res, res_json);
@ -800,7 +800,7 @@ pub async fn test_introspection_interface() {
} }
}); });
res = schema.execute(query).await.unwrap().data; res = schema.execute(query).await.into_result().unwrap().data;
assert_eq!(res, res_json); assert_eq!(res, res_json);
} }
@ -847,7 +847,7 @@ pub async fn test_introspection_enum() {
} }
}); });
let res = schema.execute(query).await.unwrap().data; let res = schema.execute(query).await.into_result().unwrap().data;
println!("{}", serde_json::to_string_pretty(&res).unwrap()); println!("{}", serde_json::to_string_pretty(&res).unwrap());
@ -882,7 +882,7 @@ pub async fn test_introspection_input_object() {
} }
}); });
let res = schema.execute(query).await.unwrap().data; let res = schema.execute(query).await.into_result().unwrap().data;
assert_eq!(res, res_json) assert_eq!(res, res_json)
} }
@ -930,7 +930,7 @@ pub async fn test_introspection_mutation() {
} }
}); });
let res = schema.execute(query).await.unwrap().data; let res = schema.execute(query).await.into_result().unwrap().data;
assert_eq!(res, res_json) assert_eq!(res, res_json)
} }
@ -978,7 +978,7 @@ pub async fn test_introspection_subscription() {
} }
}); });
let res = schema.execute(query).await.unwrap().data; let res = schema.execute(query).await.into_result().unwrap().data;
assert_eq!(res, res_json) assert_eq!(res, res_json)
} }

View File

@ -45,7 +45,7 @@ pub async fn test_merged_object() {
let schema = Schema::new(Query, EmptyMutation, EmptySubscription); let schema = Schema::new(Query, EmptyMutation, EmptySubscription);
let query = "{ obj { a b c } }"; let query = "{ obj { a b c } }";
assert_eq!( assert_eq!(
schema.execute(query).await.unwrap().data, schema.execute(query).await.into_result().unwrap().data,
serde_json::json!({ serde_json::json!({
"obj": { "obj": {
"a": 10, "a": 10,
@ -73,7 +73,7 @@ pub async fn test_merged_object_macro() {
let schema = Schema::new(Query, EmptyMutation, EmptySubscription); let schema = Schema::new(Query, EmptyMutation, EmptySubscription);
let query = "{ obj { a b c } }"; let query = "{ obj { a b c } }";
assert_eq!( assert_eq!(
schema.execute(query).await.unwrap().data, schema.execute(query).await.into_result().unwrap().data,
serde_json::json!({ serde_json::json!({
"obj": { "obj": {
"a": 10, "a": 10,
@ -101,7 +101,7 @@ pub async fn test_merged_object_derive() {
let schema = Schema::new(Query, EmptyMutation, EmptySubscription); let schema = Schema::new(Query, EmptyMutation, EmptySubscription);
let query = "{ obj { a b c } }"; let query = "{ obj { a b c } }";
assert_eq!( assert_eq!(
schema.execute(query).await.unwrap().data, schema.execute(query).await.into_result().unwrap().data,
serde_json::json!({ serde_json::json!({
"obj": { "obj": {
"a": 10, "a": 10,
@ -150,7 +150,7 @@ pub async fn test_merged_object_default() {
let schema = Schema::new(Query::default(), EmptyMutation, EmptySubscription); let schema = Schema::new(Query::default(), EmptyMutation, EmptySubscription);
let query = "{ a b }"; let query = "{ a b }";
assert_eq!( assert_eq!(
schema.execute(query).await.unwrap().data, schema.execute(query).await.into_result().unwrap().data,
serde_json::json!({ serde_json::json!({
"a": 10, "a": 10,
"b": 20, "b": 20,
@ -193,9 +193,7 @@ pub async fn test_merged_subscription() {
{ {
let mut stream = schema let mut stream = schema
.execute_stream("subscription { events1 }") .execute_stream("subscription { events1 }")
.await .map(|resp| resp.into_result().unwrap().data);
.unwrap()
.map(|resp| resp.unwrap().data);
for i in 0i32..10 { for i in 0i32..10 {
assert_eq!( assert_eq!(
Some(serde_json::json!({ Some(serde_json::json!({
@ -210,9 +208,7 @@ pub async fn test_merged_subscription() {
{ {
let mut stream = schema let mut stream = schema
.execute_stream("subscription { events2 }") .execute_stream("subscription { events2 }")
.await .map(|resp| resp.into_result().unwrap().data);
.unwrap()
.map(|resp| resp.unwrap().data);
for i in 10i32..20 { for i in 10i32..20 {
assert_eq!( assert_eq!(
Some(serde_json::json!({ Some(serde_json::json!({

View File

@ -93,6 +93,7 @@ pub async fn test_post_guard() {
schema schema
.execute(Request::new(query).data(Username("test1".to_string()))) .execute(Request::new(query).data(Username("test1".to_string())))
.await .await
.into_result()
.unwrap_err(), .unwrap_err(),
Error::Query { Error::Query {
pos: Pos { line: 1, column: 3 }, pos: Pos { line: 1, column: 3 },
@ -120,6 +121,7 @@ pub async fn test_post_guard() {
schema schema
.execute(Request::new(query).data(Username("test1".to_string()))) .execute(Request::new(query).data(Username("test1".to_string())))
.await .await
.into_result()
.unwrap_err(), .unwrap_err(),
Error::Query { Error::Query {
pos: Pos { line: 1, column: 9 }, pos: Pos { line: 1, column: 9 },
@ -167,6 +169,7 @@ pub async fn test_multiple_post_guards() {
.data(Username("test".to_string())) .data(Username("test".to_string()))
) )
.await .await
.into_result()
.unwrap_err(), .unwrap_err(),
Error::Query { Error::Query {
pos: Pos { line: 1, column: 3 }, pos: Pos { line: 1, column: 3 },
@ -187,6 +190,7 @@ pub async fn test_multiple_post_guards() {
.data(Username("test1".to_string())) .data(Username("test1".to_string()))
) )
.await .await
.into_result()
.unwrap_err(), .unwrap_err(),
Error::Query { Error::Query {
pos: Pos { line: 1, column: 3 }, pos: Pos { line: 1, column: 3 },
@ -207,6 +211,7 @@ pub async fn test_multiple_post_guards() {
.data(Username("test1".to_string())) .data(Username("test1".to_string()))
) )
.await .await
.into_result()
.unwrap_err(), .unwrap_err(),
Error::Query { Error::Query {
pos: Pos { line: 1, column: 3 }, pos: Pos { line: 1, column: 3 },
@ -263,6 +268,7 @@ pub async fn test_post_guard_forward_arguments() {
schema schema
.execute(Request::new(query).data(ID::from("aaa"))) .execute(Request::new(query).data(ID::from("aaa")))
.await .await
.into_result()
.unwrap_err(), .unwrap_err(),
Error::Query { Error::Query {
pos: Pos { line: 1, column: 3 }, pos: Pos { line: 1, column: 3 },
@ -318,6 +324,7 @@ pub async fn test_post_guard_generic() {
schema schema
.execute(Request::new(query).data(ID::from("aaa"))) .execute(Request::new(query).data(ID::from("aaa")))
.await .await
.into_result()
.unwrap_err(), .unwrap_err(),
Error::Query { Error::Query {
pos: Pos { line: 1, column: 3 }, pos: Pos { line: 1, column: 3 },

View File

@ -53,7 +53,7 @@ pub async fn test_input_value_custom_error() {
enumValue(value: TYPE) enumValue(value: TYPE)
}"#; }"#;
assert_eq!( assert_eq!(
schema.execute(query).await.unwrap().data, schema.execute(query).await.into_result().unwrap().data,
serde_json::json!({ serde_json::json!({
"type": 99, "type": 99,
"obj": { "i32": 88 }, "obj": { "i32": 88 },
@ -63,8 +63,6 @@ pub async fn test_input_value_custom_error() {
let mut stream = schema let mut stream = schema
.execute_stream("subscription { type }") .execute_stream("subscription { type }")
.await
.unwrap()
.map(|resp| resp.into_result()) .map(|resp| resp.into_result())
.map_ok(|resp| resp.data); .map_ok(|resp| resp.data);
for i in 0..10 { for i in 0..10 {

View File

@ -32,9 +32,7 @@ pub async fn test_subscription() {
{ {
let mut stream = schema let mut stream = schema
.execute_stream("subscription { values(start: 10, end: 20) }") .execute_stream("subscription { values(start: 10, end: 20) }")
.await .map(|resp| resp.into_result().unwrap().data);
.unwrap()
.map(|resp| resp.unwrap().data);
for i in 10..20 { for i in 10..20 {
assert_eq!( assert_eq!(
Some(serde_json::json!({ "values": i })), Some(serde_json::json!({ "values": i })),
@ -47,9 +45,7 @@ pub async fn test_subscription() {
{ {
let mut stream = schema let mut stream = schema
.execute_stream("subscription { events(start: 10, end: 20) { a b } }") .execute_stream("subscription { events(start: 10, end: 20) { a b } }")
.await .map(|resp| resp.into_result().unwrap().data);
.unwrap()
.map(|resp| resp.unwrap().data);
for i in 10..20 { for i in 10..20 {
assert_eq!( assert_eq!(
Some(serde_json::json!({ "events": {"a": i, "b": i * 10} })), Some(serde_json::json!({ "events": {"a": i, "b": i * 10} })),
@ -84,30 +80,27 @@ pub async fn test_simple_broker() {
#[Subscription] #[Subscription]
impl SubscriptionRoot { impl SubscriptionRoot {
async fn events1(&self) -> impl Stream<Item = Event1> { async fn events1(&self) -> impl Stream<Item = Event1> {
SimpleBroker::<Event1>::subscribe() let stream = SimpleBroker::<Event1>::subscribe();
SimpleBroker::publish(Event1 { value: 10 });
SimpleBroker::publish(Event1 { value: 15 });
stream
} }
async fn events2(&self) -> impl Stream<Item = Event2> { async fn events2(&self) -> impl Stream<Item = Event2> {
SimpleBroker::<Event2>::subscribe() let stream = SimpleBroker::<Event2>::subscribe();
SimpleBroker::publish(Event2 { value: 88 });
SimpleBroker::publish(Event2 { value: 99 });
stream
} }
} }
let schema = Schema::new(QueryRoot, EmptyMutation, SubscriptionRoot); let schema = Schema::new(QueryRoot, EmptyMutation, SubscriptionRoot);
let mut stream1 = schema let mut stream1 = schema
.execute_stream("subscription { events1 { value } }") .execute_stream("subscription { events1 { value } }")
.await .map(|resp| resp.into_result().unwrap().data);
.unwrap()
.map(|resp| resp.unwrap().data);
let mut stream2 = schema let mut stream2 = schema
.execute_stream("subscription { events2 { value } }") .execute_stream("subscription { events2 { value } }")
.await .map(|resp| resp.into_result().unwrap().data);
.unwrap()
.map(|resp| resp.unwrap().data);
SimpleBroker::publish(Event1 { value: 10 });
SimpleBroker::publish(Event2 { value: 88 });
SimpleBroker::publish(Event1 { value: 15 });
SimpleBroker::publish(Event2 { value: 99 });
assert_eq!( assert_eq!(
stream1.next().await, stream1.next().await,
@ -163,8 +156,6 @@ pub async fn test_subscription_with_ctx_data() {
{ {
let mut stream = schema let mut stream = schema
.execute_stream(Request::new("subscription { values objects { value } }").data(100i32)) .execute_stream(Request::new("subscription { values objects { value } }").data(100i32))
.await
.unwrap()
.map(|resp| resp.data); .map(|resp| resp.data);
assert_eq!( assert_eq!(
Some(serde_json::json!({ "values": 100 })), Some(serde_json::json!({ "values": 100 })),
@ -206,9 +197,7 @@ pub async fn test_subscription_with_token() {
.execute_stream( .execute_stream(
Request::new("subscription { values }").data(Token("123456".to_string())), Request::new("subscription { values }").data(Token("123456".to_string())),
) )
.await .map(|resp| resp.into_result().unwrap().data);
.unwrap()
.map(|resp| resp.unwrap().data);
assert_eq!( assert_eq!(
Some(serde_json::json!({ "values": 100 })), Some(serde_json::json!({ "values": 100 })),
stream.next().await stream.next().await
@ -221,7 +210,9 @@ pub async fn test_subscription_with_token() {
.execute_stream( .execute_stream(
Request::new("subscription { values }").data(Token("654321".to_string())) Request::new("subscription { values }").data(Token("654321".to_string()))
) )
.next()
.await .await
.unwrap()
.is_err()); .is_err());
} }
} }
@ -262,8 +253,6 @@ pub async fn test_subscription_inline_fragment() {
} }
"#, "#,
) )
.await
.unwrap()
.map(|resp| resp.data); .map(|resp| resp.data);
for i in 10..20 { for i in 10..20 {
assert_eq!( assert_eq!(
@ -317,8 +306,6 @@ pub async fn test_subscription_fragment() {
} }
"#, "#,
) )
.await
.unwrap()
.map(|resp| resp.data); .map(|resp| resp.data);
for i in 10..20 { for i in 10..20 {
assert_eq!( assert_eq!(
@ -373,8 +360,6 @@ pub async fn test_subscription_fragment2() {
} }
"#, "#,
) )
.await
.unwrap()
.map(|resp| resp.data); .map(|resp| resp.data);
for i in 10..20 { for i in 10..20 {
assert_eq!( assert_eq!(
@ -419,8 +404,6 @@ pub async fn test_subscription_error() {
let schema = Schema::new(QueryRoot, EmptyMutation, SubscriptionRoot); let schema = Schema::new(QueryRoot, EmptyMutation, SubscriptionRoot);
let mut stream = schema let mut stream = schema
.execute_stream("subscription { events { value } }") .execute_stream("subscription { events { value } }")
.await
.unwrap()
.map(|resp| resp.into_result()) .map(|resp| resp.into_result())
.map_ok(|resp| resp.data); .map_ok(|resp| resp.data);
for i in 0i32..5 { for i in 0i32..5 {
@ -470,8 +453,6 @@ pub async fn test_subscription_fieldresult() {
let schema = Schema::new(QueryRoot, EmptyMutation, SubscriptionRoot); let schema = Schema::new(QueryRoot, EmptyMutation, SubscriptionRoot);
let mut stream = schema let mut stream = schema
.execute_stream("subscription { values }") .execute_stream("subscription { values }")
.await
.unwrap()
.map(|resp| resp.into_result()) .map(|resp| resp.into_result())
.map_ok(|resp| resp.data); .map_ok(|resp| resp.data);
for i in 0i32..5 { for i in 0i32..5 {

View File

@ -35,7 +35,7 @@ pub async fn test_union_simple_object() {
}"#; }"#;
let schema = Schema::new(Query, EmptyMutation, EmptySubscription); let schema = Schema::new(Query, EmptyMutation, EmptySubscription);
assert_eq!( assert_eq!(
schema.execute(query).await.unwrap().data, schema.execute(query).await.into_result().unwrap().data,
serde_json::json!({ serde_json::json!({
"node": { "node": {
"id": 33, "id": 33,
@ -79,7 +79,7 @@ pub async fn test_union_simple_object2() {
}"#; }"#;
let schema = Schema::new(Query, EmptyMutation, EmptySubscription); let schema = Schema::new(Query, EmptyMutation, EmptySubscription);
assert_eq!( assert_eq!(
schema.execute(query).await.unwrap().data, schema.execute(query).await.into_result().unwrap().data,
serde_json::json!({ serde_json::json!({
"node": { "node": {
"id": 33, "id": 33,
@ -149,7 +149,7 @@ pub async fn test_multiple_unions() {
} }
}"#; }"#;
assert_eq!( assert_eq!(
schema.execute(query).await.unwrap().data, schema.execute(query).await.into_result().unwrap().data,
serde_json::json!({ serde_json::json!({
"unionA": { "unionA": {
"valueA": 1, "valueA": 1,
@ -229,7 +229,7 @@ pub async fn test_multiple_objects_in_multiple_unions() {
} }
}"#; }"#;
assert_eq!( assert_eq!(
schema.execute(query).await.unwrap().data, schema.execute(query).await.into_result().unwrap().data,
serde_json::json!({ serde_json::json!({
"myObj": [{ "myObj": [{
"valueA": 1, "valueA": 1,
@ -276,7 +276,7 @@ pub async fn test_union_field_result() {
}"#; }"#;
let schema = Schema::new(Query, EmptyMutation, EmptySubscription); let schema = Schema::new(Query, EmptyMutation, EmptySubscription);
assert_eq!( assert_eq!(
schema.execute(query).await.unwrap().data, schema.execute(query).await.into_result().unwrap().data,
serde_json::json!({ serde_json::json!({
"node": { "node": {
"value": 10, "value": 10,

View File

@ -88,6 +88,7 @@ pub async fn test_variable_no_value() {
"#, "#,
)) ))
.await .await
.into_result()
.unwrap(); .unwrap();
assert_eq!( assert_eq!(
resp.data, resp.data,