Skip to content

Some performance improvements #202

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 43 additions & 45 deletions juniper/src/executor_tests/directives.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use indexmap::IndexMap;

use executor::Variables;
use schema::model::RootNode;
use types::scalars::EmptyMutation;
use value::Value;
use value::{Value, Object};

struct TestType;

Expand All @@ -19,7 +17,7 @@ graphql_object!(TestType: () |&self| {

fn run_variable_query<F>(query: &str, vars: Variables, f: F)
where
F: Fn(&IndexMap<String, Value>) -> (),
F: Fn(&Object) -> (),
{
let schema = RootNode::new(TestType, EmptyMutation::<()>::new());

Expand All @@ -36,40 +34,40 @@ where

fn run_query<F>(query: &str, f: F)
where
F: Fn(&IndexMap<String, Value>) -> (),
F: Fn(&Object) -> (),
{
run_variable_query(query, Variables::new(), f);
}

#[test]
fn scalar_include_true() {
run_query("{ a, b @include(if: true) }", |result| {
assert_eq!(result.get("a"), Some(&Value::string("a")));
assert_eq!(result.get("b"), Some(&Value::string("b")));
assert_eq!(result.get_field_value("a"), Some(&Value::string("a")));
assert_eq!(result.get_field_value("b"), Some(&Value::string("b")));
});
}

#[test]
fn scalar_include_false() {
run_query("{ a, b @include(if: false) }", |result| {
assert_eq!(result.get("a"), Some(&Value::string("a")));
assert_eq!(result.get("b"), None);
assert_eq!(result.get_field_value("a"), Some(&Value::string("a")));
assert_eq!(result.get_field_value("b"), None);
});
}

#[test]
fn scalar_skip_false() {
run_query("{ a, b @skip(if: false) }", |result| {
assert_eq!(result.get("a"), Some(&Value::string("a")));
assert_eq!(result.get("b"), Some(&Value::string("b")));
assert_eq!(result.get_field_value("a"), Some(&Value::string("a")));
assert_eq!(result.get_field_value("b"), Some(&Value::string("b")));
});
}

#[test]
fn scalar_skip_true() {
run_query("{ a, b @skip(if: true) }", |result| {
assert_eq!(result.get("a"), Some(&Value::string("a")));
assert_eq!(result.get("b"), None);
assert_eq!(result.get_field_value("a"), Some(&Value::string("a")));
assert_eq!(result.get_field_value("b"), None);
});
}

Expand All @@ -78,8 +76,8 @@ fn fragment_spread_include_true() {
run_query(
"{ a, ...Frag @include(if: true) } fragment Frag on TestType { b }",
|result| {
assert_eq!(result.get("a"), Some(&Value::string("a")));
assert_eq!(result.get("b"), Some(&Value::string("b")));
assert_eq!(result.get_field_value("a"), Some(&Value::string("a")));
assert_eq!(result.get_field_value("b"), Some(&Value::string("b")));
},
);
}
Expand All @@ -89,8 +87,8 @@ fn fragment_spread_include_false() {
run_query(
"{ a, ...Frag @include(if: false) } fragment Frag on TestType { b }",
|result| {
assert_eq!(result.get("a"), Some(&Value::string("a")));
assert_eq!(result.get("b"), None);
assert_eq!(result.get_field_value("a"), Some(&Value::string("a")));
assert_eq!(result.get_field_value("b"), None);
},
);
}
Expand All @@ -100,8 +98,8 @@ fn fragment_spread_skip_false() {
run_query(
"{ a, ...Frag @skip(if: false) } fragment Frag on TestType { b }",
|result| {
assert_eq!(result.get("a"), Some(&Value::string("a")));
assert_eq!(result.get("b"), Some(&Value::string("b")));
assert_eq!(result.get_field_value("a"), Some(&Value::string("a")));
assert_eq!(result.get_field_value("b"), Some(&Value::string("b")));
},
);
}
Expand All @@ -111,8 +109,8 @@ fn fragment_spread_skip_true() {
run_query(
"{ a, ...Frag @skip(if: true) } fragment Frag on TestType { b }",
|result| {
assert_eq!(result.get("a"), Some(&Value::string("a")));
assert_eq!(result.get("b"), None);
assert_eq!(result.get_field_value("a"), Some(&Value::string("a")));
assert_eq!(result.get_field_value("b"), None);
},
);
}
Expand All @@ -122,8 +120,8 @@ fn inline_fragment_include_true() {
run_query(
"{ a, ... on TestType @include(if: true) { b } }",
|result| {
assert_eq!(result.get("a"), Some(&Value::string("a")));
assert_eq!(result.get("b"), Some(&Value::string("b")));
assert_eq!(result.get_field_value("a"), Some(&Value::string("a")));
assert_eq!(result.get_field_value("b"), Some(&Value::string("b")));
},
);
}
Expand All @@ -133,88 +131,88 @@ fn inline_fragment_include_false() {
run_query(
"{ a, ... on TestType @include(if: false) { b } }",
|result| {
assert_eq!(result.get("a"), Some(&Value::string("a")));
assert_eq!(result.get("b"), None);
assert_eq!(result.get_field_value("a"), Some(&Value::string("a")));
assert_eq!(result.get_field_value("b"), None);
},
);
}

#[test]
fn inline_fragment_skip_false() {
run_query("{ a, ... on TestType @skip(if: false) { b } }", |result| {
assert_eq!(result.get("a"), Some(&Value::string("a")));
assert_eq!(result.get("b"), Some(&Value::string("b")));
assert_eq!(result.get_field_value("a"), Some(&Value::string("a")));
assert_eq!(result.get_field_value("b"), Some(&Value::string("b")));
});
}

#[test]
fn inline_fragment_skip_true() {
run_query("{ a, ... on TestType @skip(if: true) { b } }", |result| {
assert_eq!(result.get("a"), Some(&Value::string("a")));
assert_eq!(result.get("b"), None);
assert_eq!(result.get_field_value("a"), Some(&Value::string("a")));
assert_eq!(result.get_field_value("b"), None);
});
}

#[test]
fn anonymous_inline_fragment_include_true() {
run_query("{ a, ... @include(if: true) { b } }", |result| {
assert_eq!(result.get("a"), Some(&Value::string("a")));
assert_eq!(result.get("b"), Some(&Value::string("b")));
assert_eq!(result.get_field_value("a"), Some(&Value::string("a")));
assert_eq!(result.get_field_value("b"), Some(&Value::string("b")));
});
}

#[test]
fn anonymous_inline_fragment_include_false() {
run_query("{ a, ... @include(if: false) { b } }", |result| {
assert_eq!(result.get("a"), Some(&Value::string("a")));
assert_eq!(result.get("b"), None);
assert_eq!(result.get_field_value("a"), Some(&Value::string("a")));
assert_eq!(result.get_field_value("b"), None);
});
}

#[test]
fn anonymous_inline_fragment_skip_false() {
run_query("{ a, ... @skip(if: false) { b } }", |result| {
assert_eq!(result.get("a"), Some(&Value::string("a")));
assert_eq!(result.get("b"), Some(&Value::string("b")));
assert_eq!(result.get_field_value("a"), Some(&Value::string("a")));
assert_eq!(result.get_field_value("b"), Some(&Value::string("b")));
});
}

#[test]
fn anonymous_inline_fragment_skip_true() {
run_query("{ a, ... @skip(if: true) { b } }", |result| {
assert_eq!(result.get("a"), Some(&Value::string("a")));
assert_eq!(result.get("b"), None);
assert_eq!(result.get_field_value("a"), Some(&Value::string("a")));
assert_eq!(result.get_field_value("b"), None);
});
}

#[test]
fn scalar_include_true_skip_true() {
run_query("{ a, b @include(if: true) @skip(if: true) }", |result| {
assert_eq!(result.get("a"), Some(&Value::string("a")));
assert_eq!(result.get("b"), None);
assert_eq!(result.get_field_value("a"), Some(&Value::string("a")));
assert_eq!(result.get_field_value("b"), None);
});
}

#[test]
fn scalar_include_true_skip_false() {
run_query("{ a, b @include(if: true) @skip(if: false) }", |result| {
assert_eq!(result.get("a"), Some(&Value::string("a")));
assert_eq!(result.get("b"), Some(&Value::string("b")));
assert_eq!(result.get_field_value("a"), Some(&Value::string("a")));
assert_eq!(result.get_field_value("b"), Some(&Value::string("b")));
});
}

#[test]
fn scalar_include_false_skip_true() {
run_query("{ a, b @include(if: false) @skip(if: true) }", |result| {
assert_eq!(result.get("a"), Some(&Value::string("a")));
assert_eq!(result.get("b"), None);
assert_eq!(result.get_field_value("a"), Some(&Value::string("a")));
assert_eq!(result.get_field_value("b"), None);
});
}

#[test]
fn scalar_include_false_skip_false() {
run_query("{ a, b @include(if: false) @skip(if: false) }", |result| {
assert_eq!(result.get("a"), Some(&Value::string("a")));
assert_eq!(result.get("b"), None);
assert_eq!(result.get_field_value("a"), Some(&Value::string("a")));
assert_eq!(result.get_field_value("b"), None);
});
}
14 changes: 6 additions & 8 deletions juniper/src/executor_tests/enums.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
use indexmap::IndexMap;

use ast::InputValue;
use executor::Variables;
use parser::SourcePosition;
use schema::model::RootNode;
use types::scalars::EmptyMutation;
use validation::RuleError;
use value::Value;
use value::{Value, Object};
use GraphQLError::ValidationError;

#[derive(GraphQLEnum, Debug)]
Expand All @@ -30,7 +28,7 @@ graphql_object!(TestType: () |&self| {

fn run_variable_query<F>(query: &str, vars: Variables, f: F)
where
F: Fn(&IndexMap<String, Value>) -> (),
F: Fn(&Object) -> (),
{
let schema = RootNode::new(TestType, EmptyMutation::<()>::new());

Expand All @@ -47,22 +45,22 @@ where

fn run_query<F>(query: &str, f: F)
where
F: Fn(&IndexMap<String, Value>) -> (),
F: Fn(&Object) -> (),
{
run_variable_query(query, Variables::new(), f);
}

#[test]
fn accepts_enum_literal() {
run_query("{ toString(color: RED) }", |result| {
assert_eq!(result.get("toString"), Some(&Value::string("Color::Red")));
assert_eq!(result.get_field_value("toString"), Some(&Value::string("Color::Red")));
});
}

#[test]
fn serializes_as_output() {
run_query("{ aColor }", |result| {
assert_eq!(result.get("aColor"), Some(&Value::string("RED")));
assert_eq!(result.get_field_value("aColor"), Some(&Value::string("RED")));
});
}

Expand Down Expand Up @@ -92,7 +90,7 @@ fn accepts_strings_in_variables() {
.into_iter()
.collect(),
|result| {
assert_eq!(result.get("toString"), Some(&Value::string("Color::Red")));
assert_eq!(result.get_field_value("toString"), Some(&Value::string("Color::Red")));
},
);
}
Expand Down
Loading