Async tests (#559)

Convert more tests to async
This commit is contained in:
Christian Legnitto 2020-03-10 19:11:40 -07:00 committed by GitHub
parent 961a07125f
commit 48c924ea27
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 358 additions and 290 deletions

View file

@ -74,8 +74,8 @@ impl Root {
}
}
#[test]
fn test_execution() {
#[tokio::test]
async fn test_execution() {
let doc = r#"
{
sampleEnum
@ -85,8 +85,9 @@ fn test_execution() {
"#;
let schema = RootNode::new(Root, EmptyMutation::<()>::new());
let (result, errs) =
crate::execute_sync(doc, None, &schema, &Variables::new(), &()).expect("Execution failed");
let (result, errs) = crate::execute(doc, None, &schema, &Variables::new(), &())
.await
.expect("Execution failed");
assert_eq!(errs, []);
@ -106,8 +107,8 @@ fn test_execution() {
);
}
#[test]
fn enum_introspection() {
#[tokio::test]
async fn enum_introspection() {
let doc = r#"
{
__type(name: "SampleEnum") {
@ -129,8 +130,9 @@ fn enum_introspection() {
"#;
let schema = RootNode::new(Root, EmptyMutation::<()>::new());
let (result, errs) =
crate::execute_sync(doc, None, &schema, &Variables::new(), &()).expect("Execution failed");
let (result, errs) = crate::execute(doc, None, &schema, &Variables::new(), &())
.await
.expect("Execution failed");
assert_eq!(errs, []);
@ -201,8 +203,8 @@ fn enum_introspection() {
)));
}
#[test]
fn interface_introspection() {
#[tokio::test]
async fn interface_introspection() {
let doc = r#"
{
__type(name: "SampleInterface") {
@ -238,8 +240,9 @@ fn interface_introspection() {
"#;
let schema = RootNode::new(Root, EmptyMutation::<()>::new());
let (result, errs) =
crate::execute_sync(doc, None, &schema, &Variables::new(), &()).expect("Execution failed");
let (result, errs) = crate::execute(doc, None, &schema, &Variables::new(), &())
.await
.expect("Execution failed");
assert_eq!(errs, []);
@ -337,8 +340,8 @@ fn interface_introspection() {
)));
}
#[test]
fn object_introspection() {
#[tokio::test]
async fn object_introspection() {
let doc = r#"
{
__type(name: "Root") {
@ -385,8 +388,9 @@ fn object_introspection() {
"#;
let schema = RootNode::new(Root, EmptyMutation::<()>::new());
let (result, errs) =
crate::execute_sync(doc, None, &schema, &Variables::new(), &()).expect("Execution failed");
let (result, errs) = crate::execute(doc, None, &schema, &Variables::new(), &())
.await
.expect("Execution failed");
assert_eq!(errs, []);
@ -573,8 +577,8 @@ fn object_introspection() {
)));
}
#[test]
fn scalar_introspection() {
#[tokio::test]
async fn scalar_introspection() {
let doc = r#"
{
__type(name: "SampleScalar") {
@ -592,8 +596,9 @@ fn scalar_introspection() {
"#;
let schema = RootNode::new(Root, EmptyMutation::<()>::new());
let (result, errs) =
crate::execute_sync(doc, None, &schema, &Variables::new(), &()).expect("Execution failed");
let (result, errs) = crate::execute(doc, None, &schema, &Variables::new(), &())
.await
.expect("Execution failed");
assert_eq!(errs, []);

View file

@ -206,8 +206,8 @@ mod integration_test {
executor::Variables, schema::model::RootNode, types::scalars::EmptyMutation, value::Value,
};
#[test]
fn test_serialization() {
#[tokio::test]
async fn test_serialization() {
struct Root;
#[crate::graphql_object_internal]
@ -237,7 +237,8 @@ mod integration_test {
let schema = RootNode::new(Root, EmptyMutation::<()>::new());
let (result, errs) = crate::execute_sync(doc, None, &schema, &Variables::new(), &())
let (result, errs) = crate::execute(doc, None, &schema, &Variables::new(), &())
.await
.expect("Execution failed");
assert_eq!(errs, []);

View file

@ -138,7 +138,7 @@ impl Root {
}
}
fn run_args_info_query<F>(field_name: &str, f: F)
async fn run_args_info_query<F>(field_name: &str, f: F)
where
F: Fn(&Vec<Value<DefaultScalarValue>>) -> (),
{
@ -164,8 +164,9 @@ where
"#;
let schema = RootNode::new(Root {}, EmptyMutation::<()>::new());
let (result, errs) =
crate::execute_sync(doc, None, &schema, &Variables::new(), &()).expect("Execution failed");
let (result, errs) = crate::execute(doc, None, &schema, &Variables::new(), &())
.await
.expect("Execution failed");
assert_eq!(errs, []);
@ -214,22 +215,24 @@ where
f(args);
}
#[test]
fn introspect_field_simple() {
#[tokio::test]
async fn introspect_field_simple() {
run_args_info_query("simple", |args| {
assert_eq!(args.len(), 0);
});
})
.await;
}
#[test]
fn introspect_field_exec_arg() {
#[tokio::test]
async fn introspect_field_exec_arg() {
run_args_info_query("execArg", |args| {
assert_eq!(args.len(), 0);
});
})
.await;
}
#[test]
fn introspect_field_exec_arg_and_more() {
#[tokio::test]
async fn introspect_field_exec_arg_and_more() {
run_args_info_query("execArgAndMore", |args| {
assert_eq!(args.len(), 1);
@ -258,11 +261,12 @@ fn introspect_field_exec_arg_and_more() {
.into_iter()
.collect(),
)));
});
})
.await;
}
#[test]
fn introspect_field_single_arg() {
#[tokio::test]
async fn introspect_field_single_arg() {
run_args_info_query("singleArg", |args| {
assert_eq!(args.len(), 1);
@ -291,11 +295,12 @@ fn introspect_field_single_arg() {
.into_iter()
.collect(),
)));
});
})
.await;
}
#[test]
fn introspect_field_multi_args() {
#[tokio::test]
async fn introspect_field_multi_args() {
run_args_info_query("multiArgs", |args| {
assert_eq!(args.len(), 2);
@ -350,11 +355,12 @@ fn introspect_field_multi_args() {
.into_iter()
.collect(),
)));
});
})
.await;
}
#[test]
fn introspect_field_multi_args_trailing_comma() {
#[tokio::test]
async fn introspect_field_multi_args_trailing_comma() {
run_args_info_query("multiArgsTrailingComma", |args| {
assert_eq!(args.len(), 2);
@ -409,11 +415,12 @@ fn introspect_field_multi_args_trailing_comma() {
.into_iter()
.collect(),
)));
});
})
.await;
}
#[test]
fn introspect_field_single_arg_descr() {
#[tokio::test]
async fn introspect_field_single_arg_descr() {
run_args_info_query("singleArgDescr", |args| {
assert_eq!(args.len(), 1);
@ -442,11 +449,12 @@ fn introspect_field_single_arg_descr() {
.into_iter()
.collect(),
)));
});
})
.await;
}
#[test]
fn introspect_field_multi_args_descr() {
#[tokio::test]
async fn introspect_field_multi_args_descr() {
run_args_info_query("multiArgsDescr", |args| {
assert_eq!(args.len(), 2);
@ -501,11 +509,12 @@ fn introspect_field_multi_args_descr() {
.into_iter()
.collect(),
)));
});
})
.await;
}
#[test]
fn introspect_field_multi_args_descr_trailing_comma() {
#[tokio::test]
async fn introspect_field_multi_args_descr_trailing_comma() {
run_args_info_query("multiArgsDescrTrailingComma", |args| {
assert_eq!(args.len(), 2);
@ -560,12 +569,13 @@ fn introspect_field_multi_args_descr_trailing_comma() {
.into_iter()
.collect(),
)));
});
})
.await;
}
// TODO: enable once [parameter attributes are supported by proc macros]
// (https://github.com/graphql-rust/juniper/pull/441)
// #[test]
// #[tokio::test]
// fn introspect_field_attr_arg_descr() {
// run_args_info_query("attrArgDescr", |args| {
// assert_eq!(args.len(), 1);
@ -600,7 +610,7 @@ fn introspect_field_multi_args_descr_trailing_comma() {
// TODO: enable once [parameter attributes are supported by proc macros]
// (https://github.com/graphql-rust/juniper/pull/441)
// #[test]
// #[tokio::test]
// fn introspect_field_attr_arg_descr_collapse() {
// run_args_info_query("attrArgDescrCollapse", |args| {
// assert_eq!(args.len(), 1);
@ -633,8 +643,8 @@ fn introspect_field_multi_args_descr_trailing_comma() {
// });
// }
#[test]
fn introspect_field_arg_with_default() {
#[tokio::test]
async fn introspect_field_arg_with_default() {
run_args_info_query("argWithDefault", |args| {
assert_eq!(args.len(), 1);
@ -655,11 +665,12 @@ fn introspect_field_arg_with_default() {
.into_iter()
.collect(),
)));
});
})
.await;
}
#[test]
fn introspect_field_multi_args_with_default() {
#[tokio::test]
async fn introspect_field_multi_args_with_default() {
run_args_info_query("multiArgsWithDefault", |args| {
assert_eq!(args.len(), 2);
@ -698,11 +709,12 @@ fn introspect_field_multi_args_with_default() {
.into_iter()
.collect(),
)));
});
})
.await;
}
#[test]
fn introspect_field_multi_args_with_default_trailing_comma() {
#[tokio::test]
async fn introspect_field_multi_args_with_default_trailing_comma() {
run_args_info_query("multiArgsWithDefaultTrailingComma", |args| {
assert_eq!(args.len(), 2);
@ -741,11 +753,12 @@ fn introspect_field_multi_args_with_default_trailing_comma() {
.into_iter()
.collect(),
)));
});
})
.await;
}
#[test]
fn introspect_field_arg_with_default_descr() {
#[tokio::test]
async fn introspect_field_arg_with_default_descr() {
run_args_info_query("argWithDefaultDescr", |args| {
assert_eq!(args.len(), 1);
@ -766,11 +779,12 @@ fn introspect_field_arg_with_default_descr() {
.into_iter()
.collect(),
)));
});
})
.await;
}
#[test]
fn introspect_field_multi_args_with_default_descr() {
#[tokio::test]
async fn introspect_field_multi_args_with_default_descr() {
run_args_info_query("multiArgsWithDefaultDescr", |args| {
assert_eq!(args.len(), 2);
@ -809,11 +823,12 @@ fn introspect_field_multi_args_with_default_descr() {
.into_iter()
.collect(),
)));
});
})
.await;
}
#[test]
fn introspect_field_multi_args_with_default_trailing_comma_descr() {
#[tokio::test]
async fn introspect_field_multi_args_with_default_trailing_comma_descr() {
run_args_info_query("multiArgsWithDefaultTrailingCommaDescr", |args| {
assert_eq!(args.len(), 2);
@ -852,11 +867,12 @@ fn introspect_field_multi_args_with_default_trailing_comma_descr() {
.into_iter()
.collect(),
)));
});
})
.await;
}
#[test]
fn introspect_field_args_with_complex_default() {
#[tokio::test]
async fn introspect_field_args_with_complex_default() {
run_args_info_query("argsWithComplexDefault", |args| {
assert_eq!(args.len(), 2);
@ -898,5 +914,6 @@ fn introspect_field_args_with_complex_default() {
.into_iter()
.collect(),
)));
});
})
.await;
}

View file

@ -143,7 +143,7 @@ graphql_interface!(Interface: () |&self| {
}
});
fn run_field_info_query<F>(type_name: &str, field_name: &str, f: F)
async fn run_field_info_query<F>(type_name: &str, field_name: &str, f: F)
where
F: Fn(&Object<DefaultScalarValue>) -> (),
{
@ -164,8 +164,9 @@ where
.into_iter()
.collect();
let (result, errs) =
crate::execute_sync(doc, None, &schema, &vars, &()).expect("Execution failed");
let (result, errs) = crate::execute(doc, None, &schema, &vars, &())
.await
.expect("Execution failed");
assert_eq!(errs, []);
@ -206,8 +207,8 @@ where
f(field);
}
#[test]
fn introspect_object_field_simple() {
#[tokio::test]
async fn introspect_object_field_simple() {
run_field_info_query("Root", "simple", |field| {
assert_eq!(
field.get_field_value("name"),
@ -222,11 +223,12 @@ fn introspect_object_field_simple() {
field.get_field_value("deprecationReason"),
Some(&Value::null())
);
});
})
.await;
}
#[test]
fn introspect_interface_field_simple() {
#[tokio::test]
async fn introspect_interface_field_simple() {
run_field_info_query("Interface", "simple", |field| {
assert_eq!(
field.get_field_value("name"),
@ -241,11 +243,12 @@ fn introspect_interface_field_simple() {
field.get_field_value("deprecationReason"),
Some(&Value::null())
);
});
})
.await;
}
#[test]
fn introspect_object_field_description() {
#[tokio::test]
async fn introspect_object_field_description() {
run_field_info_query("Root", "description", |field| {
assert_eq!(
field.get_field_value("name"),
@ -263,11 +266,12 @@ fn introspect_object_field_description() {
field.get_field_value("deprecationReason"),
Some(&Value::null())
);
});
})
.await;
}
#[test]
fn introspect_interface_field_description() {
#[tokio::test]
async fn introspect_interface_field_description() {
run_field_info_query("Interface", "description", |field| {
assert_eq!(
field.get_field_value("name"),
@ -285,11 +289,12 @@ fn introspect_interface_field_description() {
field.get_field_value("deprecationReason"),
Some(&Value::null())
);
});
})
.await;
}
#[test]
fn introspect_object_field_deprecated_outer() {
#[tokio::test]
async fn introspect_object_field_deprecated_outer() {
run_field_info_query("Root", "deprecatedOuter", |field| {
assert_eq!(
field.get_field_value("name"),
@ -304,11 +309,12 @@ fn introspect_object_field_deprecated_outer() {
field.get_field_value("deprecationReason"),
Some(&Value::null()),
);
});
})
.await;
}
#[test]
fn introspect_object_field_deprecated_outer_with_reason() {
#[tokio::test]
async fn introspect_object_field_deprecated_outer_with_reason() {
run_field_info_query("Root", "deprecatedOuterWithReason", |field| {
assert_eq!(
field.get_field_value("name"),
@ -323,11 +329,12 @@ fn introspect_object_field_deprecated_outer_with_reason() {
field.get_field_value("deprecationReason"),
Some(&Value::scalar("Deprecation Reason")),
);
});
})
.await;
}
#[test]
fn introspect_object_field_deprecated() {
#[tokio::test]
async fn introspect_object_field_deprecated() {
run_field_info_query("Root", "deprecated", |field| {
assert_eq!(
field.get_field_value("name"),
@ -342,11 +349,12 @@ fn introspect_object_field_deprecated() {
field.get_field_value("deprecationReason"),
Some(&Value::scalar("Deprecation reason"))
);
});
})
.await;
}
#[test]
fn introspect_interface_field_deprecated() {
#[tokio::test]
async fn introspect_interface_field_deprecated() {
run_field_info_query("Interface", "deprecated", |field| {
assert_eq!(
field.get_field_value("name"),
@ -361,11 +369,12 @@ fn introspect_interface_field_deprecated() {
field.get_field_value("deprecationReason"),
Some(&Value::scalar("Deprecation reason"))
);
});
})
.await;
}
#[test]
fn introspect_object_field_deprecated_descr() {
#[tokio::test]
async fn introspect_object_field_deprecated_descr() {
run_field_info_query("Root", "deprecatedDescr", |field| {
assert_eq!(
field.get_field_value("name"),
@ -383,11 +392,12 @@ fn introspect_object_field_deprecated_descr() {
field.get_field_value("deprecationReason"),
Some(&Value::scalar("Deprecation reason"))
);
});
})
.await;
}
#[test]
fn introspect_interface_field_deprecated_descr() {
#[tokio::test]
async fn introspect_interface_field_deprecated_descr() {
run_field_info_query("Interface", "deprecatedDescr", |field| {
assert_eq!(
field.get_field_value("name"),
@ -405,11 +415,12 @@ fn introspect_interface_field_deprecated_descr() {
field.get_field_value("deprecationReason"),
Some(&Value::scalar("Deprecation reason"))
);
});
})
.await;
}
#[test]
fn introspect_object_field_attr_description() {
#[tokio::test]
async fn introspect_object_field_attr_description() {
run_field_info_query("Root", "attrDescription", |field| {
assert_eq!(
field.get_field_value("name"),
@ -427,11 +438,12 @@ fn introspect_object_field_attr_description() {
field.get_field_value("deprecationReason"),
Some(&Value::null())
);
});
})
.await;
}
#[test]
fn introspect_interface_field_attr_description() {
#[tokio::test]
async fn introspect_interface_field_attr_description() {
run_field_info_query("Interface", "attrDescription", |field| {
assert_eq!(
field.get_field_value("name"),
@ -449,11 +461,12 @@ fn introspect_interface_field_attr_description() {
field.get_field_value("deprecationReason"),
Some(&Value::null())
);
});
})
.await;
}
#[test]
fn introspect_object_field_attr_description_long() {
#[tokio::test]
async fn introspect_object_field_attr_description_long() {
run_field_info_query("Root", "attrDescriptionLong", |field| {
assert_eq!(
field.get_field_value("name"),
@ -471,11 +484,11 @@ fn introspect_object_field_attr_description_long() {
field.get_field_value("deprecationReason"),
Some(&Value::null())
);
});
}).await;
}
#[test]
fn introspect_interface_field_attr_description_long() {
#[tokio::test]
async fn introspect_interface_field_attr_description_long() {
run_field_info_query("Interface", "attrDescriptionLong", |field| {
assert_eq!(
field.get_field_value("name"),
@ -493,11 +506,11 @@ fn introspect_interface_field_attr_description_long() {
field.get_field_value("deprecationReason"),
Some(&Value::null())
);
});
}).await;
}
#[test]
fn introspect_object_field_attr_description_collapse() {
#[tokio::test]
async fn introspect_object_field_attr_description_collapse() {
run_field_info_query("Root", "attrDescriptionCollapse", |field| {
assert_eq!(
field.get_field_value("name"),
@ -517,11 +530,12 @@ fn introspect_object_field_attr_description_collapse() {
field.get_field_value("deprecationReason"),
Some(&Value::null())
);
});
})
.await;
}
#[test]
fn introspect_interface_field_attr_description_collapse() {
#[tokio::test]
async fn introspect_interface_field_attr_description_collapse() {
run_field_info_query("Interface", "attrDescriptionCollapse", |field| {
assert_eq!(
field.get_field_value("name"),
@ -541,11 +555,12 @@ fn introspect_interface_field_attr_description_collapse() {
field.get_field_value("deprecationReason"),
Some(&Value::null())
);
});
})
.await;
}
#[test]
fn introspect_object_field_attr_deprecated() {
#[tokio::test]
async fn introspect_object_field_attr_deprecated() {
run_field_info_query("Root", "attrDeprecated", |field| {
assert_eq!(
field.get_field_value("name"),
@ -560,11 +575,12 @@ fn introspect_object_field_attr_deprecated() {
field.get_field_value("deprecationReason"),
Some(&Value::null())
);
});
})
.await;
}
#[test]
fn introspect_interface_field_attr_deprecated() {
#[tokio::test]
async fn introspect_interface_field_attr_deprecated() {
run_field_info_query("Interface", "attrDeprecated", |field| {
assert_eq!(
field.get_field_value("name"),
@ -579,11 +595,12 @@ fn introspect_interface_field_attr_deprecated() {
field.get_field_value("deprecationReason"),
Some(&Value::null())
);
});
})
.await;
}
#[test]
fn introspect_object_field_attr_deprecated_reason() {
#[tokio::test]
async fn introspect_object_field_attr_deprecated_reason() {
run_field_info_query("Root", "attrDeprecatedReason", |field| {
assert_eq!(
field.get_field_value("name"),
@ -598,11 +615,12 @@ fn introspect_object_field_attr_deprecated_reason() {
field.get_field_value("deprecationReason"),
Some(&Value::scalar("Deprecation reason"))
);
});
})
.await;
}
#[test]
fn introspect_interface_field_attr_deprecated_reason() {
#[tokio::test]
async fn introspect_interface_field_attr_deprecated_reason() {
run_field_info_query("Interface", "attrDeprecatedReason", |field| {
assert_eq!(
field.get_field_value("name"),
@ -617,11 +635,12 @@ fn introspect_interface_field_attr_deprecated_reason() {
field.get_field_value("deprecationReason"),
Some(&Value::scalar("Deprecation reason"))
);
});
})
.await;
}
#[test]
fn introspect_object_field_attr_deprecated_descr() {
#[tokio::test]
async fn introspect_object_field_attr_deprecated_descr() {
run_field_info_query("Root", "attrDeprecatedDescr", |field| {
assert_eq!(
field.get_field_value("name"),
@ -639,11 +658,12 @@ fn introspect_object_field_attr_deprecated_descr() {
field.get_field_value("deprecationReason"),
Some(&Value::scalar("Deprecation reason"))
);
});
})
.await;
}
#[test]
fn introspect_interface_field_attr_deprecated_descr() {
#[tokio::test]
async fn introspect_interface_field_attr_deprecated_descr() {
run_field_info_query("Interface", "attrDeprecatedDescr", |field| {
assert_eq!(
field.get_field_value("name"),
@ -661,5 +681,6 @@ fn introspect_interface_field_attr_deprecated_descr() {
field.get_field_value("deprecationReason"),
Some(&Value::scalar("Deprecation reason"))
);
});
})
.await;
}

View file

@ -122,9 +122,9 @@ impl Mutation {
}
}
#[test]
fn object_introspect() {
let res = util::run_info_query::<Query, Mutation, Context>("Query");
#[tokio::test]
async fn object_introspect() {
let res = util::run_info_query::<Query, Mutation, Context>("Query").await;
assert_eq!(
res,
crate::graphql_value!({
@ -243,8 +243,8 @@ fn object_introspect() {
);
}
#[test]
fn object_query() {
#[tokio::test]
async fn object_query() {
let doc = r#"
query {
withSelf
@ -269,7 +269,8 @@ fn object_query() {
let schema = RootNode::new(Query { b: true }, EmptyMutation::<Context>::new());
let vars = std::collections::HashMap::new();
let (result, errs) = crate::execute_sync(doc, None, &schema, &vars, &Context { flag1: true })
let (result, errs) = crate::execute(doc, None, &schema, &vars, &Context { flag1: true })
.await
.expect("Execution failed");
assert_eq!(errs, []);
assert_eq!(

View file

@ -151,7 +151,7 @@ impl<'a> Root {
}
}
fn run_type_info_query<F>(type_name: &str, f: F)
async fn run_type_info_query<F>(type_name: &str, f: F)
where
F: Fn(&Object<DefaultScalarValue>, &Vec<Value<DefaultScalarValue>>) -> (),
{
@ -171,8 +171,9 @@ where
.into_iter()
.collect();
let (result, errs) =
crate::execute_sync(doc, None, &schema, &vars, &()).expect("Execution failed");
let (result, errs) = crate::execute(doc, None, &schema, &vars, &())
.await
.expect("Execution failed");
assert_eq!(errs, []);
@ -195,8 +196,8 @@ where
f(type_info, fields);
}
#[test]
fn introspect_custom_name() {
#[tokio::test]
async fn introspect_custom_name() {
run_type_info_query("ACustomNamedInterface", |object, fields| {
assert_eq!(
object.get_field_value("name"),
@ -209,11 +210,12 @@ fn introspect_custom_name() {
.into_iter()
.collect(),
)));
});
})
.await;
}
#[test]
fn introspect_with_lifetime() {
#[tokio::test]
async fn introspect_with_lifetime() {
run_type_info_query("WithLifetime", |object, fields| {
assert_eq!(
object.get_field_value("name"),
@ -226,11 +228,12 @@ fn introspect_with_lifetime() {
.into_iter()
.collect(),
)));
});
})
.await;
}
#[test]
fn introspect_with_generics() {
#[tokio::test]
async fn introspect_with_generics() {
run_type_info_query("WithGenerics", |object, fields| {
assert_eq!(
object.get_field_value("name"),
@ -243,11 +246,12 @@ fn introspect_with_generics() {
.into_iter()
.collect(),
)));
});
})
.await;
}
#[test]
fn introspect_description_first() {
#[tokio::test]
async fn introspect_description_first() {
run_type_info_query("DescriptionFirst", |object, fields| {
assert_eq!(
object.get_field_value("name"),
@ -263,11 +267,12 @@ fn introspect_description_first() {
.into_iter()
.collect(),
)));
});
})
.await;
}
#[test]
fn introspect_fields_first() {
#[tokio::test]
async fn introspect_fields_first() {
run_type_info_query("FieldsFirst", |object, fields| {
assert_eq!(
object.get_field_value("name"),
@ -283,11 +288,12 @@ fn introspect_fields_first() {
.into_iter()
.collect(),
)));
});
})
.await;
}
#[test]
fn introspect_interfaces_first() {
#[tokio::test]
async fn introspect_interfaces_first() {
run_type_info_query("InterfacesFirst", |object, fields| {
assert_eq!(
object.get_field_value("name"),
@ -303,11 +309,12 @@ fn introspect_interfaces_first() {
.into_iter()
.collect(),
)));
});
})
.await;
}
#[test]
fn introspect_commas_with_trailing() {
#[tokio::test]
async fn introspect_commas_with_trailing() {
run_type_info_query("CommasWithTrailing", |object, fields| {
assert_eq!(
object.get_field_value("name"),
@ -323,11 +330,12 @@ fn introspect_commas_with_trailing() {
.into_iter()
.collect(),
)));
});
})
.await;
}
#[test]
fn introspect_commas_on_meta() {
#[tokio::test]
async fn introspect_commas_on_meta() {
run_type_info_query("CommasOnMeta", |object, fields| {
assert_eq!(
object.get_field_value("name"),
@ -343,11 +351,12 @@ fn introspect_commas_on_meta() {
.into_iter()
.collect(),
)));
});
})
.await;
}
#[test]
fn introspect_resolvers_with_trailing_comma() {
#[tokio::test]
async fn introspect_resolvers_with_trailing_comma() {
run_type_info_query("ResolversWithTrailingComma", |object, fields| {
assert_eq!(
object.get_field_value("name"),
@ -363,5 +372,6 @@ fn introspect_resolvers_with_trailing_comma() {
.into_iter()
.collect(),
)));
});
})
.await;
}

View file

@ -96,14 +96,15 @@ impl Root {
}
}
fn run_type_info_query<F>(doc: &str, f: F)
async fn run_type_info_query<F>(doc: &str, f: F)
where
F: Fn(&Object<DefaultScalarValue>) -> (),
{
let schema = RootNode::new(Root {}, EmptyMutation::<()>::new());
let (result, errs) =
crate::execute_sync(doc, None, &schema, &Variables::new(), &()).expect("Execution failed");
let (result, errs) = crate::execute(doc, None, &schema, &Variables::new(), &())
.await
.expect("Execution failed");
assert_eq!(errs, []);
@ -139,8 +140,8 @@ fn path_in_resolve_return_type() {
});
}
#[test]
fn default_name_introspection() {
#[tokio::test]
async fn default_name_introspection() {
let doc = r#"
{
__type(name: "DefaultName") {
@ -159,11 +160,12 @@ fn default_name_introspection() {
type_info.get_field_value("description"),
Some(&Value::null())
);
});
})
.await;
}
#[test]
fn other_order_introspection() {
#[tokio::test]
async fn other_order_introspection() {
let doc = r#"
{
__type(name: "OtherOrder") {
@ -182,11 +184,12 @@ fn other_order_introspection() {
type_info.get_field_value("description"),
Some(&Value::null())
);
});
})
.await;
}
#[test]
fn named_introspection() {
#[tokio::test]
async fn named_introspection() {
let doc = r#"
{
__type(name: "ANamedScalar") {
@ -205,11 +208,12 @@ fn named_introspection() {
type_info.get_field_value("description"),
Some(&Value::null())
);
});
})
.await;
}
#[test]
fn scalar_description_introspection() {
#[tokio::test]
async fn scalar_description_introspection() {
let doc = r#"
{
__type(name: "ScalarDescription") {
@ -228,5 +232,6 @@ fn scalar_description_introspection() {
type_info.get_field_value("description"),
Some(&Value::scalar("A sample scalar, represented as an integer"))
);
});
})
.await;
}

View file

@ -106,7 +106,7 @@ impl<'a> Root {
}
}
fn run_type_info_query<F>(type_name: &str, f: F)
async fn run_type_info_query<F>(type_name: &str, f: F)
where
F: Fn(&Object<DefaultScalarValue>, &Vec<Value<DefaultScalarValue>>) -> (),
{
@ -126,8 +126,9 @@ where
.into_iter()
.collect();
let (result, errs) =
crate::execute_sync(doc, None, &schema, &vars, &()).expect("Execution failed");
let (result, errs) = crate::execute(doc, None, &schema, &vars, &())
.await
.expect("Execution failed");
assert_eq!(errs, []);
@ -150,8 +151,8 @@ where
f(type_info, possible_types);
}
#[test]
fn introspect_custom_name() {
#[tokio::test]
async fn introspect_custom_name() {
run_type_info_query("ACustomNamedUnion", |union, possible_types| {
assert_eq!(
union.get_field_value("name"),
@ -164,11 +165,12 @@ fn introspect_custom_name() {
.into_iter()
.collect(),
)));
});
})
.await;
}
#[test]
fn introspect_with_lifetime() {
#[tokio::test]
async fn introspect_with_lifetime() {
run_type_info_query("WithLifetime", |union, possible_types| {
assert_eq!(
union.get_field_value("name"),
@ -181,11 +183,12 @@ fn introspect_with_lifetime() {
.into_iter()
.collect(),
)));
});
})
.await;
}
#[test]
fn introspect_with_generics() {
#[tokio::test]
async fn introspect_with_generics() {
run_type_info_query("WithGenerics", |union, possible_types| {
assert_eq!(
union.get_field_value("name"),
@ -198,11 +201,12 @@ fn introspect_with_generics() {
.into_iter()
.collect(),
)));
});
})
.await;
}
#[test]
fn introspect_description_first() {
#[tokio::test]
async fn introspect_description_first() {
run_type_info_query("DescriptionFirst", |union, possible_types| {
assert_eq!(
union.get_field_value("name"),
@ -218,5 +222,6 @@ fn introspect_description_first() {
.into_iter()
.collect(),
)));
});
})
.await;
}

View file

@ -1,26 +1,27 @@
use crate::{DefaultScalarValue, GraphQLType, RootNode, Value, Variables};
use crate::{DefaultScalarValue, GraphQLTypeAsync, RootNode, Value, Variables};
use std::default::Default;
pub fn run_query<Query, Mutation, Context>(query: &str) -> Value
pub async fn run_query<Query, Mutation, Context>(query: &str) -> Value
where
Query: GraphQLType<DefaultScalarValue, TypeInfo = (), Context = Context> + Default,
Mutation: GraphQLType<DefaultScalarValue, TypeInfo = (), Context = Context> + Default,
Context: Default,
Query: GraphQLTypeAsync<DefaultScalarValue, TypeInfo = (), Context = Context> + Default,
Mutation: GraphQLTypeAsync<DefaultScalarValue, TypeInfo = (), Context = Context> + Default,
Context: Default + Sync + Send,
{
let schema = RootNode::new(Query::default(), Mutation::default());
let (result, errs) =
crate::execute_sync(query, None, &schema, &Variables::new(), &Context::default())
crate::execute(query, None, &schema, &Variables::new(), &Context::default())
.await
.expect("Execution failed");
assert_eq!(errs, []);
result
}
pub fn run_info_query<Query, Mutation, Context>(type_name: &str) -> Value
pub async fn run_info_query<Query, Mutation, Context>(type_name: &str) -> Value
where
Query: GraphQLType<DefaultScalarValue, TypeInfo = (), Context = Context> + Default,
Mutation: GraphQLType<DefaultScalarValue, TypeInfo = (), Context = Context> + Default,
Context: Default,
Query: GraphQLTypeAsync<DefaultScalarValue, TypeInfo = (), Context = Context> + Default,
Mutation: GraphQLTypeAsync<DefaultScalarValue, TypeInfo = (), Context = Context> + Default,
Context: Default + Sync + Send,
{
let query = format!(
r#"
@ -44,7 +45,7 @@ where
"#,
type_name
);
let result = run_query::<Query, Mutation, Context>(&query);
let result = run_query::<Query, Mutation, Context>(&query).await;
result
.as_object_value()
.expect("Result is not an object")

View file

@ -9,8 +9,8 @@ use crate::{
types::scalars::EmptyMutation,
};
#[test]
fn test_introspection_query_type_name() {
#[tokio::test]
async fn test_introspection_query_type_name() {
let doc = r#"
query IntrospectionQueryTypeQuery {
__schema {
@ -23,7 +23,7 @@ fn test_introspection_query_type_name() {
let schema = RootNode::new(Query, EmptyMutation::<Database>::new());
assert_eq!(
crate::execute_sync(doc, None, &schema, &Variables::new(), &database),
crate::execute(doc, None, &schema, &Variables::new(), &database).await,
Ok((
graphql_value!({
"__schema": {
@ -38,8 +38,8 @@ fn test_introspection_query_type_name() {
);
}
#[test]
fn test_introspection_type_name() {
#[tokio::test]
async fn test_introspection_type_name() {
let doc = r#"
query IntrospectionQueryTypeQuery {
__type(name: "Droid") {
@ -50,7 +50,7 @@ fn test_introspection_type_name() {
let schema = RootNode::new(Query, EmptyMutation::<Database>::new());
assert_eq!(
crate::execute_sync(doc, None, &schema, &Variables::new(), &database),
crate::execute(doc, None, &schema, &Variables::new(), &database).await,
Ok((
graphql_value!({
"__type": {
@ -62,8 +62,8 @@ fn test_introspection_type_name() {
);
}
#[test]
fn test_introspection_specific_object_type_name_and_kind() {
#[tokio::test]
async fn test_introspection_specific_object_type_name_and_kind() {
let doc = r#"
query IntrospectionDroidKindQuery {
__type(name: "Droid") {
@ -76,7 +76,7 @@ fn test_introspection_specific_object_type_name_and_kind() {
let schema = RootNode::new(Query, EmptyMutation::<Database>::new());
assert_eq!(
crate::execute_sync(doc, None, &schema, &Variables::new(), &database),
crate::execute(doc, None, &schema, &Variables::new(), &database).await,
Ok((
graphql_value!({
"__type": {
@ -89,8 +89,8 @@ fn test_introspection_specific_object_type_name_and_kind() {
);
}
#[test]
fn test_introspection_specific_interface_type_name_and_kind() {
#[tokio::test]
async fn test_introspection_specific_interface_type_name_and_kind() {
let doc = r#"
query IntrospectionDroidKindQuery {
__type(name: "Character") {
@ -103,7 +103,7 @@ fn test_introspection_specific_interface_type_name_and_kind() {
let schema = RootNode::new(Query, EmptyMutation::<Database>::new());
assert_eq!(
crate::execute_sync(doc, None, &schema, &Variables::new(), &database),
crate::execute(doc, None, &schema, &Variables::new(), &database).await,
Ok((
graphql_value!({
"__type": {
@ -116,8 +116,8 @@ fn test_introspection_specific_interface_type_name_and_kind() {
);
}
#[test]
fn test_introspection_documentation() {
#[tokio::test]
async fn test_introspection_documentation() {
let doc = r#"
query IntrospectionDroidDescriptionQuery {
__type(name: "Droid") {
@ -130,7 +130,7 @@ fn test_introspection_documentation() {
let schema = RootNode::new(Query, EmptyMutation::<Database>::new());
assert_eq!(
crate::execute_sync(doc, None, &schema, &Variables::new(), &database),
crate::execute(doc, None, &schema, &Variables::new(), &database).await,
Ok((
graphql_value!({
"__type": {
@ -143,8 +143,8 @@ fn test_introspection_documentation() {
);
}
#[test]
fn test_introspection_directives() {
#[tokio::test]
async fn test_introspection_directives() {
let q = r#"
query IntrospectionQuery {
__schema {
@ -159,7 +159,9 @@ fn test_introspection_directives() {
let database = Database::new();
let schema = RootNode::new(Query, EmptyMutation::<Database>::new());
let mut result = crate::execute_sync(q, None, &schema, &Variables::new(), &database).unwrap();
let mut result = crate::execute(q, None, &schema, &Variables::new(), &database)
.await
.unwrap();
sort_schema_value(&mut result.0);
let mut expected = graphql_value!({
@ -189,8 +191,8 @@ fn test_introspection_directives() {
assert_eq!(result, (expected, vec![]));
}
#[test]
fn test_introspection_possible_types() {
#[tokio::test]
async fn test_introspection_possible_types() {
let doc = r#"
query IntrospectionDroidDescriptionQuery {
__type(name: "Character") {
@ -203,7 +205,7 @@ fn test_introspection_possible_types() {
let database = Database::new();
let schema = RootNode::new(Query, EmptyMutation::<Database>::new());
let result = crate::execute_sync(doc, None, &schema, &Variables::new(), &database);
let result = crate::execute(doc, None, &schema, &Variables::new(), &database).await;
let (result, errors) = result.ok().expect("Query returned error");
@ -234,8 +236,8 @@ fn test_introspection_possible_types() {
assert_eq!(possible_types, vec!["Human", "Droid"].into_iter().collect());
}
#[test]
fn test_builtin_introspection_query() {
#[tokio::test]
async fn test_builtin_introspection_query() {
let database = Database::new();
let schema = RootNode::new(Query, EmptyMutation::<Database>::new());
let mut result = crate::introspect(&schema, &database, IntrospectionFormat::default()).unwrap();
@ -244,8 +246,8 @@ fn test_builtin_introspection_query() {
assert_eq!(result, (expected, vec![]));
}
#[test]
fn test_builtin_introspection_query_without_descriptions() {
#[tokio::test]
async fn test_builtin_introspection_query_without_descriptions() {
let database = Database::new();
let schema = RootNode::new(Query, EmptyMutation::<Database>::new());

View file

@ -7,8 +7,8 @@ use crate::{
value::Value,
};
#[test]
fn test_hero_name() {
#[tokio::test]
async fn test_hero_name() {
let doc = r#"
{
hero {
@ -19,7 +19,7 @@ fn test_hero_name() {
let schema = RootNode::new(Query, EmptyMutation::<Database>::new());
assert_eq!(
crate::execute_sync(doc, None, &schema, &Variables::new(), &database),
crate::execute(doc, None, &schema, &Variables::new(), &database).await,
Ok((
Value::object(
vec![(
@ -34,8 +34,8 @@ fn test_hero_name() {
);
}
#[test]
fn test_hero_field_order() {
#[tokio::test]
async fn test_hero_field_order() {
let database = Database::new();
let schema = RootNode::new(Query, EmptyMutation::<Database>::new());
@ -47,7 +47,7 @@ fn test_hero_field_order() {
}
}"#;
assert_eq!(
crate::execute_sync(doc, None, &schema, &Variables::new(), &database),
crate::execute(doc, None, &schema, &Variables::new(), &database).await,
Ok((
Value::object(
vec![(
@ -76,7 +76,7 @@ fn test_hero_field_order() {
}
}"#;
assert_eq!(
crate::execute_sync(doc_reversed, None, &schema, &Variables::new(), &database),
crate::execute(doc_reversed, None, &schema, &Variables::new(), &database).await,
Ok((
Value::object(
vec![(
@ -98,8 +98,8 @@ fn test_hero_field_order() {
);
}
#[test]
fn test_hero_name_and_friends() {
#[tokio::test]
async fn test_hero_name_and_friends() {
let doc = r#"
{
hero {
@ -114,7 +114,7 @@ fn test_hero_name_and_friends() {
let schema = RootNode::new(Query, EmptyMutation::<Database>::new());
assert_eq!(
crate::execute_sync(doc, None, &schema, &Variables::new(), &database),
crate::execute(doc, None, &schema, &Variables::new(), &database).await,
Ok((
Value::object(
vec![(
@ -156,8 +156,8 @@ fn test_hero_name_and_friends() {
);
}
#[test]
fn test_hero_name_and_friends_and_friends_of_friends() {
#[tokio::test]
async fn test_hero_name_and_friends_and_friends_of_friends() {
let doc = r#"
{
hero {
@ -176,7 +176,7 @@ fn test_hero_name_and_friends_and_friends_of_friends() {
let schema = RootNode::new(Query, EmptyMutation::<Database>::new());
assert_eq!(
crate::execute_sync(doc, None, &schema, &Variables::new(), &database),
crate::execute(doc, None, &schema, &Variables::new(), &database).await,
Ok((
Value::object(
vec![(
@ -330,14 +330,14 @@ fn test_hero_name_and_friends_and_friends_of_friends() {
);
}
#[test]
fn test_query_name() {
#[tokio::test]
async fn test_query_name() {
let doc = r#"{ human(id: "1000") { name } }"#;
let database = Database::new();
let schema = RootNode::new(Query, EmptyMutation::<Database>::new());
assert_eq!(
crate::execute_sync(doc, None, &schema, &Variables::new(), &database),
crate::execute(doc, None, &schema, &Variables::new(), &database).await,
Ok((
Value::object(
vec![(
@ -356,14 +356,14 @@ fn test_query_name() {
);
}
#[test]
fn test_query_alias_single() {
#[tokio::test]
async fn test_query_alias_single() {
let doc = r#"{ luke: human(id: "1000") { name } }"#;
let database = Database::new();
let schema = RootNode::new(Query, EmptyMutation::<Database>::new());
assert_eq!(
crate::execute_sync(doc, None, &schema, &Variables::new(), &database),
crate::execute(doc, None, &schema, &Variables::new(), &database).await,
Ok((
Value::object(
vec![(
@ -382,8 +382,8 @@ fn test_query_alias_single() {
);
}
#[test]
fn test_query_alias_multiple() {
#[tokio::test]
async fn test_query_alias_multiple() {
let doc = r#"
{
luke: human(id: "1000") { name }
@ -393,7 +393,7 @@ fn test_query_alias_multiple() {
let schema = RootNode::new(Query, EmptyMutation::<Database>::new());
assert_eq!(
crate::execute_sync(doc, None, &schema, &Variables::new(), &database),
crate::execute(doc, None, &schema, &Variables::new(), &database).await,
Ok((
Value::object(
vec![
@ -422,8 +422,8 @@ fn test_query_alias_multiple() {
);
}
#[test]
fn test_query_alias_multiple_with_fragment() {
#[tokio::test]
async fn test_query_alias_multiple_with_fragment() {
let doc = r#"
query UseFragment {
luke: human(id: "1000") { ...HumanFragment }
@ -438,7 +438,7 @@ fn test_query_alias_multiple_with_fragment() {
let schema = RootNode::new(Query, EmptyMutation::<Database>::new());
assert_eq!(
crate::execute_sync(doc, None, &schema, &Variables::new(), &database),
crate::execute(doc, None, &schema, &Variables::new(), &database).await,
Ok((
Value::object(
vec![
@ -473,8 +473,8 @@ fn test_query_alias_multiple_with_fragment() {
);
}
#[test]
fn test_query_name_variable() {
#[tokio::test]
async fn test_query_name_variable() {
let doc = r#"query FetchSomeIDQuery($someId: String!) { human(id: $someId) { name } }"#;
let database = Database::new();
let schema = RootNode::new(Query, EmptyMutation::<Database>::new());
@ -484,7 +484,7 @@ fn test_query_name_variable() {
.collect();
assert_eq!(
crate::execute_sync(doc, None, &schema, &vars, &database),
crate::execute(doc, None, &schema, &vars, &database).await,
Ok((
Value::object(
vec![(
@ -503,8 +503,8 @@ fn test_query_name_variable() {
);
}
#[test]
fn test_query_name_invalid_variable() {
#[tokio::test]
async fn test_query_name_invalid_variable() {
let doc = r#"query FetchSomeIDQuery($someId: String!) { human(id: $someId) { name } }"#;
let database = Database::new();
let schema = RootNode::new(Query, EmptyMutation::<Database>::new());
@ -514,7 +514,7 @@ fn test_query_name_invalid_variable() {
.collect();
assert_eq!(
crate::execute_sync(doc, None, &schema, &vars, &database),
crate::execute(doc, None, &schema, &vars, &database).await,
Ok((
Value::object(vec![("human", Value::null())].into_iter().collect()),
vec![]
@ -522,14 +522,14 @@ fn test_query_name_invalid_variable() {
);
}
#[test]
fn test_query_friends_names() {
#[tokio::test]
async fn test_query_friends_names() {
let doc = r#"{ human(id: "1000") { friends { name } } }"#;
let database = Database::new();
let schema = RootNode::new(Query, EmptyMutation::<Database>::new());
assert_eq!(
crate::execute_sync(doc, None, &schema, &Variables::new(), &database),
crate::execute(doc, None, &schema, &Variables::new(), &database).await,
Ok((
Value::object(
vec![(
@ -568,8 +568,8 @@ fn test_query_friends_names() {
);
}
#[test]
fn test_query_inline_fragments_droid() {
#[tokio::test]
async fn test_query_inline_fragments_droid() {
let doc = r#"
query InlineFragments {
hero {
@ -586,7 +586,7 @@ fn test_query_inline_fragments_droid() {
let schema = RootNode::new(Query, EmptyMutation::<Database>::new());
assert_eq!(
crate::execute_sync(doc, None, &schema, &Variables::new(), &database),
crate::execute(doc, None, &schema, &Variables::new(), &database).await,
Ok((
Value::object(
vec![(
@ -609,8 +609,8 @@ fn test_query_inline_fragments_droid() {
);
}
#[test]
fn test_query_inline_fragments_human() {
#[tokio::test]
async fn test_query_inline_fragments_human() {
let doc = r#"
query InlineFragments {
hero(episode: EMPIRE) {
@ -623,7 +623,7 @@ fn test_query_inline_fragments_human() {
let schema = RootNode::new(Query, EmptyMutation::<Database>::new());
assert_eq!(
crate::execute_sync(doc, None, &schema, &Variables::new(), &database),
crate::execute(doc, None, &schema, &Variables::new(), &database).await,
Ok((
Value::object(
vec![(
@ -645,8 +645,8 @@ fn test_query_inline_fragments_human() {
);
}
#[test]
fn test_object_typename() {
#[tokio::test]
async fn test_object_typename() {
let doc = r#"
{
human(id: "1000") {
@ -657,7 +657,7 @@ fn test_object_typename() {
let schema = RootNode::new(Query, EmptyMutation::<Database>::new());
assert_eq!(
crate::execute_sync(doc, None, &schema, &Variables::new(), &database),
crate::execute(doc, None, &schema, &Variables::new(), &database).await,
Ok((
Value::object(
vec![(