diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 65512bd8..3046f0c7 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -1,14 +1,27 @@ jobs: -- template: _build/azure-pipelines-template.yml - parameters: - name: macOS - vmImage: macOS-10.13 + +- job: check_formatting + pool: + vmImage: ubuntu-16.04 + steps: + - script: | + curl https://sh.rustup.rs -sSf | sh -s -- -y + $HOME/.cargo/bin/rustup component add rustfmt + displayName: Install rust + - script: | + $HOME/.cargo/bin/cargo fmt -- --check + displayName: Check formatting - template: _build/azure-pipelines-template.yml parameters: name: Linux vmImage: ubuntu-16.04 +- template: _build/azure-pipelines-template.yml + parameters: + name: macOS + vmImage: macOS-10.13 + - template: _build/azure-pipelines-template.yml parameters: name: Windows diff --git a/integration_tests/juniper_2018_edition_tests/src/main.rs b/integration_tests/juniper_2018_edition_tests/src/main.rs index 82b6b3da..95677e37 100644 --- a/integration_tests/juniper_2018_edition_tests/src/main.rs +++ b/integration_tests/juniper_2018_edition_tests/src/main.rs @@ -31,6 +31,4 @@ juniper::graphql_object!(Query: () |&self| { } }); - -fn main() { -} +fn main() {} diff --git a/integration_tests/juniper_tests/src/codegen/derive_enum.rs b/integration_tests/juniper_tests/src/codegen/derive_enum.rs index 755ec67b..42f3d2c0 100644 --- a/integration_tests/juniper_tests/src/codegen/derive_enum.rs +++ b/integration_tests/juniper_tests/src/codegen/derive_enum.rs @@ -8,11 +8,7 @@ use juniper::{self, DefaultScalarValue, FromInputValue, GraphQLType, InputValue, #[graphql(name = "Some", description = "enum descr")] enum SomeEnum { Regular, - #[graphql( - name = "FULL", - description = "field descr", - deprecated = "depr" - )] + #[graphql(name = "FULL", description = "field descr", deprecated = "depr")] Full, } diff --git a/integration_tests/juniper_tests/src/codegen/derive_input_object.rs b/integration_tests/juniper_tests/src/codegen/derive_input_object.rs index cd255981..0db48933 100644 --- a/integration_tests/juniper_tests/src/codegen/derive_input_object.rs +++ b/integration_tests/juniper_tests/src/codegen/derive_input_object.rs @@ -105,7 +105,8 @@ fn test_derived_input_object() { let input_no_defaults: InputValue = ::serde_json::from_value(json!({ "regularField": "a", - })).unwrap(); + })) + .unwrap(); let output_no_defaults: Input = FromInputValue::from_input_value(&input_no_defaults).unwrap(); assert_eq!( @@ -123,7 +124,8 @@ fn test_derived_input_object() { "regularField": "a", "haha": 55, "other": true, - })).unwrap(); + })) + .unwrap(); let output: Input = FromInputValue::from_input_value(&input).unwrap(); assert_eq!( diff --git a/integration_tests/juniper_tests/src/codegen/derive_object.rs b/integration_tests/juniper_tests/src/codegen/derive_object.rs index 26acf9a1..fe63d3ae 100644 --- a/integration_tests/juniper_tests/src/codegen/derive_object.rs +++ b/integration_tests/juniper_tests/src/codegen/derive_object.rs @@ -189,10 +189,12 @@ fn test_derived_object() { vec![ ("regularField", Value::scalar(true)), ("renamedField", Value::scalar(22)), - ].into_iter() + ] + .into_iter() .collect(), ), - )].into_iter() + )] + .into_iter() .collect() ), vec![] @@ -252,13 +254,16 @@ fn test_derived_object_nested() { vec![ ("regularField", Value::scalar(false)), ("renamedField", Value::scalar(333)), - ].into_iter() + ] + .into_iter() .collect(), ), - )].into_iter() + )] + .into_iter() .collect(), ), - )].into_iter() + )] + .into_iter() .collect() ), vec![] @@ -297,15 +302,14 @@ fn check_descriptions( type_info.get_field_value("description"), Some(object_description) ); - assert!( - values.contains(&Value::object( - vec![ - ("name", Value::scalar(field_name)), - ("description", field_value.clone()), - ].into_iter() - .collect(), - )) - ); + assert!(values.contains(&Value::object( + vec![ + ("name", Value::scalar(field_name)), + ("description", field_value.clone()), + ] + .into_iter() + .collect(), + ))); }); } diff --git a/integration_tests/juniper_tests/src/custom_scalar.rs b/integration_tests/juniper_tests/src/custom_scalar.rs index d54e3fa7..4c33a5d7 100644 --- a/integration_tests/juniper_tests/src/custom_scalar.rs +++ b/integration_tests/juniper_tests/src/custom_scalar.rs @@ -220,7 +220,8 @@ fn querying_long_variable() { vec![( "test".to_owned(), InputValue::Scalar(MyScalarValue::Long((::std::i32::MAX as i64) + 42)), - )].into_iter() + )] + .into_iter() .collect(), |result| { assert_eq!( diff --git a/juniper/src/ast.rs b/juniper/src/ast.rs index df325957..21da312e 100644 --- a/juniper/src/ast.rs +++ b/juniper/src/ast.rs @@ -8,7 +8,7 @@ use indexmap::IndexMap; use executor::Variables; use parser::Spanning; -use value::{ScalarRefValue, ScalarValue, DefaultScalarValue}; +use value::{DefaultScalarValue, ScalarRefValue, ScalarValue}; /// A type literal in the syntax tree /// @@ -285,7 +285,8 @@ where Spanning::unlocated(k.as_ref().to_owned()), Spanning::unlocated(v), ) - }).collect(), + }) + .collect(), ) } @@ -346,10 +347,7 @@ where } /// View the underlying int value, if present. - #[deprecated( - since = "0.11.0", - note = "Use `InputValue::as_scalar_value` instead" - )] + #[deprecated(since = "0.11.0", note = "Use `InputValue::as_scalar_value` instead")] pub fn as_int_value<'a>(&'a self) -> Option where &'a S: Into>, @@ -358,10 +356,7 @@ where } /// View the underlying float value, if present. - #[deprecated( - since = "0.11.0", - note = "Use `InputValue::as_scalar_value` instead" - )] + #[deprecated(since = "0.11.0", note = "Use `InputValue::as_scalar_value` instead")] pub fn as_float_value<'a>(&'a self) -> Option where &'a S: Into>, @@ -370,10 +365,7 @@ where } /// View the underlying string value, if present. - #[deprecated( - since = "0.11.0", - note = "Use `InputValue::as_scalar_value` instead" - )] + #[deprecated(since = "0.11.0", note = "Use `InputValue::as_scalar_value` instead")] pub fn as_string_value<'a>(&'a self) -> Option<&'a str> where &'a S: Into>, @@ -453,11 +445,12 @@ where .zip(l2.iter()) .all(|(v1, v2)| v1.item.unlocated_eq(&v2.item)), (&Object(ref o1), &Object(ref o2)) => { - o1.len() == o2.len() && o1.iter().all(|&(ref sk1, ref sv1)| { - o2.iter().any(|&(ref sk2, ref sv2)| { - sk1.item == sk2.item && sv1.item.unlocated_eq(&sv2.item) + o1.len() == o2.len() + && o1.iter().all(|&(ref sk1, ref sv1)| { + o2.iter().any(|&(ref sk2, ref sv2)| { + sk1.item == sk2.item && sv1.item.unlocated_eq(&sv2.item) + }) }) - }) } _ => false, } diff --git a/juniper/src/executor/look_ahead.rs b/juniper/src/executor/look_ahead.rs index 37e725ba..17a144b1 100644 --- a/juniper/src/executor/look_ahead.rs +++ b/juniper/src/executor/look_ahead.rs @@ -52,7 +52,8 @@ where &n.item as &str, LookAheadValue::from_input_value(&i.item, vars), ) - }).collect(), + }) + .collect(), ), } } @@ -134,7 +135,8 @@ where } else { false } - }).unwrap_or(false), + }) + .unwrap_or(false), ("skip", &Some(ref a)) => a .item .items @@ -150,13 +152,15 @@ where } else { false } - }).unwrap_or(false), + }) + .unwrap_or(false), ("skip", &None) => false, ("include", &None) => true, (_, _) => unreachable!(), } }) - }).unwrap_or(true) + }) + .unwrap_or(true) } pub(super) fn build_from_selection( @@ -192,7 +196,8 @@ where .iter() .map(|p| LookAheadArgument::new(p, vars)) .collect() - }).unwrap_or_else(Vec::new); + }) + .unwrap_or_else(Vec::new); let mut ret = LookAheadSelection { name, alias, @@ -280,7 +285,8 @@ where } Applies::All => Some(c.inner.for_explicit_type(type_name)), Applies::OnlyType(_) => None, - }).collect(), + }) + .collect(), name: self.name, alias: self.alias, arguments: self.arguments.clone(), @@ -390,7 +396,8 @@ query Hero { } } ", - ).unwrap(); + ) + .unwrap(); let fragments = extract_fragments(&docs); if let ::ast::Definition::Operation(ref op) = docs[0] { @@ -442,7 +449,8 @@ query Hero { } } ", - ).unwrap(); + ) + .unwrap(); let fragments = extract_fragments(&docs); if let ::ast::Definition::Operation(ref op) = docs[0] { @@ -498,7 +506,8 @@ query Hero { } } ", - ).unwrap(); + ) + .unwrap(); let fragments = extract_fragments(&docs); if let ::ast::Definition::Operation(ref op) = docs[0] { @@ -578,7 +587,8 @@ query Hero { } } ", - ).unwrap(); + ) + .unwrap(); let fragments = extract_fragments(&docs); if let ::ast::Definition::Operation(ref op) = docs[0] { @@ -636,7 +646,8 @@ query Hero($episode: Episode) { } } ", - ).unwrap(); + ) + .unwrap(); let fragments = extract_fragments(&docs); if let ::ast::Definition::Operation(ref op) = docs[0] { @@ -697,7 +708,8 @@ fragment commonFields on Character { appearsIn } ", - ).unwrap(); + ) + .unwrap(); let fragments = extract_fragments(&docs); if let ::ast::Definition::Operation(ref op) = docs[0] { @@ -759,7 +771,8 @@ query Hero { height @skip(if: false) } }", - ).unwrap(); + ) + .unwrap(); let fragments = extract_fragments(&docs); if let ::ast::Definition::Operation(ref op) = docs[0] { @@ -815,7 +828,8 @@ query Hero { } } }", - ).unwrap(); + ) + .unwrap(); let fragments = extract_fragments(&docs); if let ::ast::Definition::Operation(ref op) = docs[0] { @@ -887,7 +901,8 @@ fragment comparisonFields on Character { ... on Droid { primaryFunction } ... on Human { height } }", - ).unwrap(); + ) + .unwrap(); let fragments = extract_fragments(&docs); if let ::ast::Definition::Operation(ref op) = docs[0] { @@ -1043,7 +1058,8 @@ query Hero { } } }", - ).unwrap(); + ) + .unwrap(); let fragments = extract_fragments(&docs); if let ::ast::Definition::Operation(ref op) = docs[0] { @@ -1052,7 +1068,8 @@ query Hero { &op.item.selection_set[0], &vars, &fragments, - ).for_explicit_type("Human"); + ) + .for_explicit_type("Human"); let expected = ConcreteLookAheadSelection { name: "hero", alias: None, diff --git a/juniper/src/executor/mod.rs b/juniper/src/executor/mod.rs index e06e73f7..03c923aa 100644 --- a/juniper/src/executor/mod.rs +++ b/juniper/src/executor/mod.rs @@ -515,7 +515,8 @@ where self.parent_selection_set .map(|p| { LookAheadSelection::build_from_selection(&p[0], self.variables, self.fragments) - }).unwrap_or_else(|| LookAheadSelection { + }) + .unwrap_or_else(|| LookAheadSelection { name: self.current_type.innermost_concrete().name().unwrap_or(""), alias: None, arguments: Vec::new(), @@ -530,8 +531,10 @@ where self.fragments, ), applies_for: Applies::All, - }).collect() - }).unwrap_or_else(Vec::new), + }) + .collect() + }) + .unwrap_or_else(Vec::new), }) } } @@ -627,7 +630,8 @@ where def.default_value .as_ref() .map(|i| (name.item.to_owned(), i.item.clone())) - }).collect::>>() + }) + .collect::>>() }); let errors = RwLock::new(Vec::new()); diff --git a/juniper/src/executor_tests/directives.rs b/juniper/src/executor_tests/directives.rs index 1aaaa2ac..751e5cbb 100644 --- a/juniper/src/executor_tests/directives.rs +++ b/juniper/src/executor_tests/directives.rs @@ -1,7 +1,7 @@ use executor::Variables; use schema::model::RootNode; use types::scalars::EmptyMutation; -use value::{Value, Object, DefaultScalarValue}; +use value::{DefaultScalarValue, Object, Value}; struct TestType; diff --git a/juniper/src/executor_tests/executor.rs b/juniper/src/executor_tests/executor.rs index e9fba95f..0049b46b 100644 --- a/juniper/src/executor_tests/executor.rs +++ b/juniper/src/executor_tests/executor.rs @@ -103,7 +103,8 @@ mod field_execution { vec![ ("a", Value::scalar("Apple")), ("b", Value::scalar("Banana")), - ].into_iter() + ] + .into_iter() .collect(), ), Value::null(), @@ -111,16 +112,19 @@ mod field_execution { vec![ ("a", Value::scalar("Apple")), ("b", Value::scalar("Banana")), - ].into_iter() + ] + .into_iter() .collect(), ), ]), ), - ].into_iter() + ] + .into_iter() .collect(), ), ), - ].into_iter() + ] + .into_iter() .collect() ) ); @@ -180,17 +184,20 @@ mod merge_parallel_fragments { vec![ ("b", Value::scalar("Banana")), ("c", Value::scalar("Cherry")), - ].into_iter() + ] + .into_iter() .collect(), ), ), ("c", Value::scalar("Cherry")), - ].into_iter() + ] + .into_iter() .collect(), ), ), ("c", Value::scalar("Cherry")), - ].into_iter() + ] + .into_iter() .collect() ) ); @@ -278,10 +285,12 @@ mod merge_parallel_inline_fragments { vec![ ("b", Value::scalar("Banana")), ("c", Value::scalar("Cherry")), - ].into_iter() + ] + .into_iter() .collect(), ), - )].into_iter() + )] + .into_iter() .collect(), ), Value::object( @@ -291,21 +300,25 @@ mod merge_parallel_inline_fragments { vec![ ("b", Value::scalar("Banana")), ("c", Value::scalar("Cherry")), - ].into_iter() + ] + .into_iter() .collect(), ), - )].into_iter() + )] + .into_iter() .collect(), ), ]), ), ("c", Value::scalar("Cherry")), - ].into_iter() + ] + .into_iter() .collect(), ), ), ("c", Value::scalar("Cherry")), - ].into_iter() + ] + .into_iter() .collect() ) ); @@ -345,7 +358,8 @@ mod threads_context_correctly { &TestContext { value: "Context value".to_owned(), }, - ).expect("Execution failed"); + ) + .expect("Execution failed"); assert_eq!(errs, []); @@ -438,7 +452,8 @@ mod dynamic_context_switching { value: "Second value".to_owned(), }, ), - ].into_iter() + ] + .into_iter() .collect(), }; @@ -461,7 +476,8 @@ mod dynamic_context_switching { ), ), ("missing", Value::null()), - ].into_iter() + ] + .into_iter() .collect() ) ); @@ -492,7 +508,8 @@ mod dynamic_context_switching { value: "Second value".to_owned(), }, ), - ].into_iter() + ] + .into_iter() .collect(), }; @@ -512,7 +529,8 @@ mod dynamic_context_switching { .into_iter() .collect(), ), - )].into_iter() + )] + .into_iter() .collect() ) ); @@ -543,7 +561,8 @@ mod dynamic_context_switching { value: "Second value".to_owned(), }, ), - ].into_iter() + ] + .into_iter() .collect(), }; @@ -590,7 +609,8 @@ mod dynamic_context_switching { value: "Second value".to_owned(), }, ), - ].into_iter() + ] + .into_iter() .collect(), }; @@ -621,7 +641,8 @@ mod dynamic_context_switching { ), ("missing", Value::null()), ("tooLarge", Value::null()), - ].into_iter() + ] + .into_iter() .collect() ) ); @@ -648,7 +669,8 @@ mod dynamic_context_switching { value: "Second value".to_owned(), }, ), - ].into_iter() + ] + .into_iter() .collect(), }; @@ -668,7 +690,8 @@ mod dynamic_context_switching { .into_iter() .collect(), ), - )].into_iter() + )] + .into_iter() .collect() ) ); diff --git a/juniper/src/executor_tests/interfaces_unions.rs b/juniper/src/executor_tests/interfaces_unions.rs index e4890f5a..11a64870 100644 --- a/juniper/src/executor_tests/interfaces_unions.rs +++ b/juniper/src/executor_tests/interfaces_unions.rs @@ -123,18 +123,21 @@ mod interface { vec![ ("name", Value::scalar("Odie")), ("woofs", Value::scalar(true)), - ].into_iter() + ] + .into_iter() .collect(), ), Value::object( vec![ ("name", Value::scalar("Garfield")), ("meows", Value::scalar(false)), - ].into_iter() + ] + .into_iter() .collect(), ), ]), - )].into_iter() + )] + .into_iter() .collect() ) ); @@ -255,7 +258,8 @@ mod union { ("__typename", Value::scalar("Dog")), ("name", Value::scalar("Odie")), ("woofs", Value::scalar(true)), - ].into_iter() + ] + .into_iter() .collect(), ), Value::object( @@ -263,11 +267,13 @@ mod union { ("__typename", Value::scalar("Cat")), ("name", Value::scalar("Garfield")), ("meows", Value::scalar(false)), - ].into_iter() + ] + .into_iter() .collect(), ), ]), - )].into_iter() + )] + .into_iter() .collect() ) ); diff --git a/juniper/src/executor_tests/introspection/enums.rs b/juniper/src/executor_tests/introspection/enums.rs index 287494f6..d1a267d4 100644 --- a/juniper/src/executor_tests/introspection/enums.rs +++ b/juniper/src/executor_tests/introspection/enums.rs @@ -1,7 +1,7 @@ use executor::Variables; use schema::model::RootNode; use types::scalars::EmptyMutation; -use value::{Value, Object, DefaultScalarValue}; +use value::{DefaultScalarValue, Object, Value}; /* @@ -53,7 +53,10 @@ enum EnumValueDescription { enum EnumDeprecation { #[graphql(deprecated = "Please don't use FOO any more")] Foo, - #[graphql(description = "The BAR value", deprecated = "Please don't use BAR any more")] + #[graphql( + description = "The BAR value", + deprecated = "Please don't use BAR any more" + )] Bar, } @@ -116,34 +119,38 @@ fn default_name_introspection() { "#; run_type_info_query(doc, |(type_info, values)| { - assert_eq!(type_info.get_field_value("name"), Some(&Value::scalar("DefaultName"))); - assert_eq!(type_info.get_field_value("description"), Some(&Value::null())); + assert_eq!( + type_info.get_field_value("name"), + Some(&Value::scalar("DefaultName")) + ); + assert_eq!( + type_info.get_field_value("description"), + Some(&Value::null()) + ); assert_eq!(values.len(), 2); - assert!( - values.contains(&Value::object( - vec![ - ("name", Value::scalar("FOO")), - ("description", Value::null()), - ("isDeprecated", Value::scalar(false)), - ("deprecationReason", Value::null()), - ].into_iter() - .collect(), - )) - ); + assert!(values.contains(&Value::object( + vec![ + ("name", Value::scalar("FOO")), + ("description", Value::null()), + ("isDeprecated", Value::scalar(false)), + ("deprecationReason", Value::null()), + ] + .into_iter() + .collect(), + ))); - assert!( - values.contains(&Value::object( - vec![ - ("name", Value::scalar("BAR")), - ("description", Value::null()), - ("isDeprecated", Value::scalar(false)), - ("deprecationReason", Value::null()), - ].into_iter() - .collect(), - )) - ); + assert!(values.contains(&Value::object( + vec![ + ("name", Value::scalar("BAR")), + ("description", Value::null()), + ("isDeprecated", Value::scalar(false)), + ("deprecationReason", Value::null()), + ] + .into_iter() + .collect(), + ))); }); } @@ -165,34 +172,38 @@ fn named_introspection() { "#; run_type_info_query(doc, |(type_info, values)| { - assert_eq!(type_info.get_field_value("name"), Some(&Value::scalar("ANamedEnum"))); - assert_eq!(type_info.get_field_value("description"), Some(&Value::null())); + assert_eq!( + type_info.get_field_value("name"), + Some(&Value::scalar("ANamedEnum")) + ); + assert_eq!( + type_info.get_field_value("description"), + Some(&Value::null()) + ); assert_eq!(values.len(), 2); - assert!( - values.contains(&Value::object( - vec![ - ("name", Value::scalar("FOO")), - ("description", Value::null()), - ("isDeprecated", Value::scalar(false)), - ("deprecationReason", Value::null()), - ].into_iter() - .collect(), - )) - ); + assert!(values.contains(&Value::object( + vec![ + ("name", Value::scalar("FOO")), + ("description", Value::null()), + ("isDeprecated", Value::scalar(false)), + ("deprecationReason", Value::null()), + ] + .into_iter() + .collect(), + ))); - assert!( - values.contains(&Value::object( - vec![ - ("name", Value::scalar("BAR")), - ("description", Value::null()), - ("isDeprecated", Value::scalar(false)), - ("deprecationReason", Value::null()), - ].into_iter() - .collect(), - )) - ); + assert!(values.contains(&Value::object( + vec![ + ("name", Value::scalar("BAR")), + ("description", Value::null()), + ("isDeprecated", Value::scalar(false)), + ("deprecationReason", Value::null()), + ] + .into_iter() + .collect(), + ))); }); } @@ -218,33 +229,34 @@ fn no_trailing_comma_introspection() { type_info.get_field_value("name"), Some(&Value::scalar("NoTrailingComma")) ); - assert_eq!(type_info.get_field_value("description"), Some(&Value::null())); + assert_eq!( + type_info.get_field_value("description"), + Some(&Value::null()) + ); assert_eq!(values.len(), 2); - assert!( - values.contains(&Value::object( - vec![ - ("name", Value::scalar("FOO")), - ("description", Value::null()), - ("isDeprecated", Value::scalar(false)), - ("deprecationReason", Value::null()), - ].into_iter() - .collect(), - )) - ); + assert!(values.contains(&Value::object( + vec![ + ("name", Value::scalar("FOO")), + ("description", Value::null()), + ("isDeprecated", Value::scalar(false)), + ("deprecationReason", Value::null()), + ] + .into_iter() + .collect(), + ))); - assert!( - values.contains(&Value::object( - vec![ - ("name", Value::scalar("BAR")), - ("description", Value::null()), - ("isDeprecated", Value::scalar(false)), - ("deprecationReason", Value::null()), - ].into_iter() - .collect(), - )) - ); + assert!(values.contains(&Value::object( + vec![ + ("name", Value::scalar("BAR")), + ("description", Value::null()), + ("isDeprecated", Value::scalar(false)), + ("deprecationReason", Value::null()), + ] + .into_iter() + .collect(), + ))); }); } @@ -277,29 +289,27 @@ fn enum_description_introspection() { assert_eq!(values.len(), 2); - assert!( - values.contains(&Value::object( - vec![ - ("name", Value::scalar("FOO")), - ("description", Value::null()), - ("isDeprecated", Value::scalar(false)), - ("deprecationReason", Value::null()), - ].into_iter() - .collect(), - )) - ); + assert!(values.contains(&Value::object( + vec![ + ("name", Value::scalar("FOO")), + ("description", Value::null()), + ("isDeprecated", Value::scalar(false)), + ("deprecationReason", Value::null()), + ] + .into_iter() + .collect(), + ))); - assert!( - values.contains(&Value::object( - vec![ - ("name", Value::scalar("BAR")), - ("description", Value::null()), - ("isDeprecated", Value::scalar(false)), - ("deprecationReason", Value::null()), - ].into_iter() - .collect(), - )) - ); + assert!(values.contains(&Value::object( + vec![ + ("name", Value::scalar("BAR")), + ("description", Value::null()), + ("isDeprecated", Value::scalar(false)), + ("deprecationReason", Value::null()), + ] + .into_iter() + .collect(), + ))); }); } @@ -325,33 +335,34 @@ fn enum_value_description_introspection() { type_info.get_field_value("name"), Some(&Value::scalar("EnumValueDescription")) ); - assert_eq!(type_info.get_field_value("description"), Some(&Value::null())); + assert_eq!( + type_info.get_field_value("description"), + Some(&Value::null()) + ); assert_eq!(values.len(), 2); - assert!( - values.contains(&Value::object( - vec![ - ("name", Value::scalar("FOO")), - ("description", Value::scalar("The FOO value")), - ("isDeprecated", Value::scalar(false)), - ("deprecationReason", Value::null()), - ].into_iter() - .collect(), - )) - ); + assert!(values.contains(&Value::object( + vec![ + ("name", Value::scalar("FOO")), + ("description", Value::scalar("The FOO value")), + ("isDeprecated", Value::scalar(false)), + ("deprecationReason", Value::null()), + ] + .into_iter() + .collect(), + ))); - assert!( - values.contains(&Value::object( - vec![ - ("name", Value::scalar("BAR")), - ("description", Value::scalar("The BAR value")), - ("isDeprecated", Value::scalar(false)), - ("deprecationReason", Value::null()), - ].into_iter() - .collect(), - )) - ); + assert!(values.contains(&Value::object( + vec![ + ("name", Value::scalar("BAR")), + ("description", Value::scalar("The BAR value")), + ("isDeprecated", Value::scalar(false)), + ("deprecationReason", Value::null()), + ] + .into_iter() + .collect(), + ))); }); } @@ -377,39 +388,40 @@ fn enum_deprecation_introspection() { type_info.get_field_value("name"), Some(&Value::scalar("EnumDeprecation")) ); - assert_eq!(type_info.get_field_value("description"), Some(&Value::null())); + assert_eq!( + type_info.get_field_value("description"), + Some(&Value::null()) + ); assert_eq!(values.len(), 2); - assert!( - values.contains(&Value::object( - vec![ - ("name", Value::scalar("FOO")), - ("description", Value::null()), - ("isDeprecated", Value::scalar(true)), - ( - "deprecationReason", - Value::scalar("Please don't use FOO any more"), - ), - ].into_iter() - .collect(), - )) - ); + assert!(values.contains(&Value::object( + vec![ + ("name", Value::scalar("FOO")), + ("description", Value::null()), + ("isDeprecated", Value::scalar(true)), + ( + "deprecationReason", + Value::scalar("Please don't use FOO any more"), + ), + ] + .into_iter() + .collect(), + ))); - assert!( - values.contains(&Value::object( - vec![ - ("name", Value::scalar("BAR")), - ("description", Value::scalar("The BAR value")), - ("isDeprecated", Value::scalar(true)), - ( - "deprecationReason", - Value::scalar("Please don't use BAR any more"), - ), - ].into_iter() - .collect(), - )) - ); + assert!(values.contains(&Value::object( + vec![ + ("name", Value::scalar("BAR")), + ("description", Value::scalar("The BAR value")), + ("isDeprecated", Value::scalar(true)), + ( + "deprecationReason", + Value::scalar("Please don't use BAR any more"), + ), + ] + .into_iter() + .collect(), + ))); }); } @@ -435,7 +447,10 @@ fn enum_deprecation_no_values_introspection() { type_info.get_field_value("name"), Some(&Value::scalar("EnumDeprecation")) ); - assert_eq!(type_info.get_field_value("description"), Some(&Value::null())); + assert_eq!( + type_info.get_field_value("description"), + Some(&Value::null()) + ); assert_eq!(values.len(), 0); }); diff --git a/juniper/src/executor_tests/introspection/input_object.rs b/juniper/src/executor_tests/introspection/input_object.rs index 9258f1ca..f87539af 100644 --- a/juniper/src/executor_tests/introspection/input_object.rs +++ b/juniper/src/executor_tests/introspection/input_object.rs @@ -49,7 +49,7 @@ pub struct PublicWithDescription { #[derive(GraphQLInputObjectInternal, Debug)] #[graphql( name = "APublicNamedInputObjectWithDescription", - description = "Description for the input object", + description = "Description for the input object" )] pub struct NamedPublicWithDescription { field_one: String, @@ -158,55 +158,55 @@ fn default_name_introspection() { assert_eq!(fields.len(), 2); - assert!( - fields.contains(&Value::object( - vec![ - ("name", Value::scalar("fieldOne")), - ("description", Value::null()), - ( - "type", - Value::object( - vec![( - "ofType", - Value::object( - vec![("name", Value::scalar("String"))] - .into_iter() - .collect(), - ), - )].into_iter() - .collect(), - ), + assert!(fields.contains(&Value::object( + vec![ + ("name", Value::scalar("fieldOne")), + ("description", Value::null()), + ( + "type", + Value::object( + vec![( + "ofType", + Value::object( + vec![("name", Value::scalar("String"))] + .into_iter() + .collect(), + ), + )] + .into_iter() + .collect(), ), - ("defaultValue", Value::null()), - ].into_iter() - .collect(), - )) - ); + ), + ("defaultValue", Value::null()), + ] + .into_iter() + .collect(), + ))); - assert!( - fields.contains(&Value::object( - vec![ - ("name", Value::scalar("fieldTwo")), - ("description", Value::null()), - ( - "type", - Value::object( - vec![( - "ofType", - Value::object( - vec![("name", Value::scalar("String"))] - .into_iter() - .collect(), - ), - )].into_iter() - .collect(), - ), + assert!(fields.contains(&Value::object( + vec![ + ("name", Value::scalar("fieldTwo")), + ("description", Value::null()), + ( + "type", + Value::object( + vec![( + "ofType", + Value::object( + vec![("name", Value::scalar("String"))] + .into_iter() + .collect(), + ), + )] + .into_iter() + .collect(), ), - ("defaultValue", Value::null()), - ].into_iter() - .collect(), - )) - ); + ), + ("defaultValue", Value::null()), + ] + .into_iter() + .collect(), + ))); }); } @@ -216,7 +216,8 @@ fn default_name_input_value() { vec![ ("fieldOne", InputValue::scalar("number one")), ("fieldTwo", InputValue::scalar("number two")), - ].into_iter() + ] + .into_iter() .collect(), ); @@ -263,55 +264,55 @@ fn no_trailing_comma_introspection() { assert_eq!(fields.len(), 2); - assert!( - fields.contains(&Value::object( - vec![ - ("name", Value::scalar("fieldOne")), - ("description", Value::null()), - ( - "type", - Value::object( - vec![( - "ofType", - Value::object( - vec![("name", Value::scalar("String"))] - .into_iter() - .collect(), - ), - )].into_iter() - .collect(), - ), + assert!(fields.contains(&Value::object( + vec![ + ("name", Value::scalar("fieldOne")), + ("description", Value::null()), + ( + "type", + Value::object( + vec![( + "ofType", + Value::object( + vec![("name", Value::scalar("String"))] + .into_iter() + .collect(), + ), + )] + .into_iter() + .collect(), ), - ("defaultValue", Value::null()), - ].into_iter() - .collect(), - )) - ); + ), + ("defaultValue", Value::null()), + ] + .into_iter() + .collect(), + ))); - assert!( - fields.contains(&Value::object( - vec![ - ("name", Value::scalar("fieldTwo")), - ("description", Value::null()), - ( - "type", - Value::object( - vec![( - "ofType", - Value::object( - vec![("name", Value::scalar("String"))] - .into_iter() - .collect(), - ), - )].into_iter() - .collect(), - ), + assert!(fields.contains(&Value::object( + vec![ + ("name", Value::scalar("fieldTwo")), + ("description", Value::null()), + ( + "type", + Value::object( + vec![( + "ofType", + Value::object( + vec![("name", Value::scalar("String"))] + .into_iter() + .collect(), + ), + )] + .into_iter() + .collect(), ), - ("defaultValue", Value::null()), - ].into_iter() - .collect(), - )) - ); + ), + ("defaultValue", Value::null()), + ] + .into_iter() + .collect(), + ))); }); } @@ -348,30 +349,30 @@ fn derive_introspection() { assert_eq!(fields.len(), 1); - assert!( - fields.contains(&Value::object( - vec![ - ("name", Value::scalar("fieldOne")), - ("description", Value::null()), - ( - "type", - Value::object( - vec![( - "ofType", - Value::object( - vec![("name", Value::scalar("String"))] - .into_iter() - .collect(), - ), - )].into_iter() - .collect(), - ), + assert!(fields.contains(&Value::object( + vec![ + ("name", Value::scalar("fieldOne")), + ("description", Value::null()), + ( + "type", + Value::object( + vec![( + "ofType", + Value::object( + vec![("name", Value::scalar("String"))] + .into_iter() + .collect(), + ), + )] + .into_iter() + .collect(), ), - ("defaultValue", Value::null()), - ].into_iter() - .collect(), - )) - ); + ), + ("defaultValue", Value::null()), + ] + .into_iter() + .collect(), + ))); }); } @@ -421,30 +422,30 @@ fn named_introspection() { assert_eq!(fields.len(), 1); - assert!( - fields.contains(&Value::object( - vec![ - ("name", Value::scalar("fieldOne")), - ("description", Value::null()), - ( - "type", - Value::object( - vec![( - "ofType", - Value::object( - vec![("name", Value::scalar("String"))] - .into_iter() - .collect(), - ), - )].into_iter() - .collect(), - ), + assert!(fields.contains(&Value::object( + vec![ + ("name", Value::scalar("fieldOne")), + ("description", Value::null()), + ( + "type", + Value::object( + vec![( + "ofType", + Value::object( + vec![("name", Value::scalar("String"))] + .into_iter() + .collect(), + ), + )] + .into_iter() + .collect(), ), - ("defaultValue", Value::null()), - ].into_iter() - .collect(), - )) - ); + ), + ("defaultValue", Value::null()), + ] + .into_iter() + .collect(), + ))); }); } @@ -481,30 +482,30 @@ fn description_introspection() { assert_eq!(fields.len(), 1); - assert!( - fields.contains(&Value::object( - vec![ - ("name", Value::scalar("fieldOne")), - ("description", Value::null()), - ( - "type", - Value::object( - vec![( - "ofType", - Value::object( - vec![("name", Value::scalar("String"))] - .into_iter() - .collect(), - ), - )].into_iter() - .collect(), - ), + assert!(fields.contains(&Value::object( + vec![ + ("name", Value::scalar("fieldOne")), + ("description", Value::null()), + ( + "type", + Value::object( + vec![( + "ofType", + Value::object( + vec![("name", Value::scalar("String"))] + .into_iter() + .collect(), + ), + )] + .into_iter() + .collect(), ), - ("defaultValue", Value::null()), - ].into_iter() - .collect(), - )) - ); + ), + ("defaultValue", Value::null()), + ] + .into_iter() + .collect(), + ))); }); } @@ -541,55 +542,55 @@ fn field_description_introspection() { assert_eq!(fields.len(), 2); - assert!( - fields.contains(&Value::object( - vec![ - ("name", Value::scalar("fieldOne")), - ("description", Value::scalar("The first field")), - ( - "type", - Value::object( - vec![( - "ofType", - Value::object( - vec![("name", Value::scalar("String"))] - .into_iter() - .collect(), - ), - )].into_iter() - .collect(), - ), + assert!(fields.contains(&Value::object( + vec![ + ("name", Value::scalar("fieldOne")), + ("description", Value::scalar("The first field")), + ( + "type", + Value::object( + vec![( + "ofType", + Value::object( + vec![("name", Value::scalar("String"))] + .into_iter() + .collect(), + ), + )] + .into_iter() + .collect(), ), - ("defaultValue", Value::null()), - ].into_iter() - .collect(), - )) - ); + ), + ("defaultValue", Value::null()), + ] + .into_iter() + .collect(), + ))); - assert!( - fields.contains(&Value::object( - vec![ - ("name", Value::scalar("fieldTwo")), - ("description", Value::scalar("The second field")), - ( - "type", - Value::object( - vec![( - "ofType", - Value::object( - vec![("name", Value::scalar("String"))] - .into_iter() - .collect(), - ), - )].into_iter() - .collect(), - ), + assert!(fields.contains(&Value::object( + vec![ + ("name", Value::scalar("fieldTwo")), + ("description", Value::scalar("The second field")), + ( + "type", + Value::object( + vec![( + "ofType", + Value::object( + vec![("name", Value::scalar("String"))] + .into_iter() + .collect(), + ), + )] + .into_iter() + .collect(), ), - ("defaultValue", Value::null()), - ].into_iter() - .collect(), - )) - ); + ), + ("defaultValue", Value::null()), + ] + .into_iter() + .collect(), + ))); }); } @@ -618,32 +619,30 @@ fn field_with_defaults_introspection() { assert_eq!(fields.len(), 2); - assert!( - fields.contains(&Value::object( - vec![ - ("name", Value::scalar("fieldOne")), - ( - "type", - Value::object(vec![("name", Value::scalar("Int"))].into_iter().collect()), - ), - ("defaultValue", Value::scalar("123")), - ].into_iter() - .collect(), - )) - ); + assert!(fields.contains(&Value::object( + vec![ + ("name", Value::scalar("fieldOne")), + ( + "type", + Value::object(vec![("name", Value::scalar("Int"))].into_iter().collect()), + ), + ("defaultValue", Value::scalar("123")), + ] + .into_iter() + .collect(), + ))); - assert!( - fields.contains(&Value::object( - vec![ - ("name", Value::scalar("fieldTwo")), - ( - "type", - Value::object(vec![("name", Value::scalar("Int"))].into_iter().collect()), - ), - ("defaultValue", Value::scalar("456")), - ].into_iter() - .collect(), - )) - ); + assert!(fields.contains(&Value::object( + vec![ + ("name", Value::scalar("fieldTwo")), + ( + "type", + Value::object(vec![("name", Value::scalar("Int"))].into_iter().collect()), + ), + ("defaultValue", Value::scalar("456")), + ] + .into_iter() + .collect(), + ))); }); } diff --git a/juniper/src/executor_tests/introspection/mod.rs b/juniper/src/executor_tests/introspection/mod.rs index d9c88b74..bc1d1a18 100644 --- a/juniper/src/executor_tests/introspection/mod.rs +++ b/juniper/src/executor_tests/introspection/mod.rs @@ -91,7 +91,8 @@ fn test_execution() { ("sampleEnum", Value::scalar("ONE")), ("first", Value::scalar(123)), ("second", Value::scalar(30)), - ].into_iter() + ] + .into_iter() .collect() ) ); @@ -169,29 +170,27 @@ fn enum_introspection() { assert_eq!(values.len(), 2); - assert!( - values.contains(&Value::object( - vec![ - ("name", Value::scalar("ONE")), - ("description", Value::null()), - ("isDeprecated", Value::scalar(false)), - ("deprecationReason", Value::null()), - ].into_iter() - .collect(), - )) - ); + assert!(values.contains(&Value::object( + vec![ + ("name", Value::scalar("ONE")), + ("description", Value::null()), + ("isDeprecated", Value::scalar(false)), + ("deprecationReason", Value::null()), + ] + .into_iter() + .collect(), + ))); - assert!( - values.contains(&Value::object( - vec![ - ("name", Value::scalar("TWO")), - ("description", Value::null()), - ("isDeprecated", Value::scalar(false)), - ("deprecationReason", Value::null()), - ].into_iter() - .collect(), - )) - ); + assert!(values.contains(&Value::object( + vec![ + ("name", Value::scalar("TWO")), + ("description", Value::null()), + ("isDeprecated", Value::scalar(false)), + ("deprecationReason", Value::null()), + ] + .into_iter() + .collect(), + ))); } #[test] @@ -292,41 +291,42 @@ fn interface_introspection() { assert_eq!(fields.len(), 1); - assert!( - fields.contains(&Value::object( - vec![ - ("name", Value::scalar("sampleEnum")), - ( - "description", - Value::scalar("A sample field in the interface"), - ), - ("args", Value::list(vec![])), - ( - "type", - Value::object( - vec![ - ("name", Value::null()), - ("kind", Value::scalar("NON_NULL")), - ( - "ofType", - Value::object( - vec![ - ("name", Value::scalar("SampleEnum")), - ("kind", Value::scalar("ENUM")), - ].into_iter() - .collect(), - ), + assert!(fields.contains(&Value::object( + vec![ + ("name", Value::scalar("sampleEnum")), + ( + "description", + Value::scalar("A sample field in the interface"), + ), + ("args", Value::list(vec![])), + ( + "type", + Value::object( + vec![ + ("name", Value::null()), + ("kind", Value::scalar("NON_NULL")), + ( + "ofType", + Value::object( + vec![ + ("name", Value::scalar("SampleEnum")), + ("kind", Value::scalar("ENUM")), + ] + .into_iter() + .collect(), ), - ].into_iter() - .collect(), - ), + ), + ] + .into_iter() + .collect(), ), - ("isDeprecated", Value::scalar(false)), - ("deprecationReason", Value::null()), - ].into_iter() - .collect(), - )) - ); + ), + ("isDeprecated", Value::scalar(false)), + ("deprecationReason", Value::null()), + ] + .into_iter() + .collect(), + ))); } #[test] @@ -436,126 +436,133 @@ fn object_introspection() { println!("Fields: {:#?}", fields); - assert!( - fields.contains(&Value::object( - vec![ - ("name", Value::scalar("sampleEnum")), - ("description", Value::null()), - ("args", Value::list(vec![])), - ( - "type", - Value::object( - vec![ - ("name", Value::null()), - ("kind", Value::scalar("NON_NULL")), - ( - "ofType", - Value::object( - vec![ - ("name", Value::scalar("SampleEnum")), - ("kind", Value::scalar("ENUM")), - ].into_iter() - .collect(), - ), + assert!(fields.contains(&Value::object( + vec![ + ("name", Value::scalar("sampleEnum")), + ("description", Value::null()), + ("args", Value::list(vec![])), + ( + "type", + Value::object( + vec![ + ("name", Value::null()), + ("kind", Value::scalar("NON_NULL")), + ( + "ofType", + Value::object( + vec![ + ("name", Value::scalar("SampleEnum")), + ("kind", Value::scalar("ENUM")), + ] + .into_iter() + .collect(), ), - ].into_iter() - .collect(), - ), + ), + ] + .into_iter() + .collect(), ), - ("isDeprecated", Value::scalar(false)), - ("deprecationReason", Value::null()), - ].into_iter() - .collect(), - )) - ); + ), + ("isDeprecated", Value::scalar(false)), + ("deprecationReason", Value::null()), + ] + .into_iter() + .collect(), + ))); - assert!( - fields.contains(&Value::object( - vec![ - ("name", Value::scalar("sampleScalar")), - ( - "description", - Value::scalar("A sample scalar field on the object"), - ), - ( - "args", - Value::list(vec![ - Value::object( - vec![ - ("name", Value::scalar("first")), - ("description", Value::scalar("The first number")), - ( - "type", - Value::object( - vec![ - ("name", Value::null()), - ("kind", Value::scalar("NON_NULL")), - ( - "ofType", - Value::object( - vec![ - ("name", Value::scalar("Int")), - ("kind", Value::scalar("SCALAR")), - ("ofType", Value::null()), - ].into_iter() - .collect(), - ), - ), - ].into_iter() - .collect(), - ), - ), - ("defaultValue", Value::null()), - ].into_iter() - .collect(), - ), - Value::object( - vec![ - ("name", Value::scalar("second")), - ("description", Value::scalar("The second number")), - ( - "type", - Value::object( - vec![ - ("name", Value::scalar("Int")), - ("kind", Value::scalar("SCALAR")), - ("ofType", Value::null()), - ].into_iter() - .collect(), - ), - ), - ("defaultValue", Value::scalar("123")), - ].into_iter() - .collect(), - ), - ]), - ), - ( - "type", + assert!(fields.contains(&Value::object( + vec![ + ("name", Value::scalar("sampleScalar")), + ( + "description", + Value::scalar("A sample scalar field on the object"), + ), + ( + "args", + Value::list(vec![ Value::object( vec![ - ("name", Value::null()), - ("kind", Value::scalar("NON_NULL")), + ("name", Value::scalar("first")), + ("description", Value::scalar("The first number")), ( - "ofType", + "type", Value::object( vec![ - ("name", Value::scalar("SampleScalar")), - ("kind", Value::scalar("SCALAR")), - ].into_iter() + ("name", Value::null()), + ("kind", Value::scalar("NON_NULL")), + ( + "ofType", + Value::object( + vec![ + ("name", Value::scalar("Int")), + ("kind", Value::scalar("SCALAR")), + ("ofType", Value::null()), + ] + .into_iter() + .collect(), + ), + ), + ] + .into_iter() .collect(), ), ), - ].into_iter() + ("defaultValue", Value::null()), + ] + .into_iter() .collect(), ), + Value::object( + vec![ + ("name", Value::scalar("second")), + ("description", Value::scalar("The second number")), + ( + "type", + Value::object( + vec![ + ("name", Value::scalar("Int")), + ("kind", Value::scalar("SCALAR")), + ("ofType", Value::null()), + ] + .into_iter() + .collect(), + ), + ), + ("defaultValue", Value::scalar("123")), + ] + .into_iter() + .collect(), + ), + ]), + ), + ( + "type", + Value::object( + vec![ + ("name", Value::null()), + ("kind", Value::scalar("NON_NULL")), + ( + "ofType", + Value::object( + vec![ + ("name", Value::scalar("SampleScalar")), + ("kind", Value::scalar("SCALAR")), + ] + .into_iter() + .collect(), + ), + ), + ] + .into_iter() + .collect(), ), - ("isDeprecated", Value::scalar(false)), - ("deprecationReason", Value::null()), - ].into_iter() - .collect(), - )) - ); + ), + ("isDeprecated", Value::scalar(false)), + ("deprecationReason", Value::null()), + ] + .into_iter() + .collect(), + ))); } #[test] @@ -603,7 +610,8 @@ fn scalar_introspection() { ("enumValues", Value::null()), ("inputFields", Value::null()), ("ofType", Value::null()), - ].into_iter() + ] + .into_iter() .collect() ) ); diff --git a/juniper/src/executor_tests/variables.rs b/juniper/src/executor_tests/variables.rs index 7cccfc0b..f17b1826 100644 --- a/juniper/src/executor_tests/variables.rs +++ b/juniper/src/executor_tests/variables.rs @@ -185,10 +185,12 @@ fn variable_complex_input() { ("a", InputValue::scalar("foo")), ("b", InputValue::list(vec![InputValue::scalar("bar")])), ("c", InputValue::scalar("baz")), - ].into_iter() + ] + .into_iter() .collect(), ), - )].into_iter() + )] + .into_iter() .collect(), |result: &Object| { assert_eq!( @@ -209,10 +211,12 @@ fn variable_parse_single_value_to_list() { ("a", InputValue::scalar("foo")), ("b", InputValue::scalar("bar")), ("c", InputValue::scalar("baz")), - ].into_iter() + ] + .into_iter() .collect(), ), - )].into_iter() + )] + .into_iter() .collect(), |result: &Object| { assert_eq!( @@ -232,10 +236,12 @@ fn variable_runs_from_input_value_on_scalar() { vec![ ("c", InputValue::scalar("baz")), ("d", InputValue::scalar("SerializedValue")), - ].into_iter() + ] + .into_iter() .collect(), ), - )].into_iter() + )] + .into_iter() .collect(), |result: &Object| { assert_eq!( @@ -257,10 +263,12 @@ fn variable_error_on_nested_non_null() { ("a", InputValue::scalar("foo")), ("b", InputValue::scalar("bar")), ("c", InputValue::null()), - ].into_iter() + ] + .into_iter() .collect(), ), - )].into_iter() + )] + .into_iter() .collect(); let error = ::execute(query, None, &schema, &vars, &()).unwrap_err(); @@ -304,10 +312,12 @@ fn variable_error_on_omit_non_null() { vec![ ("a", InputValue::scalar("foo")), ("b", InputValue::scalar("bar")), - ].into_iter() + ] + .into_iter() .collect(), ), - )].into_iter() + )] + .into_iter() .collect(); let error = ::execute(query, None, &schema, &vars, &()).unwrap_err(); @@ -333,10 +343,12 @@ fn variable_multiple_errors_with_nesting() { vec![( "na", InputValue::object(vec![("a", InputValue::scalar("foo"))].into_iter().collect()), - )].into_iter() + )] + .into_iter() .collect(), ), - )].into_iter() + )] + .into_iter() .collect(); let error = ::execute(query, None, &schema, &vars, &()).unwrap_err(); @@ -366,10 +378,12 @@ fn variable_error_on_additional_field() { ("b", InputValue::scalar("bar")), ("c", InputValue::scalar("baz")), ("extra", InputValue::scalar("dog")), - ].into_iter() + ] + .into_iter() .collect(), ), - )].into_iter() + )] + .into_iter() .collect(); let error = ::execute(query, None, &schema, &vars, &()).unwrap_err(); @@ -557,7 +571,8 @@ fn allow_lists_to_contain_values() { vec![( "input".to_owned(), InputValue::list(vec![InputValue::scalar("A")]), - )].into_iter() + )] + .into_iter() .collect(), |result| { assert_eq!( @@ -579,7 +594,8 @@ fn allow_lists_to_contain_null() { InputValue::null(), InputValue::scalar("B"), ]), - )].into_iter() + )] + .into_iter() .collect(), |result| { assert_eq!( @@ -617,7 +633,8 @@ fn allow_non_null_lists_to_contain_values() { vec![( "input".to_owned(), InputValue::list(vec![InputValue::scalar("A")]), - )].into_iter() + )] + .into_iter() .collect(), |result| { assert_eq!( @@ -638,7 +655,8 @@ fn allow_non_null_lists_to_contain_null() { InputValue::null(), InputValue::scalar("B"), ]), - )].into_iter() + )] + .into_iter() .collect(), |result| { assert_eq!( @@ -672,7 +690,8 @@ fn allow_lists_of_non_null_to_contain_values() { vec![( "input".to_owned(), InputValue::list(vec![InputValue::scalar("A")]), - )].into_iter() + )] + .into_iter() .collect(), |result| { assert_eq!( @@ -695,7 +714,8 @@ fn does_not_allow_lists_of_non_null_to_contain_null() { InputValue::null(), InputValue::scalar("B"), ]), - )].into_iter() + )] + .into_iter() .collect(); let error = ::execute(query, None, &schema, &vars, &()).unwrap_err(); @@ -720,7 +740,8 @@ fn does_not_allow_non_null_lists_of_non_null_to_contain_null() { InputValue::null(), InputValue::scalar("B"), ]), - )].into_iter() + )] + .into_iter() .collect(); let error = ::execute(query, None, &schema, &vars, &()).unwrap_err(); @@ -760,7 +781,8 @@ fn allow_non_null_lists_of_non_null_to_contain_values() { vec![( "input".to_owned(), InputValue::list(vec![InputValue::scalar("A")]), - )].into_iter() + )] + .into_iter() .collect(), |result| { assert_eq!( @@ -779,7 +801,8 @@ fn does_not_allow_invalid_types_to_be_used_as_values() { let vars = vec![( "value".to_owned(), InputValue::list(vec![InputValue::scalar("A"), InputValue::scalar("B")]), - )].into_iter() + )] + .into_iter() .collect(); let error = ::execute(query, None, &schema, &vars, &()).unwrap_err(); @@ -800,7 +823,8 @@ fn does_not_allow_unknown_types_to_be_used_as_values() { let vars = vec![( "value".to_owned(), InputValue::list(vec![InputValue::scalar("A"), InputValue::scalar("B")]), - )].into_iter() + )] + .into_iter() .collect(); let error = ::execute(query, None, &schema, &vars, &()).unwrap_err(); diff --git a/juniper/src/http/mod.rs b/juniper/src/http/mod.rs index a94c0e0c..d24695d6 100644 --- a/juniper/src/http/mod.rs +++ b/juniper/src/http/mod.rs @@ -33,7 +33,7 @@ impl GraphQLRequest where S: ScalarValue, { - /// Returns the `operation_name` associated with this request. + /// Returns the `operation_name` associated with this request. fn operation_name(&self) -> Option<&str> { self.operation_name.as_ref().map(|oper_name| &**oper_name) } @@ -47,7 +47,8 @@ where .map(|(k, v)| (k.to_owned(), v.clone())) .collect() }) - }).unwrap_or_default() + }) + .unwrap_or_default() } /// Construct a new GraphQL request from parts @@ -207,7 +208,8 @@ pub mod tests { .body .as_ref() .expect("No data returned from request"), - ).expect("Could not parse JSON object") + ) + .expect("Could not parse JSON object") } fn test_simple_get(integration: &T) { @@ -249,7 +251,8 @@ pub mod tests { } } }"# - ).expect("Invalid JSON constant in test") + ) + .expect("Invalid JSON constant in test") ); } @@ -279,7 +282,8 @@ pub mod tests { } } }"# - ).expect("Invalid JSON constant in test") + ) + .expect("Invalid JSON constant in test") ); } @@ -309,7 +313,8 @@ pub mod tests { unwrap_json_response(&response), serde_json::from_str::( r#"[{"data": {"hero": {"name": "R2-D2"}}}, {"data": {"hero": {"name": "R2-D2"}}}]"# - ).expect("Invalid JSON constant in test") + ) + .expect("Invalid JSON constant in test") ); } @@ -332,9 +337,12 @@ pub mod tests { // {hero{name}} let response = integration.get("/?query=%7B%22query%22%3A%20%22%7Bhero%7Bname%7D%7D%22%2C%20%22query%22%3A%20%22%7Bhero%7Bname%7D%7D%22%7D"); assert_eq!(response.status_code, 400); - let response = integration.post("/", r#" + let response = integration.post( + "/", + r#" {"query": "{hero{name}}", "query": "{hero{name}}"} - "#); + "#, + ); assert_eq!(response.status_code, 400); } } diff --git a/juniper/src/integrations/chrono.rs b/juniper/src/integrations/chrono.rs index 5c25d987..67a65ae6 100644 --- a/juniper/src/integrations/chrono.rs +++ b/juniper/src/integrations/chrono.rs @@ -203,7 +203,7 @@ mod integration_test { use executor::Variables; use schema::model::RootNode; use types::scalars::EmptyMutation; - use value::{Value}; + use value::Value; #[test] fn test_serialization() { @@ -232,7 +232,7 @@ mod integration_test { } "#; - let schema= RootNode::new(Root, EmptyMutation::<()>::new()); + let schema = RootNode::new(Root, EmptyMutation::<()>::new()); let (result, errs) = ::execute(doc, None, &schema, &Variables::new(), &()).expect("Execution failed"); @@ -253,7 +253,8 @@ mod integration_test { "exampleDateTimeUtc", Value::scalar("1970-01-01T00:01:01+00:00"), ), - ].into_iter() + ] + .into_iter() .collect() ) ); diff --git a/juniper/src/integrations/serde.rs b/juniper/src/integrations/serde.rs index d09fd5ce..97ded1cd 100644 --- a/juniper/src/integrations/serde.rs +++ b/juniper/src/integrations/serde.rs @@ -55,16 +55,16 @@ impl<'a> ser::Serialize for GraphQLError<'a> { GraphQLError::NoOperationProvided => [SerializeHelper { message: "Must provide an operation", }] - .serialize(serializer), + .serialize(serializer), GraphQLError::MultipleOperationsProvided => [SerializeHelper { message: "Must provide operation name \ if query contains multiple operations", }] - .serialize(serializer), + .serialize(serializer), GraphQLError::UnknownOperationName => [SerializeHelper { message: "Unknown operation", }] - .serialize(serializer), + .serialize(serializer), } } } @@ -167,7 +167,7 @@ where self.0.visit_u64(value).map(InputValue::Scalar) } - serde_if_integer128!{ + serde_if_integer128! { fn visit_u128(self, value: u128) -> Result, E> where E: de::Error, diff --git a/juniper/src/macros/common.rs b/juniper/src/macros/common.rs index 168707b8..7ba4545f 100644 --- a/juniper/src/macros/common.rs +++ b/juniper/src/macros/common.rs @@ -37,7 +37,9 @@ macro_rules! __juniper_impl_trait { #[doc(hidden)] #[macro_export] macro_rules! __juniper_insert_generic { - () => {$crate::DefaultScalarValue}; + () => { + $crate::DefaultScalarValue + }; ( <$generic:tt $(: $bound: tt)*> ) => { @@ -50,7 +52,6 @@ macro_rules! __juniper_insert_generic { }; } - #[doc(hidden)] #[macro_export] macro_rules! __juniper_parse_object_header { @@ -560,7 +561,6 @@ macro_rules! __juniper_parse_field_list { } - #[doc(hidden)] #[macro_export] macro_rules! __juniper_parse_instance_resolver { diff --git a/juniper/src/macros/tests/args.rs b/juniper/src/macros/tests/args.rs index 9898abcd..9a3420cf 100644 --- a/juniper/src/macros/tests/args.rs +++ b/juniper/src/macros/tests/args.rs @@ -139,7 +139,8 @@ where .as_scalar_value::() .expect("name is not a string") == field_name - }).next() + }) + .next() .expect("Field not found") .as_object_value() .expect("Field is not an object"); @@ -176,31 +177,31 @@ fn introspect_field_exec_arg_and_more() { run_args_info_query("execArgAndMore", |args| { assert_eq!(args.len(), 1); - assert!( - args.contains(&Value::object( - vec![ - ("name", Value::scalar("arg")), - ("description", Value::null()), - ("defaultValue", Value::null()), - ( - "type", - Value::object( - vec![ - ("name", Value::null()), - ( - "ofType", - Value::object( - vec![("name", Value::scalar("Int"))].into_iter().collect(), - ), + assert!(args.contains(&Value::object( + vec![ + ("name", Value::scalar("arg")), + ("description", Value::null()), + ("defaultValue", Value::null()), + ( + "type", + Value::object( + vec![ + ("name", Value::null()), + ( + "ofType", + Value::object( + vec![("name", Value::scalar("Int"))].into_iter().collect(), ), - ].into_iter() - .collect(), - ), + ), + ] + .into_iter() + .collect(), ), - ].into_iter() - .collect(), - )) - ); + ), + ] + .into_iter() + .collect(), + ))); }); } @@ -209,31 +210,31 @@ fn introspect_field_single_arg() { run_args_info_query("singleArg", |args| { assert_eq!(args.len(), 1); - assert!( - args.contains(&Value::object( - vec![ - ("name", Value::scalar("arg")), - ("description", Value::null()), - ("defaultValue", Value::null()), - ( - "type", - Value::object( - vec![ - ("name", Value::null()), - ( - "ofType", - Value::object( - vec![("name", Value::scalar("Int"))].into_iter().collect(), - ), + assert!(args.contains(&Value::object( + vec![ + ("name", Value::scalar("arg")), + ("description", Value::null()), + ("defaultValue", Value::null()), + ( + "type", + Value::object( + vec![ + ("name", Value::null()), + ( + "ofType", + Value::object( + vec![("name", Value::scalar("Int"))].into_iter().collect(), ), - ].into_iter() - .collect(), - ), + ), + ] + .into_iter() + .collect(), ), - ].into_iter() - .collect(), - )) - ); + ), + ] + .into_iter() + .collect(), + ))); }); } @@ -242,57 +243,57 @@ fn introspect_field_multi_args() { run_args_info_query("multiArgs", |args| { assert_eq!(args.len(), 2); - assert!( - args.contains(&Value::object( - vec![ - ("name", Value::scalar("arg1")), - ("description", Value::null()), - ("defaultValue", Value::null()), - ( - "type", - Value::object( - vec![ - ("name", Value::null()), - ( - "ofType", - Value::object( - vec![("name", Value::scalar("Int"))].into_iter().collect(), - ), + assert!(args.contains(&Value::object( + vec![ + ("name", Value::scalar("arg1")), + ("description", Value::null()), + ("defaultValue", Value::null()), + ( + "type", + Value::object( + vec![ + ("name", Value::null()), + ( + "ofType", + Value::object( + vec![("name", Value::scalar("Int"))].into_iter().collect(), ), - ].into_iter() - .collect(), - ), + ), + ] + .into_iter() + .collect(), ), - ].into_iter() - .collect(), - )) - ); + ), + ] + .into_iter() + .collect(), + ))); - assert!( - args.contains(&Value::object( - vec![ - ("name", Value::scalar("arg2")), - ("description", Value::null()), - ("defaultValue", Value::null()), - ( - "type", - Value::object( - vec![ - ("name", Value::null()), - ( - "ofType", - Value::object( - vec![("name", Value::scalar("Int"))].into_iter().collect(), - ), + assert!(args.contains(&Value::object( + vec![ + ("name", Value::scalar("arg2")), + ("description", Value::null()), + ("defaultValue", Value::null()), + ( + "type", + Value::object( + vec![ + ("name", Value::null()), + ( + "ofType", + Value::object( + vec![("name", Value::scalar("Int"))].into_iter().collect(), ), - ].into_iter() - .collect(), - ), + ), + ] + .into_iter() + .collect(), ), - ].into_iter() - .collect(), - )) - ); + ), + ] + .into_iter() + .collect(), + ))); }); } @@ -301,57 +302,57 @@ fn introspect_field_multi_args_trailing_comma() { run_args_info_query("multiArgsTrailingComma", |args| { assert_eq!(args.len(), 2); - assert!( - args.contains(&Value::object( - vec![ - ("name", Value::scalar("arg1")), - ("description", Value::null()), - ("defaultValue", Value::null()), - ( - "type", - Value::object( - vec![ - ("name", Value::null()), - ( - "ofType", - Value::object( - vec![("name", Value::scalar("Int"))].into_iter().collect(), - ), + assert!(args.contains(&Value::object( + vec![ + ("name", Value::scalar("arg1")), + ("description", Value::null()), + ("defaultValue", Value::null()), + ( + "type", + Value::object( + vec![ + ("name", Value::null()), + ( + "ofType", + Value::object( + vec![("name", Value::scalar("Int"))].into_iter().collect(), ), - ].into_iter() - .collect(), - ), + ), + ] + .into_iter() + .collect(), ), - ].into_iter() - .collect(), - )) - ); + ), + ] + .into_iter() + .collect(), + ))); - assert!( - args.contains(&Value::object( - vec![ - ("name", Value::scalar("arg2")), - ("description", Value::null()), - ("defaultValue", Value::null()), - ( - "type", - Value::object( - vec![ - ("name", Value::null()), - ( - "ofType", - Value::object( - vec![("name", Value::scalar("Int"))].into_iter().collect(), - ), + assert!(args.contains(&Value::object( + vec![ + ("name", Value::scalar("arg2")), + ("description", Value::null()), + ("defaultValue", Value::null()), + ( + "type", + Value::object( + vec![ + ("name", Value::null()), + ( + "ofType", + Value::object( + vec![("name", Value::scalar("Int"))].into_iter().collect(), ), - ].into_iter() - .collect(), - ), + ), + ] + .into_iter() + .collect(), ), - ].into_iter() - .collect(), - )) - ); + ), + ] + .into_iter() + .collect(), + ))); }); } @@ -360,31 +361,31 @@ fn introspect_field_single_arg_descr() { run_args_info_query("singleArgDescr", |args| { assert_eq!(args.len(), 1); - assert!( - args.contains(&Value::object( - vec![ - ("name", Value::scalar("arg")), - ("description", Value::scalar("The arg")), - ("defaultValue", Value::null()), - ( - "type", - Value::object( - vec![ - ("name", Value::null()), - ( - "ofType", - Value::object( - vec![("name", Value::scalar("Int"))].into_iter().collect(), - ), + assert!(args.contains(&Value::object( + vec![ + ("name", Value::scalar("arg")), + ("description", Value::scalar("The arg")), + ("defaultValue", Value::null()), + ( + "type", + Value::object( + vec![ + ("name", Value::null()), + ( + "ofType", + Value::object( + vec![("name", Value::scalar("Int"))].into_iter().collect(), ), - ].into_iter() - .collect(), - ), + ), + ] + .into_iter() + .collect(), ), - ].into_iter() - .collect(), - )) - ); + ), + ] + .into_iter() + .collect(), + ))); }); } @@ -393,57 +394,57 @@ fn introspect_field_multi_args_descr() { run_args_info_query("multiArgsDescr", |args| { assert_eq!(args.len(), 2); - assert!( - args.contains(&Value::object( - vec![ - ("name", Value::scalar("arg1")), - ("description", Value::scalar("The first arg")), - ("defaultValue", Value::null()), - ( - "type", - Value::object( - vec![ - ("name", Value::null()), - ( - "ofType", - Value::object( - vec![("name", Value::scalar("Int"))].into_iter().collect(), - ), + assert!(args.contains(&Value::object( + vec![ + ("name", Value::scalar("arg1")), + ("description", Value::scalar("The first arg")), + ("defaultValue", Value::null()), + ( + "type", + Value::object( + vec![ + ("name", Value::null()), + ( + "ofType", + Value::object( + vec![("name", Value::scalar("Int"))].into_iter().collect(), ), - ].into_iter() - .collect(), - ), + ), + ] + .into_iter() + .collect(), ), - ].into_iter() - .collect(), - )) - ); + ), + ] + .into_iter() + .collect(), + ))); - assert!( - args.contains(&Value::object( - vec![ - ("name", Value::scalar("arg2")), - ("description", Value::scalar("The second arg")), - ("defaultValue", Value::null()), - ( - "type", - Value::object( - vec![ - ("name", Value::null()), - ( - "ofType", - Value::object( - vec![("name", Value::scalar("Int"))].into_iter().collect(), - ), + assert!(args.contains(&Value::object( + vec![ + ("name", Value::scalar("arg2")), + ("description", Value::scalar("The second arg")), + ("defaultValue", Value::null()), + ( + "type", + Value::object( + vec![ + ("name", Value::null()), + ( + "ofType", + Value::object( + vec![("name", Value::scalar("Int"))].into_iter().collect(), ), - ].into_iter() - .collect(), - ), + ), + ] + .into_iter() + .collect(), ), - ].into_iter() - .collect(), - )) - ); + ), + ] + .into_iter() + .collect(), + ))); }); } @@ -452,57 +453,57 @@ fn introspect_field_multi_args_descr_trailing_comma() { run_args_info_query("multiArgsDescrTrailingComma", |args| { assert_eq!(args.len(), 2); - assert!( - args.contains(&Value::object( - vec![ - ("name", Value::scalar("arg1")), - ("description", Value::scalar("The first arg")), - ("defaultValue", Value::null()), - ( - "type", - Value::object( - vec![ - ("name", Value::null()), - ( - "ofType", - Value::object( - vec![("name", Value::scalar("Int"))].into_iter().collect(), - ), + assert!(args.contains(&Value::object( + vec![ + ("name", Value::scalar("arg1")), + ("description", Value::scalar("The first arg")), + ("defaultValue", Value::null()), + ( + "type", + Value::object( + vec![ + ("name", Value::null()), + ( + "ofType", + Value::object( + vec![("name", Value::scalar("Int"))].into_iter().collect(), ), - ].into_iter() - .collect(), - ), + ), + ] + .into_iter() + .collect(), ), - ].into_iter() - .collect(), - )) - ); + ), + ] + .into_iter() + .collect(), + ))); - assert!( - args.contains(&Value::object( - vec![ - ("name", Value::scalar("arg2")), - ("description", Value::scalar("The second arg")), - ("defaultValue", Value::null()), - ( - "type", - Value::object( - vec![ - ("name", Value::null()), - ( - "ofType", - Value::object( - vec![("name", Value::scalar("Int"))].into_iter().collect(), - ), + assert!(args.contains(&Value::object( + vec![ + ("name", Value::scalar("arg2")), + ("description", Value::scalar("The second arg")), + ("defaultValue", Value::null()), + ( + "type", + Value::object( + vec![ + ("name", Value::null()), + ( + "ofType", + Value::object( + vec![("name", Value::scalar("Int"))].into_iter().collect(), ), - ].into_iter() - .collect(), - ), + ), + ] + .into_iter() + .collect(), ), - ].into_iter() - .collect(), - )) - ); + ), + ] + .into_iter() + .collect(), + ))); }); } @@ -511,31 +512,31 @@ fn introspect_field_attr_arg_descr() { run_args_info_query("attrArgDescr", |args| { assert_eq!(args.len(), 1); - assert!( - args.contains(&Value::object( - vec![ - ("name", Value::scalar("arg")), - ("description", Value::scalar("The arg")), - ("defaultValue", Value::null()), - ( - "type", - Value::object( - vec![ - ("name", Value::null()), - ( - "ofType", - Value::object( - vec![("name", Value::scalar("Int"))].into_iter().collect(), - ), + assert!(args.contains(&Value::object( + vec![ + ("name", Value::scalar("arg")), + ("description", Value::scalar("The arg")), + ("defaultValue", Value::null()), + ( + "type", + Value::object( + vec![ + ("name", Value::null()), + ( + "ofType", + Value::object( + vec![("name", Value::scalar("Int"))].into_iter().collect(), ), - ].into_iter() - .collect(), - ), + ), + ] + .into_iter() + .collect(), ), - ].into_iter() - .collect(), - )) - ); + ), + ] + .into_iter() + .collect(), + ))); }); } @@ -544,31 +545,31 @@ fn introspect_field_attr_arg_descr_collapse() { run_args_info_query("attrArgDescrCollapse", |args| { assert_eq!(args.len(), 1); - assert!( - args.contains(&Value::object( - vec![ - ("name", Value::scalar("arg")), - ("description", Value::scalar("The arg\nand more details")), - ("defaultValue", Value::null()), - ( - "type", - Value::object( - vec![ - ("name", Value::null()), - ( - "ofType", - Value::object( - vec![("name", Value::scalar("Int"))].into_iter().collect(), - ), + assert!(args.contains(&Value::object( + vec![ + ("name", Value::scalar("arg")), + ("description", Value::scalar("The arg\nand more details")), + ("defaultValue", Value::null()), + ( + "type", + Value::object( + vec![ + ("name", Value::null()), + ( + "ofType", + Value::object( + vec![("name", Value::scalar("Int"))].into_iter().collect(), ), - ].into_iter() - .collect(), - ), + ), + ] + .into_iter() + .collect(), ), - ].into_iter() - .collect(), - )) - ); + ), + ] + .into_iter() + .collect(), + ))); }); } @@ -577,24 +578,23 @@ fn introspect_field_arg_with_default() { run_args_info_query("argWithDefault", |args| { assert_eq!(args.len(), 1); - assert!( - args.contains(&Value::object( - vec![ - ("name", Value::scalar("arg")), - ("description", Value::null()), - ("defaultValue", Value::scalar("123")), - ( - "type", - Value::object( - vec![("name", Value::scalar("Int")), ("ofType", Value::null())] - .into_iter() - .collect(), - ), + assert!(args.contains(&Value::object( + vec![ + ("name", Value::scalar("arg")), + ("description", Value::null()), + ("defaultValue", Value::scalar("123")), + ( + "type", + Value::object( + vec![("name", Value::scalar("Int")), ("ofType", Value::null())] + .into_iter() + .collect(), ), - ].into_iter() - .collect(), - )) - ); + ), + ] + .into_iter() + .collect(), + ))); }); } @@ -603,43 +603,41 @@ fn introspect_field_multi_args_with_default() { run_args_info_query("multiArgsWithDefault", |args| { assert_eq!(args.len(), 2); - assert!( - args.contains(&Value::object( - vec![ - ("name", Value::scalar("arg1")), - ("description", Value::null()), - ("defaultValue", Value::scalar("123")), - ( - "type", - Value::object( - vec![("name", Value::scalar("Int")), ("ofType", Value::null())] - .into_iter() - .collect(), - ), + assert!(args.contains(&Value::object( + vec![ + ("name", Value::scalar("arg1")), + ("description", Value::null()), + ("defaultValue", Value::scalar("123")), + ( + "type", + Value::object( + vec![("name", Value::scalar("Int")), ("ofType", Value::null())] + .into_iter() + .collect(), ), - ].into_iter() - .collect(), - )) - ); + ), + ] + .into_iter() + .collect(), + ))); - assert!( - args.contains(&Value::object( - vec![ - ("name", Value::scalar("arg2")), - ("description", Value::null()), - ("defaultValue", Value::scalar("456")), - ( - "type", - Value::object( - vec![("name", Value::scalar("Int")), ("ofType", Value::null())] - .into_iter() - .collect(), - ), + assert!(args.contains(&Value::object( + vec![ + ("name", Value::scalar("arg2")), + ("description", Value::null()), + ("defaultValue", Value::scalar("456")), + ( + "type", + Value::object( + vec![("name", Value::scalar("Int")), ("ofType", Value::null())] + .into_iter() + .collect(), ), - ].into_iter() - .collect(), - )) - ); + ), + ] + .into_iter() + .collect(), + ))); }); } @@ -648,43 +646,41 @@ fn introspect_field_multi_args_with_default_trailing_comma() { run_args_info_query("multiArgsWithDefaultTrailingComma", |args| { assert_eq!(args.len(), 2); - assert!( - args.contains(&Value::object( - vec![ - ("name", Value::scalar("arg1")), - ("description", Value::null()), - ("defaultValue", Value::scalar("123")), - ( - "type", - Value::object( - vec![("name", Value::scalar("Int")), ("ofType", Value::null())] - .into_iter() - .collect(), - ), + assert!(args.contains(&Value::object( + vec![ + ("name", Value::scalar("arg1")), + ("description", Value::null()), + ("defaultValue", Value::scalar("123")), + ( + "type", + Value::object( + vec![("name", Value::scalar("Int")), ("ofType", Value::null())] + .into_iter() + .collect(), ), - ].into_iter() - .collect(), - )) - ); + ), + ] + .into_iter() + .collect(), + ))); - assert!( - args.contains(&Value::object( - vec![ - ("name", Value::scalar("arg2")), - ("description", Value::null()), - ("defaultValue", Value::scalar("456")), - ( - "type", - Value::object( - vec![("name", Value::scalar("Int")), ("ofType", Value::null())] - .into_iter() - .collect(), - ), + assert!(args.contains(&Value::object( + vec![ + ("name", Value::scalar("arg2")), + ("description", Value::null()), + ("defaultValue", Value::scalar("456")), + ( + "type", + Value::object( + vec![("name", Value::scalar("Int")), ("ofType", Value::null())] + .into_iter() + .collect(), ), - ].into_iter() - .collect(), - )) - ); + ), + ] + .into_iter() + .collect(), + ))); }); } @@ -693,24 +689,23 @@ fn introspect_field_arg_with_default_descr() { run_args_info_query("argWithDefaultDescr", |args| { assert_eq!(args.len(), 1); - assert!( - args.contains(&Value::object( - vec![ - ("name", Value::scalar("arg")), - ("description", Value::scalar("The arg")), - ("defaultValue", Value::scalar("123")), - ( - "type", - Value::object( - vec![("name", Value::scalar("Int")), ("ofType", Value::null())] - .into_iter() - .collect(), - ), + assert!(args.contains(&Value::object( + vec![ + ("name", Value::scalar("arg")), + ("description", Value::scalar("The arg")), + ("defaultValue", Value::scalar("123")), + ( + "type", + Value::object( + vec![("name", Value::scalar("Int")), ("ofType", Value::null())] + .into_iter() + .collect(), ), - ].into_iter() - .collect(), - )) - ); + ), + ] + .into_iter() + .collect(), + ))); }); } @@ -719,43 +714,41 @@ fn introspect_field_multi_args_with_default_descr() { run_args_info_query("multiArgsWithDefaultDescr", |args| { assert_eq!(args.len(), 2); - assert!( - args.contains(&Value::object( - vec![ - ("name", Value::scalar("arg1")), - ("description", Value::scalar("The first arg")), - ("defaultValue", Value::scalar("123")), - ( - "type", - Value::object( - vec![("name", Value::scalar("Int")), ("ofType", Value::null())] - .into_iter() - .collect(), - ), + assert!(args.contains(&Value::object( + vec![ + ("name", Value::scalar("arg1")), + ("description", Value::scalar("The first arg")), + ("defaultValue", Value::scalar("123")), + ( + "type", + Value::object( + vec![("name", Value::scalar("Int")), ("ofType", Value::null())] + .into_iter() + .collect(), ), - ].into_iter() - .collect(), - )) - ); + ), + ] + .into_iter() + .collect(), + ))); - assert!( - args.contains(&Value::object( - vec![ - ("name", Value::scalar("arg2")), - ("description", Value::scalar("The second arg")), - ("defaultValue", Value::scalar("456")), - ( - "type", - Value::object( - vec![("name", Value::scalar("Int")), ("ofType", Value::null())] - .into_iter() - .collect(), - ), + assert!(args.contains(&Value::object( + vec![ + ("name", Value::scalar("arg2")), + ("description", Value::scalar("The second arg")), + ("defaultValue", Value::scalar("456")), + ( + "type", + Value::object( + vec![("name", Value::scalar("Int")), ("ofType", Value::null())] + .into_iter() + .collect(), ), - ].into_iter() - .collect(), - )) - ); + ), + ] + .into_iter() + .collect(), + ))); }); } @@ -764,43 +757,41 @@ fn introspect_field_multi_args_with_default_trailing_comma_descr() { run_args_info_query("multiArgsWithDefaultTrailingCommaDescr", |args| { assert_eq!(args.len(), 2); - assert!( - args.contains(&Value::object( - vec![ - ("name", Value::scalar("arg1")), - ("description", Value::scalar("The first arg")), - ("defaultValue", Value::scalar("123")), - ( - "type", - Value::object( - vec![("name", Value::scalar("Int")), ("ofType", Value::null())] - .into_iter() - .collect(), - ), + assert!(args.contains(&Value::object( + vec![ + ("name", Value::scalar("arg1")), + ("description", Value::scalar("The first arg")), + ("defaultValue", Value::scalar("123")), + ( + "type", + Value::object( + vec![("name", Value::scalar("Int")), ("ofType", Value::null())] + .into_iter() + .collect(), ), - ].into_iter() - .collect(), - )) - ); + ), + ] + .into_iter() + .collect(), + ))); - assert!( - args.contains(&Value::object( - vec![ - ("name", Value::scalar("arg2")), - ("description", Value::scalar("The second arg")), - ("defaultValue", Value::scalar("456")), - ( - "type", - Value::object( - vec![("name", Value::scalar("Int")), ("ofType", Value::null())] - .into_iter() - .collect(), - ), + assert!(args.contains(&Value::object( + vec![ + ("name", Value::scalar("arg2")), + ("description", Value::scalar("The second arg")), + ("defaultValue", Value::scalar("456")), + ( + "type", + Value::object( + vec![("name", Value::scalar("Int")), ("ofType", Value::null())] + .into_iter() + .collect(), ), - ].into_iter() - .collect(), - )) - ); + ), + ] + .into_iter() + .collect(), + ))); }); } @@ -809,45 +800,43 @@ fn introspect_field_args_with_complex_default() { run_args_info_query("argsWithComplexDefault", |args| { assert_eq!(args.len(), 2); - assert!( - args.contains(&Value::object( - vec![ - ("name", Value::scalar("arg1")), - ("description", Value::scalar("A string default argument")), - ("defaultValue", Value::scalar(r#""test""#)), - ( - "type", - Value::object( - vec![("name", Value::scalar("String")), ("ofType", Value::null())] - .into_iter() - .collect(), - ), + assert!(args.contains(&Value::object( + vec![ + ("name", Value::scalar("arg1")), + ("description", Value::scalar("A string default argument")), + ("defaultValue", Value::scalar(r#""test""#)), + ( + "type", + Value::object( + vec![("name", Value::scalar("String")), ("ofType", Value::null())] + .into_iter() + .collect(), ), - ].into_iter() - .collect(), - )) - ); + ), + ] + .into_iter() + .collect(), + ))); - assert!( - args.contains(&Value::object( - vec![ - ("name", Value::scalar("arg2")), - ( - "description", - Value::scalar("An input object default argument"), + assert!(args.contains(&Value::object( + vec![ + ("name", Value::scalar("arg2")), + ( + "description", + Value::scalar("An input object default argument"), + ), + ("defaultValue", Value::scalar(r#"{x: 1}"#)), + ( + "type", + Value::object( + vec![("name", Value::scalar("Point")), ("ofType", Value::null())] + .into_iter() + .collect(), ), - ("defaultValue", Value::scalar(r#"{x: 1}"#)), - ( - "type", - Value::object( - vec![("name", Value::scalar("Point")), ("ofType", Value::null())] - .into_iter() - .collect(), - ), - ), - ].into_iter() - .collect(), - )) - ); + ), + ] + .into_iter() + .collect(), + ))); }); } diff --git a/juniper/src/macros/tests/field.rs b/juniper/src/macros/tests/field.rs index 220ed411..17e80bde 100644 --- a/juniper/src/macros/tests/field.rs +++ b/juniper/src/macros/tests/field.rs @@ -154,7 +154,8 @@ where .as_scalar_value::() .expect("name is not a string") == field_name - }).next() + }) + .next() .expect("Field not found") .as_object_value() .expect("Field is not an object"); @@ -425,7 +426,9 @@ fn introspect_object_field_attr_description_collapse() { ); assert_eq!( field.get_field_value("description"), - Some(&Value::scalar("Field description\nwith `collapse_docs` behavior")) + Some(&Value::scalar( + "Field description\nwith `collapse_docs` behavior" + )) ); assert_eq!( field.get_field_value("isDeprecated"), @@ -447,7 +450,9 @@ fn introspect_interface_field_attr_description_collapse() { ); assert_eq!( field.get_field_value("description"), - Some(&Value::scalar("Field description\nwith `collapse_docs` behavior")) + Some(&Value::scalar( + "Field description\nwith `collapse_docs` behavior" + )) ); assert_eq!( field.get_field_value("isDeprecated"), diff --git a/juniper/src/macros/tests/interface.rs b/juniper/src/macros/tests/interface.rs index 162ed01d..ef4b1dc1 100644 --- a/juniper/src/macros/tests/interface.rs +++ b/juniper/src/macros/tests/interface.rs @@ -3,7 +3,7 @@ use std::marker::PhantomData; use ast::InputValue; use schema::model::RootNode; use types::scalars::EmptyMutation; -use value::{Value, Object, DefaultScalarValue}; +use value::{DefaultScalarValue, Object, Value}; /* @@ -179,102 +179,105 @@ fn introspect_custom_name() { ); assert_eq!(object.get_field_value("description"), Some(&Value::null())); - assert!( - fields.contains(&Value::object( - vec![("name", Value::scalar("simple"))] - .into_iter() - .collect(), - )) - ); + assert!(fields.contains(&Value::object( + vec![("name", Value::scalar("simple"))] + .into_iter() + .collect(), + ))); }); } #[test] fn introspect_with_lifetime() { run_type_info_query("WithLifetime", |object, fields| { - assert_eq!(object.get_field_value("name"), Some(&Value::scalar("WithLifetime"))); + assert_eq!( + object.get_field_value("name"), + Some(&Value::scalar("WithLifetime")) + ); assert_eq!(object.get_field_value("description"), Some(&Value::null())); - assert!( - fields.contains(&Value::object( - vec![("name", Value::scalar("simple"))] - .into_iter() - .collect(), - )) - ); + assert!(fields.contains(&Value::object( + vec![("name", Value::scalar("simple"))] + .into_iter() + .collect(), + ))); }); } #[test] fn introspect_with_generics() { run_type_info_query("WithGenerics", |object, fields| { - assert_eq!(object.get_field_value("name"), Some(&Value::scalar("WithGenerics"))); + assert_eq!( + object.get_field_value("name"), + Some(&Value::scalar("WithGenerics")) + ); assert_eq!(object.get_field_value("description"), Some(&Value::null())); - assert!( - fields.contains(&Value::object( - vec![("name", Value::scalar("simple"))] - .into_iter() - .collect(), - )) - ); + assert!(fields.contains(&Value::object( + vec![("name", Value::scalar("simple"))] + .into_iter() + .collect(), + ))); }); } #[test] fn introspect_description_first() { run_type_info_query("DescriptionFirst", |object, fields| { - assert_eq!(object.get_field_value("name"), Some(&Value::scalar("DescriptionFirst"))); + assert_eq!( + object.get_field_value("name"), + Some(&Value::scalar("DescriptionFirst")) + ); assert_eq!( object.get_field_value("description"), Some(&Value::scalar("A description")) ); - assert!( - fields.contains(&Value::object( - vec![("name", Value::scalar("simple"))] - .into_iter() - .collect(), - )) - ); + assert!(fields.contains(&Value::object( + vec![("name", Value::scalar("simple"))] + .into_iter() + .collect(), + ))); }); } #[test] fn introspect_fields_first() { run_type_info_query("FieldsFirst", |object, fields| { - assert_eq!(object.get_field_value("name"), Some(&Value::scalar("FieldsFirst"))); + assert_eq!( + object.get_field_value("name"), + Some(&Value::scalar("FieldsFirst")) + ); assert_eq!( object.get_field_value("description"), Some(&Value::scalar("A description")) ); - assert!( - fields.contains(&Value::object( - vec![("name", Value::scalar("simple"))] - .into_iter() - .collect(), - )) - ); + assert!(fields.contains(&Value::object( + vec![("name", Value::scalar("simple"))] + .into_iter() + .collect(), + ))); }); } #[test] fn introspect_interfaces_first() { run_type_info_query("InterfacesFirst", |object, fields| { - assert_eq!(object.get_field_value("name"), Some(&Value::scalar("InterfacesFirst"))); + assert_eq!( + object.get_field_value("name"), + Some(&Value::scalar("InterfacesFirst")) + ); assert_eq!( object.get_field_value("description"), Some(&Value::scalar("A description")) ); - assert!( - fields.contains(&Value::object( - vec![("name", Value::scalar("simple"))] - .into_iter() - .collect(), - )) - ); + assert!(fields.contains(&Value::object( + vec![("name", Value::scalar("simple"))] + .into_iter() + .collect(), + ))); }); } @@ -290,32 +293,31 @@ fn introspect_commas_with_trailing() { Some(&Value::scalar("A description")) ); - assert!( - fields.contains(&Value::object( - vec![("name", Value::scalar("simple"))] - .into_iter() - .collect(), - )) - ); + assert!(fields.contains(&Value::object( + vec![("name", Value::scalar("simple"))] + .into_iter() + .collect(), + ))); }); } #[test] fn introspect_commas_on_meta() { run_type_info_query("CommasOnMeta", |object, fields| { - assert_eq!(object.get_field_value("name"), Some(&Value::scalar("CommasOnMeta"))); + assert_eq!( + object.get_field_value("name"), + Some(&Value::scalar("CommasOnMeta")) + ); assert_eq!( object.get_field_value("description"), Some(&Value::scalar("A description")) ); - assert!( - fields.contains(&Value::object( - vec![("name", Value::scalar("simple"))] - .into_iter() - .collect(), - )) - ); + assert!(fields.contains(&Value::object( + vec![("name", Value::scalar("simple"))] + .into_iter() + .collect(), + ))); }); } @@ -331,12 +333,10 @@ fn introspect_resolvers_with_trailing_comma() { Some(&Value::scalar("A description")) ); - assert!( - fields.contains(&Value::object( - vec![("name", Value::scalar("simple"))] - .into_iter() - .collect(), - )) - ); + assert!(fields.contains(&Value::object( + vec![("name", Value::scalar("simple"))] + .into_iter() + .collect(), + ))); }); } diff --git a/juniper/src/macros/tests/object.rs b/juniper/src/macros/tests/object.rs index f7323f18..f31300e9 100644 --- a/juniper/src/macros/tests/object.rs +++ b/juniper/src/macros/tests/object.rs @@ -274,7 +274,8 @@ fn introspect_description_first() { vec![ ("name", Value::scalar("Interface")), ("kind", Value::scalar("INTERFACE")), - ].into_iter() + ] + .into_iter() .collect(), )])) ); @@ -303,7 +304,8 @@ fn introspect_fields_first() { vec![ ("name", Value::scalar("Interface")), ("kind", Value::scalar("INTERFACE")), - ].into_iter() + ] + .into_iter() .collect(), )])) ); @@ -332,7 +334,8 @@ fn introspect_interfaces_first() { vec![ ("name", Value::scalar("Interface")), ("kind", Value::scalar("INTERFACE")), - ].into_iter() + ] + .into_iter() .collect(), )])) ); @@ -361,7 +364,8 @@ fn introspect_commas_with_trailing() { vec![ ("name", Value::scalar("Interface")), ("kind", Value::scalar("INTERFACE")), - ].into_iter() + ] + .into_iter() .collect(), )])) ); @@ -390,7 +394,8 @@ fn introspect_commas_on_meta() { vec![ ("name", Value::scalar("Interface")), ("kind", Value::scalar("INTERFACE")), - ].into_iter() + ] + .into_iter() .collect(), )])) ); diff --git a/juniper/src/macros/tests/scalar.rs b/juniper/src/macros/tests/scalar.rs index 3c50318d..fbc29f87 100644 --- a/juniper/src/macros/tests/scalar.rs +++ b/juniper/src/macros/tests/scalar.rs @@ -1,7 +1,7 @@ use executor::Variables; use schema::model::RootNode; use types::scalars::EmptyMutation; -use value::{Value, Object, DefaultScalarValue, ParseScalarValue, ParseScalarResult}; +use value::{DefaultScalarValue, Object, ParseScalarResult, ParseScalarValue, Value}; struct DefaultName(i32); struct OtherOrder(i32); @@ -140,8 +140,14 @@ fn default_name_introspection() { "#; run_type_info_query(doc, |type_info| { - assert_eq!(type_info.get_field_value("name"), Some(&Value::scalar("DefaultName"))); - assert_eq!(type_info.get_field_value("description"), Some(&Value::null())); + assert_eq!( + type_info.get_field_value("name"), + Some(&Value::scalar("DefaultName")) + ); + assert_eq!( + type_info.get_field_value("description"), + Some(&Value::null()) + ); }); } @@ -157,8 +163,14 @@ fn other_order_introspection() { "#; run_type_info_query(doc, |type_info| { - assert_eq!(type_info.get_field_value("name"), Some(&Value::scalar("OtherOrder"))); - assert_eq!(type_info.get_field_value("description"), Some(&Value::null())); + assert_eq!( + type_info.get_field_value("name"), + Some(&Value::scalar("OtherOrder")) + ); + assert_eq!( + type_info.get_field_value("description"), + Some(&Value::null()) + ); }); } @@ -174,8 +186,14 @@ fn named_introspection() { "#; run_type_info_query(doc, |type_info| { - assert_eq!(type_info.get_field_value("name"), Some(&Value::scalar("ANamedScalar"))); - assert_eq!(type_info.get_field_value("description"), Some(&Value::null())); + assert_eq!( + type_info.get_field_value("name"), + Some(&Value::scalar("ANamedScalar")) + ); + assert_eq!( + type_info.get_field_value("description"), + Some(&Value::null()) + ); }); } diff --git a/juniper/src/macros/tests/union.rs b/juniper/src/macros/tests/union.rs index 4b0cd570..fa0db5b7 100644 --- a/juniper/src/macros/tests/union.rs +++ b/juniper/src/macros/tests/union.rs @@ -3,7 +3,7 @@ use std::marker::PhantomData; use ast::InputValue; use schema::model::RootNode; use types::scalars::EmptyMutation; -use value::{Value, Object, DefaultScalarValue}; +use value::{DefaultScalarValue, Object, Value}; /* @@ -154,86 +154,91 @@ where #[test] fn introspect_custom_name() { run_type_info_query("ACustomNamedUnion", |union, possible_types| { - assert_eq!(union.get_field_value("name"), Some(&Value::scalar("ACustomNamedUnion"))); + assert_eq!( + union.get_field_value("name"), + Some(&Value::scalar("ACustomNamedUnion")) + ); assert_eq!(union.get_field_value("description"), Some(&Value::null())); - assert!( - possible_types.contains(&Value::object( - vec![("name", Value::scalar("Concrete"))] - .into_iter() - .collect(), - )) - ); + assert!(possible_types.contains(&Value::object( + vec![("name", Value::scalar("Concrete"))] + .into_iter() + .collect(), + ))); }); } #[test] fn introspect_with_lifetime() { run_type_info_query("WithLifetime", |union, possible_types| { - assert_eq!(union.get_field_value("name"), Some(&Value::scalar("WithLifetime"))); + assert_eq!( + union.get_field_value("name"), + Some(&Value::scalar("WithLifetime")) + ); assert_eq!(union.get_field_value("description"), Some(&Value::null())); - assert!( - possible_types.contains(&Value::object( - vec![("name", Value::scalar("Concrete"))] - .into_iter() - .collect(), - )) - ); + assert!(possible_types.contains(&Value::object( + vec![("name", Value::scalar("Concrete"))] + .into_iter() + .collect(), + ))); }); } #[test] fn introspect_with_generics() { run_type_info_query("WithGenerics", |union, possible_types| { - assert_eq!(union.get_field_value("name"), Some(&Value::scalar("WithGenerics"))); + assert_eq!( + union.get_field_value("name"), + Some(&Value::scalar("WithGenerics")) + ); assert_eq!(union.get_field_value("description"), Some(&Value::null())); - assert!( - possible_types.contains(&Value::object( - vec![("name", Value::scalar("Concrete"))] - .into_iter() - .collect(), - )) - ); + assert!(possible_types.contains(&Value::object( + vec![("name", Value::scalar("Concrete"))] + .into_iter() + .collect(), + ))); }); } #[test] fn introspect_description_first() { run_type_info_query("DescriptionFirst", |union, possible_types| { - assert_eq!(union.get_field_value("name"), Some(&Value::scalar("DescriptionFirst"))); + assert_eq!( + union.get_field_value("name"), + Some(&Value::scalar("DescriptionFirst")) + ); assert_eq!( union.get_field_value("description"), Some(&Value::scalar("A description")) ); - assert!( - possible_types.contains(&Value::object( - vec![("name", Value::scalar("Concrete"))] - .into_iter() - .collect(), - )) - ); + assert!(possible_types.contains(&Value::object( + vec![("name", Value::scalar("Concrete"))] + .into_iter() + .collect(), + ))); }); } #[test] fn introspect_resolvers_first() { run_type_info_query("ResolversFirst", |union, possible_types| { - assert_eq!(union.get_field_value("name"), Some(&Value::scalar("ResolversFirst"))); + assert_eq!( + union.get_field_value("name"), + Some(&Value::scalar("ResolversFirst")) + ); assert_eq!( union.get_field_value("description"), Some(&Value::scalar("A description")) ); - assert!( - possible_types.contains(&Value::object( - vec![("name", Value::scalar("Concrete"))] - .into_iter() - .collect(), - )) - ); + assert!(possible_types.contains(&Value::object( + vec![("name", Value::scalar("Concrete"))] + .into_iter() + .collect(), + ))); }); } @@ -249,13 +254,11 @@ fn introspect_commas_with_trailing() { Some(&Value::scalar("A description")) ); - assert!( - possible_types.contains(&Value::object( - vec![("name", Value::scalar("Concrete"))] - .into_iter() - .collect(), - )) - ); + assert!(possible_types.contains(&Value::object( + vec![("name", Value::scalar("Concrete"))] + .into_iter() + .collect(), + ))); }); } @@ -271,12 +274,10 @@ fn introspect_resolvers_with_trailing_comma() { Some(&Value::scalar("A description")) ); - assert!( - possible_types.contains(&Value::object( - vec![("name", Value::scalar("Concrete"))] - .into_iter() - .collect(), - )) - ); + assert!(possible_types.contains(&Value::object( + vec![("name", Value::scalar("Concrete"))] + .into_iter() + .collect(), + ))); }); } diff --git a/juniper/src/parser/document.rs b/juniper/src/parser/document.rs index 0a7b7fbe..4a0bd94f 100644 --- a/juniper/src/parser/document.rs +++ b/juniper/src/parser/document.rs @@ -129,11 +129,13 @@ where start: start_pos, .. } = parser.expect(&Token::Name("fragment"))?; let name = match parser.expect_name() { - Ok(n) => if n.item == "on" { - return Err(n.map(|_| ParseError::UnexpectedToken(Token::Name("on")))); - } else { - n - }, + Ok(n) => { + if n.item == "on" { + return Err(n.map(|_| ParseError::UnexpectedToken(Token::Name("on")))); + } else { + n + } + } Err(e) => return Err(e), }; @@ -354,7 +356,8 @@ where &Token::ParenOpen, |p| parse_argument(p, schema, arguments), &Token::ParenClose, - )?.map(|args| Arguments { + )? + .map(|args| Arguments { items: args.into_iter().map(|s| s.item).collect(), }), )) @@ -408,7 +411,8 @@ where &Token::ParenOpen, |p| parse_variable_definition(p, schema), &Token::ParenClose, - )?.map(|defs| VariableDefinitions { + )? + .map(|defs| VariableDefinitions { items: defs.into_iter().map(|s| s.item).collect(), }), )) diff --git a/juniper/src/parser/lexer.rs b/juniper/src/parser/lexer.rs index 6602a815..bb009548 100644 --- a/juniper/src/parser/lexer.rs +++ b/juniper/src/parser/lexer.rs @@ -24,7 +24,7 @@ pub struct Lexer<'a> { pub enum ScalarToken<'a> { String(&'a str), Float(&'a str), - Int(&'a str) + Int(&'a str), } /// A single token in the input source @@ -231,32 +231,32 @@ impl<'a> Lexer<'a> { let mut old_pos = self.position; while let Some((idx, ch)) = self.next_char() { match ch { - 'b' |'f' |'n'|'r' |'t'|'\\'|'/'| '"' if escaped => { + 'b' | 'f' | 'n' | 'r' | 't' | '\\' | '/' | '"' if escaped => { escaped = false; } 'u' if escaped => { self.scan_escaped_unicode(&old_pos)?; escaped = false; - }, + } c if escaped => { return Err(Spanning::zero_width( &old_pos, - LexerError::UnknownEscapeSequence(format!("\\{}", c)) - )) + LexerError::UnknownEscapeSequence(format!("\\{}", c)), + )) } '\\' => escaped = true, '"' if !escaped => { return Ok(Spanning::start_end( &start_pos, &self.position, - Token::Scalar(ScalarToken::String(&self.source[start_idx+1..idx])), + Token::Scalar(ScalarToken::String(&self.source[start_idx + 1..idx])), )); } '\n' | '\r' => { return Err(Spanning::zero_width( &old_pos, LexerError::UnterminatedString, - )); + )); } c if !is_source_char(c) => { return Err(Spanning::zero_width( @@ -316,12 +316,14 @@ impl<'a> Lexer<'a> { ) })?; - char::from_u32(code_point).ok_or_else(|| { - Spanning::zero_width( - start_pos, - LexerError::UnknownEscapeSequence("\\u".to_owned() + escape), - ) - }).map(|_|()) + char::from_u32(code_point) + .ok_or_else(|| { + Spanning::zero_width( + start_pos, + LexerError::UnknownEscapeSequence("\\u".to_owned() + escape), + ) + }) + .map(|_| ()) } fn scan_number(&mut self) -> LexerResult<'a> { @@ -424,15 +426,11 @@ impl<'a> Lexer<'a> { let token = if is_float { Token::Scalar(ScalarToken::Float(number)) - }else { + } else { Token::Scalar(ScalarToken::Int(number)) }; - Ok(Spanning::start_end( - &start_pos, - end_pos, - token, - )) + Ok(Spanning::start_end(&start_pos, end_pos, token)) } } @@ -463,16 +461,18 @@ impl<'a> Iterator for Lexer<'a> { Some('|') => Ok(self.emit_single_char(Token::Pipe)), Some('.') => self.scan_ellipsis(), Some('"') => self.scan_string(), - Some(ch) => if is_number_start(ch) { - self.scan_number() - } else if is_name_start(ch) { - self.scan_name() - } else { - Err(Spanning::zero_width( - &self.position, - LexerError::UnknownCharacter(ch), - )) - }, + Some(ch) => { + if is_number_start(ch) { + self.scan_number() + } else if is_name_start(ch) { + self.scan_name() + } else { + Err(Spanning::zero_width( + &self.position, + LexerError::UnknownCharacter(ch), + )) + } + } None => { self.has_reached_eof = true; Ok(Spanning::zero_width(&self.position, Token::EndOfFile)) @@ -485,10 +485,12 @@ impl<'a> fmt::Display for Token<'a> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match *self { Token::Name(name) => write!(f, "{}", name), - Token::Scalar(ScalarToken::Int(s)) | Token::Scalar(ScalarToken::Float(s)) => write!(f, "{}", s), + Token::Scalar(ScalarToken::Int(s)) | Token::Scalar(ScalarToken::Float(s)) => { + write!(f, "{}", s) + } Token::Scalar(ScalarToken::String(s)) => { write!(f, "\"{}\"", s.replace('\\', "\\\\").replace('"', "\\\"")) - }, + } Token::ExclamationMark => write!(f, "!"), Token::Dollar => write!(f, "$"), Token::ParenOpen => write!(f, "("), diff --git a/juniper/src/parser/mod.rs b/juniper/src/parser/mod.rs index 45865d31..a7cbd10a 100644 --- a/juniper/src/parser/mod.rs +++ b/juniper/src/parser/mod.rs @@ -11,6 +11,6 @@ mod tests; pub use self::document::parse_document_source; -pub use self::lexer::{Lexer, LexerError, Token, ScalarToken}; +pub use self::lexer::{Lexer, LexerError, ScalarToken, Token}; pub use self::parser::{OptionParseResult, ParseError, ParseResult, Parser, UnlocatedParseResult}; pub use self::utils::{SourcePosition, Spanning}; diff --git a/juniper/src/parser/tests/document.rs b/juniper/src/parser/tests/document.rs index 653becf1..06bebeca 100644 --- a/juniper/src/parser/tests/document.rs +++ b/juniper/src/parser/tests/document.rs @@ -5,7 +5,7 @@ use parser::document::parse_document_source; use parser::{ParseError, SourcePosition, Spanning, Token}; use schema::model::SchemaType; use validation::test_harness::{MutationRoot, QueryRoot}; -use value::{ScalarRefValue, ScalarValue, DefaultScalarValue}; +use value::{DefaultScalarValue, ScalarRefValue, ScalarValue}; fn parse_document(s: &str) -> Document where diff --git a/juniper/src/parser/tests/lexer.rs b/juniper/src/parser/tests/lexer.rs index 28360753..369aa112 100644 --- a/juniper/src/parser/tests/lexer.rs +++ b/juniper/src/parser/tests/lexer.rs @@ -1,4 +1,4 @@ -use parser::{Lexer, LexerError, SourcePosition, Spanning, Token, ScalarToken}; +use parser::{Lexer, LexerError, ScalarToken, SourcePosition, Spanning, Token}; fn tokenize_to_vec<'a>(s: &'a str) -> Vec>> { let mut tokens = Vec::new(); @@ -35,9 +35,11 @@ fn tokenize_error(s: &str) -> Spanning { loop { match lexer.next() { - Some(Ok(t)) => if t.item == Token::EndOfFile { - panic!("Tokenizer did not return error for {:#?}", s); - }, + Some(Ok(t)) => { + if t.item == Token::EndOfFile { + panic!("Tokenizer did not return error for {:#?}", s); + } + } Some(Err(e)) => { return e; } @@ -133,7 +135,8 @@ fn error_positions() { ? "# - ).next(), + ) + .next(), Some(Err(Spanning::zero_width( &SourcePosition::new(14, 2, 12), LexerError::UnknownCharacter('?') @@ -654,7 +657,10 @@ fn display() { assert_eq!(format!("{}", Token::Scalar(ScalarToken::Int("123"))), "123"); - assert_eq!(format!("{}", Token::Scalar(ScalarToken::Float("4.5"))), "4.5"); + assert_eq!( + format!("{}", Token::Scalar(ScalarToken::Float("4.5"))), + "4.5" + ); assert_eq!( format!("{}", Token::Scalar(ScalarToken::String("some string"))), diff --git a/juniper/src/parser/tests/value.rs b/juniper/src/parser/tests/value.rs index e74cb475..619f8bf3 100644 --- a/juniper/src/parser/tests/value.rs +++ b/juniper/src/parser/tests/value.rs @@ -5,13 +5,13 @@ use parser::value::parse_value_literal; use parser::{Lexer, Parser, SourcePosition, Spanning}; use value::{DefaultScalarValue, ParseScalarValue, ScalarRefValue, ScalarValue}; -use schema::meta::{MetaType, ScalarMeta, EnumMeta, EnumValue, InputObjectMeta, Argument}; +use schema::meta::{Argument, EnumMeta, EnumValue, InputObjectMeta, MetaType, ScalarMeta}; use schema::model::SchemaType; use types::scalars::EmptyMutation; #[derive(GraphQLEnumInternal)] enum Enum { - EnumValue + EnumValue, } #[derive(GraphQLInputObjectInternal)] @@ -168,8 +168,10 @@ fn input_value_literals() { ]) ) ); - let fields = [ Argument::new("key", Type::NonNullNamed("Int".into())), - Argument::new("other", Type::NonNullNamed("Bar".into()))]; + let fields = [ + Argument::new("key", Type::NonNullNamed("Int".into())), + Argument::new("other", Type::NonNullNamed("Bar".into())), + ]; let meta = &MetaType::InputObject(InputObjectMeta::new::("foo".into(), &fields)); assert_eq!( parse_value::("{}", meta), @@ -181,10 +183,7 @@ fn input_value_literals() { ); assert_eq!( - parse_value::( - r#"{key: 123, other: {foo: "bar"}}"#, - meta - ), + parse_value::(r#"{key: 123, other: {foo: "bar"}}"#, meta), Spanning::start_end( &SourcePosition::new(0, 0, 0), &SourcePosition::new(31, 0, 31), diff --git a/juniper/src/parser/value.rs b/juniper/src/parser/value.rs index 297fa7c0..a1d7416d 100644 --- a/juniper/src/parser/value.rs +++ b/juniper/src/parser/value.rs @@ -42,11 +42,7 @@ where .. }, _, - ) - if !is_const => - { - parse_variable_literal(parser) - } + ) if !is_const => parse_variable_literal(parser), ( &Spanning { item: Token::Scalar(_), @@ -133,7 +129,8 @@ where &Token::BracketOpen, |p| parse_value_literal(p, is_const, schema, tpe), &Token::BracketClose, - )?.map(InputValue::parsed_list)) + )? + .map(InputValue::parsed_list)) } fn parse_object_literal<'a, 'b, S>( @@ -150,7 +147,8 @@ where &Token::CurlyOpen, |p| parse_object_field(p, is_const, schema, object_tpe), &Token::CurlyClose, - )?.map(|items| InputValue::parsed_object(items.into_iter().map(|s| s.item).collect()))) + )? + .map(|items| InputValue::parsed_object(items.into_iter().map(|s| s.item).collect()))) } fn parse_object_field<'a, 'b, S>( diff --git a/juniper/src/schema/meta.rs b/juniper/src/schema/meta.rs index 8d712378..df93dd9d 100644 --- a/juniper/src/schema/meta.rs +++ b/juniper/src/schema/meta.rs @@ -365,8 +365,9 @@ impl<'a, S> MetaType<'a, S> { } pub(crate) fn fields<'b>(&self, schema: &'b SchemaType) -> Option>> { - schema.lookup_type(&self.as_type()).and_then(|tpe| { - match *tpe { + schema + .lookup_type(&self.as_type()) + .and_then(|tpe| match *tpe { MetaType::Interface(ref i) => Some(i.fields.iter().collect()), MetaType::Object(ref o) => Some(o.fields.iter().collect()), MetaType::Union(ref u) => Some( @@ -378,8 +379,7 @@ impl<'a, S> MetaType<'a, S> { .collect(), ), _ => None, - } - }) + }) } } @@ -687,9 +687,7 @@ impl<'a, S> Argument<'a, S> { desc.push('\n'); desc.push_str(&docstring); } - desc @ &mut None => { - *desc = Some(docstring) - } + desc @ &mut None => *desc = Some(docstring), } } self @@ -800,6 +798,7 @@ fn clean_docstring(multiline: &[&str]) -> Option { .take_while(move |_| line < multiline.len() - 1) .cloned(), ) - }).collect::(), + }) + .collect::(), ) } diff --git a/juniper/src/schema/model.rs b/juniper/src/schema/model.rs index 77b43c60..2a4fab8b 100644 --- a/juniper/src/schema/model.rs +++ b/juniper/src/schema/model.rs @@ -302,7 +302,8 @@ impl<'a, S> SchemaType<'a, S> { .. }) => interface_names.iter().any(|iname| iname == name), _ => false, - }).collect(), + }) + .collect(), _ => panic!("Can't retrieve possible types from non-abstract meta type"), } } diff --git a/juniper/src/tests/introspection_tests.rs b/juniper/src/tests/introspection_tests.rs index 70384aa1..c9cf88b8 100644 --- a/juniper/src/tests/introspection_tests.rs +++ b/juniper/src/tests/introspection_tests.rs @@ -31,10 +31,12 @@ fn test_query_type_name() { Value::object( vec![("name", Value::scalar("Query"))].into_iter().collect(), ), - )].into_iter() + )] + .into_iter() .collect(), ), - )].into_iter() + )] + .into_iter() .collect() ), vec![] @@ -60,7 +62,8 @@ fn test_specific_type_name() { vec![( "__type", Value::object(vec![("name", Value::scalar("Droid"))].into_iter().collect()), - )].into_iter() + )] + .into_iter() .collect() ), vec![] @@ -91,10 +94,12 @@ fn test_specific_object_type_name_and_kind() { vec![ ("name", Value::scalar("Droid")), ("kind", Value::scalar("OBJECT")), - ].into_iter() + ] + .into_iter() .collect(), ), - )].into_iter() + )] + .into_iter() .collect() ), vec![] @@ -125,10 +130,12 @@ fn test_specific_interface_type_name_and_kind() { vec![ ("name", Value::scalar("Character")), ("kind", Value::scalar("INTERFACE")), - ].into_iter() + ] + .into_iter() .collect(), ), - )].into_iter() + )] + .into_iter() .collect() ), vec![] @@ -162,10 +169,12 @@ fn test_documentation() { "description", Value::scalar("A mechanical creature in the Star Wars universe."), ), - ].into_iter() + ] + .into_iter() .collect(), ), - )].into_iter() + )] + .into_iter() .collect() ), vec![] @@ -214,7 +223,8 @@ fn test_possible_types() { .expect("'name' not present in type") .as_scalar_value::() .expect("'name' not a string") as &str - }).collect::>(); + }) + .collect::>(); assert_eq!(possible_types, vec!["Human", "Droid"].into_iter().collect()); } diff --git a/juniper/src/tests/query_tests.rs b/juniper/src/tests/query_tests.rs index 5ad26474..8f14e05e 100644 --- a/juniper/src/tests/query_tests.rs +++ b/juniper/src/tests/query_tests.rs @@ -23,7 +23,8 @@ fn test_hero_name() { vec![( "hero", Value::object(vec![("name", Value::scalar("R2-D2"))].into_iter().collect()), - )].into_iter() + )] + .into_iter() .collect() ), vec![] @@ -53,10 +54,12 @@ fn test_hero_field_order() { vec![ ("id", Value::scalar("2001")), ("name", Value::scalar("R2-D2")), - ].into_iter() + ] + .into_iter() .collect(), ), - )].into_iter() + )] + .into_iter() .collect() ), vec![] @@ -80,10 +83,12 @@ fn test_hero_field_order() { vec![ ("name", Value::scalar("R2-D2")), ("id", Value::scalar("2001")), - ].into_iter() + ] + .into_iter() .collect(), ), - )].into_iter() + )] + .into_iter() .collect() ), vec![] @@ -136,10 +141,12 @@ fn test_hero_name_and_friends() { ), ]), ), - ].into_iter() + ] + .into_iter() .collect(), ), - )].into_iter() + )] + .into_iter() .collect() ), vec![] @@ -202,7 +209,8 @@ fn test_hero_name_and_friends_and_friends_of_friends() { vec![( "name", Value::scalar("Leia Organa"), - )].into_iter() + )] + .into_iter() .collect(), ), Value::object( @@ -217,7 +225,8 @@ fn test_hero_name_and_friends_and_friends_of_friends() { ), ]), ), - ].into_iter() + ] + .into_iter() .collect(), ), Value::object( @@ -238,14 +247,16 @@ fn test_hero_name_and_friends_and_friends_of_friends() { vec![( "name", Value::scalar("Luke Skywalker"), - )].into_iter() + )] + .into_iter() .collect(), ), Value::object( vec![( "name", Value::scalar("Leia Organa"), - )].into_iter() + )] + .into_iter() .collect(), ), Value::object( @@ -255,7 +266,8 @@ fn test_hero_name_and_friends_and_friends_of_friends() { ), ]), ), - ].into_iter() + ] + .into_iter() .collect(), ), Value::object( @@ -276,7 +288,8 @@ fn test_hero_name_and_friends_and_friends_of_friends() { vec![( "name", Value::scalar("Luke Skywalker"), - )].into_iter() + )] + .into_iter() .collect(), ), Value::object( @@ -296,15 +309,18 @@ fn test_hero_name_and_friends_and_friends_of_friends() { ), ]), ), - ].into_iter() + ] + .into_iter() .collect(), ), ]), ), - ].into_iter() + ] + .into_iter() .collect(), ), - )].into_iter() + )] + .into_iter() .collect() ), vec![] @@ -329,7 +345,8 @@ fn test_query_name() { .into_iter() .collect(), ), - )].into_iter() + )] + .into_iter() .collect() ), vec![] @@ -354,7 +371,8 @@ fn test_query_alias_single() { .into_iter() .collect(), ), - )].into_iter() + )] + .into_iter() .collect() ), vec![] @@ -393,7 +411,8 @@ fn test_query_alias_multiple() { .collect(), ), ), - ].into_iter() + ] + .into_iter() .collect() ), vec![] @@ -427,7 +446,8 @@ fn test_query_alias_multiple_with_fragment() { vec![ ("name", Value::scalar("Luke Skywalker")), ("homePlanet", Value::scalar("Tatooine")), - ].into_iter() + ] + .into_iter() .collect(), ), ), @@ -437,11 +457,13 @@ fn test_query_alias_multiple_with_fragment() { vec![ ("name", Value::scalar("Leia Organa")), ("homePlanet", Value::scalar("Alderaan")), - ].into_iter() + ] + .into_iter() .collect(), ), ), - ].into_iter() + ] + .into_iter() .collect() ), vec![] @@ -470,7 +492,8 @@ fn test_query_name_variable() { .into_iter() .collect(), ), - )].into_iter() + )] + .into_iter() .collect() ), vec![] @@ -530,10 +553,12 @@ fn test_query_friends_names() { vec![("name", Value::scalar("R2-D2"))].into_iter().collect(), ), ]), - )].into_iter() + )] + .into_iter() .collect(), ), - )].into_iter() + )] + .into_iter() .collect() ), vec![] @@ -569,10 +594,12 @@ fn test_query_inline_fragments_droid() { ("name", Value::scalar("R2-D2")), ("__typename", Value::scalar("Droid")), ("primaryFunction", Value::scalar("Astromech")), - ].into_iter() + ] + .into_iter() .collect(), ), - )].into_iter() + )] + .into_iter() .collect() ), vec![] @@ -603,10 +630,12 @@ fn test_query_inline_fragments_human() { vec![ ("name", Value::scalar("Luke Skywalker")), ("__typename", Value::scalar("Human")), - ].into_iter() + ] + .into_iter() .collect(), ), - )].into_iter() + )] + .into_iter() .collect() ), vec![] @@ -636,7 +665,8 @@ fn test_object_typename() { .into_iter() .collect(), ), - )].into_iter() + )] + .into_iter() .collect() ), vec![] diff --git a/juniper/src/tests/type_info_tests.rs b/juniper/src/tests/type_info_tests.rs index 63b777ef..9fc7e45f 100644 --- a/juniper/src/tests/type_info_tests.rs +++ b/juniper/src/tests/type_info_tests.rs @@ -82,7 +82,8 @@ fn test_node() { ("foo", Value::scalar("1")), ("bar", Value::scalar("2")), ("baz", Value::scalar("3")), - ].into_iter() + ] + .into_iter() .collect() ), vec![] diff --git a/juniper/src/types/base.rs b/juniper/src/types/base.rs index 69a2ae95..f54149fd 100644 --- a/juniper/src/types/base.rs +++ b/juniper/src/types/base.rs @@ -355,7 +355,8 @@ where T::name(info) .expect("Resolving named type's selection set") .as_ref(), - ).expect("Type not found in schema"); + ) + .expect("Type not found in schema"); for selection in selection_set { match *selection { @@ -404,7 +405,8 @@ where .iter() .map(|&(ref k, ref v)| { (k.item, v.item.clone().into_const(exec_vars)) - }).collect() + }) + .collect() }), &meta_field.arguments, ), diff --git a/juniper/src/types/containers.rs b/juniper/src/types/containers.rs index 1cfd5fc0..354f4533 100644 --- a/juniper/src/types/containers.rs +++ b/juniper/src/types/containers.rs @@ -121,11 +121,13 @@ where None } } - ref other => if let Some(e) = other.convert() { - Some(vec![e]) - } else { - None - }, + ref other => { + if let Some(e) = other.convert() { + Some(vec![e]) + } else { + None + } + } } } } diff --git a/juniper/src/types/pointers.rs b/juniper/src/types/pointers.rs index 4cb4b2d4..e516b6b1 100644 --- a/juniper/src/types/pointers.rs +++ b/juniper/src/types/pointers.rs @@ -11,7 +11,7 @@ impl GraphQLType for Box where S: ScalarValue, T: GraphQLType, - for<'b> &'b S: ScalarRefValue<'b> + for<'b> &'b S: ScalarRefValue<'b>, { type Context = CtxT; type TypeInfo = T::TypeInfo; @@ -65,7 +65,7 @@ where { fn from_input_value<'a>(v: &'a InputValue) -> Option> where - for<'b> &'b S: ScalarRefValue<'b> + for<'b> &'b S: ScalarRefValue<'b>, { match >::from_input_value(v) { Some(v) => Some(Box::new(v)), @@ -88,7 +88,7 @@ impl<'a, S, T, CtxT> GraphQLType for &'a T where S: ScalarValue, T: GraphQLType, - for<'b> &'b S: ScalarRefValue<'b> + for<'b> &'b S: ScalarRefValue<'b>, { type Context = CtxT; type TypeInfo = T::TypeInfo; @@ -149,7 +149,7 @@ impl GraphQLType for Arc where S: ScalarValue, T: GraphQLType, - for<'b> &'b S: ScalarRefValue<'b> + for<'b> &'b S: ScalarRefValue<'b>, { type Context = T::Context; type TypeInfo = T::TypeInfo; diff --git a/juniper/src/types/scalars.rs b/juniper/src/types/scalars.rs index 8855f1ac..57d27cc1 100644 --- a/juniper/src/types/scalars.rs +++ b/juniper/src/types/scalars.rs @@ -116,14 +116,16 @@ where .next() .ok_or_else(|| { ParseError::LexerError(LexerError::UnknownEscapeSequence(String::from("\\u"))) - }).and_then(|c1| { + }) + .and_then(|c1| { char_iter .next() .map(|c2| format!("{}{}", c1, c2)) .ok_or_else(|| { ParseError::LexerError(LexerError::UnknownEscapeSequence(format!("\\u{}", c1))) }) - }).and_then(|mut s| { + }) + .and_then(|mut s| { char_iter .next() .ok_or_else(|| { @@ -131,11 +133,13 @@ where "\\u{}", s.clone() ))) - }).map(|c2| { + }) + .map(|c2| { s.push(c2); s }) - }).and_then(|mut s| { + }) + .and_then(|mut s| { char_iter .next() .ok_or_else(|| { @@ -143,7 +147,8 @@ where "\\u{}", s.clone() ))) - }).map(|c2| { + }) + .map(|c2| { s.push(c2); s }) diff --git a/juniper/src/types/utilities.rs b/juniper/src/types/utilities.rs index 0997d4c8..085f0aa1 100644 --- a/juniper/src/types/utilities.rs +++ b/juniper/src/types/utilities.rs @@ -13,11 +13,13 @@ where S: ScalarValue, { match *arg_type { - TypeType::NonNull(ref inner) => if arg_value.is_null() { - false - } else { - is_valid_literal_value(schema, inner, arg_value) - }, + TypeType::NonNull(ref inner) => { + if arg_value.is_null() { + false + } else { + is_valid_literal_value(schema, inner, arg_value) + } + } TypeType::List(ref inner) => match *arg_value { InputValue::List(ref items) => items .iter() @@ -35,47 +37,49 @@ where match *arg_value { InputValue::Null | InputValue::Variable(_) => true, - ref v @ InputValue::Scalar(_) - | ref v @ InputValue::Enum(_) => if let Some(parse_fn) = t.input_value_parse_fn() { - parse_fn(v) - } else { - false - }, + ref v @ InputValue::Scalar(_) | ref v @ InputValue::Enum(_) => { + if let Some(parse_fn) = t.input_value_parse_fn() { + parse_fn(v) + } else { + false + } + } InputValue::List(_) => false, - InputValue::Object(ref obj) => if let MetaType::InputObject(InputObjectMeta { - ref input_fields, - .. - }) = *t - { - let mut remaining_required_fields = input_fields - .iter() - .filter_map(|f| { - if f.arg_type.is_non_null() { - Some(&f.name) - } else { - None - } - }) - .collect::>(); - - let all_types_ok = obj.iter().all(|&(ref key, ref value)| { - remaining_required_fields.remove(&key.item); - if let Some(ref arg_type) = input_fields + InputValue::Object(ref obj) => { + if let MetaType::InputObject(InputObjectMeta { + ref input_fields, .. + }) = *t + { + let mut remaining_required_fields = input_fields .iter() - .filter(|f| f.name == key.item) - .map(|f| schema.make_type(&f.arg_type)) - .next() - { - is_valid_literal_value(schema, arg_type, &value.item) - } else { - false - } - }); + .filter_map(|f| { + if f.arg_type.is_non_null() { + Some(&f.name) + } else { + None + } + }) + .collect::>(); - all_types_ok && remaining_required_fields.is_empty() - } else { - false - }, + let all_types_ok = obj.iter().all(|&(ref key, ref value)| { + remaining_required_fields.remove(&key.item); + if let Some(ref arg_type) = input_fields + .iter() + .filter(|f| f.name == key.item) + .map(|f| schema.make_type(&f.arg_type)) + .next() + { + is_valid_literal_value(schema, arg_type, &value.item) + } else { + false + } + }); + + all_types_ok && remaining_required_fields.is_empty() + } else { + false + } + } } } } diff --git a/juniper/src/util.rs b/juniper/src/util.rs index 972f1b25..c2b49a84 100644 --- a/juniper/src/util.rs +++ b/juniper/src/util.rs @@ -11,7 +11,8 @@ pub fn to_camel_case<'a>(s: &'a str) -> Cow<'a, str> { if i > 0 && part.len() == 1 { dest += Cow::Owned(part.to_uppercase()); } else if i > 0 && part.len() > 1 { - let first = part.chars() + let first = part + .chars() .next() .unwrap() .to_uppercase() diff --git a/juniper/src/validation/input_value.rs b/juniper/src/validation/input_value.rs index 219fb573..4ced7c4e 100644 --- a/juniper/src/validation/input_value.rs +++ b/juniper/src/validation/input_value.rs @@ -93,18 +93,20 @@ where let mut errors: Vec = vec![]; match *meta_type { - TypeType::NonNull(ref inner) => if value.is_null() { - errors.push(unification_error( - var_name, - var_pos, - &path, - &format!(r#"Expected "{}", found null"#, meta_type), - )); - } else { - errors.append(&mut unify_value( - var_name, var_pos, value, inner, schema, path, - )); - }, + TypeType::NonNull(ref inner) => { + if value.is_null() { + errors.push(unification_error( + var_name, + var_pos, + &path, + &format!(r#"Expected "{}", found null"#, meta_type), + )); + } else { + errors.append(&mut unify_value( + var_name, var_pos, value, inner, schema, path, + )); + } + } TypeType::List(ref inner) => { if value.is_null() { @@ -112,16 +114,18 @@ where } match value.to_list_value() { - Some(l) => for (i, v) in l.iter().enumerate() { - errors.append(&mut unify_value( - var_name, - var_pos, - v, - inner, - schema, - Path::ArrayElement(i, &path), - )); - }, + Some(l) => { + for (i, v) in l.iter().enumerate() { + errors.append(&mut unify_value( + var_name, + var_pos, + v, + inner, + schema, + Path::ArrayElement(i, &path), + )); + } + } _ => errors.append(&mut unify_value( var_name, var_pos, value, inner, schema, path, )), diff --git a/juniper/src/validation/rules/fields_on_correct_type.rs b/juniper/src/validation/rules/fields_on_correct_type.rs index e3bef3d9..789ab33a 100644 --- a/juniper/src/validation/rules/fields_on_correct_type.rs +++ b/juniper/src/validation/rules/fields_on_correct_type.rs @@ -14,7 +14,6 @@ impl<'a, S> Visitor<'a, S> for FieldsOnCorrectType where S: ScalarValue, { - fn enter_field( &mut self, context: &mut ValidatorContext<'a, S>, diff --git a/juniper/src/validation/rules/known_directives.rs b/juniper/src/validation/rules/known_directives.rs index 6e93098b..cffdfc72 100644 --- a/juniper/src/validation/rules/known_directives.rs +++ b/juniper/src/validation/rules/known_directives.rs @@ -18,7 +18,6 @@ impl<'a, S> Visitor<'a, S> for KnownDirectives where S: ScalarValue, { - fn enter_operation_definition( &mut self, _: &mut ValidatorContext<'a, S>, diff --git a/juniper/src/validation/rules/known_fragment_names.rs b/juniper/src/validation/rules/known_fragment_names.rs index 60301854..cc9cd530 100644 --- a/juniper/src/validation/rules/known_fragment_names.rs +++ b/juniper/src/validation/rules/known_fragment_names.rs @@ -13,7 +13,6 @@ impl<'a, S> Visitor<'a, S> for KnownFragmentNames where S: ScalarValue, { - fn enter_fragment_spread( &mut self, context: &mut ValidatorContext<'a, S>, diff --git a/juniper/src/validation/rules/lone_anonymous_operation.rs b/juniper/src/validation/rules/lone_anonymous_operation.rs index dae46518..90c9965b 100644 --- a/juniper/src/validation/rules/lone_anonymous_operation.rs +++ b/juniper/src/validation/rules/lone_anonymous_operation.rs @@ -23,7 +23,8 @@ where .filter(|d| match **d { Definition::Operation(_) => true, Definition::Fragment(_) => false, - }).count(), + }) + .count(), ); } diff --git a/juniper/src/validation/rules/no_fragment_cycles.rs b/juniper/src/validation/rules/no_fragment_cycles.rs index dae0c7f3..f577452e 100644 --- a/juniper/src/validation/rules/no_fragment_cycles.rs +++ b/juniper/src/validation/rules/no_fragment_cycles.rs @@ -30,7 +30,6 @@ impl<'a, S> Visitor<'a, S> for NoFragmentCycles<'a> where S: ScalarValue, { - fn exit_document(&mut self, ctx: &mut ValidatorContext<'a, S>, _: &'a Document) { assert!(self.current_fragment.is_none()); diff --git a/juniper/src/validation/rules/no_undefined_variables.rs b/juniper/src/validation/rules/no_undefined_variables.rs index e3b40be3..57d20322 100644 --- a/juniper/src/validation/rules/no_undefined_variables.rs +++ b/juniper/src/validation/rules/no_undefined_variables.rs @@ -79,7 +79,8 @@ where &error_message(var.item, *op_name), &[var.start.clone(), pos.clone()], ) - }).collect(), + }) + .collect(), ); } } @@ -144,7 +145,8 @@ where .iter() .map(|&var_name| { Spanning::start_end(&value.start.clone(), &value.end.clone(), var_name) - }).collect(), + }) + .collect(), ); } } diff --git a/juniper/src/validation/rules/overlapping_fields_can_be_merged.rs b/juniper/src/validation/rules/overlapping_fields_can_be_merged.rs index dd9b1286..1600a537 100644 --- a/juniper/src/validation/rules/overlapping_fields_can_be_merged.rs +++ b/juniper/src/validation/rules/overlapping_fields_can_be_merged.rs @@ -515,14 +515,16 @@ impl<'a, S: Debug> OverlappingFieldsCanBeMerged<'a, S> { conflicts .iter() .flat_map(|&Conflict(_, ref fs1, _)| fs1.clone()), - ).collect(), + ) + .collect(), vec![pos2.clone()] .into_iter() .chain( conflicts .iter() .flat_map(|&Conflict(_, _, ref fs2)| fs2.clone()), - ).collect(), + ) + .collect(), )) } @@ -653,9 +655,11 @@ impl<'a, S: Debug> OverlappingFieldsCanBeMerged<'a, S> { Selection::FragmentSpread(Spanning { item: FragmentSpread { ref name, .. }, .. - }) => if fragment_names.iter().find(|n| *n == &name.item).is_none() { - fragment_names.push(name.item); - }, + }) => { + if fragment_names.iter().find(|n| *n == &name.item).is_none() { + fragment_names.push(name.item); + } + } Selection::InlineFragment(Spanning { item: ref inline, .. }) => { @@ -725,7 +729,8 @@ fn format_reason(reason: &ConflictReasonMessage) -> String { name, format_reason(subreason) ) - }).collect::>() + }) + .collect::>() .join(" and "), } } @@ -1004,7 +1009,10 @@ mod tests { } "#, &[RuleError::new( - &error_message("x", &Message("name and barks are different fields".to_owned())), + &error_message( + "x", + &Message("name and barks are different fields".to_owned()), + ), &[ SourcePosition::new(101, 6, 12), SourcePosition::new(163, 9, 12), @@ -1042,21 +1050,30 @@ mod tests { "#, &[ RuleError::new( - &error_message("x", &Message("name and barks are different fields".to_owned())), + &error_message( + "x", + &Message("name and barks are different fields".to_owned()), + ), &[ SourcePosition::new(235, 13, 14), SourcePosition::new(311, 17, 12), ], ), RuleError::new( - &error_message("x", &Message("name and nickname are different fields".to_owned())), + &error_message( + "x", + &Message("name and nickname are different fields".to_owned()), + ), &[ SourcePosition::new(235, 13, 14), SourcePosition::new(374, 20, 12), ], ), RuleError::new( - &error_message("x", &Message("barks and nickname are different fields".to_owned())), + &error_message( + "x", + &Message("barks and nickname are different fields".to_owned()), + ), &[ SourcePosition::new(311, 17, 12), SourcePosition::new(374, 20, 12), @@ -1495,7 +1512,8 @@ mod tests { .interfaces(&[ registry.get_type::(i), registry.get_type::(i), - ]).into_meta() + ]) + .into_meta() } } @@ -1548,7 +1566,8 @@ mod tests { .interfaces(&[ registry.get_type::(i), registry.get_type::(i), - ]).into_meta() + ]) + .into_meta() } } diff --git a/juniper/src/validation/rules/possible_fragment_spreads.rs b/juniper/src/validation/rules/possible_fragment_spreads.rs index a8e614e0..5792b204 100644 --- a/juniper/src/validation/rules/possible_fragment_spreads.rs +++ b/juniper/src/validation/rules/possible_fragment_spreads.rs @@ -21,7 +21,6 @@ impl<'a, S> Visitor<'a, S> for PossibleFragmentSpreads<'a, S> where S: ScalarValue, { - fn enter_document(&mut self, ctx: &mut ValidatorContext<'a, S>, defs: &'a Document) { for def in defs { if let Definition::Fragment(Spanning { ref item, .. }) = *def { diff --git a/juniper/src/validation/rules/provided_non_null_arguments.rs b/juniper/src/validation/rules/provided_non_null_arguments.rs index d11bc1ac..4a918b64 100644 --- a/juniper/src/validation/rules/provided_non_null_arguments.rs +++ b/juniper/src/validation/rules/provided_non_null_arguments.rs @@ -24,13 +24,13 @@ where }) = ctx.parent_type().and_then(|t| t.field_by_name(field_name)) { for meta_arg in meta_args { - if meta_arg.arg_type.is_non_null() && field - .item - .arguments - .as_ref() - .and_then(|args| { - args.item.get(&meta_arg.name) - }).is_none() + if meta_arg.arg_type.is_non_null() + && field + .item + .arguments + .as_ref() + .and_then(|args| args.item.get(&meta_arg.name)) + .is_none() { ctx.report_error( &field_error_message( @@ -58,12 +58,13 @@ where }) = ctx.schema.directive_by_name(directive_name) { for meta_arg in meta_args { - if meta_arg.arg_type.is_non_null() && directive - .item - .arguments - .as_ref() - .and_then(|args| args.item.get(&meta_arg.name)) - .is_none() + if meta_arg.arg_type.is_non_null() + && directive + .item + .arguments + .as_ref() + .and_then(|args| args.item.get(&meta_arg.name)) + .is_none() { ctx.report_error( &directive_error_message( diff --git a/juniper/src/validation/rules/scalar_leafs.rs b/juniper/src/validation/rules/scalar_leafs.rs index e916d29b..6aff06ff 100644 --- a/juniper/src/validation/rules/scalar_leafs.rs +++ b/juniper/src/validation/rules/scalar_leafs.rs @@ -13,12 +13,7 @@ impl<'a, S> Visitor<'a, S> for ScalarLeafs where S: ScalarValue, { - - fn enter_field( - &mut self, - ctx: &mut ValidatorContext<'a, S>, - field: &'a Spanning>, - ) { + fn enter_field(&mut self, ctx: &mut ValidatorContext<'a, S>, field: &'a Spanning>) { let field_name = &field.item.name.item; let error = if let (Some(field_type), Some(field_type_literal)) = diff --git a/juniper/src/validation/rules/unique_argument_names.rs b/juniper/src/validation/rules/unique_argument_names.rs index a5f304a7..8f893f4e 100644 --- a/juniper/src/validation/rules/unique_argument_names.rs +++ b/juniper/src/validation/rules/unique_argument_names.rs @@ -19,20 +19,11 @@ impl<'a, S> Visitor<'a, S> for UniqueArgumentNames<'a> where S: ScalarValue, { - - fn enter_directive( - &mut self, - _: &mut ValidatorContext<'a, S>, - _: &'a Spanning>, - ) { + fn enter_directive(&mut self, _: &mut ValidatorContext<'a, S>, _: &'a Spanning>) { self.known_names = HashMap::new(); } - fn enter_field( - &mut self, - _: &mut ValidatorContext<'a, S>, - _: &'a Spanning>, - ) { + fn enter_field(&mut self, _: &mut ValidatorContext<'a, S>, _: &'a Spanning>) { self.known_names = HashMap::new(); } diff --git a/juniper/src/validation/rules/unique_fragment_names.rs b/juniper/src/validation/rules/unique_fragment_names.rs index 02fcc438..d75b16a5 100644 --- a/juniper/src/validation/rules/unique_fragment_names.rs +++ b/juniper/src/validation/rules/unique_fragment_names.rs @@ -19,7 +19,6 @@ impl<'a, S> Visitor<'a, S> for UniqueFragmentNames<'a> where S: ScalarValue, { - fn enter_fragment_definition( &mut self, context: &mut ValidatorContext<'a, S>, diff --git a/juniper/src/validation/rules/unique_operation_names.rs b/juniper/src/validation/rules/unique_operation_names.rs index 0b86191c..29e218d1 100644 --- a/juniper/src/validation/rules/unique_operation_names.rs +++ b/juniper/src/validation/rules/unique_operation_names.rs @@ -19,7 +19,6 @@ impl<'a, S> Visitor<'a, S> for UniqueOperationNames<'a> where S: ScalarValue, { - fn enter_operation_definition( &mut self, ctx: &mut ValidatorContext<'a, S>, diff --git a/juniper/src/validation/rules/unique_variable_names.rs b/juniper/src/validation/rules/unique_variable_names.rs index 0730ce93..6c6eb574 100644 --- a/juniper/src/validation/rules/unique_variable_names.rs +++ b/juniper/src/validation/rules/unique_variable_names.rs @@ -19,7 +19,6 @@ impl<'a, S> Visitor<'a, S> for UniqueVariableNames<'a> where S: ScalarValue, { - fn enter_operation_definition( &mut self, _: &mut ValidatorContext<'a, S>, diff --git a/juniper/src/validation/test_harness.rs b/juniper/src/validation/test_harness.rs index 73e86b83..b9e9f5f1 100644 --- a/juniper/src/validation/test_harness.rs +++ b/juniper/src/validation/test_harness.rs @@ -156,7 +156,8 @@ where EnumValue::new("HEEL"), EnumValue::new("DOWN"), ], - ).into_meta() + ) + .into_meta() } } @@ -218,7 +219,8 @@ where registry.get_type::(i), registry.get_type::(i), registry.get_type::(i), - ]).into_meta() + ]) + .into_meta() } } @@ -247,7 +249,8 @@ where EnumValue::new("TAN"), EnumValue::new("SPOTTED"), ], - ).into_meta() + ) + .into_meta() } } @@ -377,7 +380,8 @@ where .interfaces(&[ registry.get_type::(i), registry.get_type::(i), - ]).into_meta() + ]) + .into_meta() } } @@ -410,7 +414,8 @@ where .interfaces(&[ registry.get_type::(i), registry.get_type::(i), - ]).into_meta() + ]) + .into_meta() } } @@ -768,6 +773,5 @@ fn print_errors(errs: &[RuleError]) { print!("[{:>3},{:>3},{:>3}] ", p.index(), p.line(), p.column()); } println!("{}", err.message()); - } } diff --git a/juniper/src/validation/visitor.rs b/juniper/src/validation/visitor.rs index 12417473..1fc981d0 100644 --- a/juniper/src/validation/visitor.rs +++ b/juniper/src/validation/visitor.rs @@ -305,23 +305,26 @@ fn visit_input_value<'a, S, V>( enter_input_value(v, ctx, input_value); match input_value.item { - InputValue::Object(ref fields) => for field in fields { - let inner_type = ctx - .current_input_type_literal() - .and_then(|t| match *t { - Type::NonNullNamed(ref name) | Type::Named(ref name) => { - ctx.schema.concrete_type_by_name(name) - } - _ => None, - }).and_then(|ct| ct.input_field_by_name(&field.0.item)) - .map(|f| &f.arg_type); + InputValue::Object(ref fields) => { + for field in fields { + let inner_type = ctx + .current_input_type_literal() + .and_then(|t| match *t { + Type::NonNullNamed(ref name) | Type::Named(ref name) => { + ctx.schema.concrete_type_by_name(name) + } + _ => None, + }) + .and_then(|ct| ct.input_field_by_name(&field.0.item)) + .map(|f| &f.arg_type); - ctx.with_pushed_input_type(inner_type, |ctx| { - v.enter_object_field(ctx, field); - visit_input_value(v, ctx, &field.1); - v.exit_object_field(ctx, field); - }) - }, + ctx.with_pushed_input_type(inner_type, |ctx| { + v.enter_object_field(ctx, field); + visit_input_value(v, ctx, &field.1); + v.exit_object_field(ctx, field); + }) + } + } InputValue::List(ref ls) => { let inner_type = ctx.current_input_type_literal().and_then(|t| match *t { Type::List(ref inner) | Type::NonNullList(ref inner) => { diff --git a/juniper/src/value/mod.rs b/juniper/src/value/mod.rs index 95e72c23..e3e8c155 100644 --- a/juniper/src/value/mod.rs +++ b/juniper/src/value/mod.rs @@ -102,10 +102,7 @@ where } /// View the underlying float value, if present. - #[deprecated( - since = "0.11", - note = "Use `Value::as_scalar_value` instead" - )] + #[deprecated(since = "0.11", note = "Use `Value::as_scalar_value` instead")] pub fn as_float_value(&self) -> Option where for<'a> &'a S: ScalarRefValue<'a>, @@ -146,10 +143,7 @@ where } /// View the underlying string value, if present. - #[deprecated( - since = "0.11", - note = "Use `Value::as_scalar_value` instead" - )] + #[deprecated(since = "0.11", note = "Use `Value::as_scalar_value` instead")] pub fn as_string_value<'a>(&'a self) -> Option<&'a str> where Option<&'a String>: From<&'a S>, @@ -175,7 +169,8 @@ impl ToInputValue for Value { Spanning::unlocated(k.clone()), Spanning::unlocated(v.to_input_value()), ) - }).collect(), + }) + .collect(), ), } } diff --git a/juniper/src/value/scalar.rs b/juniper/src/value/scalar.rs index 2f61fee3..2604859f 100644 --- a/juniper/src/value/scalar.rs +++ b/juniper/src/value/scalar.rs @@ -246,7 +246,8 @@ where + Into> + Into> + Into>, -{} +{ +} /// The default scalar value representation in juniper /// diff --git a/juniper_codegen/src/derive_enum.rs b/juniper_codegen/src/derive_enum.rs index bfc8c832..be526e3e 100644 --- a/juniper_codegen/src/derive_enum.rs +++ b/juniper_codegen/src/derive_enum.rs @@ -1,4 +1,4 @@ -use proc_macro2::{TokenStream}; +use proc_macro2::TokenStream; use syn; use syn::{Data, DeriveInput, Fields, Variant}; @@ -139,8 +139,8 @@ pub fn impl_enum(ast: &syn::DeriveInput, is_internal: bool) -> TokenStream { let name = attrs.name.unwrap_or(ast.ident.to_string()); let meta_description = match attrs.description { - Some(descr) => quote!{ let meta = meta.description(#descr); }, - None => quote!{ let meta = meta; }, + Some(descr) => quote! { let meta = meta.description(#descr); }, + None => quote! { let meta = meta; }, }; let mut values = TokenStream::new(); @@ -167,21 +167,21 @@ pub fn impl_enum(ast: &syn::DeriveInput, is_internal: bool) -> TokenStream { .name .unwrap_or(::util::to_upper_snake_case(&variant.ident.to_string())); let descr = match var_attrs.description { - Some(s) => quote!{ Some(#s.to_string()) }, - None => quote!{ None }, + Some(s) => quote! { Some(#s.to_string()) }, + None => quote! { None }, }; let depr = match var_attrs.deprecation { - Some(DeprecationAttr { reason: Some(s) }) => quote!{ + Some(DeprecationAttr { reason: Some(s) }) => quote! { #juniper_path::meta::DeprecationStatus::Deprecated(Some(#s.to_string())) }, - Some(DeprecationAttr { reason: None }) => quote!{ + Some(DeprecationAttr { reason: None }) => quote! { #juniper_path::meta::DeprecationStatus::Deprecated(None) }, - None => quote!{ + None => quote! { #juniper_path::meta::DeprecationStatus::Current }, }; - values.extend(quote!{ + values.extend(quote! { #juniper_path::meta::EnumValue{ name: #name.to_string(), description: #descr, @@ -190,17 +190,17 @@ pub fn impl_enum(ast: &syn::DeriveInput, is_internal: bool) -> TokenStream { }); // Build resolve match clause. - resolves.extend(quote!{ + resolves.extend(quote! { &#ident::#var_ident => #juniper_path::Value::scalar(String::from(#name)), }); // Build from_input clause. - from_inputs.extend(quote!{ + from_inputs.extend(quote! { Some(#name) => Some(#ident::#var_ident), }); // Build to_input clause. - to_inputs.extend(quote!{ + to_inputs.extend(quote! { &#ident::#var_ident => #juniper_path::InputValue::scalar(#name.to_string()), }); diff --git a/juniper_codegen/src/derive_input_object.rs b/juniper_codegen/src/derive_input_object.rs index 342368e7..2568dbba 100644 --- a/juniper_codegen/src/derive_input_object.rs +++ b/juniper_codegen/src/derive_input_object.rs @@ -149,8 +149,8 @@ pub fn impl_input_object(ast: &syn::DeriveInput, is_internal: bool) -> TokenStre let generics = &ast.generics; let meta_description = match attrs.description { - Some(descr) => quote!{ let meta = meta.description(#descr); }, - None => quote!{ let meta = meta; }, + Some(descr) => quote! { let meta = meta.description(#descr); }, + None => quote! { let meta = meta; }, }; let mut meta_fields = TokenStream::new(); @@ -174,8 +174,8 @@ pub fn impl_input_object(ast: &syn::DeriveInput, is_internal: bool) -> TokenStre } }; let field_description = match field_attrs.description { - Some(s) => quote!{ let field = field.description(#s); }, - None => quote!{}, + Some(s) => quote! { let field = field.description(#s); }, + None => quote! {}, }; let default = { @@ -205,17 +205,17 @@ pub fn impl_input_object(ast: &syn::DeriveInput, is_internal: bool) -> TokenStre let create_meta_field = match default { Some(ref def) => { - quote!{ + quote! { let field = registry.arg_with_default::<#field_ty>( #name, &#def, &()); } } None => { - quote!{ + quote! { let field = registry.arg::<#field_ty>(#name, &()); } } }; - meta_fields.extend(quote!{ + meta_fields.extend(quote! { { #create_meta_field #field_description @@ -227,11 +227,11 @@ pub fn impl_input_object(ast: &syn::DeriveInput, is_internal: bool) -> TokenStre let from_input_default = match default { Some(ref def) => { - quote!{ + quote! { Some(&&#juniper_path::InputValue::Null) | None if true => #def, } } - None => quote!{}, + None => quote! {}, }; from_inputs.extend(quote!{ @@ -249,7 +249,7 @@ pub fn impl_input_object(ast: &syn::DeriveInput, is_internal: bool) -> TokenStre }); // Build to_input clause. - to_inputs.extend(quote!{ + to_inputs.extend(quote! { (#name, self.#field_ident.to_input_value()), }); } @@ -332,5 +332,5 @@ pub fn impl_input_object(ast: &syn::DeriveInput, is_internal: bool) -> TokenStre } }; - body + body } diff --git a/juniper_codegen/src/derive_object.rs b/juniper_codegen/src/derive_object.rs index 1d83a952..1bf5f24c 100644 --- a/juniper_codegen/src/derive_object.rs +++ b/juniper_codegen/src/derive_object.rs @@ -147,8 +147,8 @@ pub fn impl_object(ast: &syn::DeriveInput) -> TokenStream { let attrs = ObjAttrs::from_input(ast); let name = attrs.name.unwrap_or(ast.ident.to_string()); let build_description = match attrs.description { - Some(s) => quote!{ builder.description(#s) }, - None => quote!{ builder }, + Some(s) => quote! { builder.description(#s) }, + None => quote! { builder }, }; let mut meta_fields = TokenStream::new(); @@ -176,17 +176,17 @@ pub fn impl_object(ast: &syn::DeriveInput) -> TokenStream { } }; let build_description = match field_attrs.description { - Some(s) => quote!{ field.description(#s) }, - None => quote!{ field }, + Some(s) => quote! { field.description(#s) }, + None => quote! { field }, }; let build_deprecation = match field_attrs.deprecation { - Some(DeprecationAttr { reason: Some(s) }) => quote!{ field.deprecated(Some(#s)) }, - Some(DeprecationAttr { reason: None }) => quote!{ field.deprecated(None) }, - None => quote!{ field }, + Some(DeprecationAttr { reason: Some(s) }) => quote! { field.deprecated(Some(#s)) }, + Some(DeprecationAttr { reason: None }) => quote! { field.deprecated(None) }, + None => quote! { field }, }; - meta_fields.extend(quote!{ + meta_fields.extend(quote! { { let field = registry.field::<#field_ty>(#name, &()); let field = #build_description; @@ -197,7 +197,7 @@ pub fn impl_object(ast: &syn::DeriveInput) -> TokenStream { // Build from_input clause. - resolvers.extend(quote!{ + resolvers.extend(quote! { #name => executor.resolve_with_ctx(&(), &self.#field_ident), }); } diff --git a/juniper_codegen/src/derive_scalar_value.rs b/juniper_codegen/src/derive_scalar_value.rs index 75b06e4c..7ac44e4c 100644 --- a/juniper_codegen/src/derive_scalar_value.rs +++ b/juniper_codegen/src/derive_scalar_value.rs @@ -1,4 +1,4 @@ -use proc_macro2::{TokenStream}; +use proc_macro2::TokenStream; use syn::{self, Data, Fields, Ident, Variant}; @@ -22,7 +22,7 @@ pub fn impl_scalar_value(ast: &syn::DeriveInput, is_internal: bool) -> TokenStre let display = derive_display(variants.iter(), ident); - quote!{ + quote! { #(#froms)* #serialize @@ -39,7 +39,7 @@ where quote!(#ident::#variant(ref v) => write!(f, "{}", v),) }); - quote!{ + quote! { impl std::fmt::Display for #ident { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { match *self { @@ -65,7 +65,7 @@ where quote!(juniper::serde) }; - quote!{ + quote! { impl #serde_path::Serialize for #ident { fn serialize(&self, serializer: S) -> std::result::Result where S: #serde_path::Serializer @@ -91,7 +91,7 @@ fn derive_from_variant(variant: &Variant, ident: &Ident) -> Result for #ident { fn from(t: #ty) -> Self { #ident::#variant(t) diff --git a/juniper_codegen/src/util.rs b/juniper_codegen/src/util.rs index ebbf0379..12e9175d 100644 --- a/juniper_codegen/src/util.rs +++ b/juniper_codegen/src/util.rs @@ -34,14 +34,14 @@ pub fn get_deprecated(attrs: &Vec) -> Option { fn get_deprecated_meta_list(list: &MetaList) -> DeprecationAttr { for meta in &list.nested { match meta { - &NestedMeta::Meta(Meta::NameValue(ref nv)) if nv.ident == "note" => { - match &nv.lit { - &Lit::Str(ref strlit) => { - return DeprecationAttr { reason: Some(strlit.value().to_string()) }; - } - _ => panic!("deprecated attribute note value only has string literal"), + &NestedMeta::Meta(Meta::NameValue(ref nv)) if nv.ident == "note" => match &nv.lit { + &Lit::Str(ref strlit) => { + return DeprecationAttr { + reason: Some(strlit.value().to_string()), + }; } - } + _ => panic!("deprecated attribute note value only has string literal"), + }, _ => {} } } @@ -60,7 +60,8 @@ pub fn get_doc_comment(attrs: &Vec) -> Option { // Concatenates doc strings into one string. fn join_doc_strings(docs: &Vec) -> String { - let s: String = docs.iter() + let s: String = docs + .iter() // Trim any extra spaces. .map(|x| x.trim().to_string()) // Convert empty comments to newlines. @@ -118,7 +119,11 @@ pub fn get_graphql_attr(attrs: &Vec) -> Option> { None } -pub fn keyed_item_value(item: &NestedMeta, name: &str, validation: AttributeValidation) -> Option { +pub fn keyed_item_value( + item: &NestedMeta, + name: &str, + validation: AttributeValidation, +) -> Option { match item { // Attributes in the form of `#[graphql(name = "value")]`. &NestedMeta::Meta(Meta::NameValue(ref nameval)) if nameval.ident == name => { @@ -130,23 +135,21 @@ pub fn keyed_item_value(item: &NestedMeta, name: &str, validation: AttributeVali "Invalid format for attribute \"{:?}\": expected a bare attribute without a value", item )); - }, + } _ => Some(AttributeValue::String(strlit.value())), }, - _ => None, + _ => None, } - }, + } // Attributes in the form of `#[graphql(name)]`. - &NestedMeta::Meta(Meta::Word(ref ident)) if ident.to_string() == name => { - match validation { - AttributeValidation::String => { - panic!(format!( + &NestedMeta::Meta(Meta::Word(ref ident)) if ident.to_string() == name => match validation { + AttributeValidation::String => { + panic!(format!( "Invalid format for attribute \"{:?}\": expected a string value", - item - )); - }, - _ => Some(AttributeValue::Bare), + item + )); } + _ => Some(AttributeValue::Bare), }, _ => None, } @@ -161,7 +164,8 @@ pub fn to_camel_case(s: &str) -> String { if i > 0 && part.len() == 1 { dest.push_str(&part.to_uppercase()); } else if i > 0 && part.len() > 1 { - let first = part.chars() + let first = part + .chars() .next() .unwrap() .to_uppercase() diff --git a/juniper_hyper/src/lib.rs b/juniper_hyper/src/lib.rs index 03fd16d0..700a9c92 100644 --- a/juniper_hyper/src/lib.rs +++ b/juniper_hyper/src/lib.rs @@ -50,11 +50,13 @@ where .unwrap_or(Err(GraphQLRequestError::Invalid( "'query' parameter is missing".to_string(), ))), - ).and_then(move |gql_req| { + ) + .and_then(move |gql_req| { execute_request(root_node, context, gql_req).map_err(|_| { unreachable!("thread pool has shut down?!"); }) - }).or_else(|err| future::ok(render_error(err))), + }) + .or_else(|err| future::ok(render_error(err))), )), &Method::POST => Either::A(Either::B( request @@ -70,11 +72,13 @@ where .map_err(GraphQLRequestError::BodyJSONError) }) }) - }).and_then(move |gql_req| { + }) + .and_then(move |gql_req| { execute_request(root_node, context, gql_req).map_err(|_| { unreachable!("thread pool has shut down?!"); }) - }).or_else(|err| future::ok(render_error(err))), + }) + .or_else(|err| future::ok(render_error(err))), )), _ => return Either::B(future::ok(new_response(StatusCode::METHOD_NOT_ALLOWED))), } @@ -239,7 +243,8 @@ where let body = serde_json::to_string_pretty(&res).unwrap(); Ok(Async::Ready((is_ok, body))) }) - })).map(|results| { + })) + .map(|results| { let is_ok = results.iter().all(|&(is_ok, _)| is_ok); // concatenate json bodies as array // TODO: maybe use Body chunks instead? diff --git a/juniper_iron/src/lib.rs b/juniper_iron/src/lib.rs index 3b0e185b..9bff5a3b 100644 --- a/juniper_iron/src/lib.rs +++ b/juniper_iron/src/lib.rs @@ -488,7 +488,8 @@ mod tests { .get_raw("content-type") .expect("No content type header from handler")[0] .clone(), - ).expect("Content-type header invalid UTF-8"); + ) + .expect("Content-type header invalid UTF-8"); let body = response::extract_body_to_string(response); http_tests::TestResponse { diff --git a/juniper_rocket/examples/rocket_server.rs b/juniper_rocket/examples/rocket_server.rs index ef9c7010..05e88287 100644 --- a/juniper_rocket/examples/rocket_server.rs +++ b/juniper_rocket/examples/rocket_server.rs @@ -2,7 +2,8 @@ extern crate juniper; extern crate juniper_rocket; -#[macro_use] extern crate rocket; +#[macro_use] +extern crate rocket; use rocket::response::content; use rocket::State; diff --git a/juniper_rocket/src/lib.rs b/juniper_rocket/src/lib.rs index 9c624a51..ca5a7f69 100644 --- a/juniper_rocket/src/lib.rs +++ b/juniper_rocket/src/lib.rs @@ -300,7 +300,8 @@ where } impl<'v, S> FromFormValue<'v> for GraphQLRequest - where S: ScalarValue +where + S: ScalarValue, { type Error = String; @@ -459,12 +460,12 @@ mod fromform_tests { #[cfg(test)] mod tests { - use rocket::{self, get, post, routes}; - use rocket::request::Form; use rocket::http::ContentType; use rocket::local::{Client, LocalRequest}; + use rocket::request::Form; use rocket::Rocket; use rocket::State; + use rocket::{self, get, post, routes}; use juniper::http::tests as http_tests; use juniper::tests::model::Database; @@ -522,7 +523,8 @@ mod tests { .manage(Schema::new( Database::new(), EmptyMutation::::new(), - )).mount("/", routes![post_graphql_handler, get_graphql_handler]) + )) + .mount("/", routes![post_graphql_handler, get_graphql_handler]) } fn make_test_response(request: &LocalRequest) -> http_tests::TestResponse { diff --git a/juniper_warp/examples/warp_server.rs b/juniper_warp/examples/warp_server.rs index b097a763..f997be7a 100644 --- a/juniper_warp/examples/warp_server.rs +++ b/juniper_warp/examples/warp_server.rs @@ -43,5 +43,6 @@ fn main() { .or(homepage) .or(warp::path("graphql").and(graphql_filter)) .with(log), - ).run(([127, 0, 0, 1], 8080)); + ) + .run(([127, 0, 0, 1], 8080)); } diff --git a/juniper_warp/src/lib.rs b/juniper_warp/src/lib.rs index df6bee90..705c5a22 100644 --- a/juniper_warp/src/lib.rs +++ b/juniper_warp/src/lib.rs @@ -201,7 +201,8 @@ where let response = request.execute(&schema, &context); Ok((serde_json::to_vec(&response)?, response.is_ok())) }) - }).and_then(|result| ::futures::future::done(Ok(build_response(result)))) + }) + .and_then(|result| ::futures::future::done(Ok(build_response(result)))) .map_err(|e: tokio_threadpool::BlockingError| warp::reject::custom(e)), ) }; @@ -234,7 +235,8 @@ where let response = graphql_request.execute(&schema, &context); Ok((serde_json::to_vec(&response)?, response.is_ok())) }) - }).and_then(|result| ::futures::future::done(Ok(build_response(result)))) + }) + .and_then(|result| ::futures::future::done(Ok(build_response(result)))) .map_err(|e: tokio_threadpool::BlockingError| warp::reject::custom(e)), ) }; @@ -396,7 +398,8 @@ mod tests { { "variables": null, "query": "{ hero(episode: NEW_HOPE) { name } }" }, { "variables": null, "query": "{ hero(episode: EMPIRE) { id name } }" } ]"##, - ).reply(&filter); + ) + .reply(&filter); assert_eq!(response.status(), http::StatusCode::OK); assert_eq!(