Skip to content

Commit

Permalink
Rename execute -> execute_sync, execute_async -> execute (graphql-rus…
Browse files Browse the repository at this point in the history
  • Loading branch information
LegNeato authored Mar 10, 2020
1 parent 1411969 commit e9b8aa2
Show file tree
Hide file tree
Showing 45 changed files with 353 additions and 358 deletions.
6 changes: 3 additions & 3 deletions benches/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ extern crate juniper;

use bencher::Bencher;

use juniper::{execute, RootNode, EmptyMutation, Variables};
use juniper::{execute_sync, RootNode, EmptyMutation, Variables};
use juniper::tests::model::Database;

fn query_type_name(b: &mut Bencher) {
Expand All @@ -19,7 +19,7 @@ fn query_type_name(b: &mut Bencher) {
}
}"#;

b.iter(|| execute(doc, None, &schema, &Variables::new(), &database));
b.iter(|| execute_sync(doc, None, &schema, &Variables::new(), &database));
}

fn introspection_query(b: &mut Bencher) {
Expand Down Expand Up @@ -120,7 +120,7 @@ fn introspection_query(b: &mut Bencher) {
}
"#;

b.iter(|| execute(doc, None, &schema, &Variables::new(), &database));
b.iter(|| execute_sync(doc, None, &schema, &Variables::new(), &database));
}

benchmark_group!(queries, query_type_name, introspection_query);
Expand Down
2 changes: 1 addition & 1 deletion docs/book/content/advanced/dataloaders.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ pub async fn graphql(
let ctx = Context::new(cult_loader);
// Execute
let future_execute = data.execute_async(&st, &ctx);
let future_execute = data.execute(&st, &ctx);
let res = rt.run_until(future_execute);
let json = serde_json::to_string(&res).map_err(error::ErrorInternalServerError)?;
Expand Down
2 changes: 1 addition & 1 deletion docs/book/content/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ fn main() {
let ctx = Ctx(Episode::NewHope);

// Run the executor.
let (res, _errors) = juniper::execute(
let (res, _errors) = juniper::execute_sync(
"query { favoriteEpisode }",
None,
&Schema::new(Query, EmptyMutation::new()),
Expand Down
4 changes: 2 additions & 2 deletions integration_tests/async_await/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ async fn async_simple() {
"#;

let vars = Default::default();
let (res, errs) = juniper::execute_async(doc, None, &schema, &vars, &())
let (res, errs) = juniper::execute(doc, None, &schema, &vars, &())
.await
.unwrap();

Expand Down Expand Up @@ -130,7 +130,7 @@ async fn async_field_validation_error() {
"#;

let vars = Default::default();
let result = juniper::execute_async(doc, None, &schema, &vars, &()).await;
let result = juniper::execute(doc, None, &schema, &vars, &()).await;
assert!(result.is_err());

let error = result.err().unwrap();
Expand Down
3 changes: 2 additions & 1 deletion integration_tests/juniper_tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ futures = "0.3.1"

[dev-dependencies]
serde_json = { version = "1" }
fnv = "1.0.3"
fnv = "1.0.3"
tokio = { version = "0.2", features = ["rt-core", "time", "macros"] }
35 changes: 20 additions & 15 deletions integration_tests/juniper_tests/src/codegen/derive_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,8 @@ fn test_doc_comment_override() {
);
}

#[test]
fn test_derived_object() {
#[tokio::test]
async fn test_derived_object() {
assert_eq!(
<Obj as GraphQLType<DefaultScalarValue>>::name(&()),
Some("MyObj")
Expand All @@ -195,7 +195,7 @@ fn test_derived_object() {
let schema = RootNode::new(Query, EmptyMutation::<()>::new());

assert_eq!(
execute(doc, None, &schema, &Variables::new(), &()),
execute(doc, None, &schema, &Variables::new(), &()).await,
Ok((
Value::object(
vec![(
Expand All @@ -217,33 +217,37 @@ fn test_derived_object() {
);
}

#[test]
#[tokio::test]
#[should_panic]
fn test_cannot_query_skipped_field() {
async fn test_cannot_query_skipped_field() {
let doc = r#"
{
skippedFieldObj {
skippedField
}
}"#;
let schema = RootNode::new(Query, EmptyMutation::<()>::new());
execute(doc, None, &schema, &Variables::new(), &()).unwrap();
execute(doc, None, &schema, &Variables::new(), &())
.await
.unwrap();
}

#[test]
fn test_skipped_field_siblings_unaffected() {
#[tokio::test]
async fn test_skipped_field_siblings_unaffected() {
let doc = r#"
{
skippedFieldObj {
regularField
}
}"#;
let schema = RootNode::new(Query, EmptyMutation::<()>::new());
execute(doc, None, &schema, &Variables::new(), &()).unwrap();
execute(doc, None, &schema, &Variables::new(), &())
.await
.unwrap();
}

#[test]
fn test_derived_object_nested() {
#[tokio::test]
async fn test_derived_object_nested() {
let doc = r#"
{
nested {
Expand All @@ -257,7 +261,7 @@ fn test_derived_object_nested() {
let schema = RootNode::new(Query, EmptyMutation::<()>::new());

assert_eq!(
execute(doc, None, &schema, &Variables::new(), &()),
execute(doc, None, &schema, &Variables::new(), &()).await,
Ok((
Value::object(
vec![(
Expand Down Expand Up @@ -329,14 +333,15 @@ fn check_descriptions(
}

#[cfg(test)]
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>, &Vec<Value>)) -> (),
{
let schema = RootNode::new(Query, EmptyMutation::<()>::new());

let (result, errs) =
execute(doc, None, &schema, &Variables::new(), &()).expect("Execution failed");
let (result, errs) = execute(doc, None, &schema, &Variables::new(), &())
.await
.expect("Execution failed");

assert_eq!(errs, []);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ struct MyInputType {
r#trait: String,
}

#[test]
fn supports_raw_idents_in_types_and_args() {
#[tokio::test]
async fn supports_raw_idents_in_types_and_args() {
let doc = r#"
{
__type(name: "Query") {
Expand All @@ -40,7 +40,7 @@ fn supports_raw_idents_in_types_and_args() {
}
"#;

let value = run_type_info_query(&doc);
let value = run_type_info_query(&doc).await;

assert_eq!(
value,
Expand All @@ -63,8 +63,8 @@ fn supports_raw_idents_in_types_and_args() {
);
}

#[test]
fn supports_raw_idents_in_fields_of_input_types() {
#[tokio::test]
async fn supports_raw_idents_in_fields_of_input_types() {
let doc = r#"
{
__type(name: "MyInputType") {
Expand All @@ -75,7 +75,7 @@ fn supports_raw_idents_in_fields_of_input_types() {
}
"#;

let value = run_type_info_query(&doc);
let value = run_type_info_query(&doc).await;

assert_eq!(
value,
Expand All @@ -94,11 +94,12 @@ fn supports_raw_idents_in_fields_of_input_types() {
}

#[cfg(test)]
fn run_type_info_query(doc: &str) -> Value {
async fn run_type_info_query(doc: &str) -> Value {
let schema = RootNode::new(Query, EmptyMutation::<()>::new());

let (result, errs) =
execute(doc, None, &schema, &Variables::new(), &()).expect("Execution failed");
let (result, errs) = execute(doc, None, &schema, &Variables::new(), &())
.await
.expect("Execution failed");

assert_eq!(errs, []);

Expand Down
2 changes: 0 additions & 2 deletions integration_tests/juniper_tests/src/codegen/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
mod util;

mod derive_enum;
mod derive_input_object;
mod derive_object;
Expand Down
54 changes: 0 additions & 54 deletions integration_tests/juniper_tests/src/codegen/util.rs

This file was deleted.

42 changes: 21 additions & 21 deletions integration_tests/juniper_tests/src/custom_scalar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@ extern crate serde_json;

use futures;

#[cfg(test)]
use juniper::parser::Spanning;
#[cfg(test)]
use juniper::{execute, EmptyMutation, Object, RootNode, Variables};
use juniper::{
parser::{ParseError, ScalarToken, Token},
execute,
parser::{ParseError, ScalarToken, Spanning, Token},
serde::de,
InputValue, ParseScalarResult, ScalarValue, Value,
EmptyMutation, InputValue, Object, ParseScalarResult, RootNode, ScalarValue, Value, Variables,
};
use std::fmt;

Expand Down Expand Up @@ -175,14 +172,15 @@ impl TestType {
}
}

#[cfg(test)]
fn run_variable_query<F>(query: &str, vars: Variables<MyScalarValue>, f: F)
async fn run_variable_query<F>(query: &str, vars: Variables<MyScalarValue>, f: F)
where
F: Fn(&Object<MyScalarValue>) -> (),
{
let schema = RootNode::new(TestType, EmptyMutation::<()>::new());

let (result, errs) = execute(query, None, &schema, &vars, &()).expect("Execution failed");
let (result, errs) = execute(query, None, &schema, &vars, &())
.await
.expect("Execution failed");

assert_eq!(errs, []);

Expand All @@ -193,26 +191,26 @@ where
f(obj);
}

#[cfg(test)]
fn run_query<F>(query: &str, f: F)
async fn run_query<F>(query: &str, f: F)
where
F: Fn(&Object<MyScalarValue>) -> (),
{
run_variable_query(query, Variables::new(), f);
run_variable_query(query, Variables::new(), f).await;
}

#[test]
fn querying_long() {
#[tokio::test]
async fn querying_long() {
run_query("{ longField }", |result| {
assert_eq!(
result.get_field_value("longField"),
Some(&Value::scalar((::std::i32::MAX as i64) + 1))
);
});
})
.await;
}

#[test]
fn querying_long_arg() {
#[tokio::test]
async fn querying_long_arg() {
run_query(
&format!(
"{{ longWithArg(longArg: {}) }}",
Expand All @@ -224,11 +222,12 @@ fn querying_long_arg() {
Some(&Value::scalar((::std::i32::MAX as i64) + 3))
);
},
);
)
.await;
}

#[test]
fn querying_long_variable() {
#[tokio::test]
async fn querying_long_variable() {
run_variable_query(
"query q($test: Long!){ longWithArg(longArg: $test) }",
vec![(
Expand All @@ -243,7 +242,8 @@ fn querying_long_variable() {
Some(&Value::scalar((::std::i32::MAX as i64) + 42))
);
},
);
)
.await;
}

#[test]
Expand Down
Loading

0 comments on commit e9b8aa2

Please sign in to comment.