From 2cb3c761424312e3a898f53f511f34c9e7a3587b Mon Sep 17 00:00:00 2001 From: tyranron Date: Fri, 15 Oct 2021 17:50:52 +0300 Subject: [PATCH 01/22] Bootstrap macro --- .../src/codegen/derive_input_object.rs | 12 ++-- .../juniper_tests/src/custom_scalar.rs | 18 +++--- .../juniper_tests/src/explicit_null.rs | 30 ++++----- juniper/src/ast.rs | 61 +++++++++++++++---- juniper/src/executor/mod.rs | 25 ++++++++ juniper/src/value/mod.rs | 22 +++---- 6 files changed, 106 insertions(+), 62 deletions(-) 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 9b4c72909..e84eed13b 100644 --- a/integration_tests/juniper_tests/src/codegen/derive_input_object.rs +++ b/integration_tests/juniper_tests/src/codegen/derive_input_object.rs @@ -1,6 +1,6 @@ use fnv::FnvHashMap; use juniper::{ - marker, DefaultScalarValue, FromInputValue, GraphQLInputObject, GraphQLType, GraphQLValue, + graphql_input_value, marker, DefaultScalarValue, FromInputValue, GraphQLInputObject, GraphQLType, GraphQLValue, InputValue, Registry, ToInputValue, }; @@ -119,19 +119,17 @@ fn test_derived_input_object() { // Test default value injection. - let input_no_defaults: InputValue = ::serde_json::from_value(serde_json::json!({ + let input_no_defaults = graphql_input_value!({ "regularField": "a", - })) - .unwrap(); - - let output_no_defaults: Input = FromInputValue::from_input_value(&input_no_defaults).unwrap(); + }); + let output_no_defaults = Input::from_input_value(&input_no_defaults).unwrap(); assert_eq!( output_no_defaults, Input { regular_field: "a".into(), c: 33, other: None, - } + }, ); // Test with all values supplied. diff --git a/integration_tests/juniper_tests/src/custom_scalar.rs b/integration_tests/juniper_tests/src/custom_scalar.rs index 9ba6cf77b..ebacc08a9 100644 --- a/integration_tests/juniper_tests/src/custom_scalar.rs +++ b/integration_tests/juniper_tests/src/custom_scalar.rs @@ -2,8 +2,8 @@ use std::{convert::TryInto as _, fmt, pin::Pin}; use futures::{stream, Stream}; use juniper::{ - execute, graphql_object, graphql_scalar, graphql_subscription, - parser::{ParseError, ScalarToken, Spanning, Token}, + execute, graphql_input_value, graphql_object, graphql_scalar, graphql_subscription, + parser::{ParseError, ScalarToken, Token}, serde::{de, Deserialize, Deserializer, Serialize}, EmptyMutation, FieldResult, GraphQLScalarValue, InputValue, Object, ParseScalarResult, RootNode, ScalarValue, Value, Variables, @@ -235,7 +235,7 @@ async fn querying_long_variable() { "query q($test: Long!){ longWithArg(longArg: $test) }", vec![( "test".to_owned(), - InputValue::Scalar(MyScalarValue::Long(i64::from(i32::MAX) + 42)), + graphql_input_value!(MyScalarValue::Long(i64::from(i32::MAX) + 42)), )] .into_iter() .collect(), @@ -253,14 +253,10 @@ async fn querying_long_variable() { fn deserialize_variable() { let json = format!("{{\"field\": {}}}", i64::from(i32::MAX) + 42); - let input_value: InputValue = serde_json::from_str(&json).unwrap(); assert_eq!( - input_value, - InputValue::Object(vec![( - Spanning::unlocated("field".into()), - Spanning::unlocated(InputValue::Scalar(MyScalarValue::Long( - i64::from(i32::MAX) + 42 - ))) - )]) + serde_json::from_str::>(&json).unwrap(), + graphql_input_value!({ + "field": MyScalarValue::Long(i64::from(i32::MAX) + 42), + }), ); } diff --git a/integration_tests/juniper_tests/src/explicit_null.rs b/integration_tests/juniper_tests/src/explicit_null.rs index 0349f2621..2bc02f9c7 100644 --- a/integration_tests/juniper_tests/src/explicit_null.rs +++ b/integration_tests/juniper_tests/src/explicit_null.rs @@ -1,6 +1,6 @@ use juniper::{ - graphql_object, graphql_value, EmptyMutation, EmptySubscription, GraphQLInputObject, - InputValue, Nullable, + graphql_object, graphql_value, graphql_vars, EmptyMutation, EmptySubscription, + GraphQLInputObject, InputValue, Nullable, }; pub struct Context; @@ -47,23 +47,15 @@ async fn explicit_null() { EmptyMutation::::new(), EmptySubscription::::new(), ); - let vars = [ - ("emptyObj".to_string(), InputValue::Object(vec![])), - ( - "literalNullObj".to_string(), - InputValue::object(vec![("field", InputValue::null())].into_iter().collect()), - ), - ]; - let (data, errors) = juniper::execute( - query, - None, - &schema, - &vars.iter().cloned().collect(), - &Context, - ) - .await - .unwrap(); + let vars = graphql_vars!({ + "emptyObj": [], + "literalNullObj": {"field": None}, + }); + + let (data, errors) = juniper::execute(query, None, &schema, &vars, &Context) + .await + .unwrap(); assert_eq!(errors.len(), 0); assert_eq!( @@ -77,6 +69,6 @@ async fn explicit_null() { "noFieldIsExplicitNull": false, "emptyVariableObjectFieldIsExplicitNull": false, "literalNullVariableObjectFieldIsExplicitNull": true, - }) + }), ); } diff --git a/juniper/src/ast.rs b/juniper/src/ast.rs index 3ad050240..7a49bef35 100644 --- a/juniper/src/ast.rs +++ b/juniper/src/ast.rs @@ -34,7 +34,7 @@ pub enum Type<'a> { /// /// Lists and objects variants are _spanned_, i.e. they contain a reference to /// their position in the source file, if available. -#[derive(Debug, Clone, PartialEq)] +#[derive(Clone, Debug, PartialEq)] #[allow(missing_docs)] pub enum InputValue { Null, @@ -204,12 +204,12 @@ impl<'a> Type<'a> { } impl<'a> fmt::Display for Type<'a> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - match *self { - Type::Named(ref n) => write!(f, "{}", n), - Type::NonNullNamed(ref n) => write!(f, "{}!", n), - Type::List(ref t, _) => write!(f, "[{}]", t), - Type::NonNullList(ref t, _) => write!(f, "[{}]!", t), + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + Self::Named(n) => write!(f, "{}", n), + Self::NonNullNamed(n) => write!(f, "{}!", n), + Self::List(t, _) => write!(f, "[{}]", t), + Self::NonNullList(t, _) => write!(f, "[{}]!", t), } } } @@ -435,7 +435,7 @@ impl InputValue { } impl fmt::Display for InputValue { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { Self::Null => write!(f, "null"), Self::Scalar(s) => { @@ -449,33 +449,68 @@ impl fmt::Display for InputValue { Self::Variable(v) => write!(f, "${}", v), Self::List(v) => { write!(f, "[")?; - for (i, spanning) in v.iter().enumerate() { spanning.item.fmt(f)?; if i < v.len() - 1 { write!(f, ", ")?; } } - write!(f, "]") } Self::Object(o) => { write!(f, "{{")?; - - for (i, &(ref k, ref v)) in o.iter().enumerate() { + for (i, (k, v)) in o.iter().enumerate() { write!(f, "{}: ", k.item)?; v.item.fmt(f)?; if i < o.len() - 1 { write!(f, ", ")?; } } - write!(f, "}}") } } } } +/// Construct JSON-like [`InputValue`]s by using JSON syntax. +/// +/// __Note:__ [`InputValue::List`]s and [`InputValue::Object`]s will be created +/// in a [`Spanning::unlocated`]. +/// +/// # Example +/// +/// The resulting JSON will look just like what you passed in. +/// ```rust +/// # use juniper::{graphql_input_value, DefaultScalarValue, InputValue}; +/// # type V = InputValue; +/// # +/// # let _: V = +/// graphql_input_value!(None); +/// # let _: V = +/// graphql_input_value!(1234); +/// # let _: V = +/// graphql_input_value!("test"); +/// # let _: V = +/// graphql_input_value!([1234, "test", true]); +/// # let _: V = +/// graphql_input_value!({"key": "value", "foo": 1234}); +/// ``` +#[macro_export] +macro_rules! graphql_input_value { + ([ $($arg:tt),* $(,)* ]) => { + $crate::InputValue::list(vec![ + $( $crate::graphql_input_value!($arg), )* + ]) + }; + ({ $($key:tt : $val:expr ),* $(,)* }) => { + $crate::InputValue::object(::std::array::IntoIter::new([ + $( ($key, $crate::graphql_input_value!($val)), )* + ]).collect()) + }; + (None) => ($crate::InputValue::Null); + ($e:expr) => ($crate::InputValue::scalar($e)) +} + impl<'a, S> Arguments<'a, S> { pub fn into_iter(self) -> vec::IntoIter<(Spanning<&'a str>, Spanning>)> { self.items.into_iter() diff --git a/juniper/src/executor/mod.rs b/juniper/src/executor/mod.rs index c27cd843e..429e5f311 100644 --- a/juniper/src/executor/mod.rs +++ b/juniper/src/executor/mod.rs @@ -246,6 +246,31 @@ pub type ValuesStream<'a, S = DefaultScalarValue> = /// The map of variables used for substitution during query execution pub type Variables = HashMap>; +/// Construct JSON-like [`Variables`] by using JSON syntax. +/// +/// __Note:__ [`InputValue::List`]s and [`InputValue::Object`]s will be created +/// in a [`Spanning::unlocated`]. +/// +/// # Example +/// +/// The resulting JSON will look just like what you passed in. +/// ```rust +/// # use juniper::{graphql_vars, DefaultScalarValue, Variables}; +/// # type V = Variables; +/// # +/// # let _: V = +/// graphql_vars!({"key": "value", "foo": 1234}); +/// ``` +#[macro_export] +macro_rules! graphql_vars { + ({ $($key:tt : $val:expr ),* $(,)* }) => { + ::std::array::IntoIter::new([ + $( ($key.to_string(), $crate::graphql_input_value!($val)), )* + ]) + .collect::<$crate::Variables>() + } +} + /// Custom error handling trait to enable Error types other than `FieldError` to be specified /// as return value. /// diff --git a/juniper/src/value/mod.rs b/juniper/src/value/mod.rs index ce37ad001..1817aa2ed 100644 --- a/juniper/src/value/mod.rs +++ b/juniper/src/value/mod.rs @@ -276,18 +276,17 @@ impl> From for Value { } } -/// Construct JSON-like values by using JSON syntax +/// Construct JSON-like [`Value`]s by using JSON syntax. /// -/// This macro can be used to create `Value` instances using a JSON syntax. -/// Value objects are used mostly when creating custom errors from fields. +/// [`Value`] objects are used mostly when creating custom errors from fields. /// -/// Here are some examples; the resulting JSON will look just like what you -/// passed in. +/// # Example +/// +/// Resulting JSON will look just like what you passed in. /// ```rust -/// # use juniper::{Value, DefaultScalarValue, graphql_value}; +/// # use juniper::{graphql_value, DefaultScalarValue, Value}; /// # type V = Value; /// # -/// # fn main() { /// # let _: V = /// graphql_value!(None); /// # let _: V = @@ -295,21 +294,20 @@ impl> From for Value { /// # let _: V = /// graphql_value!("test"); /// # let _: V = -/// graphql_value!([ 1234, "test", true ]); +/// graphql_value!([1234, "test", true]); /// # let _: V = -/// graphql_value!({ "key": "value", "foo": 1234 }); -/// # } +/// graphql_value!({"key": "value", "foo": 1234}); /// ``` #[macro_export] macro_rules! graphql_value { ([ $($arg:tt),* $(,)* ]) => { $crate::Value::list(vec![ - $( graphql_value!($arg), )* + $( $crate::graphql_value!($arg), )* ]) }; ({ $($key:tt : $val:tt ),* $(,)* }) => { $crate::Value::object(vec![ - $( ($key, graphql_value!($val)), )* + $( ($key, $crate::graphql_value!($val)), )* ].into_iter().collect()) }; (None) => ($crate::Value::null()); From b20924fbc3af7d47e79bf64012f145351bc93231 Mon Sep 17 00:00:00 2001 From: ilslv Date: Tue, 23 Nov 2021 14:21:39 +0300 Subject: [PATCH 02/22] Replace all `None` with `null` in graphql_value! macro usage --- .../juniper_tests/src/codegen/impl_scalar.rs | 8 +- .../src/codegen/interface_attr.rs | 36 +- .../juniper_tests/src/codegen/object_attr.rs | 40 +- .../src/codegen/object_derive.rs | 14 +- .../src/codegen/subscription_attr.rs | 30 +- .../juniper_tests/src/codegen/union_attr.rs | 2 +- .../juniper_tests/src/codegen/union_derive.rs | 4 +- juniper/src/executor_tests/executor.rs | 54 +- .../src/executor_tests/introspection/enums.rs | 50 +- .../introspection/input_object.rs | 42 +- .../src/executor_tests/introspection/mod.rs | 70 +- juniper/src/tests/query_tests.rs | 2 +- juniper/src/tests/schema_introspection.rs | 1138 ++++++++--------- juniper/src/value/mod.rs | 20 +- juniper_graphql_ws/src/lib.rs | 4 +- juniper_graphql_ws/src/server_message.rs | 2 +- juniper_subscriptions/src/lib.rs | 10 +- 17 files changed, 767 insertions(+), 759 deletions(-) diff --git a/integration_tests/juniper_tests/src/codegen/impl_scalar.rs b/integration_tests/juniper_tests/src/codegen/impl_scalar.rs index 420598172..2cffdb5d1 100644 --- a/integration_tests/juniper_tests/src/codegen/impl_scalar.rs +++ b/integration_tests/juniper_tests/src/codegen/impl_scalar.rs @@ -226,7 +226,7 @@ async fn default_name_introspection() { ); assert_eq!( type_info.get_field_value("description"), - Some(&graphql_value!(None)), + Some(&graphql_value!(null)), ); }) .await; @@ -250,7 +250,7 @@ async fn other_order_introspection() { ); assert_eq!( type_info.get_field_value("description"), - Some(&graphql_value!(None)), + Some(&graphql_value!(null)), ); }) .await; @@ -274,7 +274,7 @@ async fn named_introspection() { ); assert_eq!( type_info.get_field_value("description"), - Some(&graphql_value!(None)), + Some(&graphql_value!(null)), ); }) .await; @@ -324,7 +324,7 @@ async fn generated_scalar_introspection() { ); assert_eq!( type_info.get_field_value("description"), - Some(&graphql_value!(None)), + Some(&graphql_value!(null)), ); }) .await; diff --git a/integration_tests/juniper_tests/src/codegen/interface_attr.rs b/integration_tests/juniper_tests/src/codegen/interface_attr.rs index 54d2e6e12..c4bc4c8e5 100644 --- a/integration_tests/juniper_tests/src/codegen/interface_attr.rs +++ b/integration_tests/juniper_tests/src/codegen/interface_attr.rs @@ -116,7 +116,7 @@ mod no_implers { assert_eq!( execute(&doc, None, &schema, &Variables::new(), &()).await, - Ok((graphql_value!({"__type": {"description": None}}), vec![])), + Ok((graphql_value!({"__type": {"description": null}}), vec![])), ); } } @@ -463,7 +463,7 @@ mod trivial { assert_eq!( execute(&doc, None, &schema, &Variables::new(), &()).await, - Ok((graphql_value!({"__type": {"description": None}}), vec![])), + Ok((graphql_value!({"__type": {"description": null}}), vec![])), ); } } @@ -639,7 +639,7 @@ mod explicit_alias { assert_eq!( execute(DOC, None, &schema, &Variables::new(), &()).await, - Ok((graphql_value!({"__type": {"description": None}}), vec![])), + Ok((graphql_value!({"__type": {"description": null}}), vec![])), ); } } @@ -985,7 +985,7 @@ mod trivial_async { assert_eq!( execute(&doc, None, &schema, &Variables::new(), &()).await, - Ok((graphql_value!({"__type": {"description": None}}), vec![])), + Ok((graphql_value!({"__type": {"description": null}}), vec![])), ); } } @@ -2466,8 +2466,8 @@ mod argument { execute(&doc, None, &schema, &Variables::new(), &()).await, Ok(( graphql_value!({"__type": {"fields": [ - {"args": [{"description": None}]}, - {"args": [{"description": None}, {"description": None}]}, + {"args": [{"description": null}]}, + {"args": [{"description": null}, {"description": null}]}, ]}}), vec![], )), @@ -2497,8 +2497,8 @@ mod argument { execute(&doc, None, &schema, &Variables::new(), &()).await, Ok(( graphql_value!({"__type": {"fields": [ - {"args": [{"defaultValue": None}]}, - {"args": [{"defaultValue": None}, {"defaultValue": None}]}, + {"args": [{"defaultValue": null}]}, + {"args": [{"defaultValue": null}, {"defaultValue": null}]}, ]}}), vec![], )), @@ -2627,21 +2627,21 @@ mod default_argument { "args": [{ "name": "first", "defaultValue": r#""""#, - "type": {"name": "String", "ofType": None}, + "type": {"name": "String", "ofType": null}, }, { "name": "second", "defaultValue": r#""second""#, - "type": {"name": "String", "ofType": None}, + "type": {"name": "String", "ofType": null}, }, { "name": "third", "defaultValue": r#""t""#, - "type": {"name": "String", "ofType": None}, + "type": {"name": "String", "ofType": null}, }], }, { "args": [{ "name": "coord", "defaultValue": "{x: 1}", - "type": {"name": "Point", "ofType": None}, + "type": {"name": "Point", "ofType": null}, }], }]}}), vec![], @@ -2835,8 +2835,8 @@ mod deprecation_from_attr { execute(DOC, None, &schema, &Variables::new(), &()).await, Ok(( graphql_value!({"__type": {"fields": [ - {"name": "id", "deprecationReason": None}, - {"name": "a", "deprecationReason": None}, + {"name": "id", "deprecationReason": null}, + {"name": "a", "deprecationReason": null}, {"name": "b", "deprecationReason": "Use `id`."}, ]}}), vec![], @@ -2975,11 +2975,11 @@ mod explicit_name_description_and_deprecation { "args": [{"description": "My argument."}], }, { "name": "a", - "description": None, + "description": null, "args": [], }, { "name": "b", - "description": None, + "description": null, "args": [], }], }}), @@ -3013,11 +3013,11 @@ mod explicit_name_description_and_deprecation { }, { "name": "a", "isDeprecated": true, - "deprecationReason": None, + "deprecationReason": null, }, { "name": "b", "isDeprecated": false, - "deprecationReason": None, + "deprecationReason": null, }], }}), vec![], diff --git a/integration_tests/juniper_tests/src/codegen/object_attr.rs b/integration_tests/juniper_tests/src/codegen/object_attr.rs index 797a87fc8..c896523d0 100644 --- a/integration_tests/juniper_tests/src/codegen/object_attr.rs +++ b/integration_tests/juniper_tests/src/codegen/object_attr.rs @@ -112,7 +112,7 @@ mod trivial { assert_eq!( execute(DOC, None, &schema, &Variables::new(), &()).await, - Ok((graphql_value!({"__type": {"description": None}}), vec![])), + Ok((graphql_value!({"__type": {"description": null}}), vec![])), ); } } @@ -200,7 +200,7 @@ mod trivial_async { assert_eq!( execute(DOC, None, &schema, &Variables::new(), &()).await, - Ok((graphql_value!({"__type": {"description": None}}), vec![])), + Ok((graphql_value!({"__type": {"description": null}}), vec![])), ); } } @@ -996,8 +996,8 @@ mod argument { execute(DOC, None, &schema, &Variables::new(), &()).await, Ok(( graphql_value!({"__type": {"fields": [ - {"args": [{"description": None}]}, - {"args": [{"description": None}, {"description": None}]}, + {"args": [{"description": null}]}, + {"args": [{"description": null}, {"description": null}]}, ]}}), vec![], )), @@ -1022,8 +1022,8 @@ mod argument { execute(DOC, None, &schema, &Variables::new(), &()).await, Ok(( graphql_value!({"__type": {"fields": [ - {"args": [{"defaultValue": None}]}, - {"args": [{"defaultValue": None}, {"defaultValue": None}]}, + {"args": [{"defaultValue": null}]}, + {"args": [{"defaultValue": null}, {"defaultValue": null}]}, ]}}), vec![], )), @@ -1133,21 +1133,21 @@ mod default_argument { "args": [{ "name": "arg1", "defaultValue": "0", - "type": {"name": "Int", "ofType": None}, + "type": {"name": "Int", "ofType": null}, }, { "name": "arg2", "defaultValue": r#""second""#, - "type": {"name": "String", "ofType": None}, + "type": {"name": "String", "ofType": null}, }, { "name": "arg3", "defaultValue": "true", - "type": {"name": "Boolean", "ofType": None}, + "type": {"name": "Boolean", "ofType": null}, }], }, { "args": [{ "name": "coord", "defaultValue": "{x: 1}", - "type": {"name": "Point", "ofType": None}, + "type": {"name": "Point", "ofType": null}, }], }]}}), vec![], @@ -1312,8 +1312,8 @@ mod deprecation_from_attr { execute(DOC, None, &schema, &Variables::new(), &()).await, Ok(( graphql_value!({"__type": {"fields": [ - {"name": "id", "deprecationReason": None}, - {"name": "a", "deprecationReason": None}, + {"name": "id", "deprecationReason": null}, + {"name": "a", "deprecationReason": null}, {"name": "b", "deprecationReason": "Use `id`."}, ]}}), vec![], @@ -1440,11 +1440,11 @@ mod explicit_name_description_and_deprecation { "args": [{"description": "My argument."}], }, { "name": "a", - "description": None, + "description": null, "args": [], }, { "name": "b", - "description": None, + "description": null, "args": [], }], }}), @@ -1478,11 +1478,11 @@ mod explicit_name_description_and_deprecation { }, { "name": "a", "isDeprecated": true, - "deprecationReason": None, + "deprecationReason": null, }, { "name": "b", "isDeprecated": false, - "deprecationReason": None, + "deprecationReason": null, }], }}), vec![], @@ -2092,7 +2092,7 @@ mod switched_context { "name": "switchAlways", "type": { "kind": "NON_NULL", - "name": None, + "name": null, "ofType": {"name": "Droid"}, }, }, { @@ -2100,13 +2100,13 @@ mod switched_context { "type": { "kind": "OBJECT", "name": "Droid", - "ofType": None, + "ofType": null, }, }, { "name": "switchRes", "type": { "kind": "NON_NULL", - "name": None, + "name": null, "ofType": {"name": "Droid"}, }, }, { @@ -2114,7 +2114,7 @@ mod switched_context { "type": { "kind": "OBJECT", "name": "Droid", - "ofType": None, + "ofType": null, }, }]}}), vec![], diff --git a/integration_tests/juniper_tests/src/codegen/object_derive.rs b/integration_tests/juniper_tests/src/codegen/object_derive.rs index 5162f9d95..2be660679 100644 --- a/integration_tests/juniper_tests/src/codegen/object_derive.rs +++ b/integration_tests/juniper_tests/src/codegen/object_derive.rs @@ -107,7 +107,7 @@ mod trivial { assert_eq!( execute(DOC, None, &schema, &Variables::new(), &()).await, - Ok((graphql_value!({"__type": {"description": None}}), vec![])), + Ok((graphql_value!({"__type": {"description": null}}), vec![])), ); } } @@ -578,8 +578,8 @@ mod deprecation_from_attr { execute(DOC, None, &schema, &Variables::new(), &()).await, Ok(( graphql_value!({"__type": {"fields": [ - {"name": "id", "deprecationReason": None}, - {"name": "a", "deprecationReason": None}, + {"name": "id", "deprecationReason": null}, + {"name": "a", "deprecationReason": null}, {"name": "b", "deprecationReason": "Use `id`."}, ]}}), vec![], @@ -693,10 +693,10 @@ mod explicit_name_description_and_deprecation { "description": "My human ID.", }, { "name": "a", - "description": None, + "description": null, }, { "name": "b", - "description": None, + "description": null, }], }}), vec![], @@ -729,11 +729,11 @@ mod explicit_name_description_and_deprecation { }, { "name": "a", "isDeprecated": true, - "deprecationReason": None, + "deprecationReason": null, }, { "name": "b", "isDeprecated": false, - "deprecationReason": None, + "deprecationReason": null, }], }}), vec![], diff --git a/integration_tests/juniper_tests/src/codegen/subscription_attr.rs b/integration_tests/juniper_tests/src/codegen/subscription_attr.rs index 5b69da154..cd3ae4ab3 100644 --- a/integration_tests/juniper_tests/src/codegen/subscription_attr.rs +++ b/integration_tests/juniper_tests/src/codegen/subscription_attr.rs @@ -138,7 +138,7 @@ mod trivial { assert_eq!( execute(DOC, None, &schema, &Variables::new(), &()).await, - Ok((graphql_value!({"__type": {"description": None}}), vec![])), + Ok((graphql_value!({"__type": {"description": null}}), vec![])), ); } } @@ -471,8 +471,8 @@ mod argument { execute(DOC, None, &schema, &Variables::new(), &()).await, Ok(( graphql_value!({"__type": {"fields": [ - {"args": [{"description": None}]}, - {"args": [{"description": None}, {"description": None}]}, + {"args": [{"description": null}]}, + {"args": [{"description": null}, {"description": null}]}, ]}}), vec![], )), @@ -497,8 +497,8 @@ mod argument { execute(DOC, None, &schema, &Variables::new(), &()).await, Ok(( graphql_value!({"__type": {"fields": [ - {"args": [{"defaultValue": None}]}, - {"args": [{"defaultValue": None}, {"defaultValue": None}]}, + {"args": [{"defaultValue": null}]}, + {"args": [{"defaultValue": null}, {"defaultValue": null}]}, ]}}), vec![], )), @@ -607,21 +607,21 @@ mod default_argument { "args": [{ "name": "arg1", "defaultValue": "0", - "type": {"name": "Int", "ofType": None}, + "type": {"name": "Int", "ofType": null}, }, { "name": "arg2", "defaultValue": r#""second""#, - "type": {"name": "String", "ofType": None}, + "type": {"name": "String", "ofType": null}, }, { "name": "arg3", "defaultValue": "true", - "type": {"name": "Boolean", "ofType": None}, + "type": {"name": "Boolean", "ofType": null}, }], }, { "args": [{ "name": "coord", "defaultValue": "{x: 1}", - "type": {"name": "Point", "ofType": None}, + "type": {"name": "Point", "ofType": null}, }], }]}}), vec![], @@ -1017,8 +1017,8 @@ mod deprecation_from_attr { execute(DOC, None, &schema, &Variables::new(), &()).await, Ok(( graphql_value!({"__type": {"fields": [ - {"name": "id", "deprecationReason": None}, - {"name": "a", "deprecationReason": None}, + {"name": "id", "deprecationReason": null}, + {"name": "a", "deprecationReason": null}, {"name": "b", "deprecationReason": "Use `id`."}, ]}}), vec![], @@ -1163,11 +1163,11 @@ mod explicit_name_description_and_deprecation { "args": [{"description": "My argument."}], }, { "name": "a", - "description": None, + "description": null, "args": [], }, { "name": "b", - "description": None, + "description": null, "args": [], }], }}), @@ -1201,11 +1201,11 @@ mod explicit_name_description_and_deprecation { }, { "name": "a", "isDeprecated": true, - "deprecationReason": None, + "deprecationReason": null, }, { "name": "b", "isDeprecated": false, - "deprecationReason": None, + "deprecationReason": null, }], }}), vec![], diff --git a/integration_tests/juniper_tests/src/codegen/union_attr.rs b/integration_tests/juniper_tests/src/codegen/union_attr.rs index 4d831ba9c..456014ca7 100644 --- a/integration_tests/juniper_tests/src/codegen/union_attr.rs +++ b/integration_tests/juniper_tests/src/codegen/union_attr.rs @@ -208,7 +208,7 @@ mod trivial { assert_eq!( execute(DOC, None, &schema, &Variables::new(), &()).await, - Ok((graphql_value!({"__type": {"description": None}}), vec![])), + Ok((graphql_value!({"__type": {"description": null}}), vec![])), ); } } diff --git a/integration_tests/juniper_tests/src/codegen/union_derive.rs b/integration_tests/juniper_tests/src/codegen/union_derive.rs index 6fd203649..dd654d9d2 100644 --- a/integration_tests/juniper_tests/src/codegen/union_derive.rs +++ b/integration_tests/juniper_tests/src/codegen/union_derive.rs @@ -191,7 +191,7 @@ mod trivial_enum { assert_eq!( execute(DOC, None, &schema, &Variables::new(), &()).await, - Ok((graphql_value!({"__type": {"description": None}}), vec![])), + Ok((graphql_value!({"__type": {"description": null}}), vec![])), ); } } @@ -1532,7 +1532,7 @@ mod trivial_struct { assert_eq!( execute(DOC, None, &schema, &Variables::new(), &db).await, - Ok((graphql_value!({"__type": {"description": None}}), vec![])), + Ok((graphql_value!({"__type": {"description": null}}), vec![])), ); } } diff --git a/juniper/src/executor_tests/executor.rs b/juniper/src/executor_tests/executor.rs index c9245fe55..44fa17343 100644 --- a/juniper/src/executor_tests/executor.rs +++ b/juniper/src/executor_tests/executor.rs @@ -115,13 +115,13 @@ mod field_execution { "deep": { "a": "Already Been Done", "b": "Boring", - "c": ["Contrived", None, "Confusing"], + "c": ["Contrived", null, "Confusing"], "deeper": [ { "a": "Apple", "b": "Banana", }, - None, + null, { "a": "Apple", "b": "Banana", @@ -486,7 +486,7 @@ mod dynamic_context_switching { result, graphql_value!({ "first": {"value": "First value"}, - "missing": None, + "missing": null, }), ); } @@ -577,13 +577,13 @@ mod dynamic_context_switching { vec![ExecutionError::new( SourcePosition::new(14, 1, 12), &["missing"], - FieldError::new("Could not find key 2", graphql_value!(None)), + FieldError::new("Could not find key 2", graphql_value!(null)), )] ); println!("Result: {:#?}", result); - assert_eq!(result, graphql_value!(None)); + assert_eq!(result, graphql_value!(null)); } #[tokio::test] @@ -631,7 +631,7 @@ mod dynamic_context_switching { [ExecutionError::new( SourcePosition::new(123, 4, 12), &["tooLarge"], - FieldError::new("Key too large: 200", graphql_value!(None)), + FieldError::new("Key too large: 200", graphql_value!(null)), )] ); @@ -641,8 +641,8 @@ mod dynamic_context_switching { result, graphql_value!({ "first": {"value": "First value"}, - "missing": None, - "tooLarge": None, + "missing": null, + "tooLarge": null, }), ); } @@ -773,7 +773,7 @@ mod propagates_errors_to_nullable_fields { assert_eq!( result, - graphql_value!({ "inner": { "nullableErrorField": None } }) + graphql_value!({ "inner": { "nullableErrorField": null } }) ); assert_eq!( @@ -781,7 +781,7 @@ mod propagates_errors_to_nullable_fields { vec![ExecutionError::new( SourcePosition::new(10, 0, 10), &["inner", "nullableErrorField"], - FieldError::new("Error for nullableErrorField", graphql_value!(None)), + FieldError::new("Error for nullableErrorField", graphql_value!(null)), )] ); } @@ -803,14 +803,14 @@ mod propagates_errors_to_nullable_fields { println!("Result: {:#?}", result); - assert_eq!(result, graphql_value!(None)); + assert_eq!(result, graphql_value!(null)); assert_eq!( errs, vec![ExecutionError::new( SourcePosition::new(10, 0, 10), &["inner", "nonNullableErrorField"], - FieldError::new("Error for nonNullableErrorField", graphql_value!(None)), + FieldError::new("Error for nonNullableErrorField", graphql_value!(null)), )] ); } @@ -832,7 +832,7 @@ mod propagates_errors_to_nullable_fields { println!("Result: {:#?}", result); - assert_eq!(result, graphql_value!(None)); + assert_eq!(result, graphql_value!(null)); assert_eq!( errs, @@ -863,7 +863,7 @@ mod propagates_errors_to_nullable_fields { assert_eq!( result, - graphql_value!({ "inner": { "nullableField": None } }) + graphql_value!({ "inner": { "nullableField": null } }) ); assert_eq!( @@ -871,7 +871,7 @@ mod propagates_errors_to_nullable_fields { vec![ExecutionError::new( SourcePosition::new(26, 0, 26), &["inner", "nullableField", "nonNullableErrorField"], - FieldError::new("Error for nonNullableErrorField", graphql_value!(None)), + FieldError::new("Error for nonNullableErrorField", graphql_value!(null)), )] ); } @@ -893,14 +893,14 @@ mod propagates_errors_to_nullable_fields { println!("Result: {:#?}", result); - assert_eq!(result, graphql_value!(None)); + assert_eq!(result, graphql_value!(null)); assert_eq!( errs, vec![ExecutionError::new( SourcePosition::new(29, 0, 29), &["inner", "nonNullableField", "nonNullableErrorField"], - FieldError::new("Error for nonNullableErrorField", graphql_value!(None)), + FieldError::new("Error for nonNullableErrorField", graphql_value!(null)), )] ); } @@ -924,7 +924,7 @@ mod propagates_errors_to_nullable_fields { assert_eq!( result, - graphql_value!({ "inner": { "nonNullableField": { "nullableErrorField": None } } }) + graphql_value!({ "inner": { "nonNullableField": { "nullableErrorField": null } } }) ); assert_eq!( @@ -932,7 +932,7 @@ mod propagates_errors_to_nullable_fields { vec![ExecutionError::new( SourcePosition::new(29, 0, 29), &["inner", "nonNullableField", "nullableErrorField"], - FieldError::new("Error for nullableErrorField", graphql_value!(None)), + FieldError::new("Error for nullableErrorField", graphql_value!(null)), )] ); } @@ -954,14 +954,14 @@ mod propagates_errors_to_nullable_fields { println!("Result: {:#?}", result); - assert_eq!(result, graphql_value!(None)); + assert_eq!(result, graphql_value!(null)); assert_eq!( errs, vec![ExecutionError::new( SourcePosition::new(11, 0, 11), &["inners", "nonNullableErrorField"], - FieldError::new("Error for nonNullableErrorField", graphql_value!(None)), + FieldError::new("Error for nonNullableErrorField", graphql_value!(null)), )] ); } @@ -985,7 +985,7 @@ mod propagates_errors_to_nullable_fields { assert_eq!( result, - graphql_value!({ "nullableInners": [None, None, None, None, None] }) + graphql_value!({ "nullableInners": [null, null, null, null, null] }) ); assert_eq!( @@ -994,27 +994,27 @@ mod propagates_errors_to_nullable_fields { ExecutionError::new( SourcePosition::new(19, 0, 19), &["nullableInners", "nonNullableErrorField"], - FieldError::new("Error for nonNullableErrorField", graphql_value!(None)), + FieldError::new("Error for nonNullableErrorField", graphql_value!(null)), ), ExecutionError::new( SourcePosition::new(19, 0, 19), &["nullableInners", "nonNullableErrorField"], - FieldError::new("Error for nonNullableErrorField", graphql_value!(None)), + FieldError::new("Error for nonNullableErrorField", graphql_value!(null)), ), ExecutionError::new( SourcePosition::new(19, 0, 19), &["nullableInners", "nonNullableErrorField"], - FieldError::new("Error for nonNullableErrorField", graphql_value!(None)), + FieldError::new("Error for nonNullableErrorField", graphql_value!(null)), ), ExecutionError::new( SourcePosition::new(19, 0, 19), &["nullableInners", "nonNullableErrorField"], - FieldError::new("Error for nonNullableErrorField", graphql_value!(None)), + FieldError::new("Error for nonNullableErrorField", graphql_value!(null)), ), ExecutionError::new( SourcePosition::new(19, 0, 19), &["nullableInners", "nonNullableErrorField"], - FieldError::new("Error for nonNullableErrorField", graphql_value!(None)), + FieldError::new("Error for nonNullableErrorField", graphql_value!(null)), ), ] ); diff --git a/juniper/src/executor_tests/introspection/enums.rs b/juniper/src/executor_tests/introspection/enums.rs index 1b861523f..b2ba2d3c3 100644 --- a/juniper/src/executor_tests/introspection/enums.rs +++ b/juniper/src/executor_tests/introspection/enums.rs @@ -147,23 +147,23 @@ async fn default_name_introspection() { ); assert_eq!( type_info.get_field_value("description"), - Some(&graphql_value!(None)), + Some(&graphql_value!(null)), ); assert_eq!(values.len(), 2); assert!(values.contains(&graphql_value!({ "name": "FOO", - "description": None, + "description": null, "isDeprecated": false, - "deprecationReason": None, + "deprecationReason": null, }))); assert!(values.contains(&graphql_value!({ "name": "BAR", - "description": None, + "description": null, "isDeprecated": false, - "deprecationReason": None, + "deprecationReason": null, }))); }) .await; @@ -193,23 +193,23 @@ async fn named_introspection() { ); assert_eq!( type_info.get_field_value("description"), - Some(&graphql_value!(None)), + Some(&graphql_value!(null)), ); assert_eq!(values.len(), 2); assert!(values.contains(&graphql_value!({ "name": "FOO", - "description": None, + "description": null, "isDeprecated": false, - "deprecationReason": None, + "deprecationReason": null, }))); assert!(values.contains(&graphql_value!({ "name": "BAR", - "description": None, + "description": null, "isDeprecated": false, - "deprecationReason": None, + "deprecationReason": null, }))); }) .await; @@ -239,23 +239,23 @@ async fn no_trailing_comma_introspection() { ); assert_eq!( type_info.get_field_value("description"), - Some(&graphql_value!(None)), + Some(&graphql_value!(null)), ); assert_eq!(values.len(), 2); assert!(values.contains(&graphql_value!({ "name": "FOO", - "description": None, + "description": null, "isDeprecated": false, - "deprecationReason": None, + "deprecationReason": null, }))); assert!(values.contains(&graphql_value!({ "name": "BAR", - "description": None, + "description": null, "isDeprecated": false, - "deprecationReason": None, + "deprecationReason": null, }))); }) .await; @@ -292,16 +292,16 @@ async fn enum_description_introspection() { assert!(values.contains(&graphql_value!({ "name": "FOO", - "description": None, + "description": null, "isDeprecated": false, - "deprecationReason": None, + "deprecationReason": null, }))); assert!(values.contains(&graphql_value!({ "name": "BAR", - "description": None, + "description": null, "isDeprecated": false, - "deprecationReason": None, + "deprecationReason": null, }))); }) .await; @@ -331,7 +331,7 @@ async fn enum_value_description_introspection() { ); assert_eq!( type_info.get_field_value("description"), - Some(&graphql_value!(None)), + Some(&graphql_value!(null)), ); assert_eq!(values.len(), 2); @@ -340,14 +340,14 @@ async fn enum_value_description_introspection() { "name": "FOO", "description": "The FOO value", "isDeprecated": false, - "deprecationReason": None, + "deprecationReason": null, }))); assert!(values.contains(&graphql_value!({ "name": "BAR", "description": "The BAR value", "isDeprecated": false, - "deprecationReason": None, + "deprecationReason": null, }))); }) .await; @@ -377,14 +377,14 @@ async fn enum_deprecation_introspection() { ); assert_eq!( type_info.get_field_value("description"), - Some(&graphql_value!(None)), + Some(&graphql_value!(null)), ); assert_eq!(values.len(), 2); assert!(values.contains(&graphql_value!({ "name": "FOO", - "description": None, + "description": null, "isDeprecated": true, "deprecationReason": "Please don't use FOO any more", }))); @@ -423,7 +423,7 @@ async fn enum_deprecation_no_values_introspection() { ); assert_eq!( type_info.get_field_value("description"), - Some(&graphql_value!(None)), + Some(&graphql_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 d9c48bda5..7b8df4820 100644 --- a/juniper/src/executor_tests/introspection/input_object.rs +++ b/juniper/src/executor_tests/introspection/input_object.rs @@ -174,25 +174,25 @@ async fn default_name_introspection() { ); assert_eq!( type_info.get_field_value("description"), - Some(&graphql_value!(None)), + Some(&graphql_value!(null)), ); assert_eq!(fields.len(), 2); assert!(fields.contains(&graphql_value!({ "name": "fieldOne", - "description": None, + "description": null, "type": { "ofType": {"name": "String"}, }, - "defaultValue": None, + "defaultValue": null, }))); assert!(fields.contains(&graphql_value!({ "name": "fieldTwo", - "description": None, + "description": null, "type": { "ofType": {"name": "String"}, }, - "defaultValue": None, + "defaultValue": null, }))); }) .await; @@ -245,25 +245,25 @@ async fn no_trailing_comma_introspection() { ); assert_eq!( type_info.get_field_value("description"), - Some(&graphql_value!(None)), + Some(&graphql_value!(null)), ); assert_eq!(fields.len(), 2); assert!(fields.contains(&graphql_value!({ "name": "fieldOne", - "description": None, + "description": null, "type": { "ofType": {"name": "String"}, }, - "defaultValue": None, + "defaultValue": null, }))); assert!(fields.contains(&graphql_value!({ "name": "fieldTwo", - "description": None, + "description": null, "type": { "ofType": {"name": "String"}, }, - "defaultValue": None, + "defaultValue": null, }))); }) .await; @@ -295,17 +295,17 @@ async fn derive_introspection() { ); assert_eq!( type_info.get_field_value("description"), - Some(&graphql_value!(None)), + Some(&graphql_value!(null)), ); assert_eq!(fields.len(), 1); assert!(fields.contains(&graphql_value!({ "name": "fieldOne", - "description": None, + "description": null, "type": { "ofType": {"name": "String"}, }, - "defaultValue": None, + "defaultValue": null, }))); }) .await; @@ -350,17 +350,17 @@ async fn named_introspection() { ); assert_eq!( type_info.get_field_value("description"), - Some(&graphql_value!(None)) + Some(&graphql_value!(null)) ); assert_eq!(fields.len(), 1); assert!(fields.contains(&graphql_value!({ "name": "fieldOne", - "description": None, + "description": null, "type": { "ofType": {"name": "String"}, }, - "defaultValue": None, + "defaultValue": null, }))); }) .await; @@ -398,11 +398,11 @@ async fn description_introspection() { assert_eq!(fields.len(), 1); assert!(fields.contains(&graphql_value!({ "name": "fieldOne", - "description": None, + "description": null, "type": { "ofType": {"name": "String"}, }, - "defaultValue": None, + "defaultValue": null, }))); }) .await; @@ -434,7 +434,7 @@ async fn field_description_introspection() { ); assert_eq!( type_info.get_field_value("description"), - Some(&graphql_value!(None)), + Some(&graphql_value!(null)), ); assert_eq!(fields.len(), 2); @@ -444,7 +444,7 @@ async fn field_description_introspection() { "type": { "ofType": {"name": "String"}, }, - "defaultValue": None, + "defaultValue": null, }))); assert!(fields.contains(&graphql_value!({ "name": "fieldTwo", @@ -452,7 +452,7 @@ async fn field_description_introspection() { "type": { "ofType": {"name": "String"}, }, - "defaultValue": None, + "defaultValue": null, }))); }) .await; diff --git a/juniper/src/executor_tests/introspection/mod.rs b/juniper/src/executor_tests/introspection/mod.rs index be6ec7ac8..47b70f5c7 100644 --- a/juniper/src/executor_tests/introspection/mod.rs +++ b/juniper/src/executor_tests/introspection/mod.rs @@ -154,23 +154,23 @@ async fn enum_introspection() { ); assert_eq!( type_info.get_field_value("description"), - Some(&graphql_value!(None)), + Some(&graphql_value!(null)), ); assert_eq!( type_info.get_field_value("interfaces"), - Some(&graphql_value!(None)), + Some(&graphql_value!(null)), ); assert_eq!( type_info.get_field_value("possibleTypes"), - Some(&graphql_value!(None)), + Some(&graphql_value!(null)), ); assert_eq!( type_info.get_field_value("inputFields"), - Some(&graphql_value!(None)), + Some(&graphql_value!(null)), ); assert_eq!( type_info.get_field_value("ofType"), - Some(&graphql_value!(None)) + Some(&graphql_value!(null)) ); let values = type_info @@ -183,16 +183,16 @@ async fn enum_introspection() { assert!(values.contains(&graphql_value!({ "name": "ONE", - "description": None, + "description": null, "isDeprecated": false, - "deprecationReason": None, + "deprecationReason": null, }))); assert!(values.contains(&graphql_value!({ "name": "TWO", - "description": None, + "description": null, "isDeprecated": false, - "deprecationReason": None, + "deprecationReason": null, }))); } @@ -267,19 +267,19 @@ async fn interface_introspection() { ); assert_eq!( type_info.get_field_value("interfaces"), - Some(&graphql_value!(None)), + Some(&graphql_value!(null)), ); assert_eq!( type_info.get_field_value("enumValues"), - Some(&graphql_value!(None)), + Some(&graphql_value!(null)), ); assert_eq!( type_info.get_field_value("inputFields"), - Some(&graphql_value!(None)), + Some(&graphql_value!(null)), ); assert_eq!( type_info.get_field_value("ofType"), - Some(&graphql_value!(None)) + Some(&graphql_value!(null)) ); let possible_types = type_info @@ -305,7 +305,7 @@ async fn interface_introspection() { "description": "A sample field in the interface", "args": [], "type": { - "name": None, + "name": null, "kind": "NON_NULL", "ofType": { "name": "SampleEnum", @@ -313,7 +313,7 @@ async fn interface_introspection() { }, }, "isDeprecated": false, - "deprecationReason": None, + "deprecationReason": null, }))); } @@ -403,19 +403,19 @@ async fn object_introspection() { ); assert_eq!( type_info.get_field_value("enumValues"), - Some(&graphql_value!(None)), + Some(&graphql_value!(null)), ); assert_eq!( type_info.get_field_value("inputFields"), - Some(&graphql_value!(None)), + Some(&graphql_value!(null)), ); assert_eq!( type_info.get_field_value("ofType"), - Some(&graphql_value!(None)) + Some(&graphql_value!(null)) ); assert_eq!( type_info.get_field_value("possibleTypes"), - Some(&graphql_value!(None)), + Some(&graphql_value!(null)), ); let fields = type_info @@ -430,10 +430,10 @@ async fn object_introspection() { assert!(fields.contains(&graphql_value!({ "name": "sampleEnum", - "description": None, + "description": null, "args": [], "type": { - "name": None, + "name": null, "kind": "NON_NULL", "ofType": { "name": "SampleEnum", @@ -441,7 +441,7 @@ async fn object_introspection() { }, }, "isDeprecated": false, - "deprecationReason": None, + "deprecationReason": null, }))); assert!(fields.contains(&graphql_value!({ @@ -451,27 +451,27 @@ async fn object_introspection() { "name": "first", "description": "The first number", "type": { - "name": None, + "name": null, "kind": "NON_NULL", "ofType": { "name": "Int", "kind": "SCALAR", - "ofType": None, + "ofType": null, }, }, - "defaultValue": None, + "defaultValue": null, }, { "name": "second", "description": "The second number", "type": { "name": "Int", "kind": "SCALAR", - "ofType": None, + "ofType": null, }, "defaultValue": "123", }], "type": { - "name": None, + "name": null, "kind": "NON_NULL", "ofType": { "name": "SampleScalar", @@ -479,7 +479,7 @@ async fn object_introspection() { }, }, "isDeprecated": false, - "deprecationReason": None, + "deprecationReason": null, }))); } @@ -525,13 +525,13 @@ async fn scalar_introspection() { &graphql_value!({ "name": "SampleScalar", "kind": "SCALAR", - "description": None, - "fields": None, - "interfaces": None, - "possibleTypes": None, - "enumValues": None, - "inputFields": None, - "ofType": None, + "description": null, + "fields": null, + "interfaces": null, + "possibleTypes": null, + "enumValues": null, + "inputFields": null, + "ofType": null, }), ); } diff --git a/juniper/src/tests/query_tests.rs b/juniper/src/tests/query_tests.rs index 3091a1ea2..8bca5a75c 100644 --- a/juniper/src/tests/query_tests.rs +++ b/juniper/src/tests/query_tests.rs @@ -291,7 +291,7 @@ async fn test_query_name_invalid_variable() { assert_eq!( crate::execute(doc, None, &schema, &vars, &database).await, - Ok((graphql_value!({ "human": None }), vec![])), + Ok((graphql_value!({ "human": null }), vec![])), ); } diff --git a/juniper/src/tests/schema_introspection.rs b/juniper/src/tests/schema_introspection.rs index 683b19d39..5926235b0 100644 --- a/juniper/src/tests/schema_introspection.rs +++ b/juniper/src/tests/schema_introspection.rs @@ -39,8 +39,8 @@ pub(crate) fn schema_introspection_result() -> Value { "queryType": { "name": "Query" }, - "mutationType": None, - "subscriptionType": None, + "mutationType": null, + "subscriptionType": null, "types": [ { "kind": "OBJECT", @@ -53,15 +53,15 @@ pub(crate) fn schema_introspection_result() -> Value { "args": [], "type": { "kind": "NON_NULL", - "name": None, + "name": null, "ofType": { "kind": "SCALAR", "name": "String", - "ofType": None + "ofType": null } }, "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null }, { "name": "name", @@ -70,10 +70,10 @@ pub(crate) fn schema_introspection_result() -> Value { "type": { "kind": "SCALAR", "name": "String", - "ofType": None + "ofType": null }, "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null }, { "name": "friends", @@ -81,23 +81,23 @@ pub(crate) fn schema_introspection_result() -> Value { "args": [], "type": { "kind": "NON_NULL", - "name": None, + "name": null, "ofType": { "kind": "LIST", - "name": None, + "name": null, "ofType": { "kind": "NON_NULL", - "name": None, + "name": null, "ofType": { "kind": "INTERFACE", "name": "Character", - "ofType": None + "ofType": null } } } }, "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null }, { "name": "appearsIn", @@ -105,23 +105,23 @@ pub(crate) fn schema_introspection_result() -> Value { "args": [], "type": { "kind": "NON_NULL", - "name": None, + "name": null, "ofType": { "kind": "LIST", - "name": None, + "name": null, "ofType": { "kind": "NON_NULL", - "name": None, + "name": null, "ofType": { "kind": "ENUM", "name": "Episode", - "ofType": None + "ofType": null } } } }, "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null }, { "name": "homePlanet", @@ -130,559 +130,559 @@ pub(crate) fn schema_introspection_result() -> Value { "type": { "kind": "SCALAR", "name": "String", - "ofType": None + "ofType": null }, "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null } ], - "inputFields": None, + "inputFields": null, "interfaces": [ { "kind": "INTERFACE", "name": "Character", - "ofType": None + "ofType": null } ], - "enumValues": None, - "possibleTypes": None + "enumValues": null, + "possibleTypes": null }, { "kind": "SCALAR", "name": "Boolean", - "description": None, - "fields": None, - "inputFields": None, - "interfaces": None, - "enumValues": None, - "possibleTypes": None + "description": null, + "fields": null, + "inputFields": null, + "interfaces": null, + "enumValues": null, + "possibleTypes": null }, { "kind": "OBJECT", "name": "__InputValue", - "description": None, + "description": null, "fields": [ { "name": "name", - "description": None, + "description": null, "args": [], "type": { "kind": "NON_NULL", - "name": None, + "name": null, "ofType": { "kind": "SCALAR", "name": "String", - "ofType": None + "ofType": null } }, "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null }, { "name": "description", - "description": None, + "description": null, "args": [], "type": { "kind": "SCALAR", "name": "String", - "ofType": None + "ofType": null }, "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null }, { "name": "type", - "description": None, + "description": null, "args": [], "type": { "kind": "NON_NULL", - "name": None, + "name": null, "ofType": { "kind": "OBJECT", "name": "__Type", - "ofType": None + "ofType": null } }, "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null }, { "name": "defaultValue", - "description": None, + "description": null, "args": [], "type": { "kind": "SCALAR", "name": "String", - "ofType": None + "ofType": null }, "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null } ], - "inputFields": None, + "inputFields": null, "interfaces": [], - "enumValues": None, - "possibleTypes": None + "enumValues": null, + "possibleTypes": null }, { "kind": "SCALAR", "name": "String", - "description": None, - "fields": None, - "inputFields": None, - "interfaces": None, - "enumValues": None, - "possibleTypes": None + "description": null, + "fields": null, + "inputFields": null, + "interfaces": null, + "enumValues": null, + "possibleTypes": null }, { "kind": "OBJECT", "name": "__Field", - "description": None, + "description": null, "fields": [ { "name": "name", - "description": None, + "description": null, "args": [], "type": { "kind": "NON_NULL", - "name": None, + "name": null, "ofType": { "kind": "SCALAR", "name": "String", - "ofType": None + "ofType": null } }, "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null }, { "name": "description", - "description": None, + "description": null, "args": [], "type": { "kind": "SCALAR", "name": "String", - "ofType": None + "ofType": null }, "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null }, { "name": "args", - "description": None, + "description": null, "args": [], "type": { "kind": "NON_NULL", - "name": None, + "name": null, "ofType": { "kind": "LIST", - "name": None, + "name": null, "ofType": { "kind": "NON_NULL", - "name": None, + "name": null, "ofType": { "kind": "OBJECT", "name": "__InputValue", - "ofType": None + "ofType": null } } } }, "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null }, { "name": "type", - "description": None, + "description": null, "args": [], "type": { "kind": "NON_NULL", - "name": None, + "name": null, "ofType": { "kind": "OBJECT", "name": "__Type", - "ofType": None + "ofType": null } }, "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null }, { "name": "isDeprecated", - "description": None, + "description": null, "args": [], "type": { "kind": "NON_NULL", - "name": None, + "name": null, "ofType": { "kind": "SCALAR", "name": "Boolean", - "ofType": None + "ofType": null } }, "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null }, { "name": "deprecationReason", - "description": None, + "description": null, "args": [], "type": { "kind": "SCALAR", "name": "String", - "ofType": None + "ofType": null }, "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null } ], - "inputFields": None, + "inputFields": null, "interfaces": [], - "enumValues": None, - "possibleTypes": None + "enumValues": null, + "possibleTypes": null }, { "kind": "ENUM", "name": "__TypeKind", "description": "GraphQL type kind\n\nThe GraphQL specification defines a number of type kinds - the meta type of a type.", - "fields": None, - "inputFields": None, - "interfaces": None, + "fields": null, + "inputFields": null, + "interfaces": null, "enumValues": [ { "name": "SCALAR", "description": "## Scalar types\n\nScalar types appear as the leaf nodes of GraphQL queries. Strings, numbers, and booleans are the built in types, and while it's possible to define your own, it's relatively uncommon.", "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null }, { "name": "OBJECT", "description": "## Object types\n\nThe most common type to be implemented by users. Objects have fields and can implement interfaces.", "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null }, { "name": "INTERFACE", "description": "## Interface types\n\nInterface types are used to represent overlapping fields between multiple types, and can be queried for their concrete type.", "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null }, { "name": "UNION", "description": "## Union types\n\nUnions are similar to interfaces but can not contain any fields on their own.", "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null }, { "name": "ENUM", "description": "## Enum types\n\nLike scalars, enum types appear as the leaf nodes of GraphQL queries.", "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null }, { "name": "INPUT_OBJECT", "description": "## Input objects\n\nRepresents complex values provided in queries _into_ the system.", "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null }, { "name": "LIST", "description": "## List types\n\nRepresent lists of other types. This library provides implementations for vectors and slices, but other Rust types can be extended to serve as GraphQL lists.", "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null }, { "name": "NON_NULL", "description": "## Non-null types\n\nIn GraphQL, nullable types are the default. By putting a `!` after a type, it becomes non-nullable.", "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null } ], - "possibleTypes": None + "possibleTypes": null }, { "kind": "OBJECT", "name": "__Type", - "description": None, + "description": null, "fields": [ { "name": "name", - "description": None, + "description": null, "args": [], "type": { "kind": "SCALAR", "name": "String", - "ofType": None + "ofType": null }, "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null }, { "name": "description", - "description": None, + "description": null, "args": [], "type": { "kind": "SCALAR", "name": "String", - "ofType": None + "ofType": null }, "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null }, { "name": "kind", - "description": None, + "description": null, "args": [], "type": { "kind": "NON_NULL", - "name": None, + "name": null, "ofType": { "kind": "ENUM", "name": "__TypeKind", - "ofType": None + "ofType": null } }, "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null }, { "name": "fields", - "description": None, + "description": null, "args": [ { "name": "includeDeprecated", - "description": None, + "description": null, "type": { "kind": "SCALAR", "name": "Boolean", - "ofType": None + "ofType": null }, "defaultValue": "false" } ], "type": { "kind": "LIST", - "name": None, + "name": null, "ofType": { "kind": "NON_NULL", - "name": None, + "name": null, "ofType": { "kind": "OBJECT", "name": "__Field", - "ofType": None + "ofType": null } } }, "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null }, { "name": "ofType", - "description": None, + "description": null, "args": [], "type": { "kind": "OBJECT", "name": "__Type", - "ofType": None + "ofType": null }, "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null }, { "name": "inputFields", - "description": None, + "description": null, "args": [], "type": { "kind": "LIST", - "name": None, + "name": null, "ofType": { "kind": "NON_NULL", - "name": None, + "name": null, "ofType": { "kind": "OBJECT", "name": "__InputValue", - "ofType": None + "ofType": null } } }, "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null }, { "name": "interfaces", - "description": None, + "description": null, "args": [], "type": { "kind": "LIST", - "name": None, + "name": null, "ofType": { "kind": "NON_NULL", - "name": None, + "name": null, "ofType": { "kind": "OBJECT", "name": "__Type", - "ofType": None + "ofType": null } } }, "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null }, { "name": "possibleTypes", - "description": None, + "description": null, "args": [], "type": { "kind": "LIST", - "name": None, + "name": null, "ofType": { "kind": "NON_NULL", - "name": None, + "name": null, "ofType": { "kind": "OBJECT", "name": "__Type", - "ofType": None + "ofType": null } } }, "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null }, { "name": "enumValues", - "description": None, + "description": null, "args": [ { "name": "includeDeprecated", - "description": None, + "description": null, "type": { "kind": "SCALAR", "name": "Boolean", - "ofType": None + "ofType": null }, "defaultValue": "false" } ], "type": { "kind": "LIST", - "name": None, + "name": null, "ofType": { "kind": "NON_NULL", - "name": None, + "name": null, "ofType": { "kind": "OBJECT", "name": "__EnumValue", - "ofType": None + "ofType": null } } }, "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null } ], - "inputFields": None, + "inputFields": null, "interfaces": [], - "enumValues": None, - "possibleTypes": None + "enumValues": null, + "possibleTypes": null }, { "kind": "OBJECT", "name": "__Schema", - "description": None, + "description": null, "fields": [ { "name": "types", - "description": None, + "description": null, "args": [], "type": { "kind": "NON_NULL", - "name": None, + "name": null, "ofType": { "kind": "LIST", - "name": None, + "name": null, "ofType": { "kind": "NON_NULL", - "name": None, + "name": null, "ofType": { "kind": "OBJECT", "name": "__Type", - "ofType": None + "ofType": null } } } }, "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null }, { "name": "queryType", - "description": None, + "description": null, "args": [], "type": { "kind": "NON_NULL", - "name": None, + "name": null, "ofType": { "kind": "OBJECT", "name": "__Type", - "ofType": None + "ofType": null } }, "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null }, { "name": "mutationType", - "description": None, + "description": null, "args": [], "type": { "kind": "OBJECT", "name": "__Type", - "ofType": None + "ofType": null }, "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null }, { "name": "subscriptionType", - "description": None, + "description": null, "args": [], "type": { "kind": "OBJECT", "name": "__Type", - "ofType": None + "ofType": null }, "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null }, { "name": "directives", - "description": None, + "description": null, "args": [], "type": { "kind": "NON_NULL", - "name": None, + "name": null, "ofType": { "kind": "LIST", - "name": None, + "name": null, "ofType": { "kind": "NON_NULL", - "name": None, + "name": null, "ofType": { "kind": "OBJECT", "name": "__Directive", - "ofType": None + "ofType": null } } } }, "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null } ], - "inputFields": None, + "inputFields": null, "interfaces": [], - "enumValues": None, - "possibleTypes": None + "enumValues": null, + "possibleTypes": null }, { "kind": "OBJECT", @@ -695,15 +695,15 @@ pub(crate) fn schema_introspection_result() -> Value { "args": [], "type": { "kind": "NON_NULL", - "name": None, + "name": null, "ofType": { "kind": "SCALAR", "name": "String", - "ofType": None + "ofType": null } }, "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null }, { "name": "name", @@ -712,10 +712,10 @@ pub(crate) fn schema_introspection_result() -> Value { "type": { "kind": "SCALAR", "name": "String", - "ofType": None + "ofType": null }, "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null }, { "name": "friends", @@ -723,23 +723,23 @@ pub(crate) fn schema_introspection_result() -> Value { "args": [], "type": { "kind": "NON_NULL", - "name": None, + "name": null, "ofType": { "kind": "LIST", - "name": None, + "name": null, "ofType": { "kind": "NON_NULL", - "name": None, + "name": null, "ofType": { "kind": "INTERFACE", "name": "Character", - "ofType": None + "ofType": null } } } }, "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null }, { "name": "appearsIn", @@ -747,23 +747,23 @@ pub(crate) fn schema_introspection_result() -> Value { "args": [], "type": { "kind": "NON_NULL", - "name": None, + "name": null, "ofType": { "kind": "LIST", - "name": None, + "name": null, "ofType": { "kind": "NON_NULL", - "name": None, + "name": null, "ofType": { "kind": "ENUM", "name": "Episode", - "ofType": None + "ofType": null } } } }, "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null }, { "name": "primaryFunction", @@ -772,22 +772,22 @@ pub(crate) fn schema_introspection_result() -> Value { "type": { "kind": "SCALAR", "name": "String", - "ofType": None + "ofType": null }, "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null } ], - "inputFields": None, + "inputFields": null, "interfaces": [ { "kind": "INTERFACE", "name": "Character", - "ofType": None + "ofType": null } ], - "enumValues": None, - "possibleTypes": None + "enumValues": null, + "possibleTypes": null }, { "kind": "OBJECT", @@ -796,62 +796,62 @@ pub(crate) fn schema_introspection_result() -> Value { "fields": [ { "name": "human", - "description": None, + "description": null, "args": [ { "name": "id", "description": "id of the human", "type": { "kind": "NON_NULL", - "name": None, + "name": null, "ofType": { "kind": "SCALAR", "name": "String", - "ofType": None + "ofType": null } }, - "defaultValue": None + "defaultValue": null } ], "type": { "kind": "OBJECT", "name": "Human", - "ofType": None + "ofType": null }, "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null }, { "name": "droid", - "description": None, + "description": null, "args": [ { "name": "id", - "description": None, + "description": null, "description": "id of the droid", "type": { "kind": "NON_NULL", - "name": None, + "name": null, "ofType": { "kind": "SCALAR", "name": "String", - "ofType": None + "ofType": null } }, - "defaultValue": None + "defaultValue": null } ], "type": { "kind": "OBJECT", "name": "Droid", - "ofType": None + "ofType": null }, "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null }, { "name": "hero", - "description": None, + "description": null, "args": [ { "name": "episode", @@ -859,173 +859,173 @@ pub(crate) fn schema_introspection_result() -> Value { "type": { "kind": "ENUM", "name": "Episode", - "ofType": None + "ofType": null }, - "defaultValue": None + "defaultValue": null } ], "type": { "kind": "INTERFACE", "name": "Character", - "ofType": None + "ofType": null }, "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null } ], - "inputFields": None, + "inputFields": null, "interfaces": [], - "enumValues": None, - "possibleTypes": None + "enumValues": null, + "possibleTypes": null }, { "kind": "OBJECT", "name": "__EnumValue", - "description": None, + "description": null, "fields": [ { "name": "name", - "description": None, + "description": null, "args": [], "type": { "kind": "NON_NULL", - "name": None, + "name": null, "ofType": { "kind": "SCALAR", "name": "String", - "ofType": None + "ofType": null } }, "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null }, { "name": "description", - "description": None, + "description": null, "args": [], "type": { "kind": "SCALAR", "name": "String", - "ofType": None + "ofType": null }, "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null }, { "name": "isDeprecated", - "description": None, + "description": null, "args": [], "type": { "kind": "NON_NULL", - "name": None, + "name": null, "ofType": { "kind": "SCALAR", "name": "Boolean", - "ofType": None + "ofType": null } }, "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null }, { "name": "deprecationReason", - "description": None, + "description": null, "args": [], "type": { "kind": "SCALAR", "name": "String", - "ofType": None + "ofType": null }, "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null } ], - "inputFields": None, + "inputFields": null, "interfaces": [], - "enumValues": None, - "possibleTypes": None + "enumValues": null, + "possibleTypes": null }, { "kind": "ENUM", "name": "Episode", - "description": None, - "fields": None, - "inputFields": None, - "interfaces": None, + "description": null, + "fields": null, + "inputFields": null, + "interfaces": null, "enumValues": [ { "name": "NEW_HOPE", - "description": None, + "description": null, "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null }, { "name": "EMPIRE", - "description": None, + "description": null, "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null }, { "name": "JEDI", - "description": None, + "description": null, "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null } ], - "possibleTypes": None + "possibleTypes": null }, { "kind": "ENUM", "name": "__DirectiveLocation", - "description": None, - "fields": None, - "inputFields": None, - "interfaces": None, + "description": null, + "fields": null, + "inputFields": null, + "interfaces": null, "enumValues": [ { "name": "QUERY", - "description": None, + "description": null, "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null }, { "name": "MUTATION", - "description": None, + "description": null, "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null }, { "name": "SUBSCRIPTION", - "description": None, + "description": null, "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null }, { "name": "FIELD", - "description": None, + "description": null, "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null }, { "name": "FRAGMENT_DEFINITION", - "description": None, + "description": null, "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null }, { "name": "FRAGMENT_SPREAD", - "description": None, + "description": null, "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null }, { "name": "INLINE_FRAGMENT", - "description": None, + "description": null, "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null } ], - "possibleTypes": None + "possibleTypes": null }, { "kind": "INTERFACE", @@ -1038,15 +1038,15 @@ pub(crate) fn schema_introspection_result() -> Value { "args": [], "type": { "kind": "NON_NULL", - "name": None, + "name": null, "ofType": { "kind": "SCALAR", "name": "String", - "ofType": None + "ofType": null } }, "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null }, { "name": "name", @@ -1055,10 +1055,10 @@ pub(crate) fn schema_introspection_result() -> Value { "type": { "kind": "SCALAR", "name": "String", - "ofType": None + "ofType": null }, "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null }, { "name": "friends", @@ -1066,23 +1066,23 @@ pub(crate) fn schema_introspection_result() -> Value { "args": [], "type": { "kind": "NON_NULL", - "name": None, + "name": null, "ofType": { "kind": "LIST", - "name": None, + "name": null, "ofType": { "kind": "NON_NULL", - "name": None, + "name": null, "ofType": { "kind": "INTERFACE", "name": "Character", - "ofType": None + "ofType": null } } } }, "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null }, { "name": "appearsIn", @@ -1090,133 +1090,133 @@ pub(crate) fn schema_introspection_result() -> Value { "args": [], "type": { "kind": "NON_NULL", - "name": None, + "name": null, "ofType": { "kind": "LIST", - "name": None, + "name": null, "ofType": { "kind": "NON_NULL", - "name": None, + "name": null, "ofType": { "kind": "ENUM", "name": "Episode", - "ofType": None + "ofType": null } } } }, "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null } ], - "inputFields": None, - "interfaces": None, - "enumValues": None, + "inputFields": null, + "interfaces": null, + "enumValues": null, "possibleTypes": [ { "kind": "OBJECT", "name": "Human", - "ofType": None + "ofType": null }, { "kind": "OBJECT", "name": "Droid", - "ofType": None + "ofType": null } ] }, { "kind": "OBJECT", "name": "__Directive", - "description": None, + "description": null, "fields": [ { "name": "name", - "description": None, + "description": null, "args": [], "type": { "kind": "NON_NULL", - "name": None, + "name": null, "ofType": { "kind": "SCALAR", "name": "String", - "ofType": None + "ofType": null } }, "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null }, { "name": "description", - "description": None, + "description": null, "args": [], "type": { "kind": "SCALAR", "name": "String", - "ofType": None + "ofType": null }, "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null }, { "name": "locations", - "description": None, + "description": null, "args": [], "type": { "kind": "NON_NULL", - "name": None, + "name": null, "ofType": { "kind": "LIST", - "name": None, + "name": null, "ofType": { "kind": "NON_NULL", - "name": None, + "name": null, "ofType": { "kind": "ENUM", "name": "__DirectiveLocation", - "ofType": None + "ofType": null } } } }, "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null }, { "name": "args", - "description": None, + "description": null, "args": [], "type": { "kind": "NON_NULL", - "name": None, + "name": null, "ofType": { "kind": "LIST", - "name": None, + "name": null, "ofType": { "kind": "NON_NULL", - "name": None, + "name": null, "ofType": { "kind": "OBJECT", "name": "__InputValue", - "ofType": None + "ofType": null } } } }, "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null }, { "name": "onOperation", - "description": None, + "description": null, "args": [], "type": { "kind": "NON_NULL", - "name": None, + "name": null, "ofType": { "kind": "SCALAR", "name": "Boolean", - "ofType": None + "ofType": null } }, "isDeprecated": true, @@ -1224,15 +1224,15 @@ pub(crate) fn schema_introspection_result() -> Value { }, { "name": "onFragment", - "description": None, + "description": null, "args": [], "type": { "kind": "NON_NULL", - "name": None, + "name": null, "ofType": { "kind": "SCALAR", "name": "Boolean", - "ofType": None + "ofType": null } }, "isDeprecated": true, @@ -1240,31 +1240,31 @@ pub(crate) fn schema_introspection_result() -> Value { }, { "name": "onField", - "description": None, + "description": null, "args": [], "type": { "kind": "NON_NULL", - "name": None, + "name": null, "ofType": { "kind": "SCALAR", "name": "Boolean", - "ofType": None + "ofType": null } }, "isDeprecated": true, "deprecationReason": "Use the locations array instead" } ], - "inputFields": None, + "inputFields": null, "interfaces": [], - "enumValues": None, - "possibleTypes": None + "enumValues": null, + "possibleTypes": null } ], "directives": [ { "name": "skip", - "description": None, + "description": null, "locations": [ "FIELD", "FRAGMENT_SPREAD", @@ -1273,23 +1273,23 @@ pub(crate) fn schema_introspection_result() -> Value { "args": [ { "name": "if", - "description": None, + "description": null, "type": { "kind": "NON_NULL", - "name": None, + "name": null, "ofType": { "kind": "SCALAR", "name": "Boolean", - "ofType": None + "ofType": null } }, - "defaultValue": None + "defaultValue": null } ] }, { "name": "include", - "description": None, + "description": null, "locations": [ "FIELD", "FRAGMENT_SPREAD", @@ -1298,17 +1298,17 @@ pub(crate) fn schema_introspection_result() -> Value { "args": [ { "name": "if", - "description": None, + "description": null, "type": { "kind": "NON_NULL", - "name": None, + "name": null, "ofType": { "kind": "SCALAR", "name": "Boolean", - "ofType": None + "ofType": null } }, - "defaultValue": None + "defaultValue": null } ] } @@ -1325,8 +1325,8 @@ pub(crate) fn schema_introspection_result_without_descriptions() -> Value { "queryType": { "name": "Query" }, - "mutationType": None, - "subscriptionType": None, + "mutationType": null, + "subscriptionType": null, "types": [ { "kind": "OBJECT", @@ -1337,15 +1337,15 @@ pub(crate) fn schema_introspection_result_without_descriptions() -> Value { "args": [], "type": { "kind": "NON_NULL", - "name": None, + "name": null, "ofType": { "kind": "SCALAR", "name": "String", - "ofType": None + "ofType": null } }, "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null }, { "name": "name", @@ -1353,56 +1353,56 @@ pub(crate) fn schema_introspection_result_without_descriptions() -> Value { "type": { "kind": "SCALAR", "name": "String", - "ofType": None + "ofType": null }, "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null }, { "name": "friends", "args": [], "type": { "kind": "NON_NULL", - "name": None, + "name": null, "ofType": { "kind": "LIST", - "name": None, + "name": null, "ofType": { "kind": "NON_NULL", - "name": None, + "name": null, "ofType": { "kind": "INTERFACE", "name": "Character", - "ofType": None + "ofType": null } } } }, "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null }, { "name": "appearsIn", "args": [], "type": { "kind": "NON_NULL", - "name": None, + "name": null, "ofType": { "kind": "LIST", - "name": None, + "name": null, "ofType": { "kind": "NON_NULL", - "name": None, + "name": null, "ofType": { "kind": "ENUM", "name": "Episode", - "ofType": None + "ofType": null } } } }, "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null }, { "name": "homePlanet", @@ -1410,31 +1410,31 @@ pub(crate) fn schema_introspection_result_without_descriptions() -> Value { "type": { "kind": "SCALAR", "name": "String", - "ofType": None + "ofType": null }, "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null } ], - "inputFields": None, + "inputFields": null, "interfaces": [ { "kind": "INTERFACE", "name": "Character", - "ofType": None + "ofType": null } ], - "enumValues": None, - "possibleTypes": None + "enumValues": null, + "possibleTypes": null }, { "kind": "SCALAR", "name": "Boolean", - "fields": None, - "inputFields": None, - "interfaces": None, - "enumValues": None, - "possibleTypes": None + "fields": null, + "inputFields": null, + "interfaces": null, + "enumValues": null, + "possibleTypes": null }, { "kind": "OBJECT", @@ -1445,15 +1445,15 @@ pub(crate) fn schema_introspection_result_without_descriptions() -> Value { "args": [], "type": { "kind": "NON_NULL", - "name": None, + "name": null, "ofType": { "kind": "SCALAR", "name": "String", - "ofType": None + "ofType": null } }, "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null }, { "name": "description", @@ -1461,25 +1461,25 @@ pub(crate) fn schema_introspection_result_without_descriptions() -> Value { "type": { "kind": "SCALAR", "name": "String", - "ofType": None + "ofType": null }, "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null }, { "name": "type", "args": [], "type": { "kind": "NON_NULL", - "name": None, + "name": null, "ofType": { "kind": "OBJECT", "name": "__Type", - "ofType": None + "ofType": null } }, "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null }, { "name": "defaultValue", @@ -1487,25 +1487,25 @@ pub(crate) fn schema_introspection_result_without_descriptions() -> Value { "type": { "kind": "SCALAR", "name": "String", - "ofType": None + "ofType": null }, "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null } ], - "inputFields": None, + "inputFields": null, "interfaces": [], - "enumValues": None, - "possibleTypes": None + "enumValues": null, + "possibleTypes": null }, { "kind": "SCALAR", "name": "String", - "fields": None, - "inputFields": None, - "interfaces": None, - "enumValues": None, - "possibleTypes": None + "fields": null, + "inputFields": null, + "interfaces": null, + "enumValues": null, + "possibleTypes": null }, { "kind": "OBJECT", @@ -1516,15 +1516,15 @@ pub(crate) fn schema_introspection_result_without_descriptions() -> Value { "args": [], "type": { "kind": "NON_NULL", - "name": None, + "name": null, "ofType": { "kind": "SCALAR", "name": "String", - "ofType": None + "ofType": null } }, "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null }, { "name": "description", @@ -1532,63 +1532,63 @@ pub(crate) fn schema_introspection_result_without_descriptions() -> Value { "type": { "kind": "SCALAR", "name": "String", - "ofType": None + "ofType": null }, "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null }, { "name": "args", "args": [], "type": { "kind": "NON_NULL", - "name": None, + "name": null, "ofType": { "kind": "LIST", - "name": None, + "name": null, "ofType": { "kind": "NON_NULL", - "name": None, + "name": null, "ofType": { "kind": "OBJECT", "name": "__InputValue", - "ofType": None + "ofType": null } } } }, "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null }, { "name": "type", "args": [], "type": { "kind": "NON_NULL", - "name": None, + "name": null, "ofType": { "kind": "OBJECT", "name": "__Type", - "ofType": None + "ofType": null } }, "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null }, { "name": "isDeprecated", "args": [], "type": { "kind": "NON_NULL", - "name": None, + "name": null, "ofType": { "kind": "SCALAR", "name": "Boolean", - "ofType": None + "ofType": null } }, "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null }, { "name": "deprecationReason", @@ -1596,66 +1596,66 @@ pub(crate) fn schema_introspection_result_without_descriptions() -> Value { "type": { "kind": "SCALAR", "name": "String", - "ofType": None + "ofType": null }, "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null } ], - "inputFields": None, + "inputFields": null, "interfaces": [], - "enumValues": None, - "possibleTypes": None + "enumValues": null, + "possibleTypes": null }, { "kind": "ENUM", "name": "__TypeKind", - "fields": None, - "inputFields": None, - "interfaces": None, + "fields": null, + "inputFields": null, + "interfaces": null, "enumValues": [ { "name": "SCALAR", "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null }, { "name": "OBJECT", "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null }, { "name": "INTERFACE", "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null }, { "name": "UNION", "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null }, { "name": "ENUM", "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null }, { "name": "INPUT_OBJECT", "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null }, { "name": "LIST", "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null }, { "name": "NON_NULL", "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null } ], - "possibleTypes": None + "possibleTypes": null }, { "kind": "OBJECT", @@ -1667,10 +1667,10 @@ pub(crate) fn schema_introspection_result_without_descriptions() -> Value { "type": { "kind": "SCALAR", "name": "String", - "ofType": None + "ofType": null }, "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null }, { "name": "description", @@ -1678,25 +1678,25 @@ pub(crate) fn schema_introspection_result_without_descriptions() -> Value { "type": { "kind": "SCALAR", "name": "String", - "ofType": None + "ofType": null }, "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null }, { "name": "kind", "args": [], "type": { "kind": "NON_NULL", - "name": None, + "name": null, "ofType": { "kind": "ENUM", "name": "__TypeKind", - "ofType": None + "ofType": null } }, "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null }, { "name": "fields", @@ -1706,26 +1706,26 @@ pub(crate) fn schema_introspection_result_without_descriptions() -> Value { "type": { "kind": "SCALAR", "name": "Boolean", - "ofType": None + "ofType": null }, "defaultValue": "false" } ], "type": { "kind": "LIST", - "name": None, + "name": null, "ofType": { "kind": "NON_NULL", - "name": None, + "name": null, "ofType": { "kind": "OBJECT", "name": "__Field", - "ofType": None + "ofType": null } } }, "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null }, { "name": "ofType", @@ -1733,67 +1733,67 @@ pub(crate) fn schema_introspection_result_without_descriptions() -> Value { "type": { "kind": "OBJECT", "name": "__Type", - "ofType": None + "ofType": null }, "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null }, { "name": "inputFields", "args": [], "type": { "kind": "LIST", - "name": None, + "name": null, "ofType": { "kind": "NON_NULL", - "name": None, + "name": null, "ofType": { "kind": "OBJECT", "name": "__InputValue", - "ofType": None + "ofType": null } } }, "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null }, { "name": "interfaces", "args": [], "type": { "kind": "LIST", - "name": None, + "name": null, "ofType": { "kind": "NON_NULL", - "name": None, + "name": null, "ofType": { "kind": "OBJECT", "name": "__Type", - "ofType": None + "ofType": null } } }, "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null }, { "name": "possibleTypes", "args": [], "type": { "kind": "LIST", - "name": None, + "name": null, "ofType": { "kind": "NON_NULL", - "name": None, + "name": null, "ofType": { "kind": "OBJECT", "name": "__Type", - "ofType": None + "ofType": null } } }, "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null }, { "name": "enumValues", @@ -1803,32 +1803,32 @@ pub(crate) fn schema_introspection_result_without_descriptions() -> Value { "type": { "kind": "SCALAR", "name": "Boolean", - "ofType": None + "ofType": null }, "defaultValue": "false" } ], "type": { "kind": "LIST", - "name": None, + "name": null, "ofType": { "kind": "NON_NULL", - "name": None, + "name": null, "ofType": { "kind": "OBJECT", "name": "__EnumValue", - "ofType": None + "ofType": null } } }, "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null } ], - "inputFields": None, + "inputFields": null, "interfaces": [], - "enumValues": None, - "possibleTypes": None + "enumValues": null, + "possibleTypes": null }, { "kind": "OBJECT", @@ -1839,38 +1839,38 @@ pub(crate) fn schema_introspection_result_without_descriptions() -> Value { "args": [], "type": { "kind": "NON_NULL", - "name": None, + "name": null, "ofType": { "kind": "LIST", - "name": None, + "name": null, "ofType": { "kind": "NON_NULL", - "name": None, + "name": null, "ofType": { "kind": "OBJECT", "name": "__Type", - "ofType": None + "ofType": null } } } }, "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null }, { "name": "queryType", "args": [], "type": { "kind": "NON_NULL", - "name": None, + "name": null, "ofType": { "kind": "OBJECT", "name": "__Type", - "ofType": None + "ofType": null } }, "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null }, { "name": "mutationType", @@ -1878,10 +1878,10 @@ pub(crate) fn schema_introspection_result_without_descriptions() -> Value { "type": { "kind": "OBJECT", "name": "__Type", - "ofType": None + "ofType": null }, "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null }, { "name": "subscriptionType", @@ -1889,39 +1889,39 @@ pub(crate) fn schema_introspection_result_without_descriptions() -> Value { "type": { "kind": "OBJECT", "name": "__Type", - "ofType": None + "ofType": null }, "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null }, { "name": "directives", "args": [], "type": { "kind": "NON_NULL", - "name": None, + "name": null, "ofType": { "kind": "LIST", - "name": None, + "name": null, "ofType": { "kind": "NON_NULL", - "name": None, + "name": null, "ofType": { "kind": "OBJECT", "name": "__Directive", - "ofType": None + "ofType": null } } } }, "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null } ], - "inputFields": None, + "inputFields": null, "interfaces": [], - "enumValues": None, - "possibleTypes": None + "enumValues": null, + "possibleTypes": null }, { "kind": "OBJECT", @@ -1932,15 +1932,15 @@ pub(crate) fn schema_introspection_result_without_descriptions() -> Value { "args": [], "type": { "kind": "NON_NULL", - "name": None, + "name": null, "ofType": { "kind": "SCALAR", "name": "String", - "ofType": None + "ofType": null } }, "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null }, { "name": "name", @@ -1948,56 +1948,56 @@ pub(crate) fn schema_introspection_result_without_descriptions() -> Value { "type": { "kind": "SCALAR", "name": "String", - "ofType": None + "ofType": null }, "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null }, { "name": "friends", "args": [], "type": { "kind": "NON_NULL", - "name": None, + "name": null, "ofType": { "kind": "LIST", - "name": None, + "name": null, "ofType": { "kind": "NON_NULL", - "name": None, + "name": null, "ofType": { "kind": "INTERFACE", "name": "Character", - "ofType": None + "ofType": null } } } }, "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null }, { "name": "appearsIn", "args": [], "type": { "kind": "NON_NULL", - "name": None, + "name": null, "ofType": { "kind": "LIST", - "name": None, + "name": null, "ofType": { "kind": "NON_NULL", - "name": None, + "name": null, "ofType": { "kind": "ENUM", "name": "Episode", - "ofType": None + "ofType": null } } } }, "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null }, { "name": "primaryFunction", @@ -2005,22 +2005,22 @@ pub(crate) fn schema_introspection_result_without_descriptions() -> Value { "type": { "kind": "SCALAR", "name": "String", - "ofType": None + "ofType": null }, "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null } ], - "inputFields": None, + "inputFields": null, "interfaces": [ { "kind": "INTERFACE", "name": "Character", - "ofType": None + "ofType": null } ], - "enumValues": None, - "possibleTypes": None + "enumValues": null, + "possibleTypes": null }, { "kind": "OBJECT", @@ -2033,23 +2033,23 @@ pub(crate) fn schema_introspection_result_without_descriptions() -> Value { "name": "id", "type": { "kind": "NON_NULL", - "name": None, + "name": null, "ofType": { "kind": "SCALAR", "name": "String", - "ofType": None + "ofType": null } }, - "defaultValue": None + "defaultValue": null } ], "type": { "kind": "OBJECT", "name": "Human", - "ofType": None + "ofType": null }, "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null }, { "name": "droid", @@ -2058,23 +2058,23 @@ pub(crate) fn schema_introspection_result_without_descriptions() -> Value { "name": "id", "type": { "kind": "NON_NULL", - "name": None, + "name": null, "ofType": { "kind": "SCALAR", "name": "String", - "ofType": None + "ofType": null } }, - "defaultValue": None + "defaultValue": null } ], "type": { "kind": "OBJECT", "name": "Droid", - "ofType": None + "ofType": null }, "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null }, { "name": "hero", @@ -2084,24 +2084,24 @@ pub(crate) fn schema_introspection_result_without_descriptions() -> Value { "type": { "kind": "ENUM", "name": "Episode", - "ofType": None + "ofType": null }, - "defaultValue": None + "defaultValue": null } ], "type": { "kind": "INTERFACE", "name": "Character", - "ofType": None + "ofType": null }, "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null } ], - "inputFields": None, + "inputFields": null, "interfaces": [], - "enumValues": None, - "possibleTypes": None + "enumValues": null, + "possibleTypes": null }, { "kind": "OBJECT", @@ -2112,15 +2112,15 @@ pub(crate) fn schema_introspection_result_without_descriptions() -> Value { "args": [], "type": { "kind": "NON_NULL", - "name": None, + "name": null, "ofType": { "kind": "SCALAR", "name": "String", - "ofType": None + "ofType": null } }, "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null }, { "name": "description", @@ -2128,25 +2128,25 @@ pub(crate) fn schema_introspection_result_without_descriptions() -> Value { "type": { "kind": "SCALAR", "name": "String", - "ofType": None + "ofType": null }, "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null }, { "name": "isDeprecated", "args": [], "type": { "kind": "NON_NULL", - "name": None, + "name": null, "ofType": { "kind": "SCALAR", "name": "Boolean", - "ofType": None + "ofType": null } }, "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null }, { "name": "deprecationReason", @@ -2154,86 +2154,86 @@ pub(crate) fn schema_introspection_result_without_descriptions() -> Value { "type": { "kind": "SCALAR", "name": "String", - "ofType": None + "ofType": null }, "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null } ], - "inputFields": None, + "inputFields": null, "interfaces": [], - "enumValues": None, - "possibleTypes": None + "enumValues": null, + "possibleTypes": null }, { "kind": "ENUM", "name": "Episode", - "fields": None, - "inputFields": None, - "interfaces": None, + "fields": null, + "inputFields": null, + "interfaces": null, "enumValues": [ { "name": "NEW_HOPE", "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null }, { "name": "EMPIRE", "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null }, { "name": "JEDI", "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null } ], - "possibleTypes": None + "possibleTypes": null }, { "kind": "ENUM", "name": "__DirectiveLocation", - "fields": None, - "inputFields": None, - "interfaces": None, + "fields": null, + "inputFields": null, + "interfaces": null, "enumValues": [ { "name": "QUERY", "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null }, { "name": "MUTATION", "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null }, { "name": "SUBSCRIPTION", "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null }, { "name": "FIELD", "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null }, { "name": "FRAGMENT_DEFINITION", "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null }, { "name": "FRAGMENT_SPREAD", "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null }, { "name": "INLINE_FRAGMENT", "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null } ], - "possibleTypes": None + "possibleTypes": null }, { "kind": "INTERFACE", @@ -2244,15 +2244,15 @@ pub(crate) fn schema_introspection_result_without_descriptions() -> Value { "args": [], "type": { "kind": "NON_NULL", - "name": None, + "name": null, "ofType": { "kind": "SCALAR", "name": "String", - "ofType": None + "ofType": null } }, "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null }, { "name": "name", @@ -2260,71 +2260,71 @@ pub(crate) fn schema_introspection_result_without_descriptions() -> Value { "type": { "kind": "SCALAR", "name": "String", - "ofType": None + "ofType": null }, "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null }, { "name": "friends", "args": [], "type": { "kind": "NON_NULL", - "name": None, + "name": null, "ofType": { "kind": "LIST", - "name": None, + "name": null, "ofType": { "kind": "NON_NULL", - "name": None, + "name": null, "ofType": { "kind": "INTERFACE", "name": "Character", - "ofType": None + "ofType": null } } } }, "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null }, { "name": "appearsIn", "args": [], "type": { "kind": "NON_NULL", - "name": None, + "name": null, "ofType": { "kind": "LIST", - "name": None, + "name": null, "ofType": { "kind": "NON_NULL", - "name": None, + "name": null, "ofType": { "kind": "ENUM", "name": "Episode", - "ofType": None + "ofType": null } } } }, "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null } ], - "inputFields": None, - "interfaces": None, - "enumValues": None, + "inputFields": null, + "interfaces": null, + "enumValues": null, "possibleTypes": [ { "kind": "OBJECT", "name": "Human", - "ofType": None + "ofType": null }, { "kind": "OBJECT", "name": "Droid", - "ofType": None + "ofType": null } ] }, @@ -2337,15 +2337,15 @@ pub(crate) fn schema_introspection_result_without_descriptions() -> Value { "args": [], "type": { "kind": "NON_NULL", - "name": None, + "name": null, "ofType": { "kind": "SCALAR", "name": "String", - "ofType": None + "ofType": null } }, "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null }, { "name": "description", @@ -2353,67 +2353,67 @@ pub(crate) fn schema_introspection_result_without_descriptions() -> Value { "type": { "kind": "SCALAR", "name": "String", - "ofType": None + "ofType": null }, "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null }, { "name": "locations", "args": [], "type": { "kind": "NON_NULL", - "name": None, + "name": null, "ofType": { "kind": "LIST", - "name": None, + "name": null, "ofType": { "kind": "NON_NULL", - "name": None, + "name": null, "ofType": { "kind": "ENUM", "name": "__DirectiveLocation", - "ofType": None + "ofType": null } } } }, "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null }, { "name": "args", "args": [], "type": { "kind": "NON_NULL", - "name": None, + "name": null, "ofType": { "kind": "LIST", - "name": None, + "name": null, "ofType": { "kind": "NON_NULL", - "name": None, + "name": null, "ofType": { "kind": "OBJECT", "name": "__InputValue", - "ofType": None + "ofType": null } } } }, "isDeprecated": false, - "deprecationReason": None + "deprecationReason": null }, { "name": "onOperation", "args": [], "type": { "kind": "NON_NULL", - "name": None, + "name": null, "ofType": { "kind": "SCALAR", "name": "Boolean", - "ofType": None + "ofType": null } }, "isDeprecated": true, @@ -2424,11 +2424,11 @@ pub(crate) fn schema_introspection_result_without_descriptions() -> Value { "args": [], "type": { "kind": "NON_NULL", - "name": None, + "name": null, "ofType": { "kind": "SCALAR", "name": "Boolean", - "ofType": None + "ofType": null } }, "isDeprecated": true, @@ -2439,21 +2439,21 @@ pub(crate) fn schema_introspection_result_without_descriptions() -> Value { "args": [], "type": { "kind": "NON_NULL", - "name": None, + "name": null, "ofType": { "kind": "SCALAR", "name": "Boolean", - "ofType": None + "ofType": null } }, "isDeprecated": true, "deprecationReason": "Use the locations array instead" } ], - "inputFields": None, + "inputFields": null, "interfaces": [], - "enumValues": None, - "possibleTypes": None + "enumValues": null, + "possibleTypes": null } ], "directives": [ @@ -2469,14 +2469,14 @@ pub(crate) fn schema_introspection_result_without_descriptions() -> Value { "name": "if", "type": { "kind": "NON_NULL", - "name": None, + "name": null, "ofType": { "kind": "SCALAR", "name": "Boolean", - "ofType": None + "ofType": null } }, - "defaultValue": None + "defaultValue": null } ] }, @@ -2492,14 +2492,14 @@ pub(crate) fn schema_introspection_result_without_descriptions() -> Value { "name": "if", "type": { "kind": "NON_NULL", - "name": None, + "name": null, "ofType": { "kind": "SCALAR", "name": "Boolean", - "ofType": None + "ofType": null } }, - "defaultValue": None + "defaultValue": null } ] } diff --git a/juniper/src/value/mod.rs b/juniper/src/value/mod.rs index 1817aa2ed..87d2e6a4f 100644 --- a/juniper/src/value/mod.rs +++ b/juniper/src/value/mod.rs @@ -288,7 +288,7 @@ impl> From for Value { /// # type V = Value; /// # /// # let _: V = -/// graphql_value!(None); +/// graphql_value!(null); /// # let _: V = /// graphql_value!(1234); /// # let _: V = @@ -310,12 +310,14 @@ macro_rules! graphql_value { $( ($key, $crate::graphql_value!($val)), )* ].into_iter().collect()) }; - (None) => ($crate::Value::null()); + (null) => ($crate::Value::null()); ($e:expr) => ($crate::Value::from($e)) } #[cfg(test)] mod tests { + use std::iter; + use super::*; #[test] @@ -346,7 +348,7 @@ mod tests { fn value_macro_option() { let s: Value = graphql_value!(Some("test")); assert_eq!(s, Value::scalar("test")); - let s: Value = graphql_value!(None); + let s: Value = graphql_value!(null); assert_eq!(s, Value::null()); } @@ -385,9 +387,15 @@ mod tests { ); } + // #[test] + // fn value_macro_expr() { + // let s: Value = graphql_value!({ "key": 1 + 2 }); + // assert_eq!(s, Value::object(iter::once(("key", 3)).collect())); + // } + #[test] fn display_null() { - let s: Value = graphql_value!(None); + let s: Value = graphql_value!(null); assert_eq!("null", format!("{}", s)); } @@ -420,7 +428,7 @@ mod tests { #[test] fn display_list() { - let s: Value = graphql_value!([1, None, "foo"]); + let s: Value = graphql_value!([1, null, "foo"]); assert_eq!("[1, null, \"foo\"]", format!("{}", s)); } @@ -440,7 +448,7 @@ mod tests { fn display_object() { let s: Value = graphql_value!({ "int": 1, - "null": None, + "null": null, "string": "foo", }); assert_eq!( diff --git a/juniper_graphql_ws/src/lib.rs b/juniper_graphql_ws/src/lib.rs index 675f9cffb..918f006a1 100644 --- a/juniper_graphql_ws/src/lib.rs +++ b/juniper_graphql_ws/src/lib.rs @@ -681,7 +681,7 @@ mod test { async fn error(_context: &Context) -> BoxStream<'static, FieldResult> { stream::once(future::ready(Err(FieldError::new( "field error", - graphql_value!(None), + graphql_value!(null), )))) .chain( tokio::time::sleep(Duration::from_secs(10000)) @@ -1044,7 +1044,7 @@ mod test { payload: DataPayload { data, errors }, } => { assert_eq!(id, "foo"); - assert_eq!(data, graphql_value!({ "error": None }),); + assert_eq!(data, graphql_value!({ "error": null }),); assert_eq!(errors.len(), 1); } msg @ _ => panic!("expected data, got: {:?}", msg), diff --git a/juniper_graphql_ws/src/server_message.rs b/juniper_graphql_ws/src/server_message.rs index da7daf038..f52c1244b 100644 --- a/juniper_graphql_ws/src/server_message.rs +++ b/juniper_graphql_ws/src/server_message.rs @@ -159,7 +159,7 @@ mod test { serde_json::to_string(&ServerMessage::Data { id: "foo".to_string(), payload: DataPayload { - data: graphql_value!(None), + data: graphql_value!(null), errors: vec![], }, }) diff --git a/juniper_subscriptions/src/lib.rs b/juniper_subscriptions/src/lib.rs index ada8449d3..5e890b630 100644 --- a/juniper_subscriptions/src/lib.rs +++ b/juniper_subscriptions/src/lib.rs @@ -261,10 +261,10 @@ mod whole_responses_stream { #[tokio::test] async fn with_error() { let expected: Vec> = vec![ExecutionOutput { - data: graphql_value!(None), + data: graphql_value!(null), errors: vec![ExecutionError::at_origin(FieldError::new( "field error", - graphql_value!(None), + graphql_value!(null), ))], }]; let expected = serde_json::to_string(&expected).unwrap(); @@ -273,7 +273,7 @@ mod whole_responses_stream { Value::Null, vec![ExecutionError::at_origin(FieldError::new( "field error", - graphql_value!(None), + graphql_value!(null), ))], ) .collect::>() @@ -286,7 +286,7 @@ mod whole_responses_stream { #[tokio::test] async fn value_null() { let expected: Vec> = - vec![ExecutionOutput::from_data(graphql_value!(None))]; + vec![ExecutionOutput::from_data(graphql_value!(null))]; let expected = serde_json::to_string(&expected).unwrap(); let result = whole_responses_stream::(Value::Null, vec![]) @@ -333,7 +333,7 @@ mod whole_responses_stream { let expected: Vec> = vec![ ExecutionOutput::from_data(graphql_value!(1)), ExecutionOutput::from_data(graphql_value!(2)), - ExecutionOutput::from_data(graphql_value!(None)), + ExecutionOutput::from_data(graphql_value!(null)), ExecutionOutput::from_data(graphql_value!(4)), ]; let expected = serde_json::to_string(&expected).unwrap(); From a5b2a69b9ccfe9cc6ef4344223def405454f389e Mon Sep 17 00:00:00 2001 From: ilslv Date: Tue, 23 Nov 2021 16:38:47 +0300 Subject: [PATCH 03/22] Fix array support in graphql_value! macro --- juniper/src/value/mod.rs | 74 ++++++++++++++++++++++++++++++++++------ 1 file changed, 63 insertions(+), 11 deletions(-) diff --git a/juniper/src/value/mod.rs b/juniper/src/value/mod.rs index 87d2e6a4f..a1a67b2ed 100644 --- a/juniper/src/value/mod.rs +++ b/juniper/src/value/mod.rs @@ -300,24 +300,76 @@ impl> From for Value { /// ``` #[macro_export] macro_rules! graphql_value { - ([ $($arg:tt),* $(,)* ]) => { + // Done with trailing comma. + (@array [$($elems:expr,)*]) => { $crate::Value::list(vec![ - $( $crate::graphql_value!($arg), )* + $( $crate::graphql_value!($elems), )* ]) }; + + // Done without trailing comma. + (@array [$($elems:expr),*]) => { + $crate::Value::list(vec![ + $( $crate::graphql_value!($elems), )* + ]) + }; + + // Next element is `null`. + (@array [$($elems:expr,)*] null $($rest:tt)*) => { + $crate::graphql_value!( + @array [$($elems,)* $crate::graphql_value!(null)] $($rest)* + ) + }; + + // Next element is an array. + (@array [$($elems:expr,)*] [$($array:tt)*] $($rest:tt)*) => { + $crate::graphql_value!( + @array [$($elems,)* $crate::graphql_value!([$($array)*])] $($rest)* + ) + }; + + // Next element is a map. + (@array [$($elems:expr,)*] {$($map:tt)*} $($rest:tt)*) => { + $crate::graphql_value!( + @array [$($elems,)* $crate::graphql_value!({$($map)*})] $($rest)* + ) + }; + + // Next element is an expression followed by comma. + (@array [$($elems:expr,)*] $next:expr, $($rest:tt)*) => { + $crate::graphql_value!( + @array [$($elems,)* $crate::graphql_value!($next),] $($rest)* + ) + }; + + // Last element is an expression with no trailing comma. + (@array [$($elems:expr,)*] $last:expr) => { + $crate::graphql_value!( + @array [$($elems,)* $crate::graphql_value!($last)] + ) + }; + + // Comma after the most recent element. + (@array [$($elems:expr),*] , $($rest:tt)*) => { + $crate::graphql_value!(@array [$($elems,)*] $($rest)*) + }; + + ([ $($arr:tt)* ]) => { + $crate::graphql_value!(@array [] $($arr)*) + }; + (null) => ($crate::Value::null()); + ({ $($key:tt : $val:tt ),* $(,)* }) => { $crate::Value::object(vec![ $( ($key, $crate::graphql_value!($val)), )* ].into_iter().collect()) }; - (null) => ($crate::Value::null()); - ($e:expr) => ($crate::Value::from($e)) + + ($e:expr) => ($crate::Value::from($e)); } #[cfg(test)] mod tests { - use std::iter; - use super::*; #[test] @@ -387,11 +439,11 @@ mod tests { ); } - // #[test] - // fn value_macro_expr() { - // let s: Value = graphql_value!({ "key": 1 + 2 }); - // assert_eq!(s, Value::object(iter::once(("key", 3)).collect())); - // } + #[test] + fn value_macro_expr() { + let s: Value = graphql_value!([1 + 2]); + assert_eq!(s, Value::list(vec![3.into()])); + } #[test] fn display_null() { From 9b46d8a21beb4655c8d80cd5332c20d371be19ed Mon Sep 17 00:00:00 2001 From: ilslv Date: Wed, 24 Nov 2021 12:12:48 +0300 Subject: [PATCH 04/22] Fix map support in graphql_value! macro --- juniper/src/lib.rs | 1 + juniper/src/value/mod.rs | 151 +++++++++++++++++++++++++++++++++++---- 2 files changed, 140 insertions(+), 12 deletions(-) diff --git a/juniper/src/lib.rs b/juniper/src/lib.rs index aa4fcbcbf..fa407390e 100644 --- a/juniper/src/lib.rs +++ b/juniper/src/lib.rs @@ -91,6 +91,7 @@ Juniper has not reached 1.0 yet, thus some API instability should be expected. */ #![doc(html_root_url = "https://docs.rs/juniper/0.15.7")] +#![recursion_limit = "256"] #![warn(missing_docs)] // Required for using `juniper_codegen` macros inside this crate to resolve absolute `::juniper` diff --git a/juniper/src/value/mod.rs b/juniper/src/value/mod.rs index a1a67b2ed..c6855dc7c 100644 --- a/juniper/src/value/mod.rs +++ b/juniper/src/value/mod.rs @@ -300,6 +300,10 @@ impl> From for Value { /// ``` #[macro_export] macro_rules! graphql_value { + /////////// + // Array // + /////////// + // Done with trailing comma. (@array [$($elems:expr,)*]) => { $crate::Value::list(vec![ @@ -354,17 +358,128 @@ macro_rules! graphql_value { $crate::graphql_value!(@array [$($elems,)*] $($rest)*) }; + // Unexpected token after most recent element. + (@array [$($elems:expr),*] $unexpected:tt $($rest:tt)*) => { + crate::graphql_value!(@unexpected $unexpected) + }; + + //////////// + // Object // + //////////// + + // Done. + (@object $object:ident () () ()) => {}; + + // Insert the current entry followed by trailing comma. + (@object $object:ident [$($key:tt)+] ($value:expr) , $($rest:tt)*) => { + let _ = $object.add_field(($($key)+), $value); + $crate::graphql_value!(@object $object () ($($rest)*) ($($rest)*)); + }; + + // Current entry followed by unexpected token. + (@object $object:ident [$($key:tt)+] ($value:expr) $unexpected:tt $($rest:tt)*) => { + $crate::graphql_value!(@unexpected $unexpected); + }; + + // Insert the last entry without trailing comma. + (@object $object:ident [$($key:tt)+] ($value:expr)) => { + let _ = $object.add_field(($($key)+), $value); + }; + + // Next value is `null`. + (@object $object:ident ($($key:tt)+) (: null $($rest:tt)*) $copy:tt) => { + $crate::graphql_value!(@object $object [$($key)+] ($crate::graphql_value!(null)) $($rest)*); + }; + + // Next value is an array. + (@object $object:ident ($($key:tt)+) (: [$($array:tt)*] $($rest:tt)*) $copy:tt) => { + $crate::graphql_value!(@object $object [$($key)+] ($crate::graphql_value!([$($array)*])) $($rest)*); + }; + + // Next value is a map. + (@object $object:ident ($($key:tt)+) (: {$($map:tt)*} $($rest:tt)*) $copy:tt) => { + $crate::graphql_value!(@object $object [$($key)+] ($crate::graphql_value!({$($map)*})) $($rest)*); + }; + + // Next value is an expression followed by comma. + (@object $object:ident ($($key:tt)+) (: $value:expr , $($rest:tt)*) $copy:tt) => { + $crate::graphql_value!(@object $object [$($key)+] ($crate::graphql_value!($value)) , $($rest)*); + }; + + // Last value is an expression with no trailing comma. + (@object $object:ident ($($key:tt)+) (: $value:expr) $copy:tt) => { + $crate::graphql_value!(@object $object [$($key)+] ($crate::graphql_value!($value))); + }; + + // Missing value for last entry. Trigger a reasonable error message. + (@object $object:ident ($($key:tt)+) (:) $copy:tt) => { + // "unexpected end of macro invocation" + $crate::graphql_value!(); + }; + + // Missing colon and value for last entry. Trigger a reasonable error + // message. + (@object $object:ident ($($key:tt)+) () $copy:tt) => { + // "unexpected end of macro invocation" + $crate::graphql_value!(); + }; + + // Misplaced colon. Trigger a reasonable error message. + (@object $object:ident () (: $($rest:tt)*) ($colon:tt $($copy:tt)*)) => { + // Takes no arguments so "no rules expected the token `:`". + crate::graphql_value!(@unexpected $colon); + }; + + // Found a comma inside a key. Trigger a reasonable error message. + (@object $object:ident ($($key:tt)*) (, $($rest:tt)*) ($comma:tt $($copy:tt)*)) => { + // Takes no arguments so "no rules expected the token `,`". + crate::graphql_value!(@unexpected $comma); + }; + + // Key is fully parenthesized. This avoids clippy double_parens false + // positives because the parenthesization may be necessary here. + (@object $object:ident () (($key:expr) : $($rest:tt)*) $copy:tt) => { + $crate::graphql_value!(@object $object ($key) (: $($rest)*) (: $($rest)*)); + }; + + // Refuse to absorb colon token into key expression. + (@object $object:ident ($($key:tt)*) (: $($unexpected:tt)+) $copy:tt) => { + crate::graphql_value!(@unexpected $($unexpected)+); + }; + + // Munch a token into the current key. + (@object $object:ident ($($key:tt)*) ($tt:tt $($rest:tt)*) $copy:tt) => { + $crate::graphql_value!(@object $object ($($key)* $tt) ($($rest)*) ($($rest)*)); + }; + + //////////// + // Errors // + //////////// + + (@unexpected) => {}; + + ////////////// + // Defaults // + ////////////// + ([ $($arr:tt)* ]) => { $crate::graphql_value!(@array [] $($arr)*) }; - (null) => ($crate::Value::null()); - ({ $($key:tt : $val:tt ),* $(,)* }) => { - $crate::Value::object(vec![ - $( ($key, $crate::graphql_value!($val)), )* - ].into_iter().collect()) + ({}) => { + $crate::Value::object($crate::Object::with_capacity(0)) + }; + + ({ $($map:tt)+ }) => { + $crate::Value::object({ + let mut object = $crate::Object::with_capacity(0); + $crate::graphql_value!(@object object () ($($map)*) ($($map)*)); + object + }) }; + (null) => ($crate::Value::null()); + ($e:expr) => ($crate::Value::from($e)); } @@ -424,6 +539,15 @@ mod tests { Value::scalar(789), ]) ); + let s: Value = graphql_value!([123, [1 + 2], 789]); + assert_eq!( + s, + Value::list(vec![ + Value::scalar(123), + Value::list(vec![Value::scalar(3)]), + Value::scalar(789), + ]) + ); } #[test] @@ -437,12 +561,15 @@ mod tests { .collect(), ) ); - } - - #[test] - fn value_macro_expr() { - let s: Value = graphql_value!([1 + 2]); - assert_eq!(s, Value::list(vec![3.into()])); + let s: Value = graphql_value!({ "key": 1 + 2, "next": true }); + assert_eq!( + s, + Value::object( + vec![("key", Value::scalar(3)), ("next", Value::scalar(true))] + .into_iter() + .collect(), + ) + ); } #[test] @@ -519,7 +646,7 @@ mod tests { #[test] fn display_object_empty() { - let s = Value::::object(Object::with_capacity(0)); + let s: Value = graphql_value!({}); assert_eq!(r#"{}"#, format!("{}", s)); } } From 52372476b24db0dacad1724e28d770bad3cb59f4 Mon Sep 17 00:00:00 2001 From: ilslv Date: Wed, 24 Nov 2021 12:28:33 +0300 Subject: [PATCH 05/22] Move graphql_value! macro into separate module --- juniper/src/lib.rs | 3 +- juniper/src/value/macros.rs | 376 +++++++++++++++++++++++++++++++++++ juniper/src/value/mod.rs | 377 +----------------------------------- 3 files changed, 380 insertions(+), 376 deletions(-) create mode 100644 juniper/src/value/macros.rs diff --git a/juniper/src/lib.rs b/juniper/src/lib.rs index fa407390e..d7d66238e 100644 --- a/juniper/src/lib.rs +++ b/juniper/src/lib.rs @@ -90,8 +90,9 @@ Juniper has not reached 1.0 yet, thus some API instability should be expected. [bson]: https://crates.io/crates/bson */ +// Due to `schema_introspection` test. +#![cfg_attr(test, recursion_limit = "256")] #![doc(html_root_url = "https://docs.rs/juniper/0.15.7")] -#![recursion_limit = "256"] #![warn(missing_docs)] // Required for using `juniper_codegen` macros inside this crate to resolve absolute `::juniper` diff --git a/juniper/src/value/macros.rs b/juniper/src/value/macros.rs new file mode 100644 index 000000000..aae589b15 --- /dev/null +++ b/juniper/src/value/macros.rs @@ -0,0 +1,376 @@ +use super::{DefaultScalarValue, Value}; + +/// Construct JSON-like [`Value`]s by using JSON syntax. +/// +/// [`Value`] objects are used mostly when creating custom errors from fields. +/// +/// # Example +/// +/// Resulting JSON will look just like what you passed in. +/// ```rust +/// # use juniper::{graphql_value, DefaultScalarValue, Value}; +/// # type V = Value; +/// # +/// # let _: V = +/// graphql_value!(null); +/// # let _: V = +/// graphql_value!(1234); +/// # let _: V = +/// graphql_value!("test"); +/// # let _: V = +/// graphql_value!([1234, "test", true]); +/// # let _: V = +/// graphql_value!({"key": "value", "foo": 1234}); +/// ``` +#[macro_export] +macro_rules! graphql_value { + /////////// + // Array // + /////////// + + // Done with trailing comma. + (@array [$($elems:expr,)*]) => { + $crate::Value::list(vec![ + $( $crate::graphql_value!($elems), )* + ]) + }; + + // Done without trailing comma. + (@array [$($elems:expr),*]) => { + $crate::Value::list(vec![ + $( $crate::graphql_value!($elems), )* + ]) + }; + + // Next element is `null`. + (@array [$($elems:expr,)*] null $($rest:tt)*) => { + $crate::graphql_value!( + @array [$($elems,)* $crate::graphql_value!(null)] $($rest)* + ) + }; + + // Next element is an array. + (@array [$($elems:expr,)*] [$($array:tt)*] $($rest:tt)*) => { + $crate::graphql_value!( + @array [$($elems,)* $crate::graphql_value!([$($array)*])] $($rest)* + ) + }; + + // Next element is a map. + (@array [$($elems:expr,)*] {$($map:tt)*} $($rest:tt)*) => { + $crate::graphql_value!( + @array [$($elems,)* $crate::graphql_value!({$($map)*})] $($rest)* + ) + }; + + // Next element is an expression followed by comma. + (@array [$($elems:expr,)*] $next:expr, $($rest:tt)*) => { + $crate::graphql_value!( + @array [$($elems,)* $crate::graphql_value!($next),] $($rest)* + ) + }; + + // Last element is an expression with no trailing comma. + (@array [$($elems:expr,)*] $last:expr) => { + $crate::graphql_value!( + @array [$($elems,)* $crate::graphql_value!($last)] + ) + }; + + // Comma after the most recent element. + (@array [$($elems:expr),*] , $($rest:tt)*) => { + $crate::graphql_value!(@array [$($elems,)*] $($rest)*) + }; + + // Unexpected token after most recent element. + (@array [$($elems:expr),*] $unexpected:tt $($rest:tt)*) => { + crate::graphql_value!(@unexpected $unexpected) + }; + + //////////// + // Object // + //////////// + + // Done. + (@object $object:ident () () ()) => {}; + + // Insert the current entry followed by trailing comma. + (@object $object:ident [$($key:tt)+] ($value:expr) , $($rest:tt)*) => { + let _ = $object.add_field(($($key)+), $value); + $crate::graphql_value!(@object $object () ($($rest)*) ($($rest)*)); + }; + + // Current entry followed by unexpected token. + (@object $object:ident [$($key:tt)+] ($value:expr) $unexpected:tt $($rest:tt)*) => { + $crate::graphql_value!(@unexpected $unexpected); + }; + + // Insert the last entry without trailing comma. + (@object $object:ident [$($key:tt)+] ($value:expr)) => { + let _ = $object.add_field(($($key)+), $value); + }; + + // Next value is `null`. + (@object $object:ident ($($key:tt)+) (: null $($rest:tt)*) $copy:tt) => { + $crate::graphql_value!(@object $object [$($key)+] ($crate::graphql_value!(null)) $($rest)*); + }; + + // Next value is an array. + (@object $object:ident ($($key:tt)+) (: [$($array:tt)*] $($rest:tt)*) $copy:tt) => { + $crate::graphql_value!(@object $object [$($key)+] ($crate::graphql_value!([$($array)*])) $($rest)*); + }; + + // Next value is a map. + (@object $object:ident ($($key:tt)+) (: {$($map:tt)*} $($rest:tt)*) $copy:tt) => { + $crate::graphql_value!(@object $object [$($key)+] ($crate::graphql_value!({$($map)*})) $($rest)*); + }; + + // Next value is an expression followed by comma. + (@object $object:ident ($($key:tt)+) (: $value:expr , $($rest:tt)*) $copy:tt) => { + $crate::graphql_value!(@object $object [$($key)+] ($crate::graphql_value!($value)) , $($rest)*); + }; + + // Last value is an expression with no trailing comma. + (@object $object:ident ($($key:tt)+) (: $value:expr) $copy:tt) => { + $crate::graphql_value!(@object $object [$($key)+] ($crate::graphql_value!($value))); + }; + + // Missing value for last entry. Trigger a reasonable error message. + (@object $object:ident ($($key:tt)+) (:) $copy:tt) => { + // "unexpected end of macro invocation" + $crate::graphql_value!(); + }; + + // Missing colon and value for last entry. Trigger a reasonable error + // message. + (@object $object:ident ($($key:tt)+) () $copy:tt) => { + // "unexpected end of macro invocation" + $crate::graphql_value!(); + }; + + // Misplaced colon. Trigger a reasonable error message. + (@object $object:ident () (: $($rest:tt)*) ($colon:tt $($copy:tt)*)) => { + // Takes no arguments so "no rules expected the token `:`". + crate::graphql_value!(@unexpected $colon); + }; + + // Found a comma inside a key. Trigger a reasonable error message. + (@object $object:ident ($($key:tt)*) (, $($rest:tt)*) ($comma:tt $($copy:tt)*)) => { + // Takes no arguments so "no rules expected the token `,`". + crate::graphql_value!(@unexpected $comma); + }; + + // Key is fully parenthesized. This avoids clippy double_parens false + // positives because the parenthesization may be necessary here. + (@object $object:ident () (($key:expr) : $($rest:tt)*) $copy:tt) => { + $crate::graphql_value!(@object $object ($key) (: $($rest)*) (: $($rest)*)); + }; + + // Refuse to absorb colon token into key expression. + (@object $object:ident ($($key:tt)*) (: $($unexpected:tt)+) $copy:tt) => { + crate::graphql_value!(@unexpected $($unexpected)+); + }; + + // Munch a token into the current key. + (@object $object:ident ($($key:tt)*) ($tt:tt $($rest:tt)*) $copy:tt) => { + $crate::graphql_value!(@object $object ($($key)* $tt) ($($rest)*) ($($rest)*)); + }; + + //////////// + // Errors // + //////////// + + (@unexpected) => {}; + + ////////////// + // Defaults // + ////////////// + + ([ $($arr:tt)* ]) => { + $crate::graphql_value!(@array [] $($arr)*) + }; + + ({}) => { + $crate::Value::object($crate::Object::with_capacity(0)) + }; + + ({ $($map:tt)+ }) => { + $crate::Value::object({ + let mut object = $crate::Object::with_capacity(0); + $crate::graphql_value!(@object object () ($($map)*) ($($map)*)); + object + }) + }; + + (null) => ($crate::Value::null()); + + ($e:expr) => ($crate::Value::from($e)); +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn value_macro_string() { + let s: Value = graphql_value!("test"); + assert_eq!(s, Value::scalar("test")); + } + + #[test] + fn value_macro_int() { + let s: Value = graphql_value!(123); + assert_eq!(s, Value::scalar(123)); + } + + #[test] + fn value_macro_float() { + let s: Value = graphql_value!(123.5); + assert_eq!(s, Value::scalar(123.5)); + } + + #[test] + fn value_macro_boolean() { + let s: Value = graphql_value!(false); + assert_eq!(s, Value::scalar(false)); + } + + #[test] + fn value_macro_option() { + let s: Value = graphql_value!(Some("test")); + assert_eq!(s, Value::scalar("test")); + let s: Value = graphql_value!(null); + assert_eq!(s, Value::null()); + } + + #[test] + fn value_macro_list() { + let s: Value = graphql_value!([123, "Test", false]); + assert_eq!( + s, + Value::list(vec![ + Value::scalar(123), + Value::scalar("Test"), + Value::scalar(false), + ]) + ); + let s: Value = graphql_value!([123, [456], 789]); + assert_eq!( + s, + Value::list(vec![ + Value::scalar(123), + Value::list(vec![Value::scalar(456)]), + Value::scalar(789), + ]) + ); + let s: Value = graphql_value!([123, [1 + 2], 789]); + assert_eq!( + s, + Value::list(vec![ + Value::scalar(123), + Value::list(vec![Value::scalar(3)]), + Value::scalar(789), + ]) + ); + } + + #[test] + fn value_macro_object() { + let s: Value = graphql_value!({ "key": 123, "next": true }); + assert_eq!( + s, + Value::object( + vec![("key", Value::scalar(123)), ("next", Value::scalar(true))] + .into_iter() + .collect(), + ) + ); + let s: Value = graphql_value!({ "key": 1 + 2, "next": true }); + assert_eq!( + s, + Value::object( + vec![("key", Value::scalar(3)), ("next", Value::scalar(true))] + .into_iter() + .collect(), + ) + ); + } + + #[test] + fn display_null() { + let s: Value = graphql_value!(null); + assert_eq!("null", format!("{}", s)); + } + + #[test] + fn display_int() { + let s: Value = graphql_value!(123); + assert_eq!("123", format!("{}", s)); + } + + #[test] + fn display_float() { + let s: Value = graphql_value!(123.456); + assert_eq!("123.456", format!("{}", s)); + } + + #[test] + fn display_string() { + let s: Value = graphql_value!("foo"); + assert_eq!("\"foo\"", format!("{}", s)); + } + + #[test] + fn display_bool() { + let s: Value = graphql_value!(false); + assert_eq!("false", format!("{}", s)); + + let s: Value = graphql_value!(true); + assert_eq!("true", format!("{}", s)); + } + + #[test] + fn display_list() { + let s: Value = graphql_value!([1, null, "foo"]); + assert_eq!("[1, null, \"foo\"]", format!("{}", s)); + } + + #[test] + fn display_list_one_element() { + let s: Value = graphql_value!([1]); + assert_eq!("[1]", format!("{}", s)); + } + + #[test] + fn display_list_empty() { + let s: Value = graphql_value!([]); + assert_eq!("[]", format!("{}", s)); + } + + #[test] + fn display_object() { + let s: Value = graphql_value!({ + "int": 1, + "null": null, + "string": "foo", + }); + assert_eq!( + r#"{"int": 1, "null": null, "string": "foo"}"#, + format!("{}", s) + ); + } + + #[test] + fn display_object_one_field() { + let s: Value = graphql_value!({ + "int": 1, + }); + assert_eq!(r#"{"int": 1}"#, format!("{}", s)); + } + + #[test] + fn display_object_empty() { + let s: Value = graphql_value!({}); + assert_eq!(r#"{}"#, format!("{}", s)); + } +} diff --git a/juniper/src/value/mod.rs b/juniper/src/value/mod.rs index c6855dc7c..070e4902f 100644 --- a/juniper/src/value/mod.rs +++ b/juniper/src/value/mod.rs @@ -1,3 +1,5 @@ +#[macro_use] +mod macros; mod object; mod scalar; @@ -275,378 +277,3 @@ impl> From for Value { Self::scalar(b) } } - -/// Construct JSON-like [`Value`]s by using JSON syntax. -/// -/// [`Value`] objects are used mostly when creating custom errors from fields. -/// -/// # Example -/// -/// Resulting JSON will look just like what you passed in. -/// ```rust -/// # use juniper::{graphql_value, DefaultScalarValue, Value}; -/// # type V = Value; -/// # -/// # let _: V = -/// graphql_value!(null); -/// # let _: V = -/// graphql_value!(1234); -/// # let _: V = -/// graphql_value!("test"); -/// # let _: V = -/// graphql_value!([1234, "test", true]); -/// # let _: V = -/// graphql_value!({"key": "value", "foo": 1234}); -/// ``` -#[macro_export] -macro_rules! graphql_value { - /////////// - // Array // - /////////// - - // Done with trailing comma. - (@array [$($elems:expr,)*]) => { - $crate::Value::list(vec![ - $( $crate::graphql_value!($elems), )* - ]) - }; - - // Done without trailing comma. - (@array [$($elems:expr),*]) => { - $crate::Value::list(vec![ - $( $crate::graphql_value!($elems), )* - ]) - }; - - // Next element is `null`. - (@array [$($elems:expr,)*] null $($rest:tt)*) => { - $crate::graphql_value!( - @array [$($elems,)* $crate::graphql_value!(null)] $($rest)* - ) - }; - - // Next element is an array. - (@array [$($elems:expr,)*] [$($array:tt)*] $($rest:tt)*) => { - $crate::graphql_value!( - @array [$($elems,)* $crate::graphql_value!([$($array)*])] $($rest)* - ) - }; - - // Next element is a map. - (@array [$($elems:expr,)*] {$($map:tt)*} $($rest:tt)*) => { - $crate::graphql_value!( - @array [$($elems,)* $crate::graphql_value!({$($map)*})] $($rest)* - ) - }; - - // Next element is an expression followed by comma. - (@array [$($elems:expr,)*] $next:expr, $($rest:tt)*) => { - $crate::graphql_value!( - @array [$($elems,)* $crate::graphql_value!($next),] $($rest)* - ) - }; - - // Last element is an expression with no trailing comma. - (@array [$($elems:expr,)*] $last:expr) => { - $crate::graphql_value!( - @array [$($elems,)* $crate::graphql_value!($last)] - ) - }; - - // Comma after the most recent element. - (@array [$($elems:expr),*] , $($rest:tt)*) => { - $crate::graphql_value!(@array [$($elems,)*] $($rest)*) - }; - - // Unexpected token after most recent element. - (@array [$($elems:expr),*] $unexpected:tt $($rest:tt)*) => { - crate::graphql_value!(@unexpected $unexpected) - }; - - //////////// - // Object // - //////////// - - // Done. - (@object $object:ident () () ()) => {}; - - // Insert the current entry followed by trailing comma. - (@object $object:ident [$($key:tt)+] ($value:expr) , $($rest:tt)*) => { - let _ = $object.add_field(($($key)+), $value); - $crate::graphql_value!(@object $object () ($($rest)*) ($($rest)*)); - }; - - // Current entry followed by unexpected token. - (@object $object:ident [$($key:tt)+] ($value:expr) $unexpected:tt $($rest:tt)*) => { - $crate::graphql_value!(@unexpected $unexpected); - }; - - // Insert the last entry without trailing comma. - (@object $object:ident [$($key:tt)+] ($value:expr)) => { - let _ = $object.add_field(($($key)+), $value); - }; - - // Next value is `null`. - (@object $object:ident ($($key:tt)+) (: null $($rest:tt)*) $copy:tt) => { - $crate::graphql_value!(@object $object [$($key)+] ($crate::graphql_value!(null)) $($rest)*); - }; - - // Next value is an array. - (@object $object:ident ($($key:tt)+) (: [$($array:tt)*] $($rest:tt)*) $copy:tt) => { - $crate::graphql_value!(@object $object [$($key)+] ($crate::graphql_value!([$($array)*])) $($rest)*); - }; - - // Next value is a map. - (@object $object:ident ($($key:tt)+) (: {$($map:tt)*} $($rest:tt)*) $copy:tt) => { - $crate::graphql_value!(@object $object [$($key)+] ($crate::graphql_value!({$($map)*})) $($rest)*); - }; - - // Next value is an expression followed by comma. - (@object $object:ident ($($key:tt)+) (: $value:expr , $($rest:tt)*) $copy:tt) => { - $crate::graphql_value!(@object $object [$($key)+] ($crate::graphql_value!($value)) , $($rest)*); - }; - - // Last value is an expression with no trailing comma. - (@object $object:ident ($($key:tt)+) (: $value:expr) $copy:tt) => { - $crate::graphql_value!(@object $object [$($key)+] ($crate::graphql_value!($value))); - }; - - // Missing value for last entry. Trigger a reasonable error message. - (@object $object:ident ($($key:tt)+) (:) $copy:tt) => { - // "unexpected end of macro invocation" - $crate::graphql_value!(); - }; - - // Missing colon and value for last entry. Trigger a reasonable error - // message. - (@object $object:ident ($($key:tt)+) () $copy:tt) => { - // "unexpected end of macro invocation" - $crate::graphql_value!(); - }; - - // Misplaced colon. Trigger a reasonable error message. - (@object $object:ident () (: $($rest:tt)*) ($colon:tt $($copy:tt)*)) => { - // Takes no arguments so "no rules expected the token `:`". - crate::graphql_value!(@unexpected $colon); - }; - - // Found a comma inside a key. Trigger a reasonable error message. - (@object $object:ident ($($key:tt)*) (, $($rest:tt)*) ($comma:tt $($copy:tt)*)) => { - // Takes no arguments so "no rules expected the token `,`". - crate::graphql_value!(@unexpected $comma); - }; - - // Key is fully parenthesized. This avoids clippy double_parens false - // positives because the parenthesization may be necessary here. - (@object $object:ident () (($key:expr) : $($rest:tt)*) $copy:tt) => { - $crate::graphql_value!(@object $object ($key) (: $($rest)*) (: $($rest)*)); - }; - - // Refuse to absorb colon token into key expression. - (@object $object:ident ($($key:tt)*) (: $($unexpected:tt)+) $copy:tt) => { - crate::graphql_value!(@unexpected $($unexpected)+); - }; - - // Munch a token into the current key. - (@object $object:ident ($($key:tt)*) ($tt:tt $($rest:tt)*) $copy:tt) => { - $crate::graphql_value!(@object $object ($($key)* $tt) ($($rest)*) ($($rest)*)); - }; - - //////////// - // Errors // - //////////// - - (@unexpected) => {}; - - ////////////// - // Defaults // - ////////////// - - ([ $($arr:tt)* ]) => { - $crate::graphql_value!(@array [] $($arr)*) - }; - - ({}) => { - $crate::Value::object($crate::Object::with_capacity(0)) - }; - - ({ $($map:tt)+ }) => { - $crate::Value::object({ - let mut object = $crate::Object::with_capacity(0); - $crate::graphql_value!(@object object () ($($map)*) ($($map)*)); - object - }) - }; - - (null) => ($crate::Value::null()); - - ($e:expr) => ($crate::Value::from($e)); -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn value_macro_string() { - let s: Value = graphql_value!("test"); - assert_eq!(s, Value::scalar("test")); - } - - #[test] - fn value_macro_int() { - let s: Value = graphql_value!(123); - assert_eq!(s, Value::scalar(123)); - } - - #[test] - fn value_macro_float() { - let s: Value = graphql_value!(123.5); - assert_eq!(s, Value::scalar(123.5)); - } - - #[test] - fn value_macro_boolean() { - let s: Value = graphql_value!(false); - assert_eq!(s, Value::scalar(false)); - } - - #[test] - fn value_macro_option() { - let s: Value = graphql_value!(Some("test")); - assert_eq!(s, Value::scalar("test")); - let s: Value = graphql_value!(null); - assert_eq!(s, Value::null()); - } - - #[test] - fn value_macro_list() { - let s: Value = graphql_value!([123, "Test", false]); - assert_eq!( - s, - Value::list(vec![ - Value::scalar(123), - Value::scalar("Test"), - Value::scalar(false), - ]) - ); - let s: Value = graphql_value!([123, [456], 789]); - assert_eq!( - s, - Value::list(vec![ - Value::scalar(123), - Value::list(vec![Value::scalar(456)]), - Value::scalar(789), - ]) - ); - let s: Value = graphql_value!([123, [1 + 2], 789]); - assert_eq!( - s, - Value::list(vec![ - Value::scalar(123), - Value::list(vec![Value::scalar(3)]), - Value::scalar(789), - ]) - ); - } - - #[test] - fn value_macro_object() { - let s: Value = graphql_value!({ "key": 123, "next": true }); - assert_eq!( - s, - Value::object( - vec![("key", Value::scalar(123)), ("next", Value::scalar(true))] - .into_iter() - .collect(), - ) - ); - let s: Value = graphql_value!({ "key": 1 + 2, "next": true }); - assert_eq!( - s, - Value::object( - vec![("key", Value::scalar(3)), ("next", Value::scalar(true))] - .into_iter() - .collect(), - ) - ); - } - - #[test] - fn display_null() { - let s: Value = graphql_value!(null); - assert_eq!("null", format!("{}", s)); - } - - #[test] - fn display_int() { - let s: Value = graphql_value!(123); - assert_eq!("123", format!("{}", s)); - } - - #[test] - fn display_float() { - let s: Value = graphql_value!(123.456); - assert_eq!("123.456", format!("{}", s)); - } - - #[test] - fn display_string() { - let s: Value = graphql_value!("foo"); - assert_eq!("\"foo\"", format!("{}", s)); - } - - #[test] - fn display_bool() { - let s: Value = graphql_value!(false); - assert_eq!("false", format!("{}", s)); - - let s: Value = graphql_value!(true); - assert_eq!("true", format!("{}", s)); - } - - #[test] - fn display_list() { - let s: Value = graphql_value!([1, null, "foo"]); - assert_eq!("[1, null, \"foo\"]", format!("{}", s)); - } - - #[test] - fn display_list_one_element() { - let s: Value = graphql_value!([1]); - assert_eq!("[1]", format!("{}", s)); - } - - #[test] - fn display_list_empty() { - let s: Value = graphql_value!([]); - assert_eq!("[]", format!("{}", s)); - } - - #[test] - fn display_object() { - let s: Value = graphql_value!({ - "int": 1, - "null": null, - "string": "foo", - }); - assert_eq!( - r#"{"int": 1, "null": null, "string": "foo"}"#, - format!("{}", s) - ); - } - - #[test] - fn display_object_one_field() { - let s: Value = graphql_value!({ - "int": 1, - }); - assert_eq!(r#"{"int": 1}"#, format!("{}", s)); - } - - #[test] - fn display_object_empty() { - let s: Value = graphql_value!({}); - assert_eq!(r#"{}"#, format!("{}", s)); - } -} From d787c0394ed374dfe5579c52bfab9642fcdc4196 Mon Sep 17 00:00:00 2001 From: ilslv Date: Wed, 24 Nov 2021 15:31:27 +0300 Subject: [PATCH 06/22] WIP [skip ci] --- juniper/src/ast/macros.rs | 259 +++++++++++++++++++++++++++++ juniper/src/{ast.rs => ast/mod.rs} | 42 +---- juniper/src/lib.rs | 1 + juniper/src/value/macros.rs | 14 +- 4 files changed, 269 insertions(+), 47 deletions(-) create mode 100644 juniper/src/ast/macros.rs rename juniper/src/{ast.rs => ast/mod.rs} (93%) diff --git a/juniper/src/ast/macros.rs b/juniper/src/ast/macros.rs new file mode 100644 index 000000000..dde5fb19a --- /dev/null +++ b/juniper/src/ast/macros.rs @@ -0,0 +1,259 @@ +/// Construct JSON-like [`InputValue`]s by using JSON syntax. +/// +/// __Note:__ [`InputValue::List`]s and [`InputValue::Object`]s will be created +/// in a [`Spanning::unlocated`]. +/// +/// # Example +/// +/// The resulting JSON will look just like what you passed in. +/// ```rust +/// # use juniper::{graphql_input_value, DefaultScalarValue, InputValue}; +/// # type V = InputValue; +/// # +/// # let _: V = +/// graphql_input_value!(null); +/// # let _: V = +/// graphql_input_value!(1234); +/// # let _: V = +/// graphql_input_value!("test"); +/// # let _: V = +/// graphql_input_value!([1234, "test", true]); +/// # let _: V = +/// graphql_input_value!({"key": "value", "foo": 1234}); +/// ``` +#[macro_export] +macro_rules! graphql_input_value { + /////////// + // Array // + /////////// + + // Done with trailing comma. + (@@array [$($elems:expr,)*]) => { + $crate::InputValue::list(vec![ + $( $elems, )* + ]) + }; + + // Done without trailing comma. + (@@array [$($elems:expr),*]) => { + $crate::InputValue::list(vec![ + $( $elems, )* + ]) + }; + + // Next element is `null`. + (@@array [$($elems:expr,)*] null $($rest:tt)*) => { + $crate::graphql_input_value!( + @@array [$($elems,)* $crate::graphql_input_value!(null)] $($rest)* + ) + }; + + // Next element is `variable`. + (@@array [$($elems:expr,)*] @$var:ident $($rest:tt)*) => { + $crate::graphql_input_value!( + @@array [$($elems,)* $crate::graphql_input_value!(@$var)] $($rest)* + ) + }; + + // Next element is `enum`. + (@@array [$($elems:expr,)*] $enum:ident $($rest:tt)*) => { + $crate::graphql_input_value!( + @@array [$($elems,)* $crate::graphql_input_value!($enum)] $($rest)* + ) + }; + + + // Next element is an array. + (@@array [$($elems:expr,)*] [$($array:tt)*] $($rest:tt)*) => { + $crate::graphql_input_value!( + @@array [$($elems,)* $crate::graphql_input_value!([$($array)*])] $($rest)* + ) + }; + + // Next element is a map. + (@@array [$($elems:expr,)*] {$($map:tt)*} $($rest:tt)*) => { + $crate::graphql_input_value!( + @@array [$($elems,)* $crate::graphql_input_value!({$($map)*})] $($rest)* + ) + }; + + // Next element is an expression followed by comma. + (@@array [$($elems:expr,)*] $next:expr, $($rest:tt)*) => { + $crate::graphql_input_value!( + @@array [$($elems,)* $crate::graphql_input_value!($next),] $($rest)* + ) + }; + + // Last element is an expression with no trailing comma. + (@@array [$($elems:expr,)*] $last:expr) => { + $crate::graphql_input_value!( + @@array [$($elems,)* $crate::graphql_input_value!($last)] + ) + }; + + // Comma after the most recent element. + (@@array [$($elems:expr),*] , $($rest:tt)*) => { + $crate::graphql_input_value!(@@array [$($elems,)*] $($rest)*) + }; + + // Unexpected token after most recent element. + (@@array [$($elems:expr),*] $unexpected:tt $($rest:tt)*) => { + $crate::graphql_input_value!(@unexpected $unexpected) + }; + + //////////// + // Object // + //////////// + + // Done. + (@@object $object:ident () () ()) => {}; + + // Insert the current entry followed by trailing comma. + (@@object $object:ident [$($key:tt)+] ($value:expr) , $($rest:tt)*) => { + let _ = $object.push(($crate::Spanning::unlocated(($($key)+).into()), $crate::Spanning::unlocated($value))); + $crate::graphql_input_value!(@@object $object () ($($rest)*) ($($rest)*)); + }; + + // Current entry followed by unexpected token. + (@@object $object:ident [$($key:tt)+] ($value:expr) $unexpected:tt $($rest:tt)*) => { + $crate::graphql_input_value!(@unexpected $unexpected); + }; + + // Insert the last entry without trailing comma. + (@@object $object:ident [$($key:tt)+] ($value:expr)) => { + let _ = $object.push(($crate::Spanning::unlocated(($($key)+).into()), $crate::Spanning::unlocated($value))); + }; + + // Next value is `null`. + (@@object $object:ident ($($key:tt)+) (: null $($rest:tt)*) $copy:tt) => { + $crate::graphql_input_value!(@@object $object [$($key)+] ($crate::graphql_input_value!(null)) $($rest)*); + }; + + // Next value is `variable`. + (@@object $object:ident ($($key:tt)+) (: @$var:ident $($rest:tt)*) $copy:tt) => { + $crate::graphql_input_value!(@@object $object [$($key)+] ($crate::graphql_input_value!(@$var)) $($rest)*); + }; + + // Next value is `enum`. + (@@object $object:ident ($($key:tt)+) (: $enum:ident $($rest:tt)*) $copy:tt) => { + $crate::graphql_input_value!(@@object $object [$($key)+] ($crate::graphql_input_value!($enum)) $($rest)*); + }; + + // Next value is an array. + (@@object $object:ident ($($key:tt)+) (: [$($array:tt)*] $($rest:tt)*) $copy:tt) => { + $crate::graphql_input_value!(@@object $object [$($key)+] ($crate::graphql_input_value!([$($array)*])) $($rest)*); + }; + + // Next value is a map. + (@@object $object:ident ($($key:tt)+) (: {$($map:tt)*} $($rest:tt)*) $copy:tt) => { + $crate::graphql_input_value!(@@object $object [$($key)+] ($crate::graphql_input_value!({$($map)*})) $($rest)*); + }; + + // Next value is an expression followed by comma. + (@@object $object:ident ($($key:tt)+) (: $value:expr , $($rest:tt)*) $copy:tt) => { + $crate::graphql_input_value!(@@object $object [$($key)+] ($crate::graphql_input_value!($value)) , $($rest)*); + }; + + // Last value is an expression with no trailing comma. + (@@object $object:ident ($($key:tt)+) (: $value:expr) $copy:tt) => { + $crate::graphql_input_value!(@@object $object [$($key)+] ($crate::graphql_input_value!($value))); + }; + + // Missing value for last entry. Trigger a reasonable error message. + (@@object $object:ident ($($key:tt)+) (:) $copy:tt) => { + // "unexpected end of macro invocation" + $crate::graphql_input_value!(); + }; + + // Missing colon and value for last entry. Trigger a reasonable error + // message. + (@@object $object:ident ($($key:tt)+) () $copy:tt) => { + // "unexpected end of macro invocation" + $crate::graphql_input_value!(); + }; + + // Misplaced colon. Trigger a reasonable error message. + (@@object $object:ident () (: $($rest:tt)*) ($colon:tt $($copy:tt)*)) => { + // Takes no arguments so "no rules expected the token `:`". + $crate::graphql_input_value!(@unexpected $colon); + }; + + // Found a comma inside a key. Trigger a reasonable error message. + (@@object $object:ident ($($key:tt)*) (, $($rest:tt)*) ($comma:tt $($copy:tt)*)) => { + // Takes no arguments so "no rules expected the token `,`". + $crate::graphql_input_value!(@unexpected $comma); + }; + + // Key is fully parenthesized. This avoids clippy double_parens false + // positives because the parenthesization may be necessary here. + (@@object $object:ident () (($key:expr) : $($rest:tt)*) $copy:tt) => { + $crate::graphql_input_value!(@@object $object ($key) (: $($rest)*) (: $($rest)*)); + }; + + // Refuse to absorb colon token into key expression. + (@@object $object:ident ($($key:tt)*) (: $($unexpected:tt)+) $copy:tt) => { + $crate::graphql_input_value!(@unexpected $($unexpected)+); + }; + + // Munch a token into the current key. + (@@object $object:ident ($($key:tt)*) ($tt:tt $($rest:tt)*) $copy:tt) => { + $crate::graphql_input_value!(@@object $object ($($key)* $tt) ($($rest)*) ($($rest)*)); + }; + + //////////// + // Errors // + //////////// + + (@unexpected) => {}; + + ////////////// + // Defaults // + ////////////// + + ([ $($arr:tt)* ]) => { + $crate::graphql_input_value!(@@array [] $($arr)*) + }; + + ({}) => { + $crate::InputValue::parsed_object(vec![]) + }; + + ({ $($map:tt)+ }) => { + $crate::InputValue::parsed_object({ + let mut object = vec![]; + $crate::graphql_input_value!(@@object object () ($($map)*) ($($map)*)); + object + }) + }; + + (null) => ($crate::InputValue::null()); + + (@$var:ident) => ($crate::InputValue::variable(stringify!($var))); + + ($enum:ident) => ($crate::InputValue::enum_value(stringify!($enum))); + + ($e:expr) => ($crate::InputValue::scalar($e)); +} + +#[cfg(test)] +mod test { + use crate::{DefaultScalarValue, InputValue}; + + #[test] + fn test() { + assert_eq!( + InputValue::::variable("var"), + graphql_input_value!(@var), + ); + assert_eq!( + InputValue::::enum_value("ENUM"), + graphql_input_value!(ENUM), + ); + + let _: InputValue = graphql_input_value!({ "key": @var }); + let _: InputValue = graphql_input_value!({ "key": @var, }); + let _: InputValue = graphql_input_value!({ "key": @var, "k": 1 + 2 }); + let _: InputValue = graphql_input_value!([@var]); + let _: InputValue = graphql_input_value!([]); + } +} diff --git a/juniper/src/ast.rs b/juniper/src/ast/mod.rs similarity index 93% rename from juniper/src/ast.rs rename to juniper/src/ast/mod.rs index 7a49bef35..e4dca236a 100644 --- a/juniper/src/ast.rs +++ b/juniper/src/ast/mod.rs @@ -1,3 +1,6 @@ +#[macro_use] +mod macros; + use std::{borrow::Cow, fmt, hash::Hash, slice, vec}; use indexmap::IndexMap; @@ -472,45 +475,6 @@ impl fmt::Display for InputValue { } } -/// Construct JSON-like [`InputValue`]s by using JSON syntax. -/// -/// __Note:__ [`InputValue::List`]s and [`InputValue::Object`]s will be created -/// in a [`Spanning::unlocated`]. -/// -/// # Example -/// -/// The resulting JSON will look just like what you passed in. -/// ```rust -/// # use juniper::{graphql_input_value, DefaultScalarValue, InputValue}; -/// # type V = InputValue; -/// # -/// # let _: V = -/// graphql_input_value!(None); -/// # let _: V = -/// graphql_input_value!(1234); -/// # let _: V = -/// graphql_input_value!("test"); -/// # let _: V = -/// graphql_input_value!([1234, "test", true]); -/// # let _: V = -/// graphql_input_value!({"key": "value", "foo": 1234}); -/// ``` -#[macro_export] -macro_rules! graphql_input_value { - ([ $($arg:tt),* $(,)* ]) => { - $crate::InputValue::list(vec![ - $( $crate::graphql_input_value!($arg), )* - ]) - }; - ({ $($key:tt : $val:expr ),* $(,)* }) => { - $crate::InputValue::object(::std::array::IntoIter::new([ - $( ($key, $crate::graphql_input_value!($val)), )* - ]).collect()) - }; - (None) => ($crate::InputValue::Null); - ($e:expr) => ($crate::InputValue::scalar($e)) -} - impl<'a, S> Arguments<'a, S> { pub fn into_iter(self) -> vec::IntoIter<(Spanning<&'a str>, Spanning>)> { self.items.into_iter() diff --git a/juniper/src/lib.rs b/juniper/src/lib.rs index d7d66238e..b62d7105e 100644 --- a/juniper/src/lib.rs +++ b/juniper/src/lib.rs @@ -120,6 +120,7 @@ pub use juniper_codegen::{ mod value; #[macro_use] mod macros; +#[macro_use] mod ast; pub mod executor; mod introspection; diff --git a/juniper/src/value/macros.rs b/juniper/src/value/macros.rs index aae589b15..03eb771b4 100644 --- a/juniper/src/value/macros.rs +++ b/juniper/src/value/macros.rs @@ -1,5 +1,3 @@ -use super::{DefaultScalarValue, Value}; - /// Construct JSON-like [`Value`]s by using JSON syntax. /// /// [`Value`] objects are used mostly when creating custom errors from fields. @@ -31,7 +29,7 @@ macro_rules! graphql_value { // Done with trailing comma. (@array [$($elems:expr,)*]) => { $crate::Value::list(vec![ - $( $crate::graphql_value!($elems), )* + $( $elems, )* ]) }; @@ -84,7 +82,7 @@ macro_rules! graphql_value { // Unexpected token after most recent element. (@array [$($elems:expr),*] $unexpected:tt $($rest:tt)*) => { - crate::graphql_value!(@unexpected $unexpected) + $crate::graphql_value!(@unexpected $unexpected) }; //////////// @@ -151,13 +149,13 @@ macro_rules! graphql_value { // Misplaced colon. Trigger a reasonable error message. (@object $object:ident () (: $($rest:tt)*) ($colon:tt $($copy:tt)*)) => { // Takes no arguments so "no rules expected the token `:`". - crate::graphql_value!(@unexpected $colon); + $crate::graphql_value!(@unexpected $colon); }; // Found a comma inside a key. Trigger a reasonable error message. (@object $object:ident ($($key:tt)*) (, $($rest:tt)*) ($comma:tt $($copy:tt)*)) => { // Takes no arguments so "no rules expected the token `,`". - crate::graphql_value!(@unexpected $comma); + $crate::graphql_value!(@unexpected $comma); }; // Key is fully parenthesized. This avoids clippy double_parens false @@ -168,7 +166,7 @@ macro_rules! graphql_value { // Refuse to absorb colon token into key expression. (@object $object:ident ($($key:tt)*) (: $($unexpected:tt)+) $copy:tt) => { - crate::graphql_value!(@unexpected $($unexpected)+); + $crate::graphql_value!(@unexpected $($unexpected)+); }; // Munch a token into the current key. @@ -209,7 +207,7 @@ macro_rules! graphql_value { #[cfg(test)] mod tests { - use super::*; + use crate::{DefaultScalarValue, Value}; #[test] fn value_macro_string() { From 56a32d384866a589a410c1cd57da270897385c20 Mon Sep 17 00:00:00 2001 From: ilslv Date: Wed, 24 Nov 2021 17:22:52 +0300 Subject: [PATCH 07/22] Add more tests --- juniper/src/ast/macros.rs | 241 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 230 insertions(+), 11 deletions(-) diff --git a/juniper/src/ast/macros.rs b/juniper/src/ast/macros.rs index dde5fb19a..031ba9f72 100644 --- a/juniper/src/ast/macros.rs +++ b/juniper/src/ast/macros.rs @@ -232,28 +232,247 @@ macro_rules! graphql_input_value { ($enum:ident) => ($crate::InputValue::enum_value(stringify!($enum))); + (($e:expr)) => ($crate::InputValue::scalar($e)); + ($e:expr) => ($crate::InputValue::scalar($e)); } #[cfg(test)] -mod test { +mod tests { + use indexmap::{indexmap, IndexMap}; + use crate::{DefaultScalarValue, InputValue}; + type V = InputValue; + + #[test] + fn null() { + assert_eq!(graphql_input_value!(null), V::Null); + } + + #[test] + fn scalar() { + let val = 42; + assert_eq!(graphql_input_value!(1), V::scalar(1)); + assert_eq!(graphql_input_value!("val"), V::scalar("val")); + assert_eq!(graphql_input_value!(1 + 2), V::scalar(3)); + assert_eq!(graphql_input_value!((val)), V::scalar(42)); + } + + #[test] + fn enums() { + assert_eq!(graphql_input_value!(ENUM), V::enum_value("ENUM")); + assert_eq!(graphql_input_value!(lowercase), V::enum_value("lowercase")); + } + + #[test] + fn variables() { + assert_eq!(graphql_input_value!(@var), V::variable("var")); + assert_eq!(graphql_input_value!(@array), V::variable("array")); + assert_eq!(graphql_input_value!(@object), V::variable("object")); + } + + #[test] + fn lists() { + let val = 42; + assert_eq!(graphql_input_value!([]), V::list(vec![])); + + assert_eq!(graphql_input_value!([null]), V::list(vec![V::Null])); + + assert_eq!(graphql_input_value!([1]), V::list(vec![V::scalar(1)])); + assert_eq!(graphql_input_value!([1 + 2]), V::list(vec![V::scalar(3)])); + assert_eq!(graphql_input_value!([(val)]), V::list(vec![V::scalar(42)])); + + assert_eq!( + graphql_input_value!([ENUM]), + V::list(vec![V::enum_value("ENUM")]), + ); + assert_eq!( + graphql_input_value!([lowercase]), + V::list(vec![V::enum_value("lowercase")]), + ); + + assert_eq!( + graphql_input_value!([@var]), + V::list(vec![V::variable("var")]), + ); + assert_eq!( + graphql_input_value!([@array]), + V::list(vec![V::variable("array")]), + ); + assert_eq!( + graphql_input_value!([@object]), + V::list(vec![V::variable("object")]), + ); + + assert_eq!( + graphql_input_value!([1, [2], 3]), + V::list(vec![ + V::scalar(1), + V::list(vec![V::scalar(2)]), + V::scalar(3), + ]), + ); + assert_eq!( + graphql_input_value!([1, [2 + 3], 3]), + V::list(vec![ + V::scalar(1), + V::list(vec![V::scalar(5)]), + V::scalar(3), + ]), + ); + assert_eq!( + graphql_input_value!([1, [ENUM], (val),]), + V::list(vec![ + V::scalar(1), + V::list(vec![V::enum_value("ENUM")]), + V::scalar(42), + ]), + ); + assert_eq!( + graphql_input_value!([1 + 2, [(val)], @val,]), + V::list(vec![ + V::scalar(3), + V::list(vec![V::scalar(42)]), + V::variable("val"), + ]), + ); + assert_eq!( + graphql_input_value!([1, [@val], ENUM,]), + V::list(vec![ + V::scalar(1), + V::list(vec![V::variable("val")]), + V::enum_value("ENUM"), + ]), + ); + assert_eq!( + graphql_input_value!({ "key": ENUM }), + V::object(indexmap! { "key" => V::enum_value("ENUM") }), + ); + assert_eq!( + graphql_input_value!({ "key": lowercase }), + V::object(indexmap! { "key" => V::enum_value("lowercase") }), + ); + assert_eq!( + graphql_input_value!({ "key": @var }), + V::object(indexmap! { "key" => V::variable("var") }), + ); + assert_eq!( + graphql_input_value!({ "key": @array }), + V::object(indexmap! { "key" => V::variable("array") }), + ); + } + #[test] - fn test() { + fn objects() { + let val = 42; + assert_eq!( + graphql_input_value!({}), + V::object(IndexMap::::new()), + ); + + assert_eq!( + graphql_input_value!({ "key": null }), + V::object(indexmap! { "key" => V::Null }), + ); + + assert_eq!( + graphql_input_value!({ "key": 123 }), + V::object(indexmap! { "key" => V::scalar(123) }), + ); + assert_eq!( + graphql_input_value!({ "key": 1 + 2 }), + V::object(indexmap! { "key" => V::scalar(3) }), + ); + assert_eq!( + graphql_input_value!({ "key": (val) }), + V::object(indexmap! { "key" => V::scalar(42) }), + ); + + assert_eq!( + graphql_input_value!({ "key": [] }), + V::object(indexmap! { "key" => V::list(vec![]) }), + ); + assert_eq!( + graphql_input_value!({ "key": [null] }), + V::object(indexmap! { "key" => V::list(vec![V::Null]) }), + ); + assert_eq!( + graphql_input_value!({ "key": [1] }), + V::object(indexmap! { "key" => V::list(vec![V::scalar(1)]) }), + ); assert_eq!( - InputValue::::variable("var"), - graphql_input_value!(@var), + graphql_input_value!({ "key": [1 + 2] }), + V::object(indexmap! { "key" => V::list(vec![V::scalar(3)]) }), ); assert_eq!( - InputValue::::enum_value("ENUM"), - graphql_input_value!(ENUM), + graphql_input_value!({ "key": [(val)] }), + V::object(indexmap! { "key" => V::list(vec![V::scalar(42)]) }), + ); + assert_eq!( + graphql_input_value!({ "key": ENUM }), + V::object(indexmap! { "key" => V::enum_value("ENUM") }), + ); + assert_eq!( + graphql_input_value!({ "key": lowercase }), + V::object(indexmap! { "key" => V::enum_value("lowercase") }), + ); + assert_eq!( + graphql_input_value!({ "key": @val }), + V::object(indexmap! { "key" => V::variable("val") }), + ); + assert_eq!( + graphql_input_value!({ "key": @array }), + V::object(indexmap! { "key" => V::variable("array") }), ); - let _: InputValue = graphql_input_value!({ "key": @var }); - let _: InputValue = graphql_input_value!({ "key": @var, }); - let _: InputValue = graphql_input_value!({ "key": @var, "k": 1 + 2 }); - let _: InputValue = graphql_input_value!([@var]); - let _: InputValue = graphql_input_value!([]); + assert_eq!( + graphql_input_value!({ + "inner": { + "key1": (val), + "key2": "val", + "key3": [ + { + "inner": 42, + }, + { + "inner": ENUM, + "even-more": { + "var": @var, + }, + } + ], + "key4": [1, ["val", 1 + 3], null, @array], + }, + "more": @var, + }), + V::object(indexmap! { + "inner" => V::object(indexmap! { + "key1" => V::scalar(42), + "key2" => V::scalar("val"), + "key3" => V::list(vec![ + V::object(indexmap! { + "inner" => V::scalar(42), + }), + V::object(indexmap! { + "inner" => V::enum_value("ENUM"), + "even-more" => V::object(indexmap! { + "var" => V::variable("var"), + }) + }), + ]), + "key4" => V::list(vec![ + V::scalar(1), + V::list(vec![ + V::scalar("val"), + V::scalar(4), + ]), + V::Null, + V::variable("array"), + ]), + }), + "more" => V::variable("var"), + }), + ); } } From 6789a18139059366feee4047ba5b4ae71db0b73b Mon Sep 17 00:00:00 2001 From: ilslv Date: Wed, 24 Nov 2021 17:26:21 +0300 Subject: [PATCH 08/22] WIP --- juniper/src/ast/macros.rs | 2 + juniper/src/value/macros.rs | 78 ---------------------------------- juniper/src/value/mod.rs | 83 +++++++++++++++++++++++++++++++++++++ 3 files changed, 85 insertions(+), 78 deletions(-) diff --git a/juniper/src/ast/macros.rs b/juniper/src/ast/macros.rs index 031ba9f72..e7a77bffa 100644 --- a/juniper/src/ast/macros.rs +++ b/juniper/src/ast/macros.rs @@ -255,6 +255,8 @@ mod tests { let val = 42; assert_eq!(graphql_input_value!(1), V::scalar(1)); assert_eq!(graphql_input_value!("val"), V::scalar("val")); + assert_eq!(graphql_input_value!(1.34), V::scalar(1.34)); + assert_eq!(graphql_input_value!(false), V::scalar(false)); assert_eq!(graphql_input_value!(1 + 2), V::scalar(3)); assert_eq!(graphql_input_value!((val)), V::scalar(42)); } diff --git a/juniper/src/value/macros.rs b/juniper/src/value/macros.rs index 03eb771b4..eb1279988 100644 --- a/juniper/src/value/macros.rs +++ b/juniper/src/value/macros.rs @@ -293,82 +293,4 @@ mod tests { ) ); } - - #[test] - fn display_null() { - let s: Value = graphql_value!(null); - assert_eq!("null", format!("{}", s)); - } - - #[test] - fn display_int() { - let s: Value = graphql_value!(123); - assert_eq!("123", format!("{}", s)); - } - - #[test] - fn display_float() { - let s: Value = graphql_value!(123.456); - assert_eq!("123.456", format!("{}", s)); - } - - #[test] - fn display_string() { - let s: Value = graphql_value!("foo"); - assert_eq!("\"foo\"", format!("{}", s)); - } - - #[test] - fn display_bool() { - let s: Value = graphql_value!(false); - assert_eq!("false", format!("{}", s)); - - let s: Value = graphql_value!(true); - assert_eq!("true", format!("{}", s)); - } - - #[test] - fn display_list() { - let s: Value = graphql_value!([1, null, "foo"]); - assert_eq!("[1, null, \"foo\"]", format!("{}", s)); - } - - #[test] - fn display_list_one_element() { - let s: Value = graphql_value!([1]); - assert_eq!("[1]", format!("{}", s)); - } - - #[test] - fn display_list_empty() { - let s: Value = graphql_value!([]); - assert_eq!("[]", format!("{}", s)); - } - - #[test] - fn display_object() { - let s: Value = graphql_value!({ - "int": 1, - "null": null, - "string": "foo", - }); - assert_eq!( - r#"{"int": 1, "null": null, "string": "foo"}"#, - format!("{}", s) - ); - } - - #[test] - fn display_object_one_field() { - let s: Value = graphql_value!({ - "int": 1, - }); - assert_eq!(r#"{"int": 1}"#, format!("{}", s)); - } - - #[test] - fn display_object_empty() { - let s: Value = graphql_value!({}); - assert_eq!(r#"{}"#, format!("{}", s)); - } } diff --git a/juniper/src/value/mod.rs b/juniper/src/value/mod.rs index 070e4902f..622e07d6d 100644 --- a/juniper/src/value/mod.rs +++ b/juniper/src/value/mod.rs @@ -277,3 +277,86 @@ impl> From for Value { Self::scalar(b) } } + +#[cfg(test)] +mod tests { + use super::{DefaultScalarValue, Value}; + + #[test] + fn display_null() { + let s: Value = graphql_value!(null); + assert_eq!("null", format!("{}", s)); + } + + #[test] + fn display_int() { + let s: Value = graphql_value!(123); + assert_eq!("123", format!("{}", s)); + } + + #[test] + fn display_float() { + let s: Value = graphql_value!(123.456); + assert_eq!("123.456", format!("{}", s)); + } + + #[test] + fn display_string() { + let s: Value = graphql_value!("foo"); + assert_eq!("\"foo\"", format!("{}", s)); + } + + #[test] + fn display_bool() { + let s: Value = graphql_value!(false); + assert_eq!("false", format!("{}", s)); + + let s: Value = graphql_value!(true); + assert_eq!("true", format!("{}", s)); + } + + #[test] + fn display_list() { + let s: Value = graphql_value!([1, null, "foo"]); + assert_eq!("[1, null, \"foo\"]", format!("{}", s)); + } + + #[test] + fn display_list_one_element() { + let s: Value = graphql_value!([1]); + assert_eq!("[1]", format!("{}", s)); + } + + #[test] + fn display_list_empty() { + let s: Value = graphql_value!([]); + assert_eq!("[]", format!("{}", s)); + } + + #[test] + fn display_object() { + let s: Value = graphql_value!({ + "int": 1, + "null": null, + "string": "foo", + }); + assert_eq!( + r#"{"int": 1, "null": null, "string": "foo"}"#, + format!("{}", s) + ); + } + + #[test] + fn display_object_one_field() { + let s: Value = graphql_value!({ + "int": 1, + }); + assert_eq!(r#"{"int": 1}"#, format!("{}", s)); + } + + #[test] + fn display_object_empty() { + let s: Value = graphql_value!({}); + assert_eq!(r#"{}"#, format!("{}", s)); + } +} From a000a0b66085d2ee7337ce5a3cef7c863ffd3607 Mon Sep 17 00:00:00 2001 From: ilslv Date: Wed, 24 Nov 2021 17:40:14 +0300 Subject: [PATCH 09/22] Add more tests to the graphql_value! macro --- juniper/src/value/macros.rs | 133 ++++++++++++++++++++---------------- 1 file changed, 74 insertions(+), 59 deletions(-) diff --git a/juniper/src/value/macros.rs b/juniper/src/value/macros.rs index eb1279988..a6db12fe5 100644 --- a/juniper/src/value/macros.rs +++ b/juniper/src/value/macros.rs @@ -209,88 +209,103 @@ macro_rules! graphql_value { mod tests { use crate::{DefaultScalarValue, Value}; - #[test] - fn value_macro_string() { - let s: Value = graphql_value!("test"); - assert_eq!(s, Value::scalar("test")); - } + type V = Value; #[test] - fn value_macro_int() { - let s: Value = graphql_value!(123); - assert_eq!(s, Value::scalar(123)); + fn null() { + assert_eq!(graphql_value!(null), V::Null); } #[test] - fn value_macro_float() { - let s: Value = graphql_value!(123.5); - assert_eq!(s, Value::scalar(123.5)); + fn scalar() { + let val = 42; + assert_eq!(graphql_value!(1), V::scalar(1)); + assert_eq!(graphql_value!("val"), V::scalar("val")); + assert_eq!(graphql_value!(1.34), V::scalar(1.34)); + assert_eq!(graphql_value!(false), V::scalar(false)); + assert_eq!(graphql_value!(1 + 2), V::scalar(3)); + assert_eq!(graphql_value!(val), V::scalar(42)); } #[test] - fn value_macro_boolean() { - let s: Value = graphql_value!(false); - assert_eq!(s, Value::scalar(false)); - } + fn lists() { + let val = 42; + assert_eq!(graphql_value!([]), V::list(vec![])); - #[test] - fn value_macro_option() { - let s: Value = graphql_value!(Some("test")); - assert_eq!(s, Value::scalar("test")); - let s: Value = graphql_value!(null); - assert_eq!(s, Value::null()); + assert_eq!(graphql_value!([null]), V::list(vec![V::Null])); + + assert_eq!(graphql_value!([1]), V::list(vec![V::scalar(1)])); + assert_eq!(graphql_value!([1 + 2]), V::list(vec![V::scalar(3)])); + assert_eq!(graphql_value!([val]), V::list(vec![V::scalar(42)])); + + assert_eq!( + graphql_value!([1, [2], 3]), + V::list(vec![ + V::scalar(1), + V::list(vec![V::scalar(2)]), + V::scalar(3), + ]), + ); + assert_eq!( + graphql_value!(["string", [2 + 3], true,]), + V::list(vec![ + V::scalar("string"), + V::list(vec![V::scalar(5)]), + V::scalar(true), + ]), + ); } #[test] - fn value_macro_list() { - let s: Value = graphql_value!([123, "Test", false]); + fn objects() { + let val = 42; assert_eq!( - s, - Value::list(vec![ - Value::scalar(123), - Value::scalar("Test"), - Value::scalar(false), - ]) + graphql_value!({}), + V::object(Vec::<(String, _)>::new().into_iter().collect()) ); - let s: Value = graphql_value!([123, [456], 789]); assert_eq!( - s, - Value::list(vec![ - Value::scalar(123), - Value::list(vec![Value::scalar(456)]), - Value::scalar(789), - ]) + graphql_value!({ "key": null }), + V::object(vec![("key", V::Null)].into_iter().collect()), ); - let s: Value = graphql_value!([123, [1 + 2], 789]); assert_eq!( - s, - Value::list(vec![ - Value::scalar(123), - Value::list(vec![Value::scalar(3)]), - Value::scalar(789), - ]) + graphql_value!({ "key": 123 }), + V::object(vec![("key", V::scalar(123))].into_iter().collect()), + ); + assert_eq!( + graphql_value!({ "key": 1 + 2 }), + V::object(vec![("key", V::scalar(3))].into_iter().collect()), + ); + assert_eq!( + graphql_value!({ "key": [] }), + V::object(vec![("key", V::list(vec![]))].into_iter().collect()), + ); + assert_eq!( + graphql_value!({ "key": [null] }), + V::object(vec![("key", V::list(vec![V::Null]))].into_iter().collect()), + ); + assert_eq!( + graphql_value!({ "key": [1] }), + V::object( + vec![("key", V::list(vec![V::scalar(1)]))] + .into_iter() + .collect() + ), ); - } - - #[test] - fn value_macro_object() { - let s: Value = graphql_value!({ "key": 123, "next": true }); assert_eq!( - s, - Value::object( - vec![("key", Value::scalar(123)), ("next", Value::scalar(true))] + graphql_value!({ "key": [1 + 2] }), + V::object( + vec![("key", V::list(vec![V::scalar(3)]))] .into_iter() - .collect(), - ) + .collect() + ), ); - let s: Value = graphql_value!({ "key": 1 + 2, "next": true }); assert_eq!( - s, - Value::object( - vec![("key", Value::scalar(3)), ("next", Value::scalar(true))] + graphql_value!({ "key": [val] }), + V::object( + vec![("key", V::list(vec![V::scalar(42)]))] .into_iter() - .collect(), - ) + .collect() + ), ); } } From 6a819e1450854425b4b22363c362875788e1a4a0 Mon Sep 17 00:00:00 2001 From: ilslv Date: Wed, 24 Nov 2021 18:28:12 +0300 Subject: [PATCH 10/22] Hack around `ident` accepting keywords too --- .../juniper_tests/src/codegen/derive_enum.rs | 12 +- .../src/codegen/derive_input_object.rs | 6 +- .../src/codegen/scalar_value_transparent.rs | 8 +- juniper/src/ast/macros.rs | 4 + juniper/src/ast/mod.rs | 29 +-- juniper/src/executor/look_ahead.rs | 4 +- juniper/src/executor_tests/enums.rs | 6 +- juniper/src/executor_tests/executor.rs | 2 +- .../introspection/input_object.rs | 12 +- juniper/src/executor_tests/variables.rs | 225 ++++++------------ juniper/src/integrations/bson.rs | 4 +- juniper/src/integrations/chrono.rs | 8 +- juniper/src/integrations/serde.rs | 6 +- juniper/src/parser/tests/value.rs | 18 +- juniper/src/parser/value.rs | 6 +- juniper/src/tests/query_tests.rs | 4 +- juniper_graphql_ws/src/client_message.rs | 7 +- 17 files changed, 141 insertions(+), 220 deletions(-) diff --git a/integration_tests/juniper_tests/src/codegen/derive_enum.rs b/integration_tests/juniper_tests/src/codegen/derive_enum.rs index 26b0f2e1f..cb3a9f493 100644 --- a/integration_tests/juniper_tests/src/codegen/derive_enum.rs +++ b/integration_tests/juniper_tests/src/codegen/derive_enum.rs @@ -58,6 +58,8 @@ enum ContextEnum { #[test] fn test_derived_enum() { + use juniper::graphql_input_value; + // Ensure that rename works. assert_eq!( >::name(&()), @@ -74,26 +76,26 @@ fn test_derived_enum() { // Test no rename variant. assert_eq!( <_ as ToInputValue>::to_input_value(&NoRenameEnum::AnotherVariant), - InputValue::scalar("AnotherVariant") + graphql_input_value!("AnotherVariant"), ); // Test Regular variant. assert_eq!( <_ as ToInputValue>::to_input_value(&SomeEnum::Regular), - InputValue::scalar("REGULAR") + graphql_input_value!("REGULAR") ); assert_eq!( - FromInputValue::::from_input_value(&InputValue::scalar("REGULAR")), + FromInputValue::::from_input_value(&graphql_input_value!("REGULAR")), Some(SomeEnum::Regular) ); // Test FULL variant. assert_eq!( <_ as ToInputValue>::to_input_value(&SomeEnum::Full), - InputValue::scalar("FULL") + graphql_input_value!("FULL") ); assert_eq!( - FromInputValue::::from_input_value(&InputValue::scalar("FULL")), + FromInputValue::::from_input_value(&graphql_input_value!("FULL")), Some(SomeEnum::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 e84eed13b..805f5f638 100644 --- a/integration_tests/juniper_tests/src/codegen/derive_input_object.rs +++ b/integration_tests/juniper_tests/src/codegen/derive_input_object.rs @@ -1,7 +1,7 @@ use fnv::FnvHashMap; use juniper::{ - graphql_input_value, marker, DefaultScalarValue, FromInputValue, GraphQLInputObject, GraphQLType, GraphQLValue, - InputValue, Registry, ToInputValue, + graphql_input_value, marker, DefaultScalarValue, FromInputValue, GraphQLInputObject, + GraphQLType, GraphQLValue, InputValue, Registry, ToInputValue, }; #[derive(GraphQLInputObject, Debug, PartialEq)] @@ -65,7 +65,7 @@ impl<'a> FromInputValue for &'a Fake { impl<'a> ToInputValue for &'a Fake { fn to_input_value(&self) -> InputValue { - InputValue::scalar("this is fake") + graphql_input_value!("this is fake") } } diff --git a/integration_tests/juniper_tests/src/codegen/scalar_value_transparent.rs b/integration_tests/juniper_tests/src/codegen/scalar_value_transparent.rs index 613d6394f..510a71f11 100644 --- a/integration_tests/juniper_tests/src/codegen/scalar_value_transparent.rs +++ b/integration_tests/juniper_tests/src/codegen/scalar_value_transparent.rs @@ -1,7 +1,7 @@ use fnv::FnvHashMap; use juniper::{ - graphql_object, DefaultScalarValue, FromInputValue, GraphQLObject, GraphQLScalarValue, - GraphQLType, InputValue, Registry, ToInputValue, + graphql_input_value, graphql_object, DefaultScalarValue, FromInputValue, GraphQLObject, + GraphQLScalarValue, GraphQLType, InputValue, Registry, ToInputValue, }; #[derive(GraphQLScalarValue, Debug, Eq, PartialEq)] @@ -50,7 +50,7 @@ fn test_scalar_value_simple() { let id = UserId("111".into()); let output = ToInputValue::::to_input_value(&id); - assert_eq!(output, InputValue::scalar("111"),); + assert_eq!(output, graphql_input_value!("111"),); } #[test] @@ -71,7 +71,7 @@ fn test_scalar_value_custom() { let id = CustomUserId("111".into()); let output = ToInputValue::::to_input_value(&id); - assert_eq!(output, InputValue::scalar("111"),); + assert_eq!(output, graphql_input_value!("111"),); } #[test] diff --git a/juniper/src/ast/macros.rs b/juniper/src/ast/macros.rs index e7a77bffa..4755d648e 100644 --- a/juniper/src/ast/macros.rs +++ b/juniper/src/ast/macros.rs @@ -228,6 +228,10 @@ macro_rules! graphql_input_value { (null) => ($crate::InputValue::null()); + (true) => ($crate::InputValue::scalar(true)); + + (false) => ($crate::InputValue::scalar(false)); + (@$var:ident) => ($crate::InputValue::variable(stringify!($var))); ($enum:ident) => ($crate::InputValue::enum_value(stringify!($enum))); diff --git a/juniper/src/ast/mod.rs b/juniper/src/ast/mod.rs index e4dca236a..a497fb233 100644 --- a/juniper/src/ast/mod.rs +++ b/juniper/src/ast/mod.rs @@ -514,42 +514,31 @@ mod tests { #[test] fn test_input_value_fmt() { - let value: InputValue = InputValue::null(); + let value: InputValue = graphql_input_value!(null); assert_eq!(format!("{}", value), "null"); - let value: InputValue = InputValue::scalar(123); + let value: InputValue = graphql_input_value!(123); assert_eq!(format!("{}", value), "123"); - let value: InputValue = InputValue::scalar(12.3); + let value: InputValue = graphql_input_value!(12.3); assert_eq!(format!("{}", value), "12.3"); - let value: InputValue = InputValue::scalar("FOO".to_owned()); + let value: InputValue = graphql_input_value!("FOO"); assert_eq!(format!("{}", value), "\"FOO\""); - let value: InputValue = InputValue::scalar(true); + let value: InputValue = graphql_input_value!(true); assert_eq!(format!("{}", value), "true"); - let value: InputValue = InputValue::enum_value("BAR".to_owned()); + let value: InputValue = graphql_input_value!(BAR); assert_eq!(format!("{}", value), "BAR"); - let value: InputValue = InputValue::variable("baz".to_owned()); + let value: InputValue = graphql_input_value!(@baz); assert_eq!(format!("{}", value), "$baz"); - let list = vec![InputValue::scalar(1), InputValue::scalar(2)]; - let value: InputValue = InputValue::list(list); + let value: InputValue = graphql_input_value!([1, 2]); assert_eq!(format!("{}", value), "[1, 2]"); - let object = vec![ - ( - Spanning::unlocated("foo".to_owned()), - Spanning::unlocated(InputValue::scalar(1)), - ), - ( - Spanning::unlocated("bar".to_owned()), - Spanning::unlocated(InputValue::scalar(2)), - ), - ]; - let value: InputValue = InputValue::parsed_object(object); + let value: InputValue = graphql_input_value!({ "foo": 1, "bar": 2 }); assert_eq!(format!("{}", value), "{foo: 1, bar: 2}"); } } diff --git a/juniper/src/executor/look_ahead.rs b/juniper/src/executor/look_ahead.rs index f7f020b3e..b2a3b336d 100644 --- a/juniper/src/executor/look_ahead.rs +++ b/juniper/src/executor/look_ahead.rs @@ -743,7 +743,7 @@ query Hero($episode: Episode) { if let crate::ast::Definition::Operation(ref op) = docs[0] { let mut vars = Variables::default(); - vars.insert("episode".into(), InputValue::Enum("JEDI".into())); + vars.insert("episode".into(), graphql_input_value!(JEDI)); let look_ahead = LookAheadSelection::build_from_selection( &op.item.selection_set[0], &vars, @@ -1113,7 +1113,7 @@ fragment comparisonFields on Character { if let crate::ast::Definition::Operation(ref op) = docs[0] { let mut vars = Variables::default(); - vars.insert("id".into(), InputValue::Scalar(DefaultScalarValue::Int(42))); + vars.insert("id".into(), graphql_input_value!(42)); // This will normally be there vars.insert( "withFriends".into(), diff --git a/juniper/src/executor_tests/enums.rs b/juniper/src/executor_tests/enums.rs index 8528aa11c..f4f943c55 100644 --- a/juniper/src/executor_tests/enums.rs +++ b/juniper/src/executor_tests/enums.rs @@ -109,7 +109,7 @@ async fn does_not_accept_string_literals() { async fn accepts_strings_in_variables() { run_variable_query( "query q($color: Color!) { toString(color: $color) }", - vec![("color".to_owned(), InputValue::scalar("RED"))] + vec![("color".to_owned(), graphql_input_value!("RED"))] .into_iter() .collect(), |result| { @@ -131,7 +131,7 @@ async fn does_not_accept_incorrect_enum_name_in_variables() { ); let query = r#"query q($color: Color!) { toString(color: $color) }"#; - let vars = vec![("color".to_owned(), InputValue::scalar("BLURPLE"))] + let vars = vec![("color".to_owned(), graphql_input_value!("BLURPLE"))] .into_iter() .collect(); @@ -157,7 +157,7 @@ async fn does_not_accept_incorrect_type_in_variables() { ); let query = r#"query q($color: Color!) { toString(color: $color) }"#; - let vars = vec![("color".to_owned(), InputValue::scalar(123))] + let vars = vec![("color".to_owned(), graphql_input_value!(123))] .into_iter() .collect(); diff --git a/juniper/src/executor_tests/executor.rs b/juniper/src/executor_tests/executor.rs index 44fa17343..bfaac1264 100644 --- a/juniper/src/executor_tests/executor.rs +++ b/juniper/src/executor_tests/executor.rs @@ -90,7 +90,7 @@ mod field_execution { } "; - let vars = vec![("size".to_owned(), InputValue::scalar(100))] + let vars = vec![("size".to_owned(), graphql_input_value!(100))] .into_iter() .collect(); diff --git a/juniper/src/executor_tests/introspection/input_object.rs b/juniper/src/executor_tests/introspection/input_object.rs index 7b8df4820..1d4f1b82f 100644 --- a/juniper/src/executor_tests/introspection/input_object.rs +++ b/juniper/src/executor_tests/introspection/input_object.rs @@ -200,14 +200,10 @@ async fn default_name_introspection() { #[test] fn default_name_input_value() { - let iv: InputValue = InputValue::object( - vec![ - ("fieldOne", InputValue::scalar("number one")), - ("fieldTwo", InputValue::scalar("number two")), - ] - .into_iter() - .collect(), - ); + let iv: InputValue = graphql_input_value!({ + "fieldOne": "number one", + "fieldTwo": "number two", + }); let dv: Option = FromInputValue::from_input_value(&iv); diff --git a/juniper/src/executor_tests/variables.rs b/juniper/src/executor_tests/variables.rs index fa8739fd0..ac90b6f6a 100644 --- a/juniper/src/executor_tests/variables.rs +++ b/juniper/src/executor_tests/variables.rs @@ -201,15 +201,11 @@ async fn variable_complex_input() { r#"query q($input: TestInputObject) { fieldWithObjectInput(input: $input) }"#, vec![( "input".to_owned(), - InputValue::object( - vec![ - ("a", InputValue::scalar("foo")), - ("b", InputValue::list(vec![InputValue::scalar("bar")])), - ("c", InputValue::scalar("baz")), - ] - .into_iter() - .collect(), - ), + graphql_input_value!({ + "a": "foo", + "b": ["bar"], + "c": "baz", + }), )] .into_iter() .collect(), @@ -230,15 +226,11 @@ async fn variable_parse_single_value_to_list() { r#"query q($input: TestInputObject) { fieldWithObjectInput(input: $input) }"#, vec![( "input".to_owned(), - InputValue::object( - vec![ - ("a", InputValue::scalar("foo")), - ("b", InputValue::scalar("bar")), - ("c", InputValue::scalar("baz")), - ] - .into_iter() - .collect(), - ), + graphql_input_value!({ + "a": "foo", + "b": "bar", + "c": "baz", + }), )] .into_iter() .collect(), @@ -259,14 +251,10 @@ async fn variable_runs_from_input_value_on_scalar() { r#"query q($input: TestInputObject) { fieldWithObjectInput(input: $input) }"#, vec![( "input".to_owned(), - InputValue::object( - vec![ - ("c", InputValue::scalar("baz")), - ("d", InputValue::scalar("SerializedValue")), - ] - .into_iter() - .collect(), - ), + graphql_input_value!({ + "c": "baz", + "d": "SerializedValue", + }), )] .into_iter() .collect(), @@ -292,15 +280,11 @@ async fn variable_error_on_nested_non_null() { let query = r#"query q($input: TestInputObject) { fieldWithObjectInput(input: $input) }"#; let vars = vec![( "input".to_owned(), - InputValue::object( - vec![ - ("a", InputValue::scalar("foo")), - ("b", InputValue::scalar("bar")), - ("c", InputValue::null()), - ] - .into_iter() - .collect(), - ), + graphql_input_value!({ + "a": "foo", + "b": "bar", + "c": null, + }), )] .into_iter() .collect(); @@ -327,7 +311,7 @@ async fn variable_error_on_incorrect_type() { ); let query = r#"query q($input: TestInputObject) { fieldWithObjectInput(input: $input) }"#; - let vars = vec![("input".to_owned(), InputValue::scalar("foo bar"))] + let vars = vec![("input".to_owned(), graphql_input_value!("foo bar"))] .into_iter() .collect(); @@ -355,14 +339,10 @@ async fn variable_error_on_omit_non_null() { let query = r#"query q($input: TestInputObject) { fieldWithObjectInput(input: $input) }"#; let vars = vec![( "input".to_owned(), - InputValue::object( - vec![ - ("a", InputValue::scalar("foo")), - ("b", InputValue::scalar("bar")), - ] - .into_iter() - .collect(), - ), + graphql_input_value!({ + "a": "foo", + "b": "bar", + }), )] .into_iter() .collect(); @@ -392,14 +372,9 @@ async fn variable_multiple_errors_with_nesting() { r#"query q($input: TestNestedInputObject) { fieldWithNestedObjectInput(input: $input) }"#; let vars = vec![( "input".to_owned(), - InputValue::object( - vec![( - "na", - InputValue::object(vec![("a", InputValue::scalar("foo"))].into_iter().collect()), - )] - .into_iter() - .collect(), - ), + graphql_input_value!({ + "na": { "a": "foo" }, + }), )] .into_iter() .collect(); @@ -434,16 +409,12 @@ async fn variable_error_on_additional_field() { let query = r#"query q($input: TestInputObject) { fieldWithObjectInput(input: $input) }"#; let vars = vec![( "input".to_owned(), - InputValue::object( - vec![ - ("a", InputValue::scalar("foo")), - ("b", InputValue::scalar("bar")), - ("c", InputValue::scalar("baz")), - ("extra", InputValue::scalar("dog")), - ] - .into_iter() - .collect(), - ), + graphql_input_value!({ + "a": "foo", + "b": "bar", + "c": "baz", + "extra": "dog", + }), )] .into_iter() .collect(); @@ -507,7 +478,7 @@ async fn allow_nullable_inputs_to_be_explicitly_null() { async fn allow_nullable_inputs_to_be_set_to_null_in_variable() { run_variable_query( r#"query q($value: String) { fieldWithNullableStringInput(input: $value) }"#, - vec![("value".to_owned(), InputValue::null())] + vec![("value".to_owned(), graphql_input_value!(null))] .into_iter() .collect(), |result: &Object| { @@ -524,7 +495,7 @@ async fn allow_nullable_inputs_to_be_set_to_null_in_variable() { async fn allow_nullable_inputs_to_be_set_to_value_in_variable() { run_variable_query( r#"query q($value: String) { fieldWithNullableStringInput(input: $value) }"#, - vec![("value".to_owned(), InputValue::scalar("a"))] + vec![("value".to_owned(), graphql_input_value!("a"))] .into_iter() .collect(), |result: &Object| { @@ -584,7 +555,7 @@ async fn does_not_allow_non_nullable_input_to_be_set_to_null_in_variable() { ); let query = r#"query q($value: String!) { fieldWithNonNullableStringInput(input: $value) }"#; - let vars = vec![("value".to_owned(), InputValue::null())] + let vars = vec![("value".to_owned(), graphql_input_value!(null))] .into_iter() .collect(); @@ -605,7 +576,7 @@ async fn does_not_allow_non_nullable_input_to_be_set_to_null_in_variable() { async fn allow_non_nullable_inputs_to_be_set_to_value_in_variable() { run_variable_query( r#"query q($value: String!) { fieldWithNonNullableStringInput(input: $value) }"#, - vec![("value".to_owned(), InputValue::scalar("a"))] + vec![("value".to_owned(), graphql_input_value!("a"))] .into_iter() .collect(), |result| { @@ -636,7 +607,7 @@ async fn allow_non_nullable_inputs_to_be_set_to_value_directly() { async fn allow_lists_to_be_null() { run_variable_query( r#"query q($input: [String]) { list(input: $input) }"#, - vec![("input".to_owned(), InputValue::null())] + vec![("input".to_owned(), graphql_input_value!(null))] .into_iter() .collect(), |result: &Object| { @@ -653,12 +624,9 @@ async fn allow_lists_to_be_null() { async fn allow_lists_to_contain_values() { run_variable_query( r#"query q($input: [String]) { list(input: $input) }"#, - vec![( - "input".to_owned(), - InputValue::list(vec![InputValue::scalar("A")]), - )] - .into_iter() - .collect(), + vec![("input".to_owned(), graphql_input_value!(["A"]))] + .into_iter() + .collect(), |result| { assert_eq!( result.get_field_value("list"), @@ -673,16 +641,9 @@ async fn allow_lists_to_contain_values() { async fn allow_lists_to_contain_null() { run_variable_query( r#"query q($input: [String]) { list(input: $input) }"#, - vec![( - "input".to_owned(), - InputValue::list(vec![ - InputValue::scalar("A"), - InputValue::null(), - InputValue::scalar("B"), - ]), - )] - .into_iter() - .collect(), + vec![("input".to_owned(), graphql_input_value!(["A", null, "B"]))] + .into_iter() + .collect(), |result| { assert_eq!( result.get_field_value("list"), @@ -702,7 +663,7 @@ async fn does_not_allow_non_null_lists_to_be_null() { ); let query = r#"query q($input: [String]!) { nnList(input: $input) }"#; - let vars = vec![("input".to_owned(), InputValue::null())] + let vars = vec![("input".to_owned(), graphql_input_value!(null))] .into_iter() .collect(); @@ -723,12 +684,9 @@ async fn does_not_allow_non_null_lists_to_be_null() { async fn allow_non_null_lists_to_contain_values() { run_variable_query( r#"query q($input: [String]!) { nnList(input: $input) }"#, - vec![( - "input".to_owned(), - InputValue::list(vec![InputValue::scalar("A")]), - )] - .into_iter() - .collect(), + vec![("input".to_owned(), graphql_input_value!(["A"]))] + .into_iter() + .collect(), |result| { assert_eq!( result.get_field_value("nnList"), @@ -742,16 +700,9 @@ async fn allow_non_null_lists_to_contain_values() { async fn allow_non_null_lists_to_contain_null() { run_variable_query( r#"query q($input: [String]!) { nnList(input: $input) }"#, - vec![( - "input".to_owned(), - InputValue::list(vec![ - InputValue::scalar("A"), - InputValue::null(), - InputValue::scalar("B"), - ]), - )] - .into_iter() - .collect(), + vec![("input".to_owned(), graphql_input_value!(["A", null, "B"]))] + .into_iter() + .collect(), |result| { assert_eq!( result.get_field_value("nnList"), @@ -766,7 +717,7 @@ async fn allow_non_null_lists_to_contain_null() { async fn allow_lists_of_non_null_to_be_null() { run_variable_query( r#"query q($input: [String!]) { listNn(input: $input) }"#, - vec![("input".to_owned(), InputValue::null())] + vec![("input".to_owned(), graphql_input_value!(null))] .into_iter() .collect(), |result| { @@ -783,12 +734,9 @@ async fn allow_lists_of_non_null_to_be_null() { async fn allow_lists_of_non_null_to_contain_values() { run_variable_query( r#"query q($input: [String!]) { listNn(input: $input) }"#, - vec![( - "input".to_owned(), - InputValue::list(vec![InputValue::scalar("A")]), - )] - .into_iter() - .collect(), + vec![("input".to_owned(), graphql_input_value!(["A"]))] + .into_iter() + .collect(), |result| { assert_eq!( result.get_field_value("listNn"), @@ -808,16 +756,9 @@ async fn does_not_allow_lists_of_non_null_to_contain_null() { ); let query = r#"query q($input: [String!]) { listNn(input: $input) }"#; - let vars = vec![( - "input".to_owned(), - InputValue::list(vec![ - InputValue::scalar("A"), - InputValue::null(), - InputValue::scalar("B"), - ]), - )] - .into_iter() - .collect(); + let vars = vec![("input".to_owned(), graphql_input_value!(["A", null, "B"]))] + .into_iter() + .collect(); let error = crate::execute(query, None, &schema, &vars, &()) .await @@ -841,16 +782,9 @@ async fn does_not_allow_non_null_lists_of_non_null_to_contain_null() { ); let query = r#"query q($input: [String!]!) { nnListNn(input: $input) }"#; - let vars = vec![( - "input".to_owned(), - InputValue::list(vec![ - InputValue::scalar("A"), - InputValue::null(), - InputValue::scalar("B"), - ]), - )] - .into_iter() - .collect(); + let vars = vec![("input".to_owned(), graphql_input_value!(["A", null, "B"]))] + .into_iter() + .collect(); let error = crate::execute(query, None, &schema, &vars, &()) .await @@ -874,7 +808,7 @@ async fn does_not_allow_non_null_lists_of_non_null_to_be_null() { ); let query = r#"query q($input: [String!]!) { nnListNn(input: $input) }"#; - let vars = vec![("value".to_owned(), InputValue::null())] + let vars = vec![("value".to_owned(), graphql_input_value!(null))] .into_iter() .collect(); @@ -895,12 +829,9 @@ async fn does_not_allow_non_null_lists_of_non_null_to_be_null() { async fn allow_non_null_lists_of_non_null_to_contain_values() { run_variable_query( r#"query q($input: [String!]!) { nnListNn(input: $input) }"#, - vec![( - "input".to_owned(), - InputValue::list(vec![InputValue::scalar("A")]), - )] - .into_iter() - .collect(), + vec![("input".to_owned(), graphql_input_value!(["A"]))] + .into_iter() + .collect(), |result| { assert_eq!( result.get_field_value("nnListNn"), @@ -940,7 +871,7 @@ async fn default_argument_when_nullable_variable_not_provided() { async fn default_argument_when_nullable_variable_set_to_null() { run_variable_query( r#"query q($input: String) { fieldWithDefaultArgumentValue(input: $input) }"#, - vec![("input".to_owned(), InputValue::null())] + vec![("input".to_owned(), graphql_input_value!(null))] .into_iter() .collect(), |result| { @@ -976,7 +907,7 @@ async fn nullable_input_object_arguments_successful_without_variables() { async fn nullable_input_object_arguments_successful_with_variables() { run_variable_query( r#"query q($var: Int!) { exampleInput(arg: {b: $var}) }"#, - vec![("var".to_owned(), InputValue::scalar(123))] + vec![("var".to_owned(), graphql_input_value!(123))] .into_iter() .collect(), |result| { @@ -990,7 +921,7 @@ async fn nullable_input_object_arguments_successful_with_variables() { run_variable_query( r#"query q($var: String) { exampleInput(arg: {a: $var, b: 1}) }"#, - vec![("var".to_owned(), InputValue::null())] + vec![("var".to_owned(), graphql_input_value!(null))] .into_iter() .collect(), |result| { @@ -1096,7 +1027,7 @@ async fn does_not_allow_null_variable_for_required_field() { ); let query = r#"query q($var: Int!) { exampleInput(arg: {b: $var}) }"#; - let vars = vec![("var".to_owned(), InputValue::null())] + let vars = vec![("var".to_owned(), graphql_input_value!(null))] .into_iter() .collect(); @@ -1125,7 +1056,7 @@ async fn input_object_with_default_values() { run_variable_query( r#"query q($var: Int!) { inputWithDefaults(arg: {a: $var}) }"#, - vec![("var".to_owned(), InputValue::scalar(1))] + vec![("var".to_owned(), graphql_input_value!(1))] .into_iter() .collect(), |result| { @@ -1151,7 +1082,7 @@ async fn input_object_with_default_values() { run_variable_query( r#"query q($var: Int = 1) { inputWithDefaults(arg: {a: $var}) }"#, - vec![("var".to_owned(), InputValue::scalar(2))] + vec![("var".to_owned(), graphql_input_value!(2))] .into_iter() .collect(), |result| { @@ -1171,7 +1102,7 @@ mod integers { async fn positive_and_negative_should_work() { run_variable_query( r#"query q($var: Int!) { integerInput(value: $var) }"#, - vec![("var".to_owned(), InputValue::scalar(1))] + vec![("var".to_owned(), graphql_input_value!(1))] .into_iter() .collect(), |result| { @@ -1185,7 +1116,7 @@ mod integers { run_variable_query( r#"query q($var: Int!) { integerInput(value: $var) }"#, - vec![("var".to_owned(), InputValue::scalar(-1))] + vec![("var".to_owned(), graphql_input_value!(-1))] .into_iter() .collect(), |result| { @@ -1207,7 +1138,7 @@ mod integers { ); let query = r#"query q($var: Int!) { integerInput(value: $var) }"#; - let vars = vec![("var".to_owned(), InputValue::scalar(10.0))] + let vars = vec![("var".to_owned(), graphql_input_value!(10.0))] .into_iter() .collect(); @@ -1233,7 +1164,7 @@ mod integers { ); let query = r#"query q($var: Int!) { integerInput(value: $var) }"#; - let vars = vec![("var".to_owned(), InputValue::scalar("10"))] + let vars = vec![("var".to_owned(), graphql_input_value!("10"))] .into_iter() .collect(); @@ -1258,7 +1189,7 @@ mod floats { async fn float_values_should_work() { run_variable_query( r#"query q($var: Float!) { floatInput(value: $var) }"#, - vec![("var".to_owned(), InputValue::scalar(10.0))] + vec![("var".to_owned(), graphql_input_value!(10.0))] .into_iter() .collect(), |result| { @@ -1275,7 +1206,7 @@ mod floats { async fn coercion_from_integers_should_work() { run_variable_query( r#"query q($var: Float!) { floatInput(value: $var) }"#, - vec![("var".to_owned(), InputValue::scalar(-1))] + vec![("var".to_owned(), graphql_input_value!(-1))] .into_iter() .collect(), |result| { @@ -1297,7 +1228,7 @@ mod floats { ); let query = r#"query q($var: Float!) { floatInput(value: $var) }"#; - let vars = vec![("var".to_owned(), InputValue::scalar("10"))] + let vars = vec![("var".to_owned(), graphql_input_value!("10"))] .into_iter() .collect(); diff --git a/juniper/src/integrations/bson.rs b/juniper/src/integrations/bson.rs index e11c752db..048ec375b 100644 --- a/juniper/src/integrations/bson.rs +++ b/juniper/src/integrations/bson.rs @@ -66,7 +66,7 @@ mod test { #[test] fn objectid_from_input_value() { let raw = "53e37d08776f724e42000000"; - let input = InputValue::::scalar(raw.to_string()); + let input = InputValue::::scalar(raw); let parsed: ObjectId = FromInputValue::from_input_value(&input).unwrap(); let id = ObjectId::parse_str(raw).unwrap(); @@ -77,7 +77,7 @@ mod test { #[test] fn utcdatetime_from_input_value() { let raw = "2020-03-23T17:38:32.446+00:00"; - let input = InputValue::::scalar(raw.to_string()); + let input = InputValue::::scalar(raw); let parsed: UtcDateTime = FromInputValue::from_input_value(&input).unwrap(); let date_time = UtcDateTime::from_chrono( diff --git a/juniper/src/integrations/chrono.rs b/juniper/src/integrations/chrono.rs index dec58f14e..4c192d7a0 100644 --- a/juniper/src/integrations/chrono.rs +++ b/juniper/src/integrations/chrono.rs @@ -152,7 +152,7 @@ mod test { use chrono::prelude::*; fn datetime_fixedoffset_test(raw: &'static str) { - let input: crate::InputValue = InputValue::scalar(raw.to_string()); + let input: crate::InputValue = InputValue::scalar(raw); let parsed: DateTime = crate::FromInputValue::from_input_value(&input).unwrap(); @@ -204,8 +204,7 @@ mod test { #[test] fn naivedate_from_input_value() { - let input: crate::InputValue = - InputValue::scalar("1996-12-19".to_string()); + let input: crate::InputValue = graphql_input_value!("1996-12-19"); let y = 1996; let m = 12; let d = 19; @@ -223,8 +222,7 @@ mod test { #[test] #[cfg(feature = "scalar-naivetime")] fn naivetime_from_input_value() { - let input: crate::InputValue; - input = InputValue::scalar("21:12:19".to_string()); + let input: crate::InputValue = graphql_input_value!("21:12:19"); let [h, m, s] = [21, 12, 19]; let parsed: NaiveTime = crate::FromInputValue::from_input_value(&input).unwrap(); let expected = NaiveTime::from_hms(h, m, s); diff --git a/juniper/src/integrations/serde.rs b/juniper/src/integrations/serde.rs index 8954bb722..aaf037d2d 100644 --- a/juniper/src/integrations/serde.rs +++ b/juniper/src/integrations/serde.rs @@ -367,7 +367,7 @@ mod tests { fn int() { assert_eq!( from_str::>("1235").unwrap(), - InputValue::scalar(1235), + graphql_input_value!(1235), ); } @@ -375,12 +375,12 @@ mod tests { fn float() { assert_eq!( from_str::>("2.0").unwrap(), - InputValue::scalar(2.0), + graphql_input_value!(2.0), ); // large value without a decimal part is also float assert_eq!( from_str::>("123567890123").unwrap(), - InputValue::scalar(123_567_890_123.0), + graphql_input_value!(123_567_890_123.0), ); } diff --git a/juniper/src/parser/tests/value.rs b/juniper/src/parser/tests/value.rs index c8b1ac9b9..76a6b2580 100644 --- a/juniper/src/parser/tests/value.rs +++ b/juniper/src/parser/tests/value.rs @@ -79,7 +79,7 @@ fn input_value_literals() { Spanning::start_end( &SourcePosition::new(0, 0, 0), &SourcePosition::new(3, 0, 3), - InputValue::scalar(123) + graphql_input_value!(123) ) ); assert_eq!( @@ -87,7 +87,7 @@ fn input_value_literals() { Spanning::start_end( &SourcePosition::new(0, 0, 0), &SourcePosition::new(6, 0, 6), - InputValue::scalar(123.45) + graphql_input_value!(123.45) ) ); assert_eq!( @@ -95,7 +95,7 @@ fn input_value_literals() { Spanning::start_end( &SourcePosition::new(0, 0, 0), &SourcePosition::new(4, 0, 4), - InputValue::scalar(true) + graphql_input_value!(true) ) ); assert_eq!( @@ -103,7 +103,7 @@ fn input_value_literals() { Spanning::start_end( &SourcePosition::new(0, 0, 0), &SourcePosition::new(5, 0, 5), - InputValue::scalar(false) + graphql_input_value!(false) ) ); assert_eq!( @@ -111,7 +111,7 @@ fn input_value_literals() { Spanning::start_end( &SourcePosition::new(0, 0, 0), &SourcePosition::new(6, 0, 6), - InputValue::scalar("test") + graphql_input_value!("test") ) ); let values = &[EnumValue::new("enum_value")]; @@ -122,7 +122,7 @@ fn input_value_literals() { Spanning::start_end( &SourcePosition::new(0, 0, 0), &SourcePosition::new(10, 0, 10), - InputValue::enum_value("enum_value") + graphql_input_value!(enum_value) ) ); assert_eq!( @@ -130,7 +130,7 @@ fn input_value_literals() { Spanning::start_end( &SourcePosition::new(0, 0, 0), &SourcePosition::new(9, 0, 9), - InputValue::variable("variable") + graphql_input_value!(@variable) ) ); assert_eq!( @@ -138,7 +138,7 @@ fn input_value_literals() { Spanning::start_end( &SourcePosition::new(0, 0, 0), &SourcePosition::new(2, 0, 2), - InputValue::list(vec![]) + graphql_input_value!([]), ) ); assert_eq!( @@ -181,7 +181,7 @@ fn input_value_literals() { Spanning::start_end( &SourcePosition::new(0, 0, 0), &SourcePosition::new(2, 0, 2), - InputValue::object(IndexMap::>::new()) + graphql_input_value!({}), ) ); diff --git a/juniper/src/parser/value.rs b/juniper/src/parser/value.rs index 8d66661c9..f609c299d 100644 --- a/juniper/src/parser/value.rs +++ b/juniper/src/parser/value.rs @@ -91,21 +91,21 @@ where .. }, _, - ) => Ok(parser.next_token()?.map(|_| InputValue::scalar(true))), + ) => Ok(parser.next_token()?.map(|_| graphql_input_value!(true))), ( &Spanning { item: Token::Name("false"), .. }, _, - ) => Ok(parser.next_token()?.map(|_| InputValue::scalar(false))), + ) => Ok(parser.next_token()?.map(|_| graphql_input_value!(false))), ( &Spanning { item: Token::Name("null"), .. }, _, - ) => Ok(parser.next_token()?.map(|_| InputValue::null())), + ) => Ok(parser.next_token()?.map(|_| graphql_input_value!(null))), ( &Spanning { item: Token::Name(name), diff --git a/juniper/src/tests/query_tests.rs b/juniper/src/tests/query_tests.rs index 8bca5a75c..73b4f381d 100644 --- a/juniper/src/tests/query_tests.rs +++ b/juniper/src/tests/query_tests.rs @@ -262,7 +262,7 @@ async fn test_query_name_variable() { EmptySubscription::::new(), ); - let vars = vec![("someId".to_owned(), InputValue::scalar("1000"))] + let vars = vec![("someId".to_owned(), graphql_input_value!("1000"))] .into_iter() .collect(); @@ -285,7 +285,7 @@ async fn test_query_name_invalid_variable() { EmptySubscription::::new(), ); - let vars = vec![("someId".to_owned(), InputValue::scalar("some invalid id"))] + let vars = vec![("someId".to_owned(), graphql_input_value!("some invalid id"))] .into_iter() .collect(); diff --git a/juniper_graphql_ws/src/client_message.rs b/juniper_graphql_ws/src/client_message.rs index 08745bd28..60779548a 100644 --- a/juniper_graphql_ws/src/client_message.rs +++ b/juniper_graphql_ws/src/client_message.rs @@ -53,8 +53,9 @@ pub enum ClientMessage { #[cfg(test)] mod test { + use juniper::{graphql_input_value, DefaultScalarValue, InputValue}; + use super::*; - use juniper::{DefaultScalarValue, InputValue}; #[test] fn test_deserialization() { @@ -62,7 +63,7 @@ mod test { assert_eq!( ClientMessage::ConnectionInit { - payload: [("foo".to_string(), InputValue::scalar("bar"))] + payload: [("foo".to_string(), graphql_input_value!("bar"))] .iter() .cloned() .collect(), @@ -83,7 +84,7 @@ mod test { id: "foo".to_string(), payload: StartPayload { query: "query MyQuery { __typename }".to_string(), - variables: [("foo".to_string(), InputValue::scalar("bar"))] + variables: [("foo".to_string(), graphql_input_value!("bar"))] .iter() .cloned() .collect(), From 8392d77a3edaeabfbe48d9cba63c50b3039beb06 Mon Sep 17 00:00:00 2001 From: ilslv Date: Wed, 24 Nov 2021 18:32:04 +0300 Subject: [PATCH 11/22] Lint --- juniper_graphql_ws/src/client_message.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/juniper_graphql_ws/src/client_message.rs b/juniper_graphql_ws/src/client_message.rs index 60779548a..3d8a6d56d 100644 --- a/juniper_graphql_ws/src/client_message.rs +++ b/juniper_graphql_ws/src/client_message.rs @@ -53,7 +53,7 @@ pub enum ClientMessage { #[cfg(test)] mod test { - use juniper::{graphql_input_value, DefaultScalarValue, InputValue}; + use juniper::{graphql_input_value, DefaultScalarValue}; use super::*; From bafea878c42730b7abc012581f249681da37c491 Mon Sep 17 00:00:00 2001 From: ilslv Date: Thu, 25 Nov 2021 10:07:45 +0300 Subject: [PATCH 12/22] Implement graphql_vars! macro --- .../juniper_tests/src/custom_scalar.rs | 4 +- .../juniper_tests/src/explicit_null.rs | 2 +- juniper/src/ast/macros.rs | 74 ++- juniper/src/ast/mod.rs | 2 +- juniper/src/executor/macros.rs | 550 ++++++++++++++++++ juniper/src/executor/mod.rs | 27 +- juniper/src/value/macros.rs | 6 +- juniper/src/value/scalar.rs | 10 + 8 files changed, 616 insertions(+), 59 deletions(-) create mode 100644 juniper/src/executor/macros.rs diff --git a/integration_tests/juniper_tests/src/custom_scalar.rs b/integration_tests/juniper_tests/src/custom_scalar.rs index ebacc08a9..704fadaf8 100644 --- a/integration_tests/juniper_tests/src/custom_scalar.rs +++ b/integration_tests/juniper_tests/src/custom_scalar.rs @@ -235,7 +235,7 @@ async fn querying_long_variable() { "query q($test: Long!){ longWithArg(longArg: $test) }", vec![( "test".to_owned(), - graphql_input_value!(MyScalarValue::Long(i64::from(i32::MAX) + 42)), + graphql_input_value!(i64::from(i32::MAX) + 42), )] .into_iter() .collect(), @@ -256,7 +256,7 @@ fn deserialize_variable() { assert_eq!( serde_json::from_str::>(&json).unwrap(), graphql_input_value!({ - "field": MyScalarValue::Long(i64::from(i32::MAX) + 42), + "field": i64::from(i32::MAX) + 42, }), ); } diff --git a/integration_tests/juniper_tests/src/explicit_null.rs b/integration_tests/juniper_tests/src/explicit_null.rs index 2bc02f9c7..7e3581501 100644 --- a/integration_tests/juniper_tests/src/explicit_null.rs +++ b/integration_tests/juniper_tests/src/explicit_null.rs @@ -50,7 +50,7 @@ async fn explicit_null() { let vars = graphql_vars!({ "emptyObj": [], - "literalNullObj": {"field": None}, + "literalNullObj": {"field": null}, }); let (data, errors) = juniper::execute(query, None, &schema, &vars, &Context) diff --git a/juniper/src/ast/macros.rs b/juniper/src/ast/macros.rs index 4755d648e..8adc02167 100644 --- a/juniper/src/ast/macros.rs +++ b/juniper/src/ast/macros.rs @@ -1,14 +1,38 @@ -/// Construct JSON-like [`InputValue`]s by using JSON syntax. +/// Construct JSON-like [`InputValue`]s by using JSON-like syntax. +/// +/// # Differences from [`graphql_value!`] +/// +/// - [`InputValue::Enum`] is constructed with `ident`, so to capture outer +/// variable surround it with parens: `(var)`. +/// ```rust +/// # use juniper::{graphql_input_value, graphql_value}; +/// # +/// # type InputValue = juniper::InputValue; +/// # type Value = juniper::Value; +/// # +/// const OUTER_VAR: i32 = 42; +/// assert_eq!(graphql_value!(OUTER_VAR), Value::scalar(42)); +/// assert_eq!(graphql_input_value!(OUTER_VAR), InputValue::enum_value("OUTER_VAR")); +/// assert_eq!(graphql_input_value!((OUTER_VAR)), InputValue::scalar(42)); +/// ``` +/// +/// - [`InputValue::Variable`] is constructed by prefixing `ident` with `@`. +/// ```rust +/// # use juniper::graphql_input_value; +/// # +/// # type InputValue = juniper::InputValue; +/// # +/// assert_eq!(graphql_input_value!(@var), InputValue::variable("var")); +/// ``` /// /// __Note:__ [`InputValue::List`]s and [`InputValue::Object`]s will be created /// in a [`Spanning::unlocated`]. /// /// # Example /// -/// The resulting JSON will look just like what you passed in. /// ```rust -/// # use juniper::{graphql_input_value, DefaultScalarValue, InputValue}; -/// # type V = InputValue; +/// # use juniper::{graphql_input_value, InputValue}; +/// # type V = InputValue; /// # /// # let _: V = /// graphql_input_value!(null); @@ -20,7 +44,21 @@ /// graphql_input_value!([1234, "test", true]); /// # let _: V = /// graphql_input_value!({"key": "value", "foo": 1234}); +/// # let _: V = +/// graphql_input_value!({"key": ENUM}); +/// let captured_var = 42; +/// # let _: V = +/// graphql_input_value!({"key": (captured_var)}); +/// # let _: V = +/// graphql_input_value!({"key": @variable}); /// ``` +/// +/// [`InputValue`]: crate::InputValue +/// [`InputValue::Enum`]: crate::InputValue::Enum +/// [`InputValue::List`]: crate::InputValue::List +/// [`InputValue::Object`]: crate::InputValue::Object +/// [`InputValue::Variable`]: crate::InputValue::Variable +/// [`Spanning::unlocated`]: crate::Spanning::unlocated #[macro_export] macro_rules! graphql_input_value { /////////// @@ -48,14 +86,14 @@ macro_rules! graphql_input_value { ) }; - // Next element is `variable`. + // Next element is a variable. (@@array [$($elems:expr,)*] @$var:ident $($rest:tt)*) => { $crate::graphql_input_value!( @@array [$($elems,)* $crate::graphql_input_value!(@$var)] $($rest)* ) }; - // Next element is `enum`. + // Next element is `true`, `false` or enum. (@@array [$($elems:expr,)*] $enum:ident $($rest:tt)*) => { $crate::graphql_input_value!( @@array [$($elems,)* $crate::graphql_input_value!($enum)] $($rest)* @@ -129,12 +167,12 @@ macro_rules! graphql_input_value { $crate::graphql_input_value!(@@object $object [$($key)+] ($crate::graphql_input_value!(null)) $($rest)*); }; - // Next value is `variable`. + // Next value is a variable. (@@object $object:ident ($($key:tt)+) (: @$var:ident $($rest:tt)*) $copy:tt) => { $crate::graphql_input_value!(@@object $object [$($key)+] ($crate::graphql_input_value!(@$var)) $($rest)*); }; - // Next value is `enum`. + // Next value is `true`, `false` or enum. (@@object $object:ident ($($key:tt)+) (: $enum:ident $($rest:tt)*) $copy:tt) => { $crate::graphql_input_value!(@@object $object [$($key)+] ($crate::graphql_input_value!($enum)) $($rest)*); }; @@ -245,9 +283,7 @@ macro_rules! graphql_input_value { mod tests { use indexmap::{indexmap, IndexMap}; - use crate::{DefaultScalarValue, InputValue}; - - type V = InputValue; + type V = crate::InputValue; #[test] fn null() { @@ -351,22 +387,6 @@ mod tests { V::enum_value("ENUM"), ]), ); - assert_eq!( - graphql_input_value!({ "key": ENUM }), - V::object(indexmap! { "key" => V::enum_value("ENUM") }), - ); - assert_eq!( - graphql_input_value!({ "key": lowercase }), - V::object(indexmap! { "key" => V::enum_value("lowercase") }), - ); - assert_eq!( - graphql_input_value!({ "key": @var }), - V::object(indexmap! { "key" => V::variable("var") }), - ); - assert_eq!( - graphql_input_value!({ "key": @array }), - V::object(indexmap! { "key" => V::variable("array") }), - ); } #[test] diff --git a/juniper/src/ast/mod.rs b/juniper/src/ast/mod.rs index a497fb233..56fbb617f 100644 --- a/juniper/src/ast/mod.rs +++ b/juniper/src/ast/mod.rs @@ -301,7 +301,7 @@ impl InputValue { } } - /// Shorthand form of invoking [`FromInputValue::from()`]. + /// Shorthand form of invoking [`FromInputValue::from_input_value()`]. pub fn convert(&self) -> Option where T: FromInputValue, diff --git a/juniper/src/executor/macros.rs b/juniper/src/executor/macros.rs new file mode 100644 index 000000000..dd94c9ca3 --- /dev/null +++ b/juniper/src/executor/macros.rs @@ -0,0 +1,550 @@ +/// Construct JSON-like [`Variables`] by using JSON-like syntax. +/// +/// See [`graphql_input_value!`] for more info on syntax of value after `:`. +/// +/// # Example +/// +/// ```rust +/// # use juniper::{graphql_vars, Variables}; +/// # type V = Variables; +/// # +/// # let _: V = +/// graphql_vars!({ "key": "value", "foo": 1234, "var": @var }); +/// ``` +/// +/// [`Variables`]: crate::Variables +#[macro_export] +macro_rules! graphql_vars { + //////////// + // Object // + //////////// + + // Done. + (@object $object:ident () () ()) => {}; + + // Insert the current entry followed by trailing comma. + (@object $object:ident [$($key:tt)+] ($value:expr) , $($rest:tt)*) => { + let _ = $object.insert(($($key)+).into(), $value); + $crate::graphql_vars!(@object $object () ($($rest)*) ($($rest)*)); + }; + + // Current entry followed by unexpected token. + (@object $object:ident [$($key:tt)+] ($value:expr) $unexpected:tt $($rest:tt)*) => { + $crate::graphql_vars!(@unexpected $unexpected); + }; + + // Insert the last entry without trailing comma. + (@object $object:ident [$($key:tt)+] ($value:expr)) => { + let _ = $object.insert(($($key)+).into(), $value); + }; + + // Next value is `null`. + (@object $object:ident ($($key:tt)+) (: null $($rest:tt)*) $copy:tt) => { + $crate::graphql_vars!(@object $object [$($key)+] ($crate::graphql_input_value!(null)) $($rest)*); + }; + + // Next value is a variable. + (@object $object:ident ($($key:tt)+) (: @$var:ident $($rest:tt)*) $copy:tt) => { + $crate::graphql_vars!(@object $object [$($key)+] ($crate::graphql_input_value!(@$var)) $($rest)*); + }; + + // Next value is `true`, `false` or enum. + (@object $object:ident ($($key:tt)+) (: $enum:ident $($rest:tt)*) $copy:tt) => { + $crate::graphql_vars!(@object $object [$($key)+] ($crate::graphql_input_value!($enum)) $($rest)*); + }; + + // Next value is an array. + (@object $object:ident ($($key:tt)+) (: [$($array:tt)*] $($rest:tt)*) $copy:tt) => { + $crate::graphql_vars!(@object $object [$($key)+] ($crate::graphql_input_value!([$($array)*])) $($rest)*); + }; + + // Next value is a map. + (@object $object:ident ($($key:tt)+) (: {$($map:tt)*} $($rest:tt)*) $copy:tt) => { + $crate::graphql_vars!(@object $object [$($key)+] ($crate::graphql_input_value!({$($map)*})) $($rest)*); + }; + + // Next value is an expression followed by comma. + (@object $object:ident ($($key:tt)+) (: $value:expr , $($rest:tt)*) $copy:tt) => { + $crate::graphql_vars!(@object $object [$($key)+] ($crate::graphql_input_value!($value)) , $($rest)*); + }; + + // Last value is an expression with no trailing comma. + (@object $object:ident ($($key:tt)+) (: $value:expr) $copy:tt) => { + $crate::graphql_vars!(@object $object [$($key)+] ($crate::graphql_input_value!($value))); + }; + + // Missing value for last entry. Trigger a reasonable error message. + (@object $object:ident ($($key:tt)+) (:) $copy:tt) => { + // "unexpected end of macro invocation" + $crate::graphql_vars!(); + }; + + // Missing colon and value for last entry. Trigger a reasonable error + // message. + (@object $object:ident ($($key:tt)+) () $copy:tt) => { + // "unexpected end of macro invocation" + $crate::graphql_vars!(); + }; + + // Misplaced colon. Trigger a reasonable error message. + (@object $object:ident () (: $($rest:tt)*) ($colon:tt $($copy:tt)*)) => { + // Takes no arguments so "no rules expected the token `:`". + $crate::graphql_vars!(@unexpected $colon); + }; + + // Found a comma inside a key. Trigger a reasonable error message. + (@object $object:ident ($($key:tt)*) (, $($rest:tt)*) ($comma:tt $($copy:tt)*)) => { + // Takes no arguments so "no rules expected the token `,`". + $crate::graphql_vars!(@unexpected $comma); + }; + + // Key is fully parenthesized. This avoids clippy double_parens false + // positives because the parenthesization may be necessary here. + (@object $object:ident () (($key:expr) : $($rest:tt)*) $copy:tt) => { + $crate::graphql_vars!(@object $object ($key) (: $($rest)*) (: $($rest)*)); + }; + + // Refuse to absorb colon token into key expression. + (@object $object:ident ($($key:tt)*) (: $($unexpected:tt)+) $copy:tt) => { + $crate::graphql_vars!(@unexpected $($unexpected)+); + }; + + // Munch a token into the current key. + (@object $object:ident ($($key:tt)*) ($tt:tt $($rest:tt)*) $copy:tt) => { + $crate::graphql_vars!(@object $object ($($key)* $tt) ($($rest)*) ($($rest)*)); + }; + + //////////// + // Errors // + //////////// + + (@unexpected) => {}; + + ////////////// + // Defaults // + ////////////// + + ({}) => {{ ::std::collections::HashMap::new() }}; + + ({ $($map:tt)* }) => {{ + let mut object = ::std::collections::HashMap::new(); + $crate::graphql_vars!(@object object () ($($map)*) ($($map)*)); + object + }}; +} + +#[cfg(test)] +mod tests { + use indexmap::{indexmap, IndexMap}; + + type V = crate::Variables; + + type IV = crate::InputValue; + + #[test] + fn empty() { + assert_eq!(graphql_vars!({}), V::new()); + } + + #[test] + fn scalar() { + let val = 42; + assert_eq!( + graphql_vars!({ "key": 123 }), + vec![("key".to_owned(), IV::scalar(123))] + .into_iter() + .collect::(), + ); + assert_eq!( + graphql_vars!({ "key": "val" }), + vec![("key".to_owned(), IV::scalar("val"))] + .into_iter() + .collect::(), + ); + assert_eq!( + graphql_vars!({ "key": 1.23 }), + vec![("key".to_owned(), IV::scalar(1.23))] + .into_iter() + .collect::(), + ); + assert_eq!( + graphql_vars!({ "key": 1 + 2 }), + vec![("key".to_owned(), IV::scalar(3))] + .into_iter() + .collect(), + ); + assert_eq!( + graphql_vars!({ "key": false }), + vec![("key".to_owned(), IV::scalar(false))] + .into_iter() + .collect::(), + ); + assert_eq!( + graphql_vars!({ "key": (val) }), + vec![("key".to_owned(), IV::scalar(42))] + .into_iter() + .collect::(), + ); + } + + #[test] + fn enums() { + assert_eq!( + graphql_vars!({ "key": ENUM }), + vec![("key".to_owned(), IV::enum_value("ENUM"))] + .into_iter() + .collect::(), + ); + assert_eq!( + graphql_vars!({ "key": lowercase }), + vec![("key".to_owned(), IV::enum_value("lowercase"))] + .into_iter() + .collect::(), + ); + } + + #[test] + fn variables() { + assert_eq!( + graphql_vars!({ "key": @var }), + vec![("key".to_owned(), IV::variable("var"))] + .into_iter() + .collect::(), + ); + assert_eq!( + graphql_vars!({ "key": @array }), + vec![("key".to_owned(), IV::variable("array"))] + .into_iter() + .collect::(), + ); + assert_eq!( + graphql_vars!({ "key": @object }), + vec![("key".to_owned(), IV::variable("object"))] + .into_iter() + .collect::(), + ); + } + + #[test] + fn lists() { + let val = 42; + assert_eq!( + graphql_vars!({ "key": [] }), + vec![("key".to_owned(), IV::list(vec![]))] + .into_iter() + .collect::(), + ); + + assert_eq!( + graphql_vars!({ "key": [null] }), + vec![("key".to_owned(), IV::list(vec![IV::Null]))] + .into_iter() + .collect::(), + ); + + assert_eq!( + graphql_vars!({ "key": [1] }), + vec![("key".to_owned(), IV::list(vec![IV::scalar(1)]))] + .into_iter() + .collect::(), + ); + assert_eq!( + graphql_vars!({ "key": [1 + 2] }), + vec![("key".to_owned(), IV::list(vec![IV::scalar(3)]))] + .into_iter() + .collect::(), + ); + assert_eq!( + graphql_vars!({ "key": [(val)] }), + vec![("key".to_owned(), IV::list(vec![IV::scalar(42)]))] + .into_iter() + .collect::(), + ); + + assert_eq!( + graphql_vars!({ "key": [ENUM] }), + vec![("key".to_owned(), IV::list(vec![IV::enum_value("ENUM")]))] + .into_iter() + .collect::(), + ); + assert_eq!( + graphql_vars!({ "key": [lowercase] }), + vec![( + "key".to_owned(), + IV::list(vec![IV::enum_value("lowercase")]) + )] + .into_iter() + .collect::(), + ); + + assert_eq!( + graphql_vars!({ "key": [@var] }), + vec![("key".to_owned(), IV::list(vec![IV::variable("var")]))] + .into_iter() + .collect::(), + ); + assert_eq!( + graphql_vars!({ "key": [@array] }), + vec![("key".to_owned(), IV::list(vec![IV::variable("array")]))] + .into_iter() + .collect::(), + ); + assert_eq!( + graphql_vars!({ "key": [@object] }), + vec![("key".to_owned(), IV::list(vec![IV::variable("object")]))] + .into_iter() + .collect::(), + ); + + assert_eq!( + graphql_vars!({ "key": [1, [2], 3] }), + vec![( + "key".to_owned(), + IV::list(vec![ + IV::scalar(1), + IV::list(vec![IV::scalar(2)]), + IV::scalar(3), + ]) + )] + .into_iter() + .collect::(), + ); + assert_eq!( + graphql_vars!({ "key": [1, [2 + 3], 3] }), + vec![( + "key".to_owned(), + IV::list(vec![ + IV::scalar(1), + IV::list(vec![IV::scalar(5)]), + IV::scalar(3), + ]) + )] + .into_iter() + .collect::(), + ); + assert_eq!( + graphql_vars!({ "key": [1, [ENUM], (val)] }), + vec![( + "key".to_owned(), + IV::list(vec![ + IV::scalar(1), + IV::list(vec![IV::enum_value("ENUM")]), + IV::scalar(42), + ]) + )] + .into_iter() + .collect::(), + ); + assert_eq!( + graphql_vars!({ "key": [1 + 2, [(val)], @val,] }), + vec![( + "key".to_owned(), + IV::list(vec![ + IV::scalar(3), + IV::list(vec![IV::scalar(42)]), + IV::variable("val"), + ]) + )] + .into_iter() + .collect::() + ); + assert_eq!( + graphql_vars!({ "key": [1, [@val], ENUM,], }), + vec![( + "key".to_owned(), + IV::list(vec![ + IV::scalar(1), + IV::list(vec![IV::variable("val")]), + IV::enum_value("ENUM"), + ]) + )] + .into_iter() + .collect::(), + ); + } + + #[test] + fn objects() { + let val = 42; + assert_eq!( + graphql_vars!({ "key": {} }), + vec![("key".to_owned(), IV::object(IndexMap::::new()))] + .into_iter() + .collect::(), + ); + + assert_eq!( + graphql_vars!({ "key": { "key": null } }), + vec![( + "key".to_owned(), + IV::object(indexmap! { "key" => IV::Null }), + )] + .into_iter() + .collect::(), + ); + + assert_eq!( + graphql_vars!({ "key": { "key": 123 } }), + vec![( + "key".to_owned(), + IV::object(indexmap! { "key" => IV::scalar(123) }), + )] + .into_iter() + .collect::(), + ); + assert_eq!( + graphql_vars!({ "key": { "key": 1 + 2 } }), + vec![( + "key".to_owned(), + IV::object(indexmap! { "key" => IV::scalar(3) }), + )] + .into_iter() + .collect::(), + ); + assert_eq!( + graphql_vars!({ "key": { "key": (val) } }), + vec![( + "key".to_owned(), + IV::object(indexmap! { "key" => IV::scalar(42) }), + )] + .into_iter() + .collect::(), + ); + + assert_eq!( + graphql_vars!({ "key": { "key": [] } }), + vec![( + "key".to_owned(), + IV::object(indexmap! { "key" => IV::list(vec![]) }), + )] + .into_iter() + .collect::(), + ); + assert_eq!( + graphql_vars!({ "key": { "key": [null] } }), + vec![( + "key".to_owned(), + IV::object(indexmap! { "key" => IV::list(vec![IV::Null]) }), + )] + .into_iter() + .collect::(), + ); + assert_eq!( + graphql_vars!({ "key": { "key": [1] } }), + vec![( + "key".to_owned(), + IV::object(indexmap! { "key" => IV::list(vec![IV::scalar(1)]) }), + )] + .into_iter() + .collect::(), + ); + assert_eq!( + graphql_vars!({ "key": { "key": [1 + 2] } }), + vec![( + "key".to_owned(), + IV::object(indexmap! { "key" => IV::list(vec![IV::scalar(3)]) }), + )] + .into_iter() + .collect::(), + ); + assert_eq!( + graphql_vars!({ "key": { "key": [(val)] } }), + vec![( + "key".to_owned(), + IV::object(indexmap! { "key" => IV::list(vec![IV::scalar(42)]) }), + )] + .into_iter() + .collect::(), + ); + assert_eq!( + graphql_vars!({ "key": { "key": ENUM } }), + vec![( + "key".to_owned(), + IV::object(indexmap! { "key" => IV::enum_value("ENUM") }), + )] + .into_iter() + .collect::(), + ); + assert_eq!( + graphql_vars!({ "key": { "key": lowercase } }), + vec![( + "key".to_owned(), + IV::object(indexmap! { "key" => IV::enum_value("lowercase") }), + )] + .into_iter() + .collect::(), + ); + assert_eq!( + graphql_vars!({ "key": { "key": @val } }), + vec![( + "key".to_owned(), + IV::object(indexmap! { "key" => IV::variable("val") }), + )] + .into_iter() + .collect::(), + ); + assert_eq!( + graphql_vars!({ "key": { "key": @array } }), + vec![( + "key".to_owned(), + IV::object(indexmap! { "key" => IV::variable("array") }), + )] + .into_iter() + .collect::(), + ); + + assert_eq!( + graphql_vars!({ + "inner": { + "key1": (val), + "key2": "val", + "key3": [ + { + "inner": 42, + }, + { + "inner": ENUM, + "even-more": { + "var": @var, + }, + } + ], + "key4": [1, ["val", 1 + 3], null, @array], + }, + "more": @var, + }), + vec![ + ( + "inner".to_owned(), + IV::object(indexmap! { + "key1" => IV::scalar(42), + "key2" => IV::scalar("val"), + "key3" => IV::list(vec![ + IV::object(indexmap! { + "inner" => IV::scalar(42), + }), + IV::object(indexmap! { + "inner" => IV::enum_value("ENUM"), + "even-more" => IV::object(indexmap! { + "var" => IV::variable("var"), + }) + }), + ]), + "key4" => IV::list(vec![ + IV::scalar(1), + IV::list(vec![ + IV::scalar("val"), + IV::scalar(4), + ]), + IV::Null, + IV::variable("array"), + ]), + }), + ), + ("more".to_owned(), IV::variable("var")), + ] + .into_iter() + .collect::(), + ); + } +} diff --git a/juniper/src/executor/mod.rs b/juniper/src/executor/mod.rs index 429e5f311..c632ddd12 100644 --- a/juniper/src/executor/mod.rs +++ b/juniper/src/executor/mod.rs @@ -45,6 +45,8 @@ pub use self::{ mod look_ahead; mod owned_executor; +#[macro_use] +mod macros; /// A type registry used to build schemas /// @@ -246,31 +248,6 @@ pub type ValuesStream<'a, S = DefaultScalarValue> = /// The map of variables used for substitution during query execution pub type Variables = HashMap>; -/// Construct JSON-like [`Variables`] by using JSON syntax. -/// -/// __Note:__ [`InputValue::List`]s and [`InputValue::Object`]s will be created -/// in a [`Spanning::unlocated`]. -/// -/// # Example -/// -/// The resulting JSON will look just like what you passed in. -/// ```rust -/// # use juniper::{graphql_vars, DefaultScalarValue, Variables}; -/// # type V = Variables; -/// # -/// # let _: V = -/// graphql_vars!({"key": "value", "foo": 1234}); -/// ``` -#[macro_export] -macro_rules! graphql_vars { - ({ $($key:tt : $val:expr ),* $(,)* }) => { - ::std::array::IntoIter::new([ - $( ($key.to_string(), $crate::graphql_input_value!($val)), )* - ]) - .collect::<$crate::Variables>() - } -} - /// Custom error handling trait to enable Error types other than `FieldError` to be specified /// as return value. /// diff --git a/juniper/src/value/macros.rs b/juniper/src/value/macros.rs index a6db12fe5..b90459354 100644 --- a/juniper/src/value/macros.rs +++ b/juniper/src/value/macros.rs @@ -20,6 +20,8 @@ /// # let _: V = /// graphql_value!({"key": "value", "foo": 1234}); /// ``` +/// +/// [`Value`]: crate::Value #[macro_export] macro_rules! graphql_value { /////////// @@ -207,9 +209,7 @@ macro_rules! graphql_value { #[cfg(test)] mod tests { - use crate::{DefaultScalarValue, Value}; - - type V = Value; + type V = crate::Value; #[test] fn null() { diff --git a/juniper/src/value/scalar.rs b/juniper/src/value/scalar.rs index d9f6ddfa0..499db2f8e 100644 --- a/juniper/src/value/scalar.rs +++ b/juniper/src/value/scalar.rs @@ -196,6 +196,8 @@ pub trait ScalarValue: /// This function is used for implementing [`GraphQLValue`] for [`i32`] for /// all possible [`ScalarValue`]s. Implementations should convert all the /// supported integer types with 32 bit or less to an integer, if requested. + /// + /// [`GraphQLValue`]: crate::GraphQLValue #[must_use] fn as_int(&self) -> Option; @@ -203,6 +205,8 @@ pub trait ScalarValue: /// /// This function is used for implementing [`GraphQLValue`] for [`String`] /// for all possible [`ScalarValue`]s. + /// + /// [`GraphQLValue`]: crate::GraphQLValue #[must_use] fn as_string(&self) -> Option; @@ -217,6 +221,8 @@ pub trait ScalarValue: /// /// This function is used for implementing [`GraphQLValue`] for [`str`] for /// all possible [`ScalarValue`]s. + /// + /// [`GraphQLValue`]: crate::GraphQLValue #[must_use] fn as_str(&self) -> Option<&str>; @@ -226,6 +232,8 @@ pub trait ScalarValue: /// all possible [`ScalarValue`]s. Implementations should convert all /// supported integer types with 64 bit or less and all floating point /// values with 64 bit or less to a float, if requested. + /// + /// [`GraphQLValue`]: crate::GraphQLValue #[must_use] fn as_float(&self) -> Option; @@ -233,6 +241,8 @@ pub trait ScalarValue: /// /// This function is used for implementing [`GraphQLValue`] for [`bool`] for /// all possible [`ScalarValue`]s. + /// + /// [`GraphQLValue`]: crate::GraphQLValue fn as_boolean(&self) -> Option; /// Converts this [`ScalarValue`] into another one. From c9fe3ab69f1087927bf8c90fcc8c73abbe503fe8 Mon Sep 17 00:00:00 2001 From: ilslv Date: Thu, 25 Nov 2021 12:13:26 +0300 Subject: [PATCH 13/22] Corrections --- juniper/src/ast/macros.rs | 131 +++++++++++++++++++----- juniper/src/ast/mod.rs | 1 - juniper/src/executor/macros.rs | 93 +++++++++++++---- juniper/src/executor_tests/enums.rs | 1 - juniper/src/executor_tests/executor.rs | 1 - juniper/src/executor_tests/variables.rs | 1 - juniper/src/parser/tests/value.rs | 2 - juniper/src/tests/query_tests.rs | 1 - juniper/src/value/macros.rs | 55 ++++++++-- 9 files changed, 224 insertions(+), 62 deletions(-) diff --git a/juniper/src/ast/macros.rs b/juniper/src/ast/macros.rs index 8adc02167..a8c62b145 100644 --- a/juniper/src/ast/macros.rs +++ b/juniper/src/ast/macros.rs @@ -1,9 +1,9 @@ -/// Construct JSON-like [`InputValue`]s by using JSON-like syntax. +/// Construct [`InputValue`]s by using JSON-like syntax. /// /// # Differences from [`graphql_value!`] /// /// - [`InputValue::Enum`] is constructed with `ident`, so to capture outer -/// variable surround it with parens: `(var)`. +/// variable as [`InputValue::Scalar`] surround it with parens: `(var)`. /// ```rust /// # use juniper::{graphql_input_value, graphql_value}; /// # @@ -25,6 +25,26 @@ /// assert_eq!(graphql_input_value!(@var), InputValue::variable("var")); /// ``` /// +/// - [`InputValue::Object`] key should implement [`Into`]`<`[`String`]`>`. +/// ```rust +/// # use std::borrow::Cow; +/// # +/// # use juniper::{graphql_input_value, InputValue}; +/// # +/// let code = 200; +/// let features = vec!["key", "value"]; +/// let key: Cow<'static, str> = "key".into(); +/// +/// let value: InputValue = graphql_input_value!({ +/// "code": code, +/// "success": code == 200, +/// "payload": { +/// features[0]: features[1], +/// key: @var, +/// }, +/// }); +/// ``` +/// /// __Note:__ [`InputValue::List`]s and [`InputValue::Object`]s will be created /// in a [`Spanning::unlocated`]. /// @@ -57,6 +77,7 @@ /// [`InputValue::Enum`]: crate::InputValue::Enum /// [`InputValue::List`]: crate::InputValue::List /// [`InputValue::Object`]: crate::InputValue::Object +/// [`InputValue::Scalar`]: crate::InputValue::Scalar /// [`InputValue::Variable`]: crate::InputValue::Variable /// [`Spanning::unlocated`]: crate::Spanning::unlocated #[macro_export] @@ -93,13 +114,6 @@ macro_rules! graphql_input_value { ) }; - // Next element is `true`, `false` or enum. - (@@array [$($elems:expr,)*] $enum:ident $($rest:tt)*) => { - $crate::graphql_input_value!( - @@array [$($elems,)* $crate::graphql_input_value!($enum)] $($rest)* - ) - }; - // Next element is an array. (@@array [$($elems:expr,)*] [$($array:tt)*] $($rest:tt)*) => { @@ -115,6 +129,20 @@ macro_rules! graphql_input_value { ) }; + // Next element is `true`, `false` or enum ident followed by comma. + (@@array [$($elems:expr,)*] $ident:ident, $($rest:tt)*) => { + $crate::graphql_input_value!( + @@array [$($elems,)* $crate::graphql_input_value!($ident),] $($rest)* + ) + }; + + // Next element is `true`, `false` or enum ident without trailing comma. + (@@array [$($elems:expr,)*] $last:ident ) => { + $crate::graphql_input_value!( + @@array [$($elems,)* $crate::graphql_input_value!($last)] + ) + }; + // Next element is an expression followed by comma. (@@array [$($elems:expr,)*] $next:expr, $($rest:tt)*) => { $crate::graphql_input_value!( @@ -148,7 +176,10 @@ macro_rules! graphql_input_value { // Insert the current entry followed by trailing comma. (@@object $object:ident [$($key:tt)+] ($value:expr) , $($rest:tt)*) => { - let _ = $object.push(($crate::Spanning::unlocated(($($key)+).into()), $crate::Spanning::unlocated($value))); + $object.push(( + $crate::Spanning::unlocated(($($key)+).into()), + $crate::Spanning::unlocated($value), + )); $crate::graphql_input_value!(@@object $object () ($($rest)*) ($($rest)*)); }; @@ -159,42 +190,82 @@ macro_rules! graphql_input_value { // Insert the last entry without trailing comma. (@@object $object:ident [$($key:tt)+] ($value:expr)) => { - let _ = $object.push(($crate::Spanning::unlocated(($($key)+).into()), $crate::Spanning::unlocated($value))); + $object.push(( + $crate::Spanning::unlocated(($($key)+).into()), + $crate::Spanning::unlocated($value), + )); }; // Next value is `null`. (@@object $object:ident ($($key:tt)+) (: null $($rest:tt)*) $copy:tt) => { - $crate::graphql_input_value!(@@object $object [$($key)+] ($crate::graphql_input_value!(null)) $($rest)*); + $crate::graphql_input_value!( + @@object $object + [$($key)+] + ($crate::graphql_input_value!(null)) $($rest)* + ); }; // Next value is a variable. (@@object $object:ident ($($key:tt)+) (: @$var:ident $($rest:tt)*) $copy:tt) => { - $crate::graphql_input_value!(@@object $object [$($key)+] ($crate::graphql_input_value!(@$var)) $($rest)*); - }; - - // Next value is `true`, `false` or enum. - (@@object $object:ident ($($key:tt)+) (: $enum:ident $($rest:tt)*) $copy:tt) => { - $crate::graphql_input_value!(@@object $object [$($key)+] ($crate::graphql_input_value!($enum)) $($rest)*); + $crate::graphql_input_value!( + @@object $object + [$($key)+] + ($crate::graphql_input_value!(@$var)) $($rest)* + ); }; // Next value is an array. (@@object $object:ident ($($key:tt)+) (: [$($array:tt)*] $($rest:tt)*) $copy:tt) => { - $crate::graphql_input_value!(@@object $object [$($key)+] ($crate::graphql_input_value!([$($array)*])) $($rest)*); + $crate::graphql_input_value!( + @@object $object + [$($key)+] + ($crate::graphql_input_value!([$($array)*])) $($rest)* + ); }; // Next value is a map. (@@object $object:ident ($($key:tt)+) (: {$($map:tt)*} $($rest:tt)*) $copy:tt) => { - $crate::graphql_input_value!(@@object $object [$($key)+] ($crate::graphql_input_value!({$($map)*})) $($rest)*); + $crate::graphql_input_value!( + @@object $object + [$($key)+] + ($crate::graphql_input_value!({$($map)*})) $($rest)* + ); + }; + + // Next value is `true`, `false` or enum ident followed by comma. + (@@object $object:ident ($($key:tt)+) (: $ident:ident , $($rest:tt)*) $copy:tt) => { + $crate::graphql_input_value!( + @@object $object + [$($key)+] + ($crate::graphql_input_value!($ident)) , $($rest)* + ); + }; + + // Next value is `true`, `false` or enum ident without trailing comma. + (@@object $object:ident ($($key:tt)+) (: $last:ident ) $copy:tt) => { + $crate::graphql_input_value!( + @@object $object + [$($key)+] + ($crate::graphql_input_value!($last)) + ); }; // Next value is an expression followed by comma. (@@object $object:ident ($($key:tt)+) (: $value:expr , $($rest:tt)*) $copy:tt) => { - $crate::graphql_input_value!(@@object $object [$($key)+] ($crate::graphql_input_value!($value)) , $($rest)*); + $crate::graphql_input_value!( + @@object $object + [$($key)+] + ($crate::graphql_input_value!($value)) , $($rest)* + ); }; // Last value is an expression with no trailing comma. (@@object $object:ident ($($key:tt)+) (: $value:expr) $copy:tt) => { - $crate::graphql_input_value!(@@object $object [$($key)+] ($crate::graphql_input_value!($value))); + $crate::graphql_input_value!( + @@object $object + [$($key)+] + ($crate::graphql_input_value!($value)) + ); }; // Missing value for last entry. Trigger a reasonable error message. @@ -225,24 +296,32 @@ macro_rules! graphql_input_value { // Key is fully parenthesized. This avoids clippy double_parens false // positives because the parenthesization may be necessary here. (@@object $object:ident () (($key:expr) : $($rest:tt)*) $copy:tt) => { - $crate::graphql_input_value!(@@object $object ($key) (: $($rest)*) (: $($rest)*)); + $crate::graphql_input_value!( + @@object $object + ($key) + (: $($rest)*) (: $($rest)*) + ); }; // Refuse to absorb colon token into key expression. (@@object $object:ident ($($key:tt)*) (: $($unexpected:tt)+) $copy:tt) => { - $crate::graphql_input_value!(@unexpected $($unexpected)+); + $crate::graphql_input_value!(@@unexpected $($unexpected)+); }; // Munch a token into the current key. (@@object $object:ident ($($key:tt)*) ($tt:tt $($rest:tt)*) $copy:tt) => { - $crate::graphql_input_value!(@@object $object ($($key)* $tt) ($($rest)*) ($($rest)*)); + $crate::graphql_input_value!( + @@object $object + ($($key)* $tt) + ($($rest)*) ($($rest)*) + ); }; //////////// // Errors // //////////// - (@unexpected) => {}; + (@@unexpected) => {}; ////////////// // Defaults // diff --git a/juniper/src/ast/mod.rs b/juniper/src/ast/mod.rs index 56fbb617f..ab0dae13c 100644 --- a/juniper/src/ast/mod.rs +++ b/juniper/src/ast/mod.rs @@ -510,7 +510,6 @@ impl<'a, S> VariableDefinitions<'a, S> { #[cfg(test)] mod tests { use super::InputValue; - use crate::parser::Spanning; #[test] fn test_input_value_fmt() { diff --git a/juniper/src/executor/macros.rs b/juniper/src/executor/macros.rs index dd94c9ca3..2c3390dac 100644 --- a/juniper/src/executor/macros.rs +++ b/juniper/src/executor/macros.rs @@ -1,17 +1,25 @@ -/// Construct JSON-like [`Variables`] by using JSON-like syntax. -/// -/// See [`graphql_input_value!`] for more info on syntax of value after `:`. -/// -/// # Example +/// Construct [`Variables`] by using JSON-like syntax. /// +/// [`Variables`] key should implement [`Into`]`<`[`String`]`>`. /// ```rust +/// # use std::borrow::Cow; +/// # /// # use juniper::{graphql_vars, Variables}; -/// # type V = Variables; /// # -/// # let _: V = -/// graphql_vars!({ "key": "value", "foo": 1234, "var": @var }); +/// let code = 200; +/// let features = vec!["key", "value"]; +/// let key: Cow<'static, str> = "key".into(); +/// +/// let value: Variables = graphql_vars!({ +/// "code": code, +/// "success": code == 200, +/// features[0]: features[1], +/// key: @var, +/// }); /// ``` /// +/// See [`graphql_input_value!`] for more info on syntax of value after `:`. +/// /// [`Variables`]: crate::Variables #[macro_export] macro_rules! graphql_vars { @@ -40,37 +48,74 @@ macro_rules! graphql_vars { // Next value is `null`. (@object $object:ident ($($key:tt)+) (: null $($rest:tt)*) $copy:tt) => { - $crate::graphql_vars!(@object $object [$($key)+] ($crate::graphql_input_value!(null)) $($rest)*); + $crate::graphql_vars!( + @object $object + [$($key)+] + ($crate::graphql_input_value!(null)) $($rest)* + ); }; // Next value is a variable. (@object $object:ident ($($key:tt)+) (: @$var:ident $($rest:tt)*) $copy:tt) => { - $crate::graphql_vars!(@object $object [$($key)+] ($crate::graphql_input_value!(@$var)) $($rest)*); - }; - - // Next value is `true`, `false` or enum. - (@object $object:ident ($($key:tt)+) (: $enum:ident $($rest:tt)*) $copy:tt) => { - $crate::graphql_vars!(@object $object [$($key)+] ($crate::graphql_input_value!($enum)) $($rest)*); + $crate::graphql_vars!( + @object $object + [$($key)+] + ($crate::graphql_input_value!(@$var)) $($rest)* + ); }; // Next value is an array. (@object $object:ident ($($key:tt)+) (: [$($array:tt)*] $($rest:tt)*) $copy:tt) => { - $crate::graphql_vars!(@object $object [$($key)+] ($crate::graphql_input_value!([$($array)*])) $($rest)*); + $crate::graphql_vars!( + @object $object + [$($key)+] + ($crate::graphql_input_value!([$($array)*])) $($rest)* + ); }; // Next value is a map. (@object $object:ident ($($key:tt)+) (: {$($map:tt)*} $($rest:tt)*) $copy:tt) => { - $crate::graphql_vars!(@object $object [$($key)+] ($crate::graphql_input_value!({$($map)*})) $($rest)*); + $crate::graphql_vars!( + @object $object + [$($key)+] + ($crate::graphql_input_value!({$($map)*})) $($rest)* + ); + }; + + // Next value is `true`, `false` or enum ident followed by a comma. + (@object $object:ident ($($key:tt)+) (: $ident:ident , $($rest:tt)*) $copy:tt) => { + $crate::graphql_vars!( + @object $object + [$($key)+] + ($crate::graphql_input_value!($ident)) , $($rest)* + ); + }; + + // Next value is `true`, `false` or enum ident without trailing comma. + (@object $object:ident ($($key:tt)+) (: $last:ident ) $copy:tt) => { + $crate::graphql_vars!( + @object $object + [$($key)+] + ($crate::graphql_input_value!($last)) + ); }; // Next value is an expression followed by comma. (@object $object:ident ($($key:tt)+) (: $value:expr , $($rest:tt)*) $copy:tt) => { - $crate::graphql_vars!(@object $object [$($key)+] ($crate::graphql_input_value!($value)) , $($rest)*); + $crate::graphql_vars!( + @object $object + [$($key)+] + ($crate::graphql_input_value!($value)) , $($rest)* + ); }; // Last value is an expression with no trailing comma. (@object $object:ident ($($key:tt)+) (: $value:expr) $copy:tt) => { - $crate::graphql_vars!(@object $object [$($key)+] ($crate::graphql_input_value!($value))); + $crate::graphql_vars!( + @object $object + [$($key)+] + ($crate::graphql_input_value!($value)) + ); }; // Missing value for last entry. Trigger a reasonable error message. @@ -111,7 +156,11 @@ macro_rules! graphql_vars { // Munch a token into the current key. (@object $object:ident ($($key:tt)*) ($tt:tt $($rest:tt)*) $copy:tt) => { - $crate::graphql_vars!(@object $object ($($key)* $tt) ($($rest)*) ($($rest)*)); + $crate::graphql_vars!( + @object $object + ($($key)* $tt) + ($($rest)*) ($($rest)*) + ); }; //////////// @@ -124,10 +173,10 @@ macro_rules! graphql_vars { // Defaults // ////////////// - ({}) => {{ ::std::collections::HashMap::new() }}; + ({}) => {{ ::std::collections::HashMap::<::std::string::String, _>::new() }}; ({ $($map:tt)* }) => {{ - let mut object = ::std::collections::HashMap::new(); + let mut object = ::std::collections::HashMap::<::std::string::String, _>::new(); $crate::graphql_vars!(@object object () ($($map)*) ($($map)*)); object }}; diff --git a/juniper/src/executor_tests/enums.rs b/juniper/src/executor_tests/enums.rs index f4f943c55..96f3ce32f 100644 --- a/juniper/src/executor_tests/enums.rs +++ b/juniper/src/executor_tests/enums.rs @@ -1,5 +1,4 @@ use crate::{ - ast::InputValue, executor::Variables, parser::SourcePosition, schema::model::RootNode, diff --git a/juniper/src/executor_tests/executor.rs b/juniper/src/executor_tests/executor.rs index bfaac1264..cdb778e40 100644 --- a/juniper/src/executor_tests/executor.rs +++ b/juniper/src/executor_tests/executor.rs @@ -1,6 +1,5 @@ mod field_execution { use crate::{ - ast::InputValue, graphql_value, schema::model::RootNode, types::scalars::{EmptyMutation, EmptySubscription}, diff --git a/juniper/src/executor_tests/variables.rs b/juniper/src/executor_tests/variables.rs index ac90b6f6a..29f36aff7 100644 --- a/juniper/src/executor_tests/variables.rs +++ b/juniper/src/executor_tests/variables.rs @@ -1,5 +1,4 @@ use crate::{ - ast::InputValue, executor::Variables, graphql_object, graphql_scalar, graphql_value, parser::SourcePosition, diff --git a/juniper/src/parser/tests/value.rs b/juniper/src/parser/tests/value.rs index 76a6b2580..3c3cce16a 100644 --- a/juniper/src/parser/tests/value.rs +++ b/juniper/src/parser/tests/value.rs @@ -1,5 +1,3 @@ -use indexmap::IndexMap; - use crate::{ ast::{FromInputValue, InputValue, Type}, parser::{value::parse_value_literal, Lexer, Parser, SourcePosition, Spanning}, diff --git a/juniper/src/tests/query_tests.rs b/juniper/src/tests/query_tests.rs index 73b4f381d..24865847b 100644 --- a/juniper/src/tests/query_tests.rs +++ b/juniper/src/tests/query_tests.rs @@ -1,5 +1,4 @@ use crate::{ - ast::InputValue, executor::Variables, graphql_value, schema::model::RootNode, diff --git a/juniper/src/value/macros.rs b/juniper/src/value/macros.rs index b90459354..e3729802a 100644 --- a/juniper/src/value/macros.rs +++ b/juniper/src/value/macros.rs @@ -1,7 +1,23 @@ -/// Construct JSON-like [`Value`]s by using JSON syntax. +/// Construct [`Value`]s by using JSON syntax. /// /// [`Value`] objects are used mostly when creating custom errors from fields. /// +/// [`Value::Object`] key should implement [`AsRef`]`<`[`str`]`>`. +/// ```rust +/// # use juniper::{graphql_value, Value}; +/// # +/// let code = 200; +/// let features = vec!["key", "value"]; +/// +/// let value: Value = graphql_value!({ +/// "code": code, +/// "success": code == 200, +/// "payload": { +/// features[0]: features[1], +/// }, +/// }); +/// ``` +/// /// # Example /// /// Resulting JSON will look just like what you passed in. @@ -22,6 +38,7 @@ /// ``` /// /// [`Value`]: crate::Value +/// [`Value::Object`]: crate::Value::Object #[macro_export] macro_rules! graphql_value { /////////// @@ -112,27 +129,47 @@ macro_rules! graphql_value { // Next value is `null`. (@object $object:ident ($($key:tt)+) (: null $($rest:tt)*) $copy:tt) => { - $crate::graphql_value!(@object $object [$($key)+] ($crate::graphql_value!(null)) $($rest)*); + $crate::graphql_value!( + @object $object + [$($key)+] + ($crate::graphql_value!(null)) $($rest)* + ); }; // Next value is an array. (@object $object:ident ($($key:tt)+) (: [$($array:tt)*] $($rest:tt)*) $copy:tt) => { - $crate::graphql_value!(@object $object [$($key)+] ($crate::graphql_value!([$($array)*])) $($rest)*); + $crate::graphql_value!( + @object $object + [$($key)+] + ($crate::graphql_value!([$($array)*])) $($rest)* + ); }; // Next value is a map. (@object $object:ident ($($key:tt)+) (: {$($map:tt)*} $($rest:tt)*) $copy:tt) => { - $crate::graphql_value!(@object $object [$($key)+] ($crate::graphql_value!({$($map)*})) $($rest)*); + $crate::graphql_value!( + @object $object + [$($key)+] + ($crate::graphql_value!({$($map)*})) $($rest)* + ); }; // Next value is an expression followed by comma. (@object $object:ident ($($key:tt)+) (: $value:expr , $($rest:tt)*) $copy:tt) => { - $crate::graphql_value!(@object $object [$($key)+] ($crate::graphql_value!($value)) , $($rest)*); + $crate::graphql_value!( + @object $object + [$($key)+] + ($crate::graphql_value!($value)) , $($rest)* + ); }; // Last value is an expression with no trailing comma. (@object $object:ident ($($key:tt)+) (: $value:expr) $copy:tt) => { - $crate::graphql_value!(@object $object [$($key)+] ($crate::graphql_value!($value))); + $crate::graphql_value!( + @object $object + [$($key)+] + ($crate::graphql_value!($value)) + ); }; // Missing value for last entry. Trigger a reasonable error message. @@ -173,7 +210,11 @@ macro_rules! graphql_value { // Munch a token into the current key. (@object $object:ident ($($key:tt)*) ($tt:tt $($rest:tt)*) $copy:tt) => { - $crate::graphql_value!(@object $object ($($key)* $tt) ($($rest)*) ($($rest)*)); + $crate::graphql_value!( + @object $object + ($($key)* $tt) + ($($rest)*) ($($rest)*) + ); }; //////////// From 7c927da364fe7477910cf91c898aae410be4185f Mon Sep 17 00:00:00 2001 From: ilslv Date: Thu, 25 Nov 2021 12:22:15 +0300 Subject: [PATCH 14/22] CHANGELOG --- juniper/CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/juniper/CHANGELOG.md b/juniper/CHANGELOG.md index f3db543ec..99680c54c 100644 --- a/juniper/CHANGELOG.md +++ b/juniper/CHANGELOG.md @@ -7,16 +7,19 @@ - `#[graphql_object]` and `#[graphql_subscription]` macros expansion now preserves defined `impl` blocks "as is" and reuses defined methods in opaque way. ([#971](https://github.com/graphql-rust/juniper/pull/971)) - `rename = ""` attribute's argument renamed to `rename_all = ""`. ([#971](https://github.com/graphql-rust/juniper/pull/971)) - Upgrade `bson` feature to [2.0 version of its crate](https://github.com/mongodb/bson-rust/releases/tag/v2.0.0). ([#979](https://github.com/graphql-rust/juniper/pull/979)) +- Use `null` instead of `None` to create `Value::Null` in `graphql_value!` macro to mirror `serde_json::json!`. ([#996](https://github.com/graphql-rust/juniper/pull/996)) ## Features - Support using Rust array as GraphQL list. ([#966](https://github.com/graphql-rust/juniper/pull/966), [#918](https://github.com/graphql-rust/juniper/issues/918)) - Expose `GraphQLRequest` fields. ([#750](https://github.com/graphql-rust/juniper/issues/750)) - `#[graphql_interface]` macro now supports `rename_all = ""` argument influencing its fields and their arguments. ([#971](https://github.com/graphql-rust/juniper/pull/971)) +- Implement `graphql_input_value!` and `graphql_vars!` macros. ([#996](https://github.com/graphql-rust/juniper/pull/996)) ## Fixes - Allow spreading interface fragments on unions and other interfaces. ([#965](https://github.com/graphql-rust/juniper/pull/965), [#798](https://github.com/graphql-rust/juniper/issues/798)) +- Support expressions in `graphql_value!` macro. ([#996](https://github.com/graphql-rust/juniper/pull/996), [#503](https://github.com/graphql-rust/juniper/issues/503)) # [[0.15.7] 2021-07-08](https://github.com/graphql-rust/juniper/releases/tag/juniper-v0.15.7) From 1e77c947ba1832b6a16539edc5b03fa737d9f6e2 Mon Sep 17 00:00:00 2001 From: ilslv Date: Thu, 25 Nov 2021 12:51:05 +0300 Subject: [PATCH 15/22] Add better support for `Option`al values for `InputValue` --- juniper/CHANGELOG.md | 3 ++- juniper/src/ast/macros.rs | 34 +++++++++++++++++++++++---- juniper/src/ast/mod.rs | 42 ++++++++++++++++++++++++++++++++++ juniper/src/executor/macros.rs | 9 ++++++++ juniper/src/value/macros.rs | 26 +++++++++++++++++++++ 5 files changed, 109 insertions(+), 5 deletions(-) diff --git a/juniper/CHANGELOG.md b/juniper/CHANGELOG.md index 99680c54c..74eed9ef1 100644 --- a/juniper/CHANGELOG.md +++ b/juniper/CHANGELOG.md @@ -7,13 +7,14 @@ - `#[graphql_object]` and `#[graphql_subscription]` macros expansion now preserves defined `impl` blocks "as is" and reuses defined methods in opaque way. ([#971](https://github.com/graphql-rust/juniper/pull/971)) - `rename = ""` attribute's argument renamed to `rename_all = ""`. ([#971](https://github.com/graphql-rust/juniper/pull/971)) - Upgrade `bson` feature to [2.0 version of its crate](https://github.com/mongodb/bson-rust/releases/tag/v2.0.0). ([#979](https://github.com/graphql-rust/juniper/pull/979)) -- Use `null` instead of `None` to create `Value::Null` in `graphql_value!` macro to mirror `serde_json::json!`. ([#996](https://github.com/graphql-rust/juniper/pull/996)) ## Features - Support using Rust array as GraphQL list. ([#966](https://github.com/graphql-rust/juniper/pull/966), [#918](https://github.com/graphql-rust/juniper/issues/918)) - Expose `GraphQLRequest` fields. ([#750](https://github.com/graphql-rust/juniper/issues/750)) - `#[graphql_interface]` macro now supports `rename_all = ""` argument influencing its fields and their arguments. ([#971](https://github.com/graphql-rust/juniper/pull/971)) +- Use `null` in addition to `None` to create `Value::Null` in `graphql_value!` macro to mirror `serde_json::json!`. ([#996](https://github.com/graphql-rust/juniper/pull/996)) +- Add `From` impls to `InputValue`, that mirror `Value` and provide better support for `Option` handling. ([#996](https://github.com/graphql-rust/juniper/pull/996)) - Implement `graphql_input_value!` and `graphql_vars!` macros. ([#996](https://github.com/graphql-rust/juniper/pull/996)) ## Fixes diff --git a/juniper/src/ast/macros.rs b/juniper/src/ast/macros.rs index a8c62b145..4efcb4058 100644 --- a/juniper/src/ast/macros.rs +++ b/juniper/src/ast/macros.rs @@ -107,6 +107,13 @@ macro_rules! graphql_input_value { ) }; + // Next element is `None`. + (@@array [$($elems:expr,)*] None $($rest:tt)*) => { + $crate::graphql_input_value!( + @@array [$($elems,)* $crate::graphql_input_value!(None)] $($rest)* + ) + }; + // Next element is a variable. (@@array [$($elems:expr,)*] @$var:ident $($rest:tt)*) => { $crate::graphql_input_value!( @@ -205,6 +212,15 @@ macro_rules! graphql_input_value { ); }; + // Next value is `None`. + (@@object $object:ident ($($key:tt)+) (: None $($rest:tt)*) $copy:tt) => { + $crate::graphql_input_value!( + @@object $object + [$($key)+] + ($crate::graphql_input_value!(None)) $($rest)* + ); + }; + // Next value is a variable. (@@object $object:ident ($($key:tt)+) (: @$var:ident $($rest:tt)*) $copy:tt) => { $crate::graphql_input_value!( @@ -345,17 +361,19 @@ macro_rules! graphql_input_value { (null) => ($crate::InputValue::null()); - (true) => ($crate::InputValue::scalar(true)); + (None) => ($crate::InputValue::null()); - (false) => ($crate::InputValue::scalar(false)); + (true) => ($crate::InputValue::from(true)); + + (false) => ($crate::InputValue::from(false)); (@$var:ident) => ($crate::InputValue::variable(stringify!($var))); ($enum:ident) => ($crate::InputValue::enum_value(stringify!($enum))); - (($e:expr)) => ($crate::InputValue::scalar($e)); + (($e:expr)) => ($crate::InputValue::from($e)); - ($e:expr) => ($crate::InputValue::scalar($e)); + ($e:expr) => ($crate::InputValue::from($e)); } #[cfg(test)] @@ -580,4 +598,12 @@ mod tests { }), ); } + + #[test] + fn option_support() { + let val = Some(42); + assert_eq!(graphql_input_value!(None), V::Null); + assert_eq!(graphql_input_value!(Some(42)), V::scalar(42)); + assert_eq!(graphql_input_value!((val)), V::scalar(42)); + } } diff --git a/juniper/src/ast/mod.rs b/juniper/src/ast/mod.rs index ab0dae13c..b72cc7466 100644 --- a/juniper/src/ast/mod.rs +++ b/juniper/src/ast/mod.rs @@ -475,6 +475,48 @@ impl fmt::Display for InputValue { } } +impl From> for InputValue +where + Self: From, +{ + fn from(v: Option) -> Self { + match v { + Some(v) => v.into(), + None => Self::Null, + } + } +} + +impl<'a, S: From> From<&'a str> for InputValue { + fn from(s: &'a str) -> Self { + Self::scalar(s.to_owned()) + } +} + +impl> From for InputValue { + fn from(s: String) -> Self { + Self::scalar(s) + } +} + +impl> From for InputValue { + fn from(i: i32) -> Self { + Self::scalar(i) + } +} + +impl> From for InputValue { + fn from(f: f64) -> Self { + Self::scalar(f) + } +} + +impl> From for InputValue { + fn from(b: bool) -> Self { + Self::scalar(b) + } +} + impl<'a, S> Arguments<'a, S> { pub fn into_iter(self) -> vec::IntoIter<(Spanning<&'a str>, Spanning>)> { self.items.into_iter() diff --git a/juniper/src/executor/macros.rs b/juniper/src/executor/macros.rs index 2c3390dac..7d9b0927d 100644 --- a/juniper/src/executor/macros.rs +++ b/juniper/src/executor/macros.rs @@ -55,6 +55,15 @@ macro_rules! graphql_vars { ); }; + // Next value is `None`. + (@object $object:ident ($($key:tt)+) (: None $($rest:tt)*) $copy:tt) => { + $crate::graphql_vars!( + @object $object + [$($key)+] + ($crate::graphql_input_value!(None)) $($rest)* + ); + }; + // Next value is a variable. (@object $object:ident ($($key:tt)+) (: @$var:ident $($rest:tt)*) $copy:tt) => { $crate::graphql_vars!( diff --git a/juniper/src/value/macros.rs b/juniper/src/value/macros.rs index e3729802a..d12bbe7a4 100644 --- a/juniper/src/value/macros.rs +++ b/juniper/src/value/macros.rs @@ -66,6 +66,13 @@ macro_rules! graphql_value { ) }; + // Next element is `None`. + (@array [$($elems:expr,)*] None $($rest:tt)*) => { + $crate::graphql_value!( + @array [$($elems,)* $crate::graphql_value!(None)] $($rest)* + ) + }; + // Next element is an array. (@array [$($elems:expr,)*] [$($array:tt)*] $($rest:tt)*) => { $crate::graphql_value!( @@ -136,6 +143,15 @@ macro_rules! graphql_value { ); }; + // Next value is `None`. + (@object $object:ident ($($key:tt)+) (: None $($rest:tt)*) $copy:tt) => { + $crate::graphql_value!( + @object $object + [$($key)+] + ($crate::graphql_value!(None)) $($rest)* + ); + }; + // Next value is an array. (@object $object:ident ($($key:tt)+) (: [$($array:tt)*] $($rest:tt)*) $copy:tt) => { $crate::graphql_value!( @@ -245,6 +261,8 @@ macro_rules! graphql_value { (null) => ($crate::Value::null()); + (None) => ($crate::Value::null()); + ($e:expr) => ($crate::Value::from($e)); } @@ -349,4 +367,12 @@ mod tests { ), ); } + + #[test] + fn option_support() { + let val = Some(42); + assert_eq!(graphql_value!(None), V::Null); + assert_eq!(graphql_value!(Some(42)), V::scalar(42)); + assert_eq!(graphql_value!(val), V::scalar(42)); + } } From 332e1995f8948cba2fdd4673fb7ea4df20af156a Mon Sep 17 00:00:00 2001 From: tyranron Date: Thu, 25 Nov 2021 16:02:27 +0100 Subject: [PATCH 16/22] Moved macro definitions to `macros` module --- juniper/src/{ast/mod.rs => ast.rs} | 3 - juniper/src/executor/mod.rs | 2 - juniper/src/lib.rs | 4 +- .../graphql_input_value.rs} | 90 ++++++----- .../macros.rs => macros/graphql_value.rs} | 31 ++-- .../macros.rs => macros/graphql_vars.rs} | 149 +++++++++--------- juniper/src/macros/mod.rs | 9 +- juniper/src/value/mod.rs | 2 - 8 files changed, 151 insertions(+), 139 deletions(-) rename juniper/src/{ast/mod.rs => ast.rs} (99%) rename juniper/src/{ast/macros.rs => macros/graphql_input_value.rs} (89%) rename juniper/src/{value/macros.rs => macros/graphql_value.rs} (95%) rename juniper/src/{executor/macros.rs => macros/graphql_vars.rs} (82%) diff --git a/juniper/src/ast/mod.rs b/juniper/src/ast.rs similarity index 99% rename from juniper/src/ast/mod.rs rename to juniper/src/ast.rs index b72cc7466..da53f7d88 100644 --- a/juniper/src/ast/mod.rs +++ b/juniper/src/ast.rs @@ -1,6 +1,3 @@ -#[macro_use] -mod macros; - use std::{borrow::Cow, fmt, hash::Hash, slice, vec}; use indexmap::IndexMap; diff --git a/juniper/src/executor/mod.rs b/juniper/src/executor/mod.rs index c632ddd12..c27cd843e 100644 --- a/juniper/src/executor/mod.rs +++ b/juniper/src/executor/mod.rs @@ -45,8 +45,6 @@ pub use self::{ mod look_ahead; mod owned_executor; -#[macro_use] -mod macros; /// A type registry used to build schemas /// diff --git a/juniper/src/lib.rs b/juniper/src/lib.rs index b62d7105e..d17f1b399 100644 --- a/juniper/src/lib.rs +++ b/juniper/src/lib.rs @@ -116,11 +116,8 @@ pub use juniper_codegen::{ GraphQLEnum, GraphQLInputObject, GraphQLObject, GraphQLScalarValue, GraphQLUnion, }; -#[macro_use] -mod value; #[macro_use] mod macros; -#[macro_use] mod ast; pub mod executor; mod introspection; @@ -129,6 +126,7 @@ pub(crate) mod schema; mod types; mod util; pub mod validation; +mod value; // This needs to be public until docs have support for private modules: // https://github.com/rust-lang/cargo/issues/1520 pub mod http; diff --git a/juniper/src/ast/macros.rs b/juniper/src/macros/graphql_input_value.rs similarity index 89% rename from juniper/src/ast/macros.rs rename to juniper/src/macros/graphql_input_value.rs index 4efcb4058..a977708ef 100644 --- a/juniper/src/ast/macros.rs +++ b/juniper/src/macros/graphql_input_value.rs @@ -1,4 +1,8 @@ -/// Construct [`InputValue`]s by using JSON-like syntax. +//! [`graphql_input_value!`] macro implementation. +//! +//! [`graphql_input_value!`]: graphql_input_value + +/// Constructs [`InputValue`]s via JSON-like syntax. /// /// # Differences from [`graphql_value!`] /// @@ -45,13 +49,14 @@ /// }); /// ``` /// -/// __Note:__ [`InputValue::List`]s and [`InputValue::Object`]s will be created -/// in a [`Spanning::unlocated`]. +/// > __NOTE:__ [`InputValue::List`]s and [`InputValue::Object`]s will be +/// > created in a [`Spanning::unlocated`]. /// /// # Example /// /// ```rust /// # use juniper::{graphql_input_value, InputValue}; +/// # /// # type V = InputValue; /// # /// # let _: V = @@ -309,7 +314,7 @@ macro_rules! graphql_input_value { $crate::graphql_input_value!(@unexpected $comma); }; - // Key is fully parenthesized. This avoids clippy double_parens false + // Key is fully parenthesized. This avoids `clippy::double_parens` false // positives because the parenthesization may be necessary here. (@@object $object:ident () (($key:expr) : $($rest:tt)*) $copy:tt) => { $crate::graphql_input_value!( @@ -399,21 +404,22 @@ mod tests { } #[test] - fn enums() { + fn r#enum() { assert_eq!(graphql_input_value!(ENUM), V::enum_value("ENUM")); assert_eq!(graphql_input_value!(lowercase), V::enum_value("lowercase")); } #[test] - fn variables() { + fn variable() { assert_eq!(graphql_input_value!(@var), V::variable("var")); assert_eq!(graphql_input_value!(@array), V::variable("array")); assert_eq!(graphql_input_value!(@object), V::variable("object")); } #[test] - fn lists() { + fn list() { let val = 42; + assert_eq!(graphql_input_value!([]), V::list(vec![])); assert_eq!(graphql_input_value!([null]), V::list(vec![V::Null])); @@ -461,7 +467,7 @@ mod tests { ]), ); assert_eq!( - graphql_input_value!([1, [ENUM], (val),]), + graphql_input_value!([1, [ENUM], (val)]), V::list(vec![ V::scalar(1), V::list(vec![V::enum_value("ENUM")]), @@ -469,7 +475,7 @@ mod tests { ]), ); assert_eq!( - graphql_input_value!([1 + 2, [(val)], @val,]), + graphql_input_value!([1 + 2, [(val)], @val]), V::list(vec![ V::scalar(3), V::list(vec![V::scalar(42)]), @@ -477,7 +483,7 @@ mod tests { ]), ); assert_eq!( - graphql_input_value!([1, [@val], ENUM,]), + graphql_input_value!([1, [@val], ENUM]), V::list(vec![ V::scalar(1), V::list(vec![V::variable("val")]), @@ -487,7 +493,7 @@ mod tests { } #[test] - fn objects() { + fn object() { let val = 42; assert_eq!( graphql_input_value!({}), @@ -496,57 +502,57 @@ mod tests { assert_eq!( graphql_input_value!({ "key": null }), - V::object(indexmap! { "key" => V::Null }), + V::object(indexmap! {"key" => V::Null}), ); assert_eq!( - graphql_input_value!({ "key": 123 }), - V::object(indexmap! { "key" => V::scalar(123) }), + graphql_input_value!({"key": 123}), + V::object(indexmap! {"key" => V::scalar(123)}), ); assert_eq!( - graphql_input_value!({ "key": 1 + 2 }), - V::object(indexmap! { "key" => V::scalar(3) }), + graphql_input_value!({"key": 1 + 2}), + V::object(indexmap! {"key" => V::scalar(3)}), ); assert_eq!( graphql_input_value!({ "key": (val) }), - V::object(indexmap! { "key" => V::scalar(42) }), + V::object(indexmap! {"key" => V::scalar(42)}), ); assert_eq!( - graphql_input_value!({ "key": [] }), - V::object(indexmap! { "key" => V::list(vec![]) }), + graphql_input_value!({"key": []}), + V::object(indexmap! {"key" => V::list(vec![])}), ); assert_eq!( graphql_input_value!({ "key": [null] }), - V::object(indexmap! { "key" => V::list(vec![V::Null]) }), + V::object(indexmap! {"key" => V::list(vec![V::Null])}), ); assert_eq!( - graphql_input_value!({ "key": [1] }), - V::object(indexmap! { "key" => V::list(vec![V::scalar(1)]) }), + graphql_input_value!({"key": [1] }), + V::object(indexmap! {"key" => V::list(vec![V::scalar(1)])}), ); assert_eq!( - graphql_input_value!({ "key": [1 + 2] }), - V::object(indexmap! { "key" => V::list(vec![V::scalar(3)]) }), + graphql_input_value!({"key": [1 + 2] }), + V::object(indexmap! {"key" => V::list(vec![V::scalar(3)])}), ); assert_eq!( graphql_input_value!({ "key": [(val)] }), - V::object(indexmap! { "key" => V::list(vec![V::scalar(42)]) }), + V::object(indexmap! {"key" => V::list(vec![V::scalar(42)])}), ); assert_eq!( graphql_input_value!({ "key": ENUM }), - V::object(indexmap! { "key" => V::enum_value("ENUM") }), + V::object(indexmap! {"key" => V::enum_value("ENUM")}), ); assert_eq!( graphql_input_value!({ "key": lowercase }), - V::object(indexmap! { "key" => V::enum_value("lowercase") }), + V::object(indexmap! {"key" => V::enum_value("lowercase")}), ); assert_eq!( - graphql_input_value!({ "key": @val }), - V::object(indexmap! { "key" => V::variable("val") }), + graphql_input_value!({"key": @val}), + V::object(indexmap! {"key" => V::variable("val")}), ); assert_eq!( - graphql_input_value!({ "key": @array }), - V::object(indexmap! { "key" => V::variable("array") }), + graphql_input_value!({"key": @array }), + V::object(indexmap! {"key" => V::variable("array")}), ); assert_eq!( @@ -554,17 +560,14 @@ mod tests { "inner": { "key1": (val), "key2": "val", - "key3": [ - { - "inner": 42, + "key3": [{ + "inner": 42, + }, { + "inner": ENUM, + "even-more": { + "var": @var, }, - { - "inner": ENUM, - "even-more": { - "var": @var, - }, - } - ], + }], "key4": [1, ["val", 1 + 3], null, @array], }, "more": @var, @@ -581,7 +584,7 @@ mod tests { "inner" => V::enum_value("ENUM"), "even-more" => V::object(indexmap! { "var" => V::variable("var"), - }) + }), }), ]), "key4" => V::list(vec![ @@ -600,8 +603,9 @@ mod tests { } #[test] - fn option_support() { + fn option() { let val = Some(42); + assert_eq!(graphql_input_value!(None), V::Null); assert_eq!(graphql_input_value!(Some(42)), V::scalar(42)); assert_eq!(graphql_input_value!((val)), V::scalar(42)); diff --git a/juniper/src/value/macros.rs b/juniper/src/macros/graphql_value.rs similarity index 95% rename from juniper/src/value/macros.rs rename to juniper/src/macros/graphql_value.rs index d12bbe7a4..af61b8922 100644 --- a/juniper/src/value/macros.rs +++ b/juniper/src/macros/graphql_value.rs @@ -1,4 +1,8 @@ -/// Construct [`Value`]s by using JSON syntax. +//! [`graphql_value!`] macro implementation. +//! +//! [`graphql_value!`]: graphql_value + +/// Constructs [`Value`]s via JSON-like syntax. /// /// [`Value`] objects are used mostly when creating custom errors from fields. /// @@ -7,7 +11,7 @@ /// # use juniper::{graphql_value, Value}; /// # /// let code = 200; -/// let features = vec!["key", "value"]; +/// let features = ["key", "value"]; /// /// let value: Value = graphql_value!({ /// "code": code, @@ -23,6 +27,7 @@ /// Resulting JSON will look just like what you passed in. /// ```rust /// # use juniper::{graphql_value, DefaultScalarValue, Value}; +/// # /// # type V = Value; /// # /// # let _: V = @@ -213,7 +218,7 @@ macro_rules! graphql_value { $crate::graphql_value!(@unexpected $comma); }; - // Key is fully parenthesized. This avoids clippy double_parens false + // Key is fully parenthesized. This avoids `clippy::double_parens` false // positives because the parenthesization may be necessary here. (@object $object:ident () (($key:expr) : $($rest:tt)*) $copy:tt) => { $crate::graphql_value!(@object $object ($key) (: $($rest)*) (: $($rest)*)); @@ -278,6 +283,7 @@ mod tests { #[test] fn scalar() { let val = 42; + assert_eq!(graphql_value!(1), V::scalar(1)); assert_eq!(graphql_value!("val"), V::scalar("val")); assert_eq!(graphql_value!(1.34), V::scalar(1.34)); @@ -287,8 +293,9 @@ mod tests { } #[test] - fn lists() { + fn list() { let val = 42; + assert_eq!(graphql_value!([]), V::list(vec![])); assert_eq!(graphql_value!([null]), V::list(vec![V::Null])); @@ -306,7 +313,7 @@ mod tests { ]), ); assert_eq!( - graphql_value!(["string", [2 + 3], true,]), + graphql_value!(["string", [2 + 3], true]), V::list(vec![ V::scalar("string"), V::list(vec![V::scalar(5)]), @@ -316,11 +323,12 @@ mod tests { } #[test] - fn objects() { + fn object() { let val = 42; + assert_eq!( graphql_value!({}), - V::object(Vec::<(String, _)>::new().into_iter().collect()) + V::object(Vec::<(String, _)>::new().into_iter().collect()), ); assert_eq!( graphql_value!({ "key": null }), @@ -347,7 +355,7 @@ mod tests { V::object( vec![("key", V::list(vec![V::scalar(1)]))] .into_iter() - .collect() + .collect(), ), ); assert_eq!( @@ -355,7 +363,7 @@ mod tests { V::object( vec![("key", V::list(vec![V::scalar(3)]))] .into_iter() - .collect() + .collect(), ), ); assert_eq!( @@ -363,14 +371,15 @@ mod tests { V::object( vec![("key", V::list(vec![V::scalar(42)]))] .into_iter() - .collect() + .collect(), ), ); } #[test] - fn option_support() { + fn option() { let val = Some(42); + assert_eq!(graphql_value!(None), V::Null); assert_eq!(graphql_value!(Some(42)), V::scalar(42)); assert_eq!(graphql_value!(val), V::scalar(42)); diff --git a/juniper/src/executor/macros.rs b/juniper/src/macros/graphql_vars.rs similarity index 82% rename from juniper/src/executor/macros.rs rename to juniper/src/macros/graphql_vars.rs index 7d9b0927d..df5e875bf 100644 --- a/juniper/src/executor/macros.rs +++ b/juniper/src/macros/graphql_vars.rs @@ -1,4 +1,8 @@ -/// Construct [`Variables`] by using JSON-like syntax. +//! [`graphql_vars!`] macro implementation. +//! +//! [`graphql_vars!`]: graphql_vars + +/// Constructs [`Variables`] via JSON-like syntax. /// /// [`Variables`] key should implement [`Into`]`<`[`String`]`>`. /// ```rust @@ -20,6 +24,7 @@ /// /// See [`graphql_input_value!`] for more info on syntax of value after `:`. /// +/// [`graphql_input_value!`]: crate::graphql_input_value /// [`Variables`]: crate::Variables #[macro_export] macro_rules! graphql_vars { @@ -207,32 +212,33 @@ mod tests { #[test] fn scalar() { let val = 42; + assert_eq!( - graphql_vars!({ "key": 123 }), + graphql_vars!({"key": 123}), vec![("key".to_owned(), IV::scalar(123))] .into_iter() .collect::(), ); assert_eq!( - graphql_vars!({ "key": "val" }), + graphql_vars!({"key": "val"}), vec![("key".to_owned(), IV::scalar("val"))] .into_iter() .collect::(), ); assert_eq!( - graphql_vars!({ "key": 1.23 }), + graphql_vars!({"key": 1.23}), vec![("key".to_owned(), IV::scalar(1.23))] .into_iter() .collect::(), ); assert_eq!( - graphql_vars!({ "key": 1 + 2 }), + graphql_vars!({"key": 1 + 2}), vec![("key".to_owned(), IV::scalar(3))] .into_iter() .collect(), ); assert_eq!( - graphql_vars!({ "key": false }), + graphql_vars!({"key": false}), vec![("key".to_owned(), IV::scalar(false))] .into_iter() .collect::(), @@ -246,7 +252,7 @@ mod tests { } #[test] - fn enums() { + fn r#enum() { assert_eq!( graphql_vars!({ "key": ENUM }), vec![("key".to_owned(), IV::enum_value("ENUM"))] @@ -262,21 +268,21 @@ mod tests { } #[test] - fn variables() { + fn variable() { assert_eq!( - graphql_vars!({ "key": @var }), + graphql_vars!({"key": @var}), vec![("key".to_owned(), IV::variable("var"))] .into_iter() .collect::(), ); assert_eq!( - graphql_vars!({ "key": @array }), + graphql_vars!({"key": @array}), vec![("key".to_owned(), IV::variable("array"))] .into_iter() .collect::(), ); assert_eq!( - graphql_vars!({ "key": @object }), + graphql_vars!({"key": @object}), vec![("key".to_owned(), IV::variable("object"))] .into_iter() .collect::(), @@ -284,10 +290,11 @@ mod tests { } #[test] - fn lists() { + fn list() { let val = 42; + assert_eq!( - graphql_vars!({ "key": [] }), + graphql_vars!({"key": []}), vec![("key".to_owned(), IV::list(vec![]))] .into_iter() .collect::(), @@ -301,13 +308,13 @@ mod tests { ); assert_eq!( - graphql_vars!({ "key": [1] }), + graphql_vars!({"key": [1]}), vec![("key".to_owned(), IV::list(vec![IV::scalar(1)]))] .into_iter() .collect::(), ); assert_eq!( - graphql_vars!({ "key": [1 + 2] }), + graphql_vars!({"key": [1 + 2]}), vec![("key".to_owned(), IV::list(vec![IV::scalar(3)]))] .into_iter() .collect::(), @@ -336,85 +343,85 @@ mod tests { ); assert_eq!( - graphql_vars!({ "key": [@var] }), + graphql_vars!({"key": [@var]}), vec![("key".to_owned(), IV::list(vec![IV::variable("var")]))] .into_iter() .collect::(), ); assert_eq!( - graphql_vars!({ "key": [@array] }), + graphql_vars!({"key": [@array]}), vec![("key".to_owned(), IV::list(vec![IV::variable("array")]))] .into_iter() .collect::(), ); assert_eq!( - graphql_vars!({ "key": [@object] }), + graphql_vars!({"key": [@object]}), vec![("key".to_owned(), IV::list(vec![IV::variable("object")]))] .into_iter() .collect::(), ); assert_eq!( - graphql_vars!({ "key": [1, [2], 3] }), + graphql_vars!({"key": [1, [2], 3]}), vec![( "key".to_owned(), IV::list(vec![ IV::scalar(1), IV::list(vec![IV::scalar(2)]), IV::scalar(3), - ]) + ]), )] .into_iter() .collect::(), ); assert_eq!( - graphql_vars!({ "key": [1, [2 + 3], 3] }), + graphql_vars!({"key": [1, [2 + 3], 3]}), vec![( "key".to_owned(), IV::list(vec![ IV::scalar(1), IV::list(vec![IV::scalar(5)]), IV::scalar(3), - ]) + ]), )] .into_iter() .collect::(), ); assert_eq!( - graphql_vars!({ "key": [1, [ENUM], (val)] }), + graphql_vars!({"key": [1, [ENUM], (val)]}), vec![( "key".to_owned(), IV::list(vec![ IV::scalar(1), IV::list(vec![IV::enum_value("ENUM")]), IV::scalar(42), - ]) + ]), )] .into_iter() .collect::(), ); assert_eq!( - graphql_vars!({ "key": [1 + 2, [(val)], @val,] }), + graphql_vars!({"key": [1 + 2, [(val)], @val]}), vec![( "key".to_owned(), IV::list(vec![ IV::scalar(3), IV::list(vec![IV::scalar(42)]), IV::variable("val"), - ]) + ]), )] .into_iter() - .collect::() + .collect::(), ); assert_eq!( - graphql_vars!({ "key": [1, [@val], ENUM,], }), + graphql_vars!({"key": [1, [@val], ENUM]}), vec![( "key".to_owned(), IV::list(vec![ IV::scalar(1), IV::list(vec![IV::variable("val")]), IV::enum_value("ENUM"), - ]) + ]), )] .into_iter() .collect::(), @@ -422,151 +429,145 @@ mod tests { } #[test] - fn objects() { + fn object() { let val = 42; + assert_eq!( - graphql_vars!({ "key": {} }), + graphql_vars!({"key": {}}), vec![("key".to_owned(), IV::object(IndexMap::::new()))] .into_iter() .collect::(), ); assert_eq!( - graphql_vars!({ "key": { "key": null } }), - vec![( - "key".to_owned(), - IV::object(indexmap! { "key" => IV::Null }), - )] - .into_iter() - .collect::(), + graphql_vars!({"key": {"key": null}}), + vec![("key".to_owned(), IV::object(indexmap! {"key" => IV::Null}),)] + .into_iter() + .collect::(), ); assert_eq!( - graphql_vars!({ "key": { "key": 123 } }), + graphql_vars!({"key": {"key": 123}}), vec![( "key".to_owned(), - IV::object(indexmap! { "key" => IV::scalar(123) }), + IV::object(indexmap! {"key" => IV::scalar(123)}), )] .into_iter() .collect::(), ); assert_eq!( - graphql_vars!({ "key": { "key": 1 + 2 } }), + graphql_vars!({"key": {"key": 1 + 2}}), vec![( "key".to_owned(), - IV::object(indexmap! { "key" => IV::scalar(3) }), + IV::object(indexmap! {"key" => IV::scalar(3)}), )] .into_iter() .collect::(), ); assert_eq!( - graphql_vars!({ "key": { "key": (val) } }), + graphql_vars!({"key": {"key": (val)}}), vec![( "key".to_owned(), - IV::object(indexmap! { "key" => IV::scalar(42) }), + IV::object(indexmap! {"key" => IV::scalar(42)}), )] .into_iter() .collect::(), ); assert_eq!( - graphql_vars!({ "key": { "key": [] } }), + graphql_vars!({"key": {"key": []}}), vec![( "key".to_owned(), - IV::object(indexmap! { "key" => IV::list(vec![]) }), + IV::object(indexmap! {"key" => IV::list(vec![])}), )] .into_iter() .collect::(), ); assert_eq!( - graphql_vars!({ "key": { "key": [null] } }), + graphql_vars!({"key": {"key": [null]}}), vec![( "key".to_owned(), - IV::object(indexmap! { "key" => IV::list(vec![IV::Null]) }), + IV::object(indexmap! {"key" => IV::list(vec![IV::Null])}), )] .into_iter() .collect::(), ); assert_eq!( - graphql_vars!({ "key": { "key": [1] } }), + graphql_vars!({"key": {"key": [1]}}), vec![( "key".to_owned(), - IV::object(indexmap! { "key" => IV::list(vec![IV::scalar(1)]) }), + IV::object(indexmap! {"key" => IV::list(vec![IV::scalar(1)])}), )] .into_iter() .collect::(), ); assert_eq!( - graphql_vars!({ "key": { "key": [1 + 2] } }), + graphql_vars!({"key": {"key": [1 + 2]}}), vec![( "key".to_owned(), - IV::object(indexmap! { "key" => IV::list(vec![IV::scalar(3)]) }), + IV::object(indexmap! {"key" => IV::list(vec![IV::scalar(3)])}), )] .into_iter() .collect::(), ); assert_eq!( - graphql_vars!({ "key": { "key": [(val)] } }), + graphql_vars!({"key": {"key": [(val)]}}), vec![( "key".to_owned(), - IV::object(indexmap! { "key" => IV::list(vec![IV::scalar(42)]) }), + IV::object(indexmap! {"key" => IV::list(vec![IV::scalar(42)])}), )] .into_iter() .collect::(), ); assert_eq!( - graphql_vars!({ "key": { "key": ENUM } }), + graphql_vars!({"key": {"key": ENUM}}), vec![( "key".to_owned(), - IV::object(indexmap! { "key" => IV::enum_value("ENUM") }), + IV::object(indexmap! {"key" => IV::enum_value("ENUM")}), )] .into_iter() .collect::(), ); assert_eq!( - graphql_vars!({ "key": { "key": lowercase } }), + graphql_vars!({"key": {"key": lowercase}}), vec![( "key".to_owned(), - IV::object(indexmap! { "key" => IV::enum_value("lowercase") }), + IV::object(indexmap! {"key" => IV::enum_value("lowercase")}), )] .into_iter() .collect::(), ); assert_eq!( - graphql_vars!({ "key": { "key": @val } }), + graphql_vars!({"key": {"key": @val}}), vec![( "key".to_owned(), - IV::object(indexmap! { "key" => IV::variable("val") }), + IV::object(indexmap! {"key" => IV::variable("val")}), )] .into_iter() .collect::(), ); assert_eq!( - graphql_vars!({ "key": { "key": @array } }), + graphql_vars!({"key": {"key": @array}}), vec![( "key".to_owned(), - IV::object(indexmap! { "key" => IV::variable("array") }), + IV::object(indexmap! {"key" => IV::variable("array")}), )] .into_iter() .collect::(), ); - assert_eq!( graphql_vars!({ "inner": { "key1": (val), "key2": "val", - "key3": [ - { - "inner": 42, + "key3": [{ + "inner": 42, + }, { + "inner": ENUM, + "even-more": { + "var": @var, }, - { - "inner": ENUM, - "even-more": { - "var": @var, - }, - } - ], + }], "key4": [1, ["val", 1 + 3], null, @array], }, "more": @var, @@ -585,7 +586,7 @@ mod tests { "inner" => IV::enum_value("ENUM"), "even-more" => IV::object(indexmap! { "var" => IV::variable("var"), - }) + }), }), ]), "key4" => IV::list(vec![ diff --git a/juniper/src/macros/mod.rs b/juniper/src/macros/mod.rs index 241878e50..273ee814e 100644 --- a/juniper/src/macros/mod.rs +++ b/juniper/src/macros/mod.rs @@ -1,3 +1,10 @@ -//! Helper definitions for macros. +//! Declarative macros and helper definitions for procedural macros. pub mod helper; + +#[macro_use] +mod graphql_input_value; +#[macro_use] +mod graphql_value; +#[macro_use] +mod graphql_vars; diff --git a/juniper/src/value/mod.rs b/juniper/src/value/mod.rs index 622e07d6d..52b46d6da 100644 --- a/juniper/src/value/mod.rs +++ b/juniper/src/value/mod.rs @@ -1,5 +1,3 @@ -#[macro_use] -mod macros; mod object; mod scalar; From a734e305a884b48b82da0e9a6219f162fcde73ec Mon Sep 17 00:00:00 2001 From: tyranron Date: Thu, 25 Nov 2021 16:28:07 +0100 Subject: [PATCH 17/22] Strip redundant parentheses in `graphql_vars!` macro --- juniper/src/macros/graphql_vars.rs | 158 +++++++++++++++-------------- 1 file changed, 80 insertions(+), 78 deletions(-) diff --git a/juniper/src/macros/graphql_vars.rs b/juniper/src/macros/graphql_vars.rs index df5e875bf..56bff3b3c 100644 --- a/juniper/src/macros/graphql_vars.rs +++ b/juniper/src/macros/graphql_vars.rs @@ -14,12 +14,12 @@ /// let features = vec!["key", "value"]; /// let key: Cow<'static, str> = "key".into(); /// -/// let value: Variables = graphql_vars!({ +/// let value: Variables = graphql_vars! { /// "code": code, /// "success": code == 200, /// features[0]: features[1], /// key: @var, -/// }); +/// }; /// ``` /// /// See [`graphql_input_value!`] for more info on syntax of value after `:`. @@ -38,12 +38,12 @@ macro_rules! graphql_vars { // Insert the current entry followed by trailing comma. (@object $object:ident [$($key:tt)+] ($value:expr) , $($rest:tt)*) => { let _ = $object.insert(($($key)+).into(), $value); - $crate::graphql_vars!(@object $object () ($($rest)*) ($($rest)*)); + $crate::graphql_vars! {@object $object () ($($rest)*) ($($rest)*)}; }; // Current entry followed by unexpected token. (@object $object:ident [$($key:tt)+] ($value:expr) $unexpected:tt $($rest:tt)*) => { - $crate::graphql_vars!(@unexpected $unexpected); + $crate::graphql_vars! {@unexpected $unexpected}; }; // Insert the last entry without trailing comma. @@ -53,128 +53,130 @@ macro_rules! graphql_vars { // Next value is `null`. (@object $object:ident ($($key:tt)+) (: null $($rest:tt)*) $copy:tt) => { - $crate::graphql_vars!( + $crate::graphql_vars! { @object $object [$($key)+] ($crate::graphql_input_value!(null)) $($rest)* - ); + }; }; // Next value is `None`. (@object $object:ident ($($key:tt)+) (: None $($rest:tt)*) $copy:tt) => { - $crate::graphql_vars!( + $crate::graphql_vars! { @object $object [$($key)+] ($crate::graphql_input_value!(None)) $($rest)* - ); + }; }; // Next value is a variable. (@object $object:ident ($($key:tt)+) (: @$var:ident $($rest:tt)*) $copy:tt) => { - $crate::graphql_vars!( + $crate::graphql_vars! { @object $object [$($key)+] ($crate::graphql_input_value!(@$var)) $($rest)* - ); + }; }; // Next value is an array. (@object $object:ident ($($key:tt)+) (: [$($array:tt)*] $($rest:tt)*) $copy:tt) => { - $crate::graphql_vars!( + $crate::graphql_vars! { @object $object [$($key)+] ($crate::graphql_input_value!([$($array)*])) $($rest)* - ); + }; }; // Next value is a map. (@object $object:ident ($($key:tt)+) (: {$($map:tt)*} $($rest:tt)*) $copy:tt) => { - $crate::graphql_vars!( + $crate::graphql_vars! { @object $object [$($key)+] ($crate::graphql_input_value!({$($map)*})) $($rest)* - ); + }; }; // Next value is `true`, `false` or enum ident followed by a comma. (@object $object:ident ($($key:tt)+) (: $ident:ident , $($rest:tt)*) $copy:tt) => { - $crate::graphql_vars!( + $crate::graphql_vars! { @object $object [$($key)+] ($crate::graphql_input_value!($ident)) , $($rest)* - ); + }; }; // Next value is `true`, `false` or enum ident without trailing comma. (@object $object:ident ($($key:tt)+) (: $last:ident ) $copy:tt) => { - $crate::graphql_vars!( + $crate::graphql_vars! { @object $object [$($key)+] ($crate::graphql_input_value!($last)) - ); + }; }; // Next value is an expression followed by comma. (@object $object:ident ($($key:tt)+) (: $value:expr , $($rest:tt)*) $copy:tt) => { - $crate::graphql_vars!( + $crate::graphql_vars! { @object $object [$($key)+] ($crate::graphql_input_value!($value)) , $($rest)* - ); + }; }; // Last value is an expression with no trailing comma. (@object $object:ident ($($key:tt)+) (: $value:expr) $copy:tt) => { - $crate::graphql_vars!( + $crate::graphql_vars! { @object $object [$($key)+] ($crate::graphql_input_value!($value)) - ); + }; }; // Missing value for last entry. Trigger a reasonable error message. (@object $object:ident ($($key:tt)+) (:) $copy:tt) => { // "unexpected end of macro invocation" - $crate::graphql_vars!(); + $crate::graphql_vars! {}; }; // Missing colon and value for last entry. Trigger a reasonable error // message. (@object $object:ident ($($key:tt)+) () $copy:tt) => { // "unexpected end of macro invocation" - $crate::graphql_vars!(); + $crate::graphql_vars! {}; }; // Misplaced colon. Trigger a reasonable error message. (@object $object:ident () (: $($rest:tt)*) ($colon:tt $($copy:tt)*)) => { // Takes no arguments so "no rules expected the token `:`". - $crate::graphql_vars!(@unexpected $colon); + $crate::graphql_vars! {@unexpected $colon}; }; // Found a comma inside a key. Trigger a reasonable error message. (@object $object:ident ($($key:tt)*) (, $($rest:tt)*) ($comma:tt $($copy:tt)*)) => { // Takes no arguments so "no rules expected the token `,`". - $crate::graphql_vars!(@unexpected $comma); + $crate::graphql_vars! {@unexpected $comma}; }; // Key is fully parenthesized. This avoids clippy double_parens false // positives because the parenthesization may be necessary here. (@object $object:ident () (($key:expr) : $($rest:tt)*) $copy:tt) => { - $crate::graphql_vars!(@object $object ($key) (: $($rest)*) (: $($rest)*)); + $crate::graphql_vars! { + @object $object ($key) (: $($rest)*) (: $($rest)*) + }; }; // Refuse to absorb colon token into key expression. (@object $object:ident ($($key:tt)*) (: $($unexpected:tt)+) $copy:tt) => { - $crate::graphql_vars!(@unexpected $($unexpected)+); + $crate::graphql_vars! {@unexpected $($unexpected)+}; }; // Munch a token into the current key. (@object $object:ident ($($key:tt)*) ($tt:tt $($rest:tt)*) $copy:tt) => { - $crate::graphql_vars!( + $crate::graphql_vars! { @object $object ($($key)* $tt) ($($rest)*) ($($rest)*) - ); + }; }; //////////// @@ -187,11 +189,11 @@ macro_rules! graphql_vars { // Defaults // ////////////// - ({}) => {{ ::std::collections::HashMap::<::std::string::String, _>::new() }}; + () => {{ $crate::Variables::<_>::new() }}; - ({ $($map:tt)* }) => {{ - let mut object = ::std::collections::HashMap::<::std::string::String, _>::new(); - $crate::graphql_vars!(@object object () ($($map)*) ($($map)*)); + ( $($map:tt)+ ) => {{ + let mut object = $crate::Variables::<_>::new(); + $crate::graphql_vars! {@object object () ($($map)*) ($($map)*)}; object }}; } @@ -206,7 +208,7 @@ mod tests { #[test] fn empty() { - assert_eq!(graphql_vars!({}), V::new()); + assert_eq!(graphql_vars! {}, V::new()); } #[test] @@ -214,37 +216,37 @@ mod tests { let val = 42; assert_eq!( - graphql_vars!({"key": 123}), + graphql_vars! {"key": 123}, vec![("key".to_owned(), IV::scalar(123))] .into_iter() .collect::(), ); assert_eq!( - graphql_vars!({"key": "val"}), + graphql_vars! {"key": "val"}, vec![("key".to_owned(), IV::scalar("val"))] .into_iter() .collect::(), ); assert_eq!( - graphql_vars!({"key": 1.23}), + graphql_vars! {"key": 1.23}, vec![("key".to_owned(), IV::scalar(1.23))] .into_iter() .collect::(), ); assert_eq!( - graphql_vars!({"key": 1 + 2}), + graphql_vars! {"key": 1 + 2}, vec![("key".to_owned(), IV::scalar(3))] .into_iter() .collect(), ); assert_eq!( - graphql_vars!({"key": false}), + graphql_vars! {"key": false}, vec![("key".to_owned(), IV::scalar(false))] .into_iter() .collect::(), ); assert_eq!( - graphql_vars!({ "key": (val) }), + graphql_vars! {"key": (val)}, vec![("key".to_owned(), IV::scalar(42))] .into_iter() .collect::(), @@ -254,13 +256,13 @@ mod tests { #[test] fn r#enum() { assert_eq!( - graphql_vars!({ "key": ENUM }), + graphql_vars! {"key": ENUM}, vec![("key".to_owned(), IV::enum_value("ENUM"))] .into_iter() .collect::(), ); assert_eq!( - graphql_vars!({ "key": lowercase }), + graphql_vars! {"key": lowercase}, vec![("key".to_owned(), IV::enum_value("lowercase"))] .into_iter() .collect::(), @@ -270,19 +272,19 @@ mod tests { #[test] fn variable() { assert_eq!( - graphql_vars!({"key": @var}), + graphql_vars! {"key": @var}, vec![("key".to_owned(), IV::variable("var"))] .into_iter() .collect::(), ); assert_eq!( - graphql_vars!({"key": @array}), + graphql_vars! {"key": @array}, vec![("key".to_owned(), IV::variable("array"))] .into_iter() .collect::(), ); assert_eq!( - graphql_vars!({"key": @object}), + graphql_vars! {"key": @object}, vec![("key".to_owned(), IV::variable("object"))] .into_iter() .collect::(), @@ -294,46 +296,46 @@ mod tests { let val = 42; assert_eq!( - graphql_vars!({"key": []}), + graphql_vars! {"key": []}, vec![("key".to_owned(), IV::list(vec![]))] .into_iter() .collect::(), ); assert_eq!( - graphql_vars!({ "key": [null] }), + graphql_vars! {"key": [null]}, vec![("key".to_owned(), IV::list(vec![IV::Null]))] .into_iter() .collect::(), ); assert_eq!( - graphql_vars!({"key": [1]}), + graphql_vars! {"key": [1]}, vec![("key".to_owned(), IV::list(vec![IV::scalar(1)]))] .into_iter() .collect::(), ); assert_eq!( - graphql_vars!({"key": [1 + 2]}), + graphql_vars! {"key": [1 + 2]}, vec![("key".to_owned(), IV::list(vec![IV::scalar(3)]))] .into_iter() .collect::(), ); assert_eq!( - graphql_vars!({ "key": [(val)] }), + graphql_vars! {"key": [(val)]}, vec![("key".to_owned(), IV::list(vec![IV::scalar(42)]))] .into_iter() .collect::(), ); assert_eq!( - graphql_vars!({ "key": [ENUM] }), + graphql_vars! {"key": [ENUM]}, vec![("key".to_owned(), IV::list(vec![IV::enum_value("ENUM")]))] .into_iter() .collect::(), ); assert_eq!( - graphql_vars!({ "key": [lowercase] }), + graphql_vars! {"key": [lowercase]}, vec![( "key".to_owned(), IV::list(vec![IV::enum_value("lowercase")]) @@ -343,26 +345,26 @@ mod tests { ); assert_eq!( - graphql_vars!({"key": [@var]}), + graphql_vars! {"key": [@var]}, vec![("key".to_owned(), IV::list(vec![IV::variable("var")]))] .into_iter() .collect::(), ); assert_eq!( - graphql_vars!({"key": [@array]}), + graphql_vars! {"key": [@array]}, vec![("key".to_owned(), IV::list(vec![IV::variable("array")]))] .into_iter() .collect::(), ); assert_eq!( - graphql_vars!({"key": [@object]}), + graphql_vars! {"key": [@object]}, vec![("key".to_owned(), IV::list(vec![IV::variable("object")]))] .into_iter() .collect::(), ); assert_eq!( - graphql_vars!({"key": [1, [2], 3]}), + graphql_vars! {"key": [1, [2], 3]}, vec![( "key".to_owned(), IV::list(vec![ @@ -375,7 +377,7 @@ mod tests { .collect::(), ); assert_eq!( - graphql_vars!({"key": [1, [2 + 3], 3]}), + graphql_vars! {"key": [1, [2 + 3], 3]}, vec![( "key".to_owned(), IV::list(vec![ @@ -388,7 +390,7 @@ mod tests { .collect::(), ); assert_eq!( - graphql_vars!({"key": [1, [ENUM], (val)]}), + graphql_vars! {"key": [1, [ENUM], (val)]}, vec![( "key".to_owned(), IV::list(vec![ @@ -401,7 +403,7 @@ mod tests { .collect::(), ); assert_eq!( - graphql_vars!({"key": [1 + 2, [(val)], @val]}), + graphql_vars! {"key": [1 + 2, [(val)], @val]}, vec![( "key".to_owned(), IV::list(vec![ @@ -414,7 +416,7 @@ mod tests { .collect::(), ); assert_eq!( - graphql_vars!({"key": [1, [@val], ENUM]}), + graphql_vars! {"key": [1, [@val], ENUM]}, vec![( "key".to_owned(), IV::list(vec![ @@ -433,21 +435,21 @@ mod tests { let val = 42; assert_eq!( - graphql_vars!({"key": {}}), + graphql_vars! {"key": {}}, vec![("key".to_owned(), IV::object(IndexMap::::new()))] .into_iter() .collect::(), ); assert_eq!( - graphql_vars!({"key": {"key": null}}), - vec![("key".to_owned(), IV::object(indexmap! {"key" => IV::Null}),)] + graphql_vars! {"key": {"key": null}}, + vec![("key".to_owned(), IV::object(indexmap! {"key" => IV::Null}))] .into_iter() .collect::(), ); assert_eq!( - graphql_vars!({"key": {"key": 123}}), + graphql_vars! {"key": {"key": 123}}, vec![( "key".to_owned(), IV::object(indexmap! {"key" => IV::scalar(123)}), @@ -456,7 +458,7 @@ mod tests { .collect::(), ); assert_eq!( - graphql_vars!({"key": {"key": 1 + 2}}), + graphql_vars! {"key": {"key": 1 + 2}}, vec![( "key".to_owned(), IV::object(indexmap! {"key" => IV::scalar(3)}), @@ -465,7 +467,7 @@ mod tests { .collect::(), ); assert_eq!( - graphql_vars!({"key": {"key": (val)}}), + graphql_vars! {"key": {"key": (val)}}, vec![( "key".to_owned(), IV::object(indexmap! {"key" => IV::scalar(42)}), @@ -475,7 +477,7 @@ mod tests { ); assert_eq!( - graphql_vars!({"key": {"key": []}}), + graphql_vars! {"key": {"key": []}}, vec![( "key".to_owned(), IV::object(indexmap! {"key" => IV::list(vec![])}), @@ -484,7 +486,7 @@ mod tests { .collect::(), ); assert_eq!( - graphql_vars!({"key": {"key": [null]}}), + graphql_vars! {"key": {"key": [null]}}, vec![( "key".to_owned(), IV::object(indexmap! {"key" => IV::list(vec![IV::Null])}), @@ -493,7 +495,7 @@ mod tests { .collect::(), ); assert_eq!( - graphql_vars!({"key": {"key": [1]}}), + graphql_vars! {"key": {"key": [1]}}, vec![( "key".to_owned(), IV::object(indexmap! {"key" => IV::list(vec![IV::scalar(1)])}), @@ -502,7 +504,7 @@ mod tests { .collect::(), ); assert_eq!( - graphql_vars!({"key": {"key": [1 + 2]}}), + graphql_vars! {"key": {"key": [1 + 2]}}, vec![( "key".to_owned(), IV::object(indexmap! {"key" => IV::list(vec![IV::scalar(3)])}), @@ -511,7 +513,7 @@ mod tests { .collect::(), ); assert_eq!( - graphql_vars!({"key": {"key": [(val)]}}), + graphql_vars! {"key": {"key": [(val)]}}, vec![( "key".to_owned(), IV::object(indexmap! {"key" => IV::list(vec![IV::scalar(42)])}), @@ -520,7 +522,7 @@ mod tests { .collect::(), ); assert_eq!( - graphql_vars!({"key": {"key": ENUM}}), + graphql_vars! {"key": {"key": ENUM}}, vec![( "key".to_owned(), IV::object(indexmap! {"key" => IV::enum_value("ENUM")}), @@ -529,7 +531,7 @@ mod tests { .collect::(), ); assert_eq!( - graphql_vars!({"key": {"key": lowercase}}), + graphql_vars! {"key": {"key": lowercase}}, vec![( "key".to_owned(), IV::object(indexmap! {"key" => IV::enum_value("lowercase")}), @@ -538,7 +540,7 @@ mod tests { .collect::(), ); assert_eq!( - graphql_vars!({"key": {"key": @val}}), + graphql_vars! {"key": {"key": @val}}, vec![( "key".to_owned(), IV::object(indexmap! {"key" => IV::variable("val")}), @@ -547,7 +549,7 @@ mod tests { .collect::(), ); assert_eq!( - graphql_vars!({"key": {"key": @array}}), + graphql_vars! {"key": {"key": @array}}, vec![( "key".to_owned(), IV::object(indexmap! {"key" => IV::variable("array")}), @@ -556,7 +558,7 @@ mod tests { .collect::(), ); assert_eq!( - graphql_vars!({ + graphql_vars! { "inner": { "key1": (val), "key2": "val", @@ -571,7 +573,7 @@ mod tests { "key4": [1, ["val", 1 + 3], null, @array], }, "more": @var, - }), + }, vec![ ( "inner".to_owned(), From 0c1aa09182cfebcfa060c70192c63bdf6d5adbb5 Mon Sep 17 00:00:00 2001 From: tyranron Date: Thu, 25 Nov 2021 17:45:35 +0100 Subject: [PATCH 18/22] Review `juniper` crate --- juniper/CHANGELOG.md | 2 +- juniper/src/ast.rs | 4 +- juniper/src/executor/look_ahead.rs | 49 ++-- juniper/src/executor_tests/enums.rs | 20 +- juniper/src/executor_tests/executor.rs | 141 ++++------ .../introspection/input_object.rs | 2 +- juniper/src/executor_tests/variables.rs | 265 ++++++------------ juniper/src/integrations/bson.rs | 6 +- juniper/src/integrations/chrono.rs | 29 +- juniper/src/integrations/serde.rs | 7 +- juniper/src/parser/tests/value.rs | 51 ++-- juniper/src/parser/value.rs | 6 +- juniper/src/tests/query_tests.rs | 41 ++- juniper/src/value/mod.rs | 28 +- 14 files changed, 266 insertions(+), 385 deletions(-) diff --git a/juniper/CHANGELOG.md b/juniper/CHANGELOG.md index 74eed9ef1..5c968de4b 100644 --- a/juniper/CHANGELOG.md +++ b/juniper/CHANGELOG.md @@ -14,7 +14,7 @@ - Expose `GraphQLRequest` fields. ([#750](https://github.com/graphql-rust/juniper/issues/750)) - `#[graphql_interface]` macro now supports `rename_all = ""` argument influencing its fields and their arguments. ([#971](https://github.com/graphql-rust/juniper/pull/971)) - Use `null` in addition to `None` to create `Value::Null` in `graphql_value!` macro to mirror `serde_json::json!`. ([#996](https://github.com/graphql-rust/juniper/pull/996)) -- Add `From` impls to `InputValue`, that mirror `Value` and provide better support for `Option` handling. ([#996](https://github.com/graphql-rust/juniper/pull/996)) +- Add `From` impls to `InputValue` mirroring the ones for `Value` and provide better support for `Option` handling. ([#996](https://github.com/graphql-rust/juniper/pull/996)) - Implement `graphql_input_value!` and `graphql_vars!` macros. ([#996](https://github.com/graphql-rust/juniper/pull/996)) ## Fixes diff --git a/juniper/src/ast.rs b/juniper/src/ast.rs index da53f7d88..fca336480 100644 --- a/juniper/src/ast.rs +++ b/juniper/src/ast.rs @@ -548,6 +548,8 @@ impl<'a, S> VariableDefinitions<'a, S> { #[cfg(test)] mod tests { + use crate::graphql_input_value; + use super::InputValue; #[test] @@ -576,7 +578,7 @@ mod tests { let value: InputValue = graphql_input_value!([1, 2]); assert_eq!(format!("{}", value), "[1, 2]"); - let value: InputValue = graphql_input_value!({ "foo": 1, "bar": 2 }); + let value: InputValue = graphql_input_value!({"foo": 1,"bar": 2}); assert_eq!(format!("{}", value), "{foo: 1, bar: 2}"); } } diff --git a/juniper/src/executor/look_ahead.rs b/juniper/src/executor/look_ahead.rs index b2a3b336d..d4664287e 100644 --- a/juniper/src/executor/look_ahead.rs +++ b/juniper/src/executor/look_ahead.rs @@ -1,11 +1,11 @@ +use std::collections::HashMap; + use crate::{ ast::{Directive, Fragment, InputValue, Selection}, parser::Spanning, value::ScalarValue, }; -use std::collections::HashMap; - use super::Variables; /// An enum that describes if a field is available in all types of the interface @@ -438,15 +438,18 @@ impl<'a, S> LookAheadMethods<'a, S> for LookAheadSelection<'a, S> { #[cfg(test)] mod tests { - use super::*; + use std::collections::HashMap; + use crate::{ ast::{Document, OwnedDocument}, + graphql_vars, parser::UnlocatedParseResult, schema::model::SchemaType, validation::test_harness::{MutationRoot, QueryRoot, SubscriptionRoot}, value::{DefaultScalarValue, ScalarValue}, }; - use std::collections::HashMap; + + use super::*; fn parse_document_source(q: &str) -> UnlocatedParseResult> where @@ -488,7 +491,7 @@ query Hero { let fragments = extract_fragments(&docs); if let crate::ast::Definition::Operation(ref op) = docs[0] { - let vars = Variables::default(); + let vars = graphql_vars! {}; let look_ahead = LookAheadSelection::build_from_selection( &op.item.selection_set[0], &vars, @@ -542,7 +545,7 @@ query Hero { let fragments = extract_fragments(&docs); if let crate::ast::Definition::Operation(ref op) = docs[0] { - let vars = Variables::default(); + let vars = graphql_vars! {}; let look_ahead = LookAheadSelection::build_from_selection( &op.item.selection_set[0], &vars, @@ -600,7 +603,7 @@ query Hero { let fragments = extract_fragments(&docs); if let crate::ast::Definition::Operation(ref op) = docs[0] { - let vars = Variables::default(); + let vars = graphql_vars! {}; let look_ahead = LookAheadSelection::build_from_selection( &op.item.selection_set[0], &vars, @@ -682,7 +685,7 @@ query Hero { let fragments = extract_fragments(&docs); if let crate::ast::Definition::Operation(ref op) = docs[0] { - let vars = Variables::default(); + let vars = graphql_vars! {}; let look_ahead = LookAheadSelection::build_from_selection( &op.item.selection_set[0], &vars, @@ -742,8 +745,7 @@ query Hero($episode: Episode) { let fragments = extract_fragments(&docs); if let crate::ast::Definition::Operation(ref op) = docs[0] { - let mut vars = Variables::default(); - vars.insert("episode".into(), graphql_input_value!(JEDI)); + let vars = graphql_vars! {"episode": JEDI}; let look_ahead = LookAheadSelection::build_from_selection( &op.item.selection_set[0], &vars, @@ -799,7 +801,7 @@ query Hero($episode: Episode) { let fragments = extract_fragments(&docs); if let crate::ast::Definition::Operation(ref op) = docs[0] { - let vars = Variables::default(); + let vars = graphql_vars! {}; let look_ahead = LookAheadSelection::build_from_selection( &op.item.selection_set[0], &vars, @@ -849,7 +851,7 @@ fragment commonFields on Character { let fragments = extract_fragments(&docs); if let crate::ast::Definition::Operation(ref op) = docs[0] { - let vars = Variables::default(); + let vars = graphql_vars! {}; let look_ahead = LookAheadSelection::build_from_selection( &op.item.selection_set[0], &vars, @@ -913,7 +915,7 @@ query Hero { let fragments = extract_fragments(&docs); if let crate::ast::Definition::Operation(ref op) = docs[0] { - let vars = Variables::default(); + let vars = graphql_vars! {}; let look_ahead = LookAheadSelection::build_from_selection( &op.item.selection_set[0], &vars, @@ -971,7 +973,7 @@ query Hero { let fragments = extract_fragments(&docs); if let crate::ast::Definition::Operation(ref op) = docs[0] { - let vars = Variables::default(); + let vars = graphql_vars! {}; let look_ahead = LookAheadSelection::build_from_selection( &op.item.selection_set[0], &vars, @@ -1036,7 +1038,7 @@ query HeroAndHuman { let fragments = extract_fragments(&docs); if let crate::ast::Definition::Operation(ref op) = docs[0] { - let vars = Variables::default(); + let vars = graphql_vars! {}; let look_ahead = LookAheadSelection::build_from_selection( &op.item.selection_set[0], &vars, @@ -1112,13 +1114,10 @@ fragment comparisonFields on Character { let fragments = extract_fragments(&docs); if let crate::ast::Definition::Operation(ref op) = docs[0] { - let mut vars = Variables::default(); - vars.insert("id".into(), graphql_input_value!(42)); - // This will normally be there - vars.insert( - "withFriends".into(), - InputValue::Scalar(DefaultScalarValue::Boolean(true)), - ); + let vars = graphql_vars! { + "id": 42, + "withFriends": true, + }; let look_ahead = LookAheadSelection::build_from_selection( &op.item.selection_set[0], &vars, @@ -1270,7 +1269,7 @@ query Hero { let fragments = extract_fragments(&docs); if let crate::ast::Definition::Operation(ref op) = docs[0] { - let vars = Variables::default(); + let vars = graphql_vars! {}; let look_ahead = LookAheadSelection::build_from_selection( &op.item.selection_set[0], &vars, @@ -1419,7 +1418,7 @@ fragment heroFriendNames on Hero { let fragments = extract_fragments(&docs); if let crate::ast::Definition::Operation(ref op) = docs[0] { - let vars = Variables::default(); + let vars = graphql_vars! {}; let look_ahead = LookAheadSelection::build_from_selection( &op.item.selection_set[0], &vars, @@ -1473,7 +1472,7 @@ query Hero { let fragments = extract_fragments(&docs); if let crate::ast::Definition::Operation(ref op) = docs[0] { - let vars = Variables::default(); + let vars = graphql_vars! {}; let look_ahead = LookAheadSelection::build_from_selection( &op.item.selection_set[0], &vars, diff --git a/juniper/src/executor_tests/enums.rs b/juniper/src/executor_tests/enums.rs index 96f3ce32f..69cda71d3 100644 --- a/juniper/src/executor_tests/enums.rs +++ b/juniper/src/executor_tests/enums.rs @@ -1,5 +1,6 @@ use crate::{ executor::Variables, + graphql_value, graphql_vars, parser::SourcePosition, schema::model::RootNode, types::scalars::{EmptyMutation, EmptySubscription}, @@ -15,6 +16,7 @@ enum Color { Green, Blue, } + struct TestType; #[crate::graphql_object] @@ -89,7 +91,7 @@ async fn does_not_accept_string_literals() { ); let query = r#"{ toString(color: "RED") }"#; - let vars = vec![].into_iter().collect(); + let vars = graphql_vars! {}; let error = crate::execute(query, None, &schema, &vars, &()) .await @@ -108,9 +110,7 @@ async fn does_not_accept_string_literals() { async fn accepts_strings_in_variables() { run_variable_query( "query q($color: Color!) { toString(color: $color) }", - vec![("color".to_owned(), graphql_input_value!("RED"))] - .into_iter() - .collect(), + graphql_vars! {"color": "RED"}, |result| { assert_eq!( result.get_field_value("toString"), @@ -130,9 +130,7 @@ async fn does_not_accept_incorrect_enum_name_in_variables() { ); let query = r#"query q($color: Color!) { toString(color: $color) }"#; - let vars = vec![("color".to_owned(), graphql_input_value!("BLURPLE"))] - .into_iter() - .collect(); + let vars = graphql_vars! {"color": "BLURPLE"}; let error = crate::execute(query, None, &schema, &vars, &()) .await @@ -143,7 +141,7 @@ async fn does_not_accept_incorrect_enum_name_in_variables() { ValidationError(vec![RuleError::new( r#"Variable "$color" got invalid value. Invalid value for enum "Color"."#, &[SourcePosition::new(8, 0, 8)], - )]) + )]), ); } @@ -156,9 +154,7 @@ async fn does_not_accept_incorrect_type_in_variables() { ); let query = r#"query q($color: Color!) { toString(color: $color) }"#; - let vars = vec![("color".to_owned(), graphql_input_value!(123))] - .into_iter() - .collect(); + let vars = graphql_vars! {"color": 123}; let error = crate::execute(query, None, &schema, &vars, &()) .await @@ -169,6 +165,6 @@ async fn does_not_accept_incorrect_type_in_variables() { ValidationError(vec![RuleError::new( r#"Variable "$color" got invalid value. Expected "Color", found not a string or enum."#, &[SourcePosition::new(8, 0, 8)], - )]) + )]), ); } diff --git a/juniper/src/executor_tests/executor.rs b/juniper/src/executor_tests/executor.rs index cdb778e40..a1da0673d 100644 --- a/juniper/src/executor_tests/executor.rs +++ b/juniper/src/executor_tests/executor.rs @@ -1,6 +1,6 @@ mod field_execution { use crate::{ - graphql_value, + graphql_object, graphql_value, graphql_vars, schema::model::RootNode, types::scalars::{EmptyMutation, EmptySubscription}, }; @@ -8,7 +8,7 @@ mod field_execution { struct DataType; struct DeepDataType; - #[crate::graphql_object] + #[graphql_object] impl DataType { fn a() -> &'static str { "Apple" @@ -38,7 +38,7 @@ mod field_execution { } } - #[crate::graphql_object] + #[graphql_object] impl DeepDataType { fn a() -> &'static str { "Already Been Done" @@ -88,10 +88,7 @@ mod field_execution { e } "; - - let vars = vec![("size".to_owned(), graphql_input_value!(100))] - .into_iter() - .collect(); + let vars = graphql_vars! {"size": 100}; let (result, errs) = crate::execute(doc, None, &schema, &vars, &()) .await @@ -134,13 +131,14 @@ mod field_execution { mod merge_parallel_fragments { use crate::{ + graphql_object, graphql_value, graphql_vars, schema::model::RootNode, types::scalars::{EmptyMutation, EmptySubscription}, }; struct Type; - #[crate::graphql_object] + #[graphql_object] impl Type { fn a() -> &'static str { "Apple" @@ -174,8 +172,7 @@ mod merge_parallel_fragments { deep { c, deeper: deep { c } } } "; - - let vars = vec![].into_iter().collect(); + let vars = graphql_vars! {}; let (result, errs) = crate::execute(doc, None, &schema, &vars, &()) .await @@ -206,6 +203,7 @@ mod merge_parallel_fragments { mod merge_parallel_inline_fragments { use crate::{ + graphql_object, graphql_value, graphql_vars, schema::model::RootNode, types::scalars::{EmptyMutation, EmptySubscription}, }; @@ -213,7 +211,7 @@ mod merge_parallel_inline_fragments { struct Type; struct Other; - #[crate::graphql_object] + #[graphql_object] impl Type { fn a() -> &'static str { "Apple" @@ -232,7 +230,7 @@ mod merge_parallel_inline_fragments { } } - #[crate::graphql_object] + #[graphql_object] impl Other { fn a() -> &'static str { "Apple" @@ -282,8 +280,7 @@ mod merge_parallel_inline_fragments { c } "; - - let vars = vec![].into_iter().collect(); + let vars = graphql_vars! {}; let (result, errs) = crate::execute(doc, None, &schema, &vars, &()) .await @@ -322,7 +319,7 @@ mod merge_parallel_inline_fragments { mod threads_context_correctly { use crate::{ executor::Context, - graphql_value, + graphql_object, graphql_value, graphql_vars, schema::model::RootNode, types::scalars::{EmptyMutation, EmptySubscription}, }; @@ -335,9 +332,7 @@ mod threads_context_correctly { impl Context for TestContext {} - #[crate::graphql_object( - Context = TestContext, - )] + #[graphql_object(context = TestContext)] impl Schema { fn a(context: &TestContext) -> String { context.value.clone() @@ -352,8 +347,7 @@ mod threads_context_correctly { EmptySubscription::::new(), ); let doc = r"{ a }"; - - let vars = vec![].into_iter().collect(); + let vars = graphql_vars! {}; let (result, errs) = crate::execute( doc, @@ -380,7 +374,7 @@ mod dynamic_context_switching { use crate::{ executor::{Context, ExecutionError, FieldError, FieldResult}, - graphql_object, + graphql_object, graphql_value, graphql_vars, parser::SourcePosition, schema::model::RootNode, types::scalars::{EmptyMutation, EmptySubscription}, @@ -451,8 +445,7 @@ mod dynamic_context_switching { EmptySubscription::::new(), ); let doc = r"{ first: itemOpt(key: 0) { value }, missing: itemOpt(key: 2) { value } }"; - - let vars = vec![].into_iter().collect(); + let vars = graphql_vars! {}; let ctx = OuterContext { items: vec![ @@ -497,13 +490,10 @@ mod dynamic_context_switching { EmptyMutation::::new(), EmptySubscription::::new(), ); - let doc = r" - { + let doc = r"{ first: itemRes(key: 0) { value } - } - "; - - let vars = vec![].into_iter().collect(); + }"; + let vars = graphql_vars! {}; let ctx = OuterContext { items: vec![ @@ -545,8 +535,7 @@ mod dynamic_context_switching { let doc = r"{ missing: itemRes(key: 2) { value } }"; - - let vars = vec![].into_iter().collect(); + let vars = graphql_vars! {}; let ctx = OuterContext { items: vec![ @@ -577,7 +566,7 @@ mod dynamic_context_switching { SourcePosition::new(14, 1, 12), &["missing"], FieldError::new("Could not find key 2", graphql_value!(null)), - )] + )], ); println!("Result: {:#?}", result); @@ -592,15 +581,12 @@ mod dynamic_context_switching { EmptyMutation::::new(), EmptySubscription::::new(), ); - let doc = r" - { + let doc = r"{ first: itemResOpt(key: 0) { value } missing: itemResOpt(key: 2) { value } tooLarge: itemResOpt(key: 200) { value } - } - "; - - let vars = vec![].into_iter().collect(); + }"; + let vars = graphql_vars! {}; let ctx = OuterContext { items: vec![ @@ -628,10 +614,10 @@ mod dynamic_context_switching { assert_eq!( errs, [ExecutionError::new( - SourcePosition::new(123, 4, 12), + SourcePosition::new(112, 3, 12), &["tooLarge"], FieldError::new("Key too large: 200", graphql_value!(null)), - )] + )], ); println!("Result: {:#?}", result); @@ -654,8 +640,7 @@ mod dynamic_context_switching { EmptySubscription::::new(), ); let doc = r"{ first: itemAlways(key: 0) { value } }"; - - let vars = vec![].into_iter().collect(); + let vars = graphql_vars! {}; let ctx = OuterContext { items: vec![ @@ -691,7 +676,7 @@ mod dynamic_context_switching { mod propagates_errors_to_nullable_fields { use crate::{ executor::{ExecutionError, FieldError, FieldResult, IntoFieldError}, - graphql_object, + graphql_object, graphql_value, graphql_vars, parser::SourcePosition, schema::model::RootNode, types::scalars::{EmptyMutation, EmptySubscription}, @@ -761,8 +746,7 @@ mod propagates_errors_to_nullable_fields { EmptySubscription::<()>::new(), ); let doc = r"{ inner { nullableErrorField } }"; - - let vars = vec![].into_iter().collect(); + let vars = graphql_vars! {}; let (result, errs) = crate::execute(doc, None, &schema, &vars, &()) .await @@ -772,7 +756,7 @@ mod propagates_errors_to_nullable_fields { assert_eq!( result, - graphql_value!({ "inner": { "nullableErrorField": null } }) + graphql_value!({"inner": {"nullableErrorField": null}}), ); assert_eq!( @@ -781,7 +765,7 @@ mod propagates_errors_to_nullable_fields { SourcePosition::new(10, 0, 10), &["inner", "nullableErrorField"], FieldError::new("Error for nullableErrorField", graphql_value!(null)), - )] + )], ); } @@ -793,8 +777,7 @@ mod propagates_errors_to_nullable_fields { EmptySubscription::<()>::new(), ); let doc = r"{ inner { nonNullableErrorField } }"; - - let vars = vec![].into_iter().collect(); + let vars = graphql_vars! {}; let (result, errs) = crate::execute(doc, None, &schema, &vars, &()) .await @@ -810,7 +793,7 @@ mod propagates_errors_to_nullable_fields { SourcePosition::new(10, 0, 10), &["inner", "nonNullableErrorField"], FieldError::new("Error for nonNullableErrorField", graphql_value!(null)), - )] + )], ); } @@ -822,8 +805,7 @@ mod propagates_errors_to_nullable_fields { EmptySubscription::<()>::new(), ); let doc = r"{ inner { customErrorField } }"; - - let vars = vec![].into_iter().collect(); + let vars = graphql_vars! {}; let (result, errs) = crate::execute(doc, None, &schema, &vars, &()) .await @@ -838,8 +820,8 @@ mod propagates_errors_to_nullable_fields { vec![ExecutionError::new( SourcePosition::new(10, 0, 10), &["inner", "customErrorField"], - FieldError::new("Not Found", graphql_value!({ "type": "NOT_FOUND" })), - )] + FieldError::new("Not Found", graphql_value!({"type": "NOT_FOUND"})), + )], ); } @@ -851,8 +833,7 @@ mod propagates_errors_to_nullable_fields { EmptySubscription::<()>::new(), ); let doc = r"{ inner { nullableField { nonNullableErrorField } } }"; - - let vars = vec![].into_iter().collect(); + let vars = graphql_vars! {}; let (result, errs) = crate::execute(doc, None, &schema, &vars, &()) .await @@ -860,10 +841,7 @@ mod propagates_errors_to_nullable_fields { println!("Result: {:#?}", result); - assert_eq!( - result, - graphql_value!({ "inner": { "nullableField": null } }) - ); + assert_eq!(result, graphql_value!({"inner": {"nullableField": null}}),); assert_eq!( errs, @@ -871,7 +849,7 @@ mod propagates_errors_to_nullable_fields { SourcePosition::new(26, 0, 26), &["inner", "nullableField", "nonNullableErrorField"], FieldError::new("Error for nonNullableErrorField", graphql_value!(null)), - )] + )], ); } @@ -883,8 +861,7 @@ mod propagates_errors_to_nullable_fields { EmptySubscription::<()>::new(), ); let doc = r"{ inner { nonNullableField { nonNullableErrorField } } }"; - - let vars = vec![].into_iter().collect(); + let vars = graphql_vars! {}; let (result, errs) = crate::execute(doc, None, &schema, &vars, &()) .await @@ -900,7 +877,7 @@ mod propagates_errors_to_nullable_fields { SourcePosition::new(29, 0, 29), &["inner", "nonNullableField", "nonNullableErrorField"], FieldError::new("Error for nonNullableErrorField", graphql_value!(null)), - )] + )], ); } @@ -912,8 +889,7 @@ mod propagates_errors_to_nullable_fields { EmptySubscription::<()>::new(), ); let doc = r"{ inner { nonNullableField { nullableErrorField } } }"; - - let vars = vec![].into_iter().collect(); + let vars = graphql_vars! {}; let (result, errs) = crate::execute(doc, None, &schema, &vars, &()) .await @@ -923,7 +899,7 @@ mod propagates_errors_to_nullable_fields { assert_eq!( result, - graphql_value!({ "inner": { "nonNullableField": { "nullableErrorField": null } } }) + graphql_value!({"inner": {"nonNullableField": {"nullableErrorField": null}}}), ); assert_eq!( @@ -932,7 +908,7 @@ mod propagates_errors_to_nullable_fields { SourcePosition::new(29, 0, 29), &["inner", "nonNullableField", "nullableErrorField"], FieldError::new("Error for nullableErrorField", graphql_value!(null)), - )] + )], ); } @@ -944,8 +920,7 @@ mod propagates_errors_to_nullable_fields { EmptySubscription::<()>::new(), ); let doc = r"{ inners { nonNullableErrorField } }"; - - let vars = vec![].into_iter().collect(); + let vars = graphql_vars! {}; let (result, errs) = crate::execute(doc, None, &schema, &vars, &()) .await @@ -961,7 +936,7 @@ mod propagates_errors_to_nullable_fields { SourcePosition::new(11, 0, 11), &["inners", "nonNullableErrorField"], FieldError::new("Error for nonNullableErrorField", graphql_value!(null)), - )] + )], ); } @@ -973,8 +948,7 @@ mod propagates_errors_to_nullable_fields { EmptySubscription::<()>::new(), ); let doc = r"{ nullableInners { nonNullableErrorField } }"; - - let vars = vec![].into_iter().collect(); + let vars = graphql_vars! {}; let (result, errs) = crate::execute(doc, None, &schema, &vars, &()) .await @@ -984,7 +958,7 @@ mod propagates_errors_to_nullable_fields { assert_eq!( result, - graphql_value!({ "nullableInners": [null, null, null, null, null] }) + graphql_value!({"nullableInners": [null, null, null, null, null]}), ); assert_eq!( @@ -1015,14 +989,14 @@ mod propagates_errors_to_nullable_fields { &["nullableInners", "nonNullableErrorField"], FieldError::new("Error for nonNullableErrorField", graphql_value!(null)), ), - ] + ], ); } } mod named_operations { use crate::{ - graphql_object, graphql_value, + graphql_object, graphql_value, graphql_vars, schema::model::RootNode, types::scalars::{EmptyMutation, EmptySubscription}, GraphQLError, @@ -1046,8 +1020,7 @@ mod named_operations { EmptySubscription::<()>::new(), ); let doc = r"{ a }"; - - let vars = vec![].into_iter().collect(); + let vars = graphql_vars! {}; let (res, errs) = crate::execute(doc, None, &schema, &vars, &()) .await @@ -1065,8 +1038,7 @@ mod named_operations { EmptySubscription::<()>::new(), ); let doc = r"query Example { a }"; - - let vars = vec![].into_iter().collect(); + let vars = graphql_vars! {}; let (res, errs) = crate::execute(doc, None, &schema, &vars, &()) .await @@ -1085,8 +1057,7 @@ mod named_operations { ); let doc = r"query Example($p: String!) { first: a(p: $p) } query OtherExample { second: a }"; - - let vars = vec![].into_iter().collect(); + let vars = graphql_vars! {}; let (res, errs) = crate::execute(doc, Some("OtherExample"), &schema, &vars, &()) .await @@ -1104,8 +1075,7 @@ mod named_operations { EmptySubscription::<()>::new(), ); let doc = r"query Example { first: a } query OtherExample { second: a }"; - - let vars = vec![].into_iter().collect(); + let vars = graphql_vars! {}; let err = crate::execute(doc, None, &schema, &vars, &()) .await @@ -1122,8 +1092,7 @@ mod named_operations { EmptySubscription::<()>::new(), ); let doc = r"query Example { first: a } query OtherExample { second: a }"; - - let vars = vec![].into_iter().collect(); + let vars = graphql_vars! {}; let err = crate::execute(doc, Some("UnknownExample"), &schema, &vars, &()) .await diff --git a/juniper/src/executor_tests/introspection/input_object.rs b/juniper/src/executor_tests/introspection/input_object.rs index 1d4f1b82f..b00401fe8 100644 --- a/juniper/src/executor_tests/introspection/input_object.rs +++ b/juniper/src/executor_tests/introspection/input_object.rs @@ -3,7 +3,7 @@ use crate::{ ast::{FromInputValue, InputValue}, executor::Variables, - graphql_object, graphql_value, + graphql_input_value, graphql_object, graphql_value, schema::model::RootNode, types::scalars::{EmptyMutation, EmptySubscription}, value::{DefaultScalarValue, Object, Value}, diff --git a/juniper/src/executor_tests/variables.rs b/juniper/src/executor_tests/variables.rs index 29f36aff7..d4266e0f5 100644 --- a/juniper/src/executor_tests/variables.rs +++ b/juniper/src/executor_tests/variables.rs @@ -1,6 +1,6 @@ use crate::{ executor::Variables, - graphql_object, graphql_scalar, graphql_value, + graphql_object, graphql_scalar, graphql_value, graphql_vars, parser::SourcePosition, schema::model::RootNode, types::scalars::{EmptyMutation, EmptySubscription}, @@ -146,7 +146,7 @@ async fn run_query(query: &str, f: F) where F: Fn(&Object) -> (), { - run_variable_query(query, Variables::new(), f).await; + run_variable_query(query, graphql_vars! {}, f).await; } #[tokio::test] @@ -198,16 +198,13 @@ async fn inline_runs_from_input_value_on_scalar() { async fn variable_complex_input() { run_variable_query( r#"query q($input: TestInputObject) { fieldWithObjectInput(input: $input) }"#, - vec![( - "input".to_owned(), - graphql_input_value!({ + graphql_vars! { + "input": { "a": "foo", "b": ["bar"], "c": "baz", - }), - )] - .into_iter() - .collect(), + }, + }, |result: &Object| { assert_eq!( result.get_field_value("fieldWithObjectInput"), @@ -223,16 +220,13 @@ async fn variable_complex_input() { async fn variable_parse_single_value_to_list() { run_variable_query( r#"query q($input: TestInputObject) { fieldWithObjectInput(input: $input) }"#, - vec![( - "input".to_owned(), - graphql_input_value!({ + graphql_vars! { + "input": { "a": "foo", "b": "bar", "c": "baz", - }), - )] - .into_iter() - .collect(), + }, + }, |result: &Object| { assert_eq!( result.get_field_value("fieldWithObjectInput"), @@ -248,15 +242,12 @@ async fn variable_parse_single_value_to_list() { async fn variable_runs_from_input_value_on_scalar() { run_variable_query( r#"query q($input: TestInputObject) { fieldWithObjectInput(input: $input) }"#, - vec![( - "input".to_owned(), - graphql_input_value!({ + graphql_vars! { + "input": { "c": "baz", "d": "SerializedValue", - }), - )] - .into_iter() - .collect(), + }, + }, |result: &Object| { assert_eq!( result.get_field_value("fieldWithObjectInput"), @@ -277,16 +268,13 @@ async fn variable_error_on_nested_non_null() { ); let query = r#"query q($input: TestInputObject) { fieldWithObjectInput(input: $input) }"#; - let vars = vec![( - "input".to_owned(), - graphql_input_value!({ + let vars = graphql_vars! { + "input": { "a": "foo", "b": "bar", "c": null, - }), - )] - .into_iter() - .collect(); + }, + }; let error = crate::execute(query, None, &schema, &vars, &()) .await @@ -297,7 +285,7 @@ async fn variable_error_on_nested_non_null() { ValidationError(vec![RuleError::new( r#"Variable "$input" got invalid value. In field "c": Expected "String!", found null."#, &[SourcePosition::new(8, 0, 8)], - )]) + )]), ); } @@ -310,9 +298,7 @@ async fn variable_error_on_incorrect_type() { ); let query = r#"query q($input: TestInputObject) { fieldWithObjectInput(input: $input) }"#; - let vars = vec![("input".to_owned(), graphql_input_value!("foo bar"))] - .into_iter() - .collect(); + let vars = graphql_vars! {"input": "foo bar"}; let error = crate::execute(query, None, &schema, &vars, &()) .await @@ -323,7 +309,7 @@ async fn variable_error_on_incorrect_type() { ValidationError(vec![RuleError::new( r#"Variable "$input" got invalid value. Expected "TestInputObject", found not an object."#, &[SourcePosition::new(8, 0, 8)], - ),]) + )]), ); } @@ -336,15 +322,12 @@ async fn variable_error_on_omit_non_null() { ); let query = r#"query q($input: TestInputObject) { fieldWithObjectInput(input: $input) }"#; - let vars = vec![( - "input".to_owned(), - graphql_input_value!({ + let vars = graphql_vars! { + "input": { "a": "foo", "b": "bar", - }), - )] - .into_iter() - .collect(); + }, + }; let error = crate::execute(query, None, &schema, &vars, &()) .await @@ -355,7 +338,7 @@ async fn variable_error_on_omit_non_null() { ValidationError(vec![RuleError::new( r#"Variable "$input" got invalid value. In field "c": Expected "String!", found null."#, &[SourcePosition::new(8, 0, 8)], - )]) + )]), ); } @@ -369,14 +352,11 @@ async fn variable_multiple_errors_with_nesting() { let query = r#"query q($input: TestNestedInputObject) { fieldWithNestedObjectInput(input: $input) }"#; - let vars = vec![( - "input".to_owned(), - graphql_input_value!({ - "na": { "a": "foo" }, - }), - )] - .into_iter() - .collect(); + let vars = graphql_vars! { + "input": { + "na": {"a": "foo"}, + }, + }; let error = crate::execute(query, None, &schema, &vars, &()) .await @@ -393,7 +373,7 @@ async fn variable_multiple_errors_with_nesting() { r#"Variable "$input" got invalid value. In field "nb": Expected "String!", found null."#, &[SourcePosition::new(8, 0, 8)], ), - ]) + ]), ); } @@ -406,17 +386,14 @@ async fn variable_error_on_additional_field() { ); let query = r#"query q($input: TestInputObject) { fieldWithObjectInput(input: $input) }"#; - let vars = vec![( - "input".to_owned(), - graphql_input_value!({ + let vars = graphql_vars! { + "input": { "a": "foo", "b": "bar", "c": "baz", "extra": "dog", - }), - )] - .into_iter() - .collect(); + }, + }; let error = crate::execute(query, None, &schema, &vars, &()) .await @@ -427,7 +404,7 @@ async fn variable_error_on_additional_field() { ValidationError(vec![RuleError::new( r#"Variable "$input" got invalid value. In field "extra": Unknown field."#, &[SourcePosition::new(8, 0, 8)], - )]) + )]), ); } @@ -477,9 +454,7 @@ async fn allow_nullable_inputs_to_be_explicitly_null() { async fn allow_nullable_inputs_to_be_set_to_null_in_variable() { run_variable_query( r#"query q($value: String) { fieldWithNullableStringInput(input: $value) }"#, - vec![("value".to_owned(), graphql_input_value!(null))] - .into_iter() - .collect(), + graphql_vars! {"value": null}, |result: &Object| { assert_eq!( result.get_field_value("fieldWithNullableStringInput"), @@ -494,9 +469,7 @@ async fn allow_nullable_inputs_to_be_set_to_null_in_variable() { async fn allow_nullable_inputs_to_be_set_to_value_in_variable() { run_variable_query( r#"query q($value: String) { fieldWithNullableStringInput(input: $value) }"#, - vec![("value".to_owned(), graphql_input_value!("a"))] - .into_iter() - .collect(), + graphql_vars! {"value": "a"}, |result: &Object| { assert_eq!( result.get_field_value("fieldWithNullableStringInput"), @@ -530,7 +503,7 @@ async fn does_not_allow_non_nullable_input_to_be_omitted_in_variable() { ); let query = r#"query q($value: String!) { fieldWithNonNullableStringInput(input: $value) }"#; - let vars = vec![].into_iter().collect(); + let vars = graphql_vars! {}; let error = crate::execute(query, None, &schema, &vars, &()) .await @@ -541,7 +514,7 @@ async fn does_not_allow_non_nullable_input_to_be_omitted_in_variable() { ValidationError(vec![RuleError::new( r#"Variable "$value" of required type "String!" was not provided."#, &[SourcePosition::new(8, 0, 8)], - )]) + )]), ); } @@ -554,9 +527,7 @@ async fn does_not_allow_non_nullable_input_to_be_set_to_null_in_variable() { ); let query = r#"query q($value: String!) { fieldWithNonNullableStringInput(input: $value) }"#; - let vars = vec![("value".to_owned(), graphql_input_value!(null))] - .into_iter() - .collect(); + let vars = graphql_vars! {"value": null}; let error = crate::execute(query, None, &schema, &vars, &()) .await @@ -567,7 +538,7 @@ async fn does_not_allow_non_nullable_input_to_be_set_to_null_in_variable() { ValidationError(vec![RuleError::new( r#"Variable "$value" of required type "String!" was not provided."#, &[SourcePosition::new(8, 0, 8)], - )]) + )]), ); } @@ -575,13 +546,11 @@ async fn does_not_allow_non_nullable_input_to_be_set_to_null_in_variable() { async fn allow_non_nullable_inputs_to_be_set_to_value_in_variable() { run_variable_query( r#"query q($value: String!) { fieldWithNonNullableStringInput(input: $value) }"#, - vec![("value".to_owned(), graphql_input_value!("a"))] - .into_iter() - .collect(), + graphql_vars! {"value": "a"}, |result| { assert_eq!( result.get_field_value("fieldWithNonNullableStringInput"), - Some(&graphql_value!(r#""a""#)) + Some(&graphql_value!(r#""a""#)), ); }, ) @@ -595,7 +564,7 @@ async fn allow_non_nullable_inputs_to_be_set_to_value_directly() { |result: &Object| { assert_eq!( result.get_field_value("fieldWithNonNullableStringInput"), - Some(&graphql_value!(r#""a""#)) + Some(&graphql_value!(r#""a""#)), ); }, ) @@ -606,13 +575,11 @@ async fn allow_non_nullable_inputs_to_be_set_to_value_directly() { async fn allow_lists_to_be_null() { run_variable_query( r#"query q($input: [String]) { list(input: $input) }"#, - vec![("input".to_owned(), graphql_input_value!(null))] - .into_iter() - .collect(), + graphql_vars! {"input": null}, |result: &Object| { assert_eq!( result.get_field_value("list"), - Some(&graphql_value!(r#"None"#)) + Some(&graphql_value!(r#"None"#)), ); }, ) @@ -623,13 +590,11 @@ async fn allow_lists_to_be_null() { async fn allow_lists_to_contain_values() { run_variable_query( r#"query q($input: [String]) { list(input: $input) }"#, - vec![("input".to_owned(), graphql_input_value!(["A"]))] - .into_iter() - .collect(), + graphql_vars! {"input": ["A"]}, |result| { assert_eq!( result.get_field_value("list"), - Some(&graphql_value!(r#"Some([Some("A")])"#)) + Some(&graphql_value!(r#"Some([Some("A")])"#)), ); }, ) @@ -640,13 +605,11 @@ async fn allow_lists_to_contain_values() { async fn allow_lists_to_contain_null() { run_variable_query( r#"query q($input: [String]) { list(input: $input) }"#, - vec![("input".to_owned(), graphql_input_value!(["A", null, "B"]))] - .into_iter() - .collect(), + graphql_vars! {"input": ["A", null, "B"]}, |result| { assert_eq!( result.get_field_value("list"), - Some(&graphql_value!(r#"Some([Some("A"), None, Some("B")])"#)) + Some(&graphql_value!(r#"Some([Some("A"), None, Some("B")])"#)), ); }, ) @@ -662,9 +625,7 @@ async fn does_not_allow_non_null_lists_to_be_null() { ); let query = r#"query q($input: [String]!) { nnList(input: $input) }"#; - let vars = vec![("input".to_owned(), graphql_input_value!(null))] - .into_iter() - .collect(); + let vars = graphql_vars! {"input": null}; let error = crate::execute(query, None, &schema, &vars, &()) .await @@ -675,7 +636,7 @@ async fn does_not_allow_non_null_lists_to_be_null() { ValidationError(vec![RuleError::new( r#"Variable "$input" of required type "[String]!" was not provided."#, &[SourcePosition::new(8, 0, 8)], - )]) + )]), ); } @@ -683,13 +644,11 @@ async fn does_not_allow_non_null_lists_to_be_null() { async fn allow_non_null_lists_to_contain_values() { run_variable_query( r#"query q($input: [String]!) { nnList(input: $input) }"#, - vec![("input".to_owned(), graphql_input_value!(["A"]))] - .into_iter() - .collect(), + graphql_vars! {"input": ["A"]}, |result| { assert_eq!( result.get_field_value("nnList"), - Some(&graphql_value!(r#"[Some("A")]"#)) + Some(&graphql_value!(r#"[Some("A")]"#)), ); }, ) @@ -699,13 +658,11 @@ async fn allow_non_null_lists_to_contain_values() { async fn allow_non_null_lists_to_contain_null() { run_variable_query( r#"query q($input: [String]!) { nnList(input: $input) }"#, - vec![("input".to_owned(), graphql_input_value!(["A", null, "B"]))] - .into_iter() - .collect(), + graphql_vars! {"input": ["A", null, "B"]}, |result| { assert_eq!( result.get_field_value("nnList"), - Some(&graphql_value!(r#"[Some("A"), None, Some("B")]"#)) + Some(&graphql_value!(r#"[Some("A"), None, Some("B")]"#)), ); }, ) @@ -716,9 +673,7 @@ async fn allow_non_null_lists_to_contain_null() { async fn allow_lists_of_non_null_to_be_null() { run_variable_query( r#"query q($input: [String!]) { listNn(input: $input) }"#, - vec![("input".to_owned(), graphql_input_value!(null))] - .into_iter() - .collect(), + graphql_vars! {"input": null}, |result| { assert_eq!( result.get_field_value("listNn"), @@ -733,9 +688,7 @@ async fn allow_lists_of_non_null_to_be_null() { async fn allow_lists_of_non_null_to_contain_values() { run_variable_query( r#"query q($input: [String!]) { listNn(input: $input) }"#, - vec![("input".to_owned(), graphql_input_value!(["A"]))] - .into_iter() - .collect(), + graphql_vars! {"input": ["A"]}, |result| { assert_eq!( result.get_field_value("listNn"), @@ -755,9 +708,7 @@ async fn does_not_allow_lists_of_non_null_to_contain_null() { ); let query = r#"query q($input: [String!]) { listNn(input: $input) }"#; - let vars = vec![("input".to_owned(), graphql_input_value!(["A", null, "B"]))] - .into_iter() - .collect(); + let vars = graphql_vars! {"input": ["A", null, "B"]}; let error = crate::execute(query, None, &schema, &vars, &()) .await @@ -768,7 +719,7 @@ async fn does_not_allow_lists_of_non_null_to_contain_null() { ValidationError(vec![RuleError::new( r#"Variable "$input" got invalid value. In element #1: Expected "String!", found null."#, &[SourcePosition::new(8, 0, 8)], - ),]) + )]), ); } @@ -781,9 +732,7 @@ async fn does_not_allow_non_null_lists_of_non_null_to_contain_null() { ); let query = r#"query q($input: [String!]!) { nnListNn(input: $input) }"#; - let vars = vec![("input".to_owned(), graphql_input_value!(["A", null, "B"]))] - .into_iter() - .collect(); + let vars = graphql_vars! {"input": ["A", null, "B"]}; let error = crate::execute(query, None, &schema, &vars, &()) .await @@ -794,7 +743,7 @@ async fn does_not_allow_non_null_lists_of_non_null_to_contain_null() { ValidationError(vec![RuleError::new( r#"Variable "$input" got invalid value. In element #1: Expected "String!", found null."#, &[SourcePosition::new(8, 0, 8)], - ),]) + )]), ); } @@ -807,9 +756,7 @@ async fn does_not_allow_non_null_lists_of_non_null_to_be_null() { ); let query = r#"query q($input: [String!]!) { nnListNn(input: $input) }"#; - let vars = vec![("value".to_owned(), graphql_input_value!(null))] - .into_iter() - .collect(); + let vars = graphql_vars! {"input": null}; let error = crate::execute(query, None, &schema, &vars, &()) .await @@ -820,7 +767,7 @@ async fn does_not_allow_non_null_lists_of_non_null_to_be_null() { ValidationError(vec![RuleError::new( r#"Variable "$input" of required type "[String!]!" was not provided."#, &[SourcePosition::new(8, 0, 8)], - )]) + )]), ); } @@ -828,9 +775,7 @@ async fn does_not_allow_non_null_lists_of_non_null_to_be_null() { async fn allow_non_null_lists_of_non_null_to_contain_values() { run_variable_query( r#"query q($input: [String!]!) { nnListNn(input: $input) }"#, - vec![("input".to_owned(), graphql_input_value!(["A"]))] - .into_iter() - .collect(), + graphql_vars! {"input": ["A"]}, |result| { assert_eq!( result.get_field_value("nnListNn"), @@ -870,9 +815,7 @@ async fn default_argument_when_nullable_variable_not_provided() { async fn default_argument_when_nullable_variable_set_to_null() { run_variable_query( r#"query q($input: String) { fieldWithDefaultArgumentValue(input: $input) }"#, - vec![("input".to_owned(), graphql_input_value!(null))] - .into_iter() - .collect(), + graphql_vars! {"input": null}, |result| { assert_eq!( result.get_field_value("fieldWithDefaultArgumentValue"), @@ -906,9 +849,7 @@ async fn nullable_input_object_arguments_successful_without_variables() { async fn nullable_input_object_arguments_successful_with_variables() { run_variable_query( r#"query q($var: Int!) { exampleInput(arg: {b: $var}) }"#, - vec![("var".to_owned(), graphql_input_value!(123))] - .into_iter() - .collect(), + graphql_vars! {"var": 123}, |result| { assert_eq!( result.get_field_value("exampleInput"), @@ -920,9 +861,7 @@ async fn nullable_input_object_arguments_successful_with_variables() { run_variable_query( r#"query q($var: String) { exampleInput(arg: {a: $var, b: 1}) }"#, - vec![("var".to_owned(), graphql_input_value!(null))] - .into_iter() - .collect(), + graphql_vars! {"var": null}, |result| { assert_eq!( result.get_field_value("exampleInput"), @@ -934,7 +873,7 @@ async fn nullable_input_object_arguments_successful_with_variables() { run_variable_query( r#"query q($var: String) { exampleInput(arg: {a: $var, b: 1}) }"#, - vec![].into_iter().collect(), + graphql_vars! {}, |result| { assert_eq!( result.get_field_value("exampleInput"), @@ -954,7 +893,7 @@ async fn does_not_allow_missing_required_field() { ); let query = r#"{ exampleInput(arg: {a: "abc"}) }"#; - let vars = vec![].into_iter().collect(); + let vars = graphql_vars! {}; let error = crate::execute(query, None, &schema, &vars, &()) .await @@ -965,7 +904,7 @@ async fn does_not_allow_missing_required_field() { ValidationError(vec![RuleError::new( r#"Invalid value for argument "arg", expected type "ExampleInputObject!""#, &[SourcePosition::new(20, 0, 20)], - )]) + )]), ); } @@ -978,7 +917,7 @@ async fn does_not_allow_null_in_required_field() { ); let query = r#"{ exampleInput(arg: {a: "abc", b: null}) }"#; - let vars = vec![].into_iter().collect(); + let vars = graphql_vars! {}; let error = crate::execute(query, None, &schema, &vars, &()) .await @@ -989,7 +928,7 @@ async fn does_not_allow_null_in_required_field() { ValidationError(vec![RuleError::new( r#"Invalid value for argument "arg", expected type "ExampleInputObject!""#, &[SourcePosition::new(20, 0, 20)], - )]) + )]), ); } @@ -1002,7 +941,7 @@ async fn does_not_allow_missing_variable_for_required_field() { ); let query = r#"query q($var: Int!) { exampleInput(arg: {b: $var}) }"#; - let vars = vec![].into_iter().collect(); + let vars = graphql_vars! {}; let error = crate::execute(query, None, &schema, &vars, &()) .await @@ -1013,7 +952,7 @@ async fn does_not_allow_missing_variable_for_required_field() { ValidationError(vec![RuleError::new( r#"Variable "$var" of required type "Int!" was not provided."#, &[SourcePosition::new(8, 0, 8)], - )]) + )]), ); } @@ -1026,9 +965,7 @@ async fn does_not_allow_null_variable_for_required_field() { ); let query = r#"query q($var: Int!) { exampleInput(arg: {b: $var}) }"#; - let vars = vec![("var".to_owned(), graphql_input_value!(null))] - .into_iter() - .collect(); + let vars = graphql_vars! {"var": null}; let error = crate::execute(query, None, &schema, &vars, &()) .await @@ -1039,7 +976,7 @@ async fn does_not_allow_null_variable_for_required_field() { ValidationError(vec![RuleError::new( r#"Variable "$var" of required type "Int!" was not provided."#, &[SourcePosition::new(8, 0, 8)], - )]) + )]), ); } @@ -1055,9 +992,7 @@ async fn input_object_with_default_values() { run_variable_query( r#"query q($var: Int!) { inputWithDefaults(arg: {a: $var}) }"#, - vec![("var".to_owned(), graphql_input_value!(1))] - .into_iter() - .collect(), + graphql_vars! {"var": 1}, |result| { assert_eq!( result.get_field_value("inputWithDefaults"), @@ -1069,7 +1004,7 @@ async fn input_object_with_default_values() { run_variable_query( r#"query q($var: Int = 1) { inputWithDefaults(arg: {a: $var}) }"#, - vec![].into_iter().collect(), + graphql_vars! {}, |result| { assert_eq!( result.get_field_value("inputWithDefaults"), @@ -1081,9 +1016,7 @@ async fn input_object_with_default_values() { run_variable_query( r#"query q($var: Int = 1) { inputWithDefaults(arg: {a: $var}) }"#, - vec![("var".to_owned(), graphql_input_value!(2))] - .into_iter() - .collect(), + graphql_vars! {"var": 2}, |result| { assert_eq!( result.get_field_value("inputWithDefaults"), @@ -1101,9 +1034,7 @@ mod integers { async fn positive_and_negative_should_work() { run_variable_query( r#"query q($var: Int!) { integerInput(value: $var) }"#, - vec![("var".to_owned(), graphql_input_value!(1))] - .into_iter() - .collect(), + graphql_vars! {"var": 1}, |result| { assert_eq!( result.get_field_value("integerInput"), @@ -1115,9 +1046,7 @@ mod integers { run_variable_query( r#"query q($var: Int!) { integerInput(value: $var) }"#, - vec![("var".to_owned(), graphql_input_value!(-1))] - .into_iter() - .collect(), + graphql_vars! {"var": -1}, |result| { assert_eq!( result.get_field_value("integerInput"), @@ -1137,9 +1066,7 @@ mod integers { ); let query = r#"query q($var: Int!) { integerInput(value: $var) }"#; - let vars = vec![("var".to_owned(), graphql_input_value!(10.0))] - .into_iter() - .collect(); + let vars = graphql_vars! {"var": 10.0}; let error = crate::execute(query, None, &schema, &vars, &()) .await @@ -1150,7 +1077,7 @@ mod integers { ValidationError(vec![RuleError::new( r#"Variable "$var" got invalid value. Expected "Int"."#, &[SourcePosition::new(8, 0, 8)], - )]) + )]), ); } @@ -1163,9 +1090,7 @@ mod integers { ); let query = r#"query q($var: Int!) { integerInput(value: $var) }"#; - let vars = vec![("var".to_owned(), graphql_input_value!("10"))] - .into_iter() - .collect(); + let vars = graphql_vars! {"var": "10"}; let error = crate::execute(query, None, &schema, &vars, &()) .await @@ -1176,7 +1101,7 @@ mod integers { ValidationError(vec![RuleError::new( r#"Variable "$var" got invalid value. Expected "Int"."#, &[SourcePosition::new(8, 0, 8)], - )]) + )]), ); } } @@ -1188,9 +1113,7 @@ mod floats { async fn float_values_should_work() { run_variable_query( r#"query q($var: Float!) { floatInput(value: $var) }"#, - vec![("var".to_owned(), graphql_input_value!(10.0))] - .into_iter() - .collect(), + graphql_vars! {"var": 10.0}, |result| { assert_eq!( result.get_field_value("floatInput"), @@ -1205,9 +1128,7 @@ mod floats { async fn coercion_from_integers_should_work() { run_variable_query( r#"query q($var: Float!) { floatInput(value: $var) }"#, - vec![("var".to_owned(), graphql_input_value!(-1))] - .into_iter() - .collect(), + graphql_vars! {"var": -1}, |result| { assert_eq!( result.get_field_value("floatInput"), @@ -1227,9 +1148,7 @@ mod floats { ); let query = r#"query q($var: Float!) { floatInput(value: $var) }"#; - let vars = vec![("var".to_owned(), graphql_input_value!("10"))] - .into_iter() - .collect(); + let vars = graphql_vars! {"var": "10"}; let error = crate::execute(query, None, &schema, &vars, &()) .await @@ -1240,7 +1159,7 @@ mod floats { ValidationError(vec![RuleError::new( r#"Variable "$var" got invalid value. Expected "Float"."#, &[SourcePosition::new(8, 0, 8)], - )]) + )]), ); } } diff --git a/juniper/src/integrations/bson.rs b/juniper/src/integrations/bson.rs index 048ec375b..4dd38dfc9 100644 --- a/juniper/src/integrations/bson.rs +++ b/juniper/src/integrations/bson.rs @@ -61,12 +61,12 @@ mod test { use bson::{oid::ObjectId, DateTime as UtcDateTime}; use chrono::{DateTime, Utc}; - use crate::{value::DefaultScalarValue, FromInputValue, InputValue}; + use crate::{graphql_input_value, FromInputValue, InputValue}; #[test] fn objectid_from_input_value() { let raw = "53e37d08776f724e42000000"; - let input = InputValue::::scalar(raw); + let input: InputValue = graphql_input_value!((raw)); let parsed: ObjectId = FromInputValue::from_input_value(&input).unwrap(); let id = ObjectId::parse_str(raw).unwrap(); @@ -77,7 +77,7 @@ mod test { #[test] fn utcdatetime_from_input_value() { let raw = "2020-03-23T17:38:32.446+00:00"; - let input = InputValue::::scalar(raw); + let input: InputValue = graphql_input_value!((raw)); let parsed: UtcDateTime = FromInputValue::from_input_value(&input).unwrap(); let date_time = UtcDateTime::from_chrono( diff --git a/juniper/src/integrations/chrono.rs b/juniper/src/integrations/chrono.rs index 4c192d7a0..eb8fcbb42 100644 --- a/juniper/src/integrations/chrono.rs +++ b/juniper/src/integrations/chrono.rs @@ -148,14 +148,14 @@ where #[cfg(test)] mod test { - use crate::{value::DefaultScalarValue, InputValue}; use chrono::prelude::*; + use crate::{graphql_input_value, FromInputValue, InputValue}; + fn datetime_fixedoffset_test(raw: &'static str) { - let input: crate::InputValue = InputValue::scalar(raw); + let input: InputValue = graphql_input_value!((raw)); - let parsed: DateTime = - crate::FromInputValue::from_input_value(&input).unwrap(); + let parsed: DateTime = FromInputValue::from_input_value(&input).unwrap(); let expected = DateTime::parse_from_rfc3339(raw).unwrap(); assert_eq!(parsed, expected); @@ -177,9 +177,9 @@ mod test { } fn datetime_utc_test(raw: &'static str) { - let input = >::scalar(raw.to_string()); + let input: InputValue = graphql_input_value!((raw)); - let parsed: DateTime = crate::FromInputValue::from_input_value(&input).unwrap(); + let parsed: DateTime = FromInputValue::from_input_value(&input).unwrap(); let expected = DateTime::parse_from_rfc3339(raw) .unwrap() .with_timezone(&Utc); @@ -204,12 +204,12 @@ mod test { #[test] fn naivedate_from_input_value() { - let input: crate::InputValue = graphql_input_value!("1996-12-19"); + let input: InputValue = graphql_input_value!("1996-12-19"); let y = 1996; let m = 12; let d = 19; - let parsed: NaiveDate = crate::FromInputValue::from_input_value(&input).unwrap(); + let parsed: NaiveDate = FromInputValue::from_input_value(&input).unwrap(); let expected = NaiveDate::from_ymd(y, m, d); assert_eq!(parsed, expected); @@ -222,9 +222,9 @@ mod test { #[test] #[cfg(feature = "scalar-naivetime")] fn naivetime_from_input_value() { - let input: crate::InputValue = graphql_input_value!("21:12:19"); + let input: InputValue = graphql_input_value!("21:12:19"); let [h, m, s] = [21, 12, 19]; - let parsed: NaiveTime = crate::FromInputValue::from_input_value(&input).unwrap(); + let parsed: NaiveTime = FromInputValue::from_input_value(&input).unwrap(); let expected = NaiveTime::from_hms(h, m, s); assert_eq!(parsed, expected); assert_eq!(parsed.hour(), h); @@ -235,9 +235,9 @@ mod test { #[test] fn naivedatetime_from_input_value() { let raw = 1_000_000_000_f64; - let input = >::scalar(raw); + let input: InputValue = graphql_input_value!((raw)); - let parsed: NaiveDateTime = crate::FromInputValue::from_input_value(&input).unwrap(); + let parsed: NaiveDateTime = FromInputValue::from_input_value(&input).unwrap(); let expected = NaiveDateTime::from_timestamp_opt(raw as i64, 0).unwrap(); assert_eq!(parsed, expected); @@ -250,8 +250,7 @@ mod integration_test { use chrono::{prelude::*, Utc}; use crate::{ - executor::Variables, - graphql_object, graphql_value, + graphql_object, graphql_value, graphql_vars, schema::model::RootNode, types::scalars::{EmptyMutation, EmptySubscription}, }; @@ -320,7 +319,7 @@ mod integration_test { EmptySubscription::<()>::new(), ); - let (result, errs) = crate::execute(doc, None, &schema, &Variables::new(), &()) + let (result, errs) = crate::execute(doc, None, &schema, &graphql_vars! {}, &()) .await .expect("Execution failed"); diff --git a/juniper/src/integrations/serde.rs b/juniper/src/integrations/serde.rs index aaf037d2d..31a0b6005 100644 --- a/juniper/src/integrations/serde.rs +++ b/juniper/src/integrations/serde.rs @@ -357,6 +357,7 @@ mod tests { use crate::{ ast::InputValue, + graphql_input_value, value::{DefaultScalarValue, Object}, FieldError, Value, }; @@ -366,7 +367,7 @@ mod tests { #[test] fn int() { assert_eq!( - from_str::>("1235").unwrap(), + from_str::("1235").unwrap(), graphql_input_value!(1235), ); } @@ -374,12 +375,12 @@ mod tests { #[test] fn float() { assert_eq!( - from_str::>("2.0").unwrap(), + from_str::("2.0").unwrap(), graphql_input_value!(2.0), ); // large value without a decimal part is also float assert_eq!( - from_str::>("123567890123").unwrap(), + from_str::("123567890123").unwrap(), graphql_input_value!(123_567_890_123.0), ); } diff --git a/juniper/src/parser/tests/value.rs b/juniper/src/parser/tests/value.rs index 3c3cce16a..77ffe9074 100644 --- a/juniper/src/parser/tests/value.rs +++ b/juniper/src/parser/tests/value.rs @@ -1,5 +1,6 @@ use crate::{ ast::{FromInputValue, InputValue, Type}, + graphql_input_value, parser::{value::parse_value_literal, Lexer, Parser, SourcePosition, Spanning}, schema::{ meta::{Argument, EnumMeta, EnumValue, InputObjectMeta, MetaType, ScalarMeta}, @@ -77,40 +78,40 @@ fn input_value_literals() { Spanning::start_end( &SourcePosition::new(0, 0, 0), &SourcePosition::new(3, 0, 3), - graphql_input_value!(123) - ) + graphql_input_value!(123), + ), ); assert_eq!( parse_value::("123.45", &scalar_meta::("Float")), Spanning::start_end( &SourcePosition::new(0, 0, 0), &SourcePosition::new(6, 0, 6), - graphql_input_value!(123.45) - ) + graphql_input_value!(123.45), + ), ); assert_eq!( parse_value::("true", &scalar_meta::("Bool")), Spanning::start_end( &SourcePosition::new(0, 0, 0), &SourcePosition::new(4, 0, 4), - graphql_input_value!(true) - ) + graphql_input_value!(true), + ), ); assert_eq!( parse_value::("false", &scalar_meta::("Bool")), Spanning::start_end( &SourcePosition::new(0, 0, 0), &SourcePosition::new(5, 0, 5), - graphql_input_value!(false) - ) + graphql_input_value!(false), + ), ); assert_eq!( parse_value::(r#""test""#, &scalar_meta::("String")), Spanning::start_end( &SourcePosition::new(0, 0, 0), &SourcePosition::new(6, 0, 6), - graphql_input_value!("test") - ) + graphql_input_value!("test"), + ), ); let values = &[EnumValue::new("enum_value")]; let e: EnumMeta = EnumMeta::new::("TestEnum".into(), values); @@ -120,16 +121,16 @@ fn input_value_literals() { Spanning::start_end( &SourcePosition::new(0, 0, 0), &SourcePosition::new(10, 0, 10), - graphql_input_value!(enum_value) - ) + graphql_input_value!(enum_value), + ), ); assert_eq!( parse_value::("$variable", &scalar_meta::("Int")), Spanning::start_end( &SourcePosition::new(0, 0, 0), &SourcePosition::new(9, 0, 9), - graphql_input_value!(@variable) - ) + graphql_input_value!(@variable), + ), ); assert_eq!( parse_value::("[]", &scalar_meta::("Int")), @@ -137,7 +138,7 @@ fn input_value_literals() { &SourcePosition::new(0, 0, 0), &SourcePosition::new(2, 0, 2), graphql_input_value!([]), - ) + ), ); assert_eq!( parse_value::("[1, [2, 3]]", &scalar_meta::("Int")), @@ -148,7 +149,7 @@ fn input_value_literals() { Spanning::start_end( &SourcePosition::new(1, 0, 1), &SourcePosition::new(2, 0, 2), - InputValue::scalar(1), + graphql_input_value!(1), ), Spanning::start_end( &SourcePosition::new(4, 0, 4), @@ -157,17 +158,17 @@ fn input_value_literals() { Spanning::start_end( &SourcePosition::new(5, 0, 5), &SourcePosition::new(6, 0, 6), - InputValue::scalar(2), + graphql_input_value!(2), ), Spanning::start_end( &SourcePosition::new(8, 0, 8), &SourcePosition::new(9, 0, 9), - InputValue::scalar(3), + graphql_input_value!(3), ), ]), ), - ]) - ) + ]), + ), ); let fields = [ Argument::new("key", Type::NonNullNamed("Int".into())), @@ -180,7 +181,7 @@ fn input_value_literals() { &SourcePosition::new(0, 0, 0), &SourcePosition::new(2, 0, 2), graphql_input_value!({}), - ) + ), ); assert_eq!( @@ -198,7 +199,7 @@ fn input_value_literals() { Spanning::start_end( &SourcePosition::new(6, 0, 6), &SourcePosition::new(9, 0, 9), - InputValue::scalar(123), + graphql_input_value!(123), ), ), ( @@ -219,12 +220,12 @@ fn input_value_literals() { Spanning::start_end( &SourcePosition::new(24, 0, 24), &SourcePosition::new(29, 0, 29), - InputValue::scalar("bar"), + graphql_input_value!("bar"), ), )]), ), ), - ]) - ) + ]), + ), ); } diff --git a/juniper/src/parser/value.rs b/juniper/src/parser/value.rs index f609c299d..8d66661c9 100644 --- a/juniper/src/parser/value.rs +++ b/juniper/src/parser/value.rs @@ -91,21 +91,21 @@ where .. }, _, - ) => Ok(parser.next_token()?.map(|_| graphql_input_value!(true))), + ) => Ok(parser.next_token()?.map(|_| InputValue::scalar(true))), ( &Spanning { item: Token::Name("false"), .. }, _, - ) => Ok(parser.next_token()?.map(|_| graphql_input_value!(false))), + ) => Ok(parser.next_token()?.map(|_| InputValue::scalar(false))), ( &Spanning { item: Token::Name("null"), .. }, _, - ) => Ok(parser.next_token()?.map(|_| graphql_input_value!(null))), + ) => Ok(parser.next_token()?.map(|_| InputValue::null())), ( &Spanning { item: Token::Name(name), diff --git a/juniper/src/tests/query_tests.rs b/juniper/src/tests/query_tests.rs index 24865847b..5dfd1a424 100644 --- a/juniper/src/tests/query_tests.rs +++ b/juniper/src/tests/query_tests.rs @@ -1,6 +1,5 @@ use crate::{ - executor::Variables, - graphql_value, + graphql_value, graphql_vars, schema::model::RootNode, tests::fixtures::starwars::schema::{Database, Query}, types::scalars::{EmptyMutation, EmptySubscription}, @@ -21,7 +20,7 @@ async fn test_hero_name() { ); assert_eq!( - crate::execute(doc, None, &schema, &Variables::new(), &database).await, + crate::execute(doc, None, &schema, &graphql_vars! {}, &database).await, Ok((graphql_value!({"hero": {"name": "R2-D2"}}), vec![])), ); } @@ -42,7 +41,7 @@ async fn test_hero_field_order() { } }"#; assert_eq!( - crate::execute(doc, None, &schema, &Variables::new(), &database).await, + crate::execute(doc, None, &schema, &graphql_vars! {}, &database).await, Ok(( graphql_value!({"hero": {"id": "2001", "name": "R2-D2"}}), vec![], @@ -56,7 +55,7 @@ async fn test_hero_field_order() { } }"#; assert_eq!( - crate::execute(doc_reversed, None, &schema, &Variables::new(), &database).await, + crate::execute(doc_reversed, None, &schema, &graphql_vars! {}, &database).await, Ok(( graphql_value!({"hero": {"name": "R2-D2", "id": "2001"}}), vec![], @@ -83,7 +82,7 @@ async fn test_hero_name_and_friends() { ); assert_eq!( - crate::execute(doc, None, &schema, &Variables::new(), &database).await, + crate::execute(doc, None, &schema, &graphql_vars! {}, &database).await, Ok(( graphql_value!({"hero": { "id": "2001", @@ -122,7 +121,7 @@ async fn test_hero_name_and_friends_and_friends_of_friends() { ); assert_eq!( - crate::execute(doc, None, &schema, &Variables::new(), &database).await, + crate::execute(doc, None, &schema, &graphql_vars! {}, &database).await, Ok(( graphql_value!({"hero": { "id": "2001", @@ -171,7 +170,7 @@ async fn test_query_name() { ); assert_eq!( - crate::execute(doc, None, &schema, &Variables::new(), &database).await, + crate::execute(doc, None, &schema, &graphql_vars! {}, &database).await, Ok(( graphql_value!({"human": {"name": "Luke Skywalker"}}), vec![], @@ -190,7 +189,7 @@ async fn test_query_alias_single() { ); assert_eq!( - crate::execute(doc, None, &schema, &Variables::new(), &database).await, + crate::execute(doc, None, &schema, &graphql_vars! {}, &database).await, Ok((graphql_value!({"luke": {"name": "Luke Skywalker"}}), vec![])), ); } @@ -209,7 +208,7 @@ async fn test_query_alias_multiple() { ); assert_eq!( - crate::execute(doc, None, &schema, &Variables::new(), &database).await, + crate::execute(doc, None, &schema, &graphql_vars! {}, &database).await, Ok(( graphql_value!({ "luke": {"name": "Luke Skywalker"}, @@ -240,7 +239,7 @@ async fn test_query_alias_multiple_with_fragment() { ); assert_eq!( - crate::execute(doc, None, &schema, &Variables::new(), &database).await, + crate::execute(doc, None, &schema, &graphql_vars! {}, &database).await, Ok(( graphql_value!({ "luke": {"name": "Luke Skywalker", "homePlanet": "Tatooine"}, @@ -260,10 +259,7 @@ async fn test_query_name_variable() { EmptyMutation::::new(), EmptySubscription::::new(), ); - - let vars = vec![("someId".to_owned(), graphql_input_value!("1000"))] - .into_iter() - .collect(); + let vars = graphql_vars! {"someId": "1000"}; assert_eq!( crate::execute(doc, None, &schema, &vars, &database).await, @@ -283,10 +279,7 @@ async fn test_query_name_invalid_variable() { EmptyMutation::::new(), EmptySubscription::::new(), ); - - let vars = vec![("someId".to_owned(), graphql_input_value!("some invalid id"))] - .into_iter() - .collect(); + let vars = graphql_vars! {"someId": "some invalid id"}; assert_eq!( crate::execute(doc, None, &schema, &vars, &database).await, @@ -305,7 +298,7 @@ async fn test_query_friends_names() { ); assert_eq!( - crate::execute(doc, None, &schema, &Variables::new(), &database).await, + crate::execute(doc, None, &schema, &graphql_vars! {}, &database).await, Ok(( graphql_value!({"human": { "friends": [ @@ -340,7 +333,7 @@ async fn test_query_inline_fragments_droid() { ); assert_eq!( - crate::execute(doc, None, &schema, &Variables::new(), &database).await, + crate::execute(doc, None, &schema, &graphql_vars! {}, &database).await, Ok(( graphql_value!({"hero": { "__typename": "Droid", @@ -368,7 +361,7 @@ async fn test_query_inline_fragments_human() { ); assert_eq!( - crate::execute(doc, None, &schema, &Variables::new(), &database).await, + crate::execute(doc, None, &schema, &graphql_vars! {}, &database).await, Ok(( graphql_value!({"hero": { "__typename": "Human", @@ -394,7 +387,7 @@ async fn test_object_typename() { ); assert_eq!( - crate::execute(doc, None, &schema, &Variables::new(), &database).await, + crate::execute(doc, None, &schema, &graphql_vars! {}, &database).await, Ok((graphql_value!({"human": {"__typename": "Human"}}), vec![])), ); } @@ -418,7 +411,7 @@ async fn interface_inline_fragment_friends() { ); assert_eq!( - crate::execute(doc, None, &schema, &Variables::new(), &database).await, + crate::execute(doc, None, &schema, &graphql_vars! {}, &database).await, Ok(( graphql_value!({"human": { "friends": [ diff --git a/juniper/src/value/mod.rs b/juniper/src/value/mod.rs index 52b46d6da..a1bf8b748 100644 --- a/juniper/src/value/mod.rs +++ b/juniper/src/value/mod.rs @@ -278,62 +278,64 @@ impl> From for Value { #[cfg(test)] mod tests { - use super::{DefaultScalarValue, Value}; + use crate::graphql_value; + + use super::Value; #[test] fn display_null() { - let s: Value = graphql_value!(null); + let s: Value = graphql_value!(null); assert_eq!("null", format!("{}", s)); } #[test] fn display_int() { - let s: Value = graphql_value!(123); + let s: Value = graphql_value!(123); assert_eq!("123", format!("{}", s)); } #[test] fn display_float() { - let s: Value = graphql_value!(123.456); + let s: Value = graphql_value!(123.456); assert_eq!("123.456", format!("{}", s)); } #[test] fn display_string() { - let s: Value = graphql_value!("foo"); + let s: Value = graphql_value!("foo"); assert_eq!("\"foo\"", format!("{}", s)); } #[test] fn display_bool() { - let s: Value = graphql_value!(false); + let s: Value = graphql_value!(false); assert_eq!("false", format!("{}", s)); - let s: Value = graphql_value!(true); + let s: Value = graphql_value!(true); assert_eq!("true", format!("{}", s)); } #[test] fn display_list() { - let s: Value = graphql_value!([1, null, "foo"]); + let s: Value = graphql_value!([1, null, "foo"]); assert_eq!("[1, null, \"foo\"]", format!("{}", s)); } #[test] fn display_list_one_element() { - let s: Value = graphql_value!([1]); + let s: Value = graphql_value!([1]); assert_eq!("[1]", format!("{}", s)); } #[test] fn display_list_empty() { - let s: Value = graphql_value!([]); + let s: Value = graphql_value!([]); assert_eq!("[]", format!("{}", s)); } #[test] fn display_object() { - let s: Value = graphql_value!({ + let s: Value = graphql_value!({ "int": 1, "null": null, "string": "foo", @@ -346,7 +348,7 @@ mod tests { #[test] fn display_object_one_field() { - let s: Value = graphql_value!({ + let s: Value = graphql_value!({ "int": 1, }); assert_eq!(r#"{"int": 1}"#, format!("{}", s)); @@ -354,7 +356,7 @@ mod tests { #[test] fn display_object_empty() { - let s: Value = graphql_value!({}); + let s: Value = graphql_value!({}); assert_eq!(r#"{}"#, format!("{}", s)); } } From 8af0cdc7c99a431e2a2d78bd8cbe46298d3fc4bd Mon Sep 17 00:00:00 2001 From: tyranron Date: Thu, 25 Nov 2021 18:08:26 +0100 Subject: [PATCH 19/22] Review `juniper_tests` crate, vol.1 --- .../juniper_tests/src/codegen/derive_enum.rs | 18 +++++------ .../src/codegen/derive_input_object.rs | 2 +- .../juniper_tests/src/custom_scalar.rs | 12 +++----- .../juniper_tests/src/explicit_null.rs | 4 +-- juniper_graphql_ws/src/client_message.rs | 16 ++++------ juniper_graphql_ws/src/lib.rs | 30 ++++++++----------- 6 files changed, 32 insertions(+), 50 deletions(-) diff --git a/integration_tests/juniper_tests/src/codegen/derive_enum.rs b/integration_tests/juniper_tests/src/codegen/derive_enum.rs index cb3a9f493..2825ecac6 100644 --- a/integration_tests/juniper_tests/src/codegen/derive_enum.rs +++ b/integration_tests/juniper_tests/src/codegen/derive_enum.rs @@ -1,7 +1,7 @@ use fnv::FnvHashMap; use juniper::{ - DefaultScalarValue, FromInputValue, GraphQLEnum, GraphQLType, InputValue, Registry, - ToInputValue, + graphql_input_value, DefaultScalarValue, FromInputValue, GraphQLEnum, GraphQLType, + Registry, ToInputValue, }; pub struct CustomContext {} @@ -58,8 +58,6 @@ enum ContextEnum { #[test] fn test_derived_enum() { - use juniper::graphql_input_value; - // Ensure that rename works. assert_eq!( >::name(&()), @@ -76,26 +74,26 @@ fn test_derived_enum() { // Test no rename variant. assert_eq!( <_ as ToInputValue>::to_input_value(&NoRenameEnum::AnotherVariant), - graphql_input_value!("AnotherVariant"), + graphql_input_value!(AnotherVariant), ); // Test Regular variant. assert_eq!( <_ as ToInputValue>::to_input_value(&SomeEnum::Regular), - graphql_input_value!("REGULAR") + graphql_input_value!(REGULAR), ); assert_eq!( - FromInputValue::::from_input_value(&graphql_input_value!("REGULAR")), - Some(SomeEnum::Regular) + FromInputValue::::from_input_value(&graphql_input_value!(REGULAR)), + Some(SomeEnum::Regular), ); // Test FULL variant. assert_eq!( <_ as ToInputValue>::to_input_value(&SomeEnum::Full), - graphql_input_value!("FULL") + graphql_input_value!(FULL), ); assert_eq!( - FromInputValue::::from_input_value(&graphql_input_value!("FULL")), + FromInputValue::::from_input_value(&graphql_input_value!(FULL)), Some(SomeEnum::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 805f5f638..e96e7139b 100644 --- a/integration_tests/juniper_tests/src/codegen/derive_input_object.rs +++ b/integration_tests/juniper_tests/src/codegen/derive_input_object.rs @@ -148,7 +148,7 @@ fn test_derived_input_object() { regular_field: "a".into(), c: 55, other: Some(true), - } + }, ); // Test disable renaming diff --git a/integration_tests/juniper_tests/src/custom_scalar.rs b/integration_tests/juniper_tests/src/custom_scalar.rs index 704fadaf8..4fda813e8 100644 --- a/integration_tests/juniper_tests/src/custom_scalar.rs +++ b/integration_tests/juniper_tests/src/custom_scalar.rs @@ -3,6 +3,7 @@ use std::{convert::TryInto as _, fmt, pin::Pin}; use futures::{stream, Stream}; use juniper::{ execute, graphql_input_value, graphql_object, graphql_scalar, graphql_subscription, + graphql_vars, parser::{ParseError, ScalarToken, Token}, serde::{de, Deserialize, Deserializer, Serialize}, EmptyMutation, FieldResult, GraphQLScalarValue, InputValue, Object, ParseScalarResult, @@ -233,16 +234,11 @@ async fn querying_long_arg() { async fn querying_long_variable() { run_variable_query( "query q($test: Long!){ longWithArg(longArg: $test) }", - vec![( - "test".to_owned(), - graphql_input_value!(i64::from(i32::MAX) + 42), - )] - .into_iter() - .collect(), + graphql_vars! {"test": MyScalarValue::Long(i64::from(i32::MAX) + 42)}, |result| { assert_eq!( result.get_field_value("longWithArg"), - Some(&Value::scalar(i64::from(i32::MAX) + 42)) + Some(&Value::scalar(i64::from(i32::MAX) + 42)), ); }, ) @@ -256,7 +252,7 @@ fn deserialize_variable() { assert_eq!( serde_json::from_str::>(&json).unwrap(), graphql_input_value!({ - "field": i64::from(i32::MAX) + 42, + "field": MyScalarValue::Long(i64::from(i32::MAX) + 42), }), ); } diff --git a/integration_tests/juniper_tests/src/explicit_null.rs b/integration_tests/juniper_tests/src/explicit_null.rs index 7e3581501..89e6dc2c7 100644 --- a/integration_tests/juniper_tests/src/explicit_null.rs +++ b/integration_tests/juniper_tests/src/explicit_null.rs @@ -1,6 +1,6 @@ use juniper::{ graphql_object, graphql_value, graphql_vars, EmptyMutation, EmptySubscription, - GraphQLInputObject, InputValue, Nullable, + GraphQLInputObject, Nullable, Variables, }; pub struct Context; @@ -48,7 +48,7 @@ async fn explicit_null() { EmptySubscription::::new(), ); - let vars = graphql_vars!({ + let vars: Variables = graphql_vars!({ "emptyObj": [], "literalNullObj": {"field": null}, }); diff --git a/juniper_graphql_ws/src/client_message.rs b/juniper_graphql_ws/src/client_message.rs index 3d8a6d56d..c24f4d5b2 100644 --- a/juniper_graphql_ws/src/client_message.rs +++ b/juniper_graphql_ws/src/client_message.rs @@ -53,7 +53,7 @@ pub enum ClientMessage { #[cfg(test)] mod test { - use juniper::{graphql_input_value, DefaultScalarValue}; + use juniper::{graphql_vars, DefaultScalarValue}; use super::*; @@ -63,10 +63,7 @@ mod test { assert_eq!( ClientMessage::ConnectionInit { - payload: [("foo".to_string(), graphql_input_value!("bar"))] - .iter() - .cloned() - .collect(), + payload: graphql_vars! {"foo": "bar"}, }, serde_json::from_str(r##"{"type": "connection_init", "payload": {"foo": "bar"}}"##) .unwrap(), @@ -84,10 +81,7 @@ mod test { id: "foo".to_string(), payload: StartPayload { query: "query MyQuery { __typename }".to_string(), - variables: [("foo".to_string(), graphql_input_value!("bar"))] - .iter() - .cloned() - .collect(), + variables: graphql_vars! {"foo": "bar"}, operation_name: Some("MyQuery".to_string()), }, }, @@ -108,7 +102,7 @@ mod test { id: "foo".to_string(), payload: StartPayload { query: "query MyQuery { __typename }".to_string(), - variables: Variables::default(), + variables: graphql_vars! {}, operation_name: None, }, }, @@ -140,7 +134,7 @@ mod test { let expected = StartPayload { query: "query".into(), - variables: Variables::default(), + variables: graphql_vars! {}, operation_name: None, }; diff --git a/juniper_graphql_ws/src/lib.rs b/juniper_graphql_ws/src/lib.rs index 918f006a1..0c47bc474 100644 --- a/juniper_graphql_ws/src/lib.rs +++ b/juniper_graphql_ws/src/lib.rs @@ -633,7 +633,7 @@ mod test { use juniper::{ futures::sink::SinkExt, - graphql_object, graphql_subscription, graphql_value, + graphql_object, graphql_subscription, graphql_value, graphql_vars, parser::{ParseError, Spanning, Token}, DefaultScalarValue, EmptyMutation, FieldError, FieldResult, InputValue, RootNode, }; @@ -825,10 +825,7 @@ mod test { }); conn.send(ClientMessage::ConnectionInit { - payload: [("foo".to_string(), InputValue::scalar("bar".to_string()))] - .iter() - .cloned() - .collect(), + payload: graphql_vars! {"foo": "bar"}, }) .await .unwrap(); @@ -844,10 +841,7 @@ mod test { }); conn.send(ClientMessage::ConnectionInit { - payload: [("foo".to_string(), InputValue::scalar("bar".to_string()))] - .iter() - .cloned() - .collect(), + payload: graphql_vars! {"foo": "bar"}, }) .await .unwrap(); @@ -872,7 +866,7 @@ mod test { ); conn.send(ClientMessage::ConnectionInit { - payload: Variables::default(), + payload: graphql_vars! {}, }) .await .unwrap(); @@ -883,7 +877,7 @@ mod test { id: "foo".to_string(), payload: StartPayload { query: "subscription Foo {never}".to_string(), - variables: Variables::default(), + variables: graphql_vars! {}, operation_name: None, }, }) @@ -894,7 +888,7 @@ mod test { id: "bar".to_string(), payload: StartPayload { query: "subscription Bar {never}".to_string(), - variables: Variables::default(), + variables: graphql_vars! {}, operation_name: None, }, }) @@ -917,7 +911,7 @@ mod test { ); conn.send(ClientMessage::ConnectionInit { - payload: Variables::default(), + payload: graphql_vars! {}, }) .await .unwrap(); @@ -928,7 +922,7 @@ mod test { id: "foo".to_string(), payload: StartPayload { query: "asd".to_string(), - variables: Variables::default(), + variables: graphql_vars! {}, operation_name: None, }, }) @@ -991,7 +985,7 @@ mod test { id: "foo".to_string(), payload: StartPayload { query: "{context}".to_string(), - variables: Variables::default(), + variables: graphql_vars! {}, operation_name: None, }, }) @@ -1020,7 +1014,7 @@ mod test { ); conn.send(ClientMessage::ConnectionInit { - payload: Variables::default(), + payload: graphql_vars! {}, }) .await .unwrap(); @@ -1031,7 +1025,7 @@ mod test { id: "foo".to_string(), payload: StartPayload { query: "subscription Foo {error}".to_string(), - variables: Variables::default(), + variables: graphql_vars! {}, operation_name: None, }, }) @@ -1044,7 +1038,7 @@ mod test { payload: DataPayload { data, errors }, } => { assert_eq!(id, "foo"); - assert_eq!(data, graphql_value!({ "error": null }),); + assert_eq!(data, graphql_value!({ "error": null })); assert_eq!(errors.len(), 1); } msg @ _ => panic!("expected data, got: {:?}", msg), From d3335cb57d64d380b4f7ec29aad12722393ac955 Mon Sep 17 00:00:00 2001 From: tyranron Date: Fri, 26 Nov 2021 12:23:54 +0100 Subject: [PATCH 20/22] Review `juniper_tests` crate, vol.2 --- .../juniper_tests/src/codegen/derive_enum.rs | 10 +- .../src/codegen/derive_input_object.rs | 2 +- .../juniper_tests/src/codegen/impl_scalar.rs | 10 +- .../src/codegen/interface_attr.rs | 298 +++++++++--------- .../juniper_tests/src/codegen/object_attr.rs | 114 +++---- .../src/codegen/object_derive.rs | 64 ++-- .../src/codegen/scalar_value_transparent.rs | 4 +- .../src/codegen/subscription_attr.rs | 132 ++++---- .../juniper_tests/src/codegen/union_attr.rs | 72 ++--- .../juniper_tests/src/codegen/union_derive.rs | 110 +++---- .../juniper_tests/src/custom_scalar.rs | 7 +- .../juniper_tests/src/explicit_null.rs | 36 +-- juniper/src/ast.rs | 6 + juniper/src/macros/graphql_input_value.rs | 22 +- juniper/src/macros/graphql_value.rs | 12 +- juniper/src/value/mod.rs | 16 +- juniper/src/value/scalar.rs | 8 +- 17 files changed, 468 insertions(+), 455 deletions(-) diff --git a/integration_tests/juniper_tests/src/codegen/derive_enum.rs b/integration_tests/juniper_tests/src/codegen/derive_enum.rs index 2825ecac6..45e90c9be 100644 --- a/integration_tests/juniper_tests/src/codegen/derive_enum.rs +++ b/integration_tests/juniper_tests/src/codegen/derive_enum.rs @@ -1,7 +1,7 @@ use fnv::FnvHashMap; use juniper::{ - graphql_input_value, DefaultScalarValue, FromInputValue, GraphQLEnum, GraphQLType, - Registry, ToInputValue, + graphql_input_value, DefaultScalarValue, FromInputValue, GraphQLEnum, GraphQLType, Registry, + ToInputValue, }; pub struct CustomContext {} @@ -74,13 +74,13 @@ fn test_derived_enum() { // Test no rename variant. assert_eq!( <_ as ToInputValue>::to_input_value(&NoRenameEnum::AnotherVariant), - graphql_input_value!(AnotherVariant), + graphql_input_value!("AnotherVariant"), ); // Test Regular variant. assert_eq!( <_ as ToInputValue>::to_input_value(&SomeEnum::Regular), - graphql_input_value!(REGULAR), + graphql_input_value!("REGULAR"), ); assert_eq!( FromInputValue::::from_input_value(&graphql_input_value!(REGULAR)), @@ -90,7 +90,7 @@ fn test_derived_enum() { // Test FULL variant. assert_eq!( <_ as ToInputValue>::to_input_value(&SomeEnum::Full), - graphql_input_value!(FULL), + graphql_input_value!("FULL"), ); assert_eq!( FromInputValue::::from_input_value(&graphql_input_value!(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 e96e7139b..90b283452 100644 --- a/integration_tests/juniper_tests/src/codegen/derive_input_object.rs +++ b/integration_tests/juniper_tests/src/codegen/derive_input_object.rs @@ -163,7 +163,7 @@ fn test_derived_input_object() { output, NoRenameInput { regular_field: "hello".into(), - } + }, ); } diff --git a/integration_tests/juniper_tests/src/codegen/impl_scalar.rs b/integration_tests/juniper_tests/src/codegen/impl_scalar.rs index 2cffdb5d1..3432c2f6a 100644 --- a/integration_tests/juniper_tests/src/codegen/impl_scalar.rs +++ b/integration_tests/juniper_tests/src/codegen/impl_scalar.rs @@ -1,6 +1,6 @@ use juniper::{ - execute, graphql_object, graphql_scalar, graphql_value, DefaultScalarValue, EmptyMutation, - EmptySubscription, Object, ParseScalarResult, ParseScalarValue, RootNode, Value, Variables, + execute, graphql_object, graphql_scalar, graphql_value, graphql_vars, DefaultScalarValue, + EmptyMutation, EmptySubscription, Object, ParseScalarResult, ParseScalarValue, RootNode, Value, }; use crate::custom_scalar::MyScalarValue; @@ -169,7 +169,7 @@ where EmptySubscription::<()>::new(), ); - let (result, errs) = execute(doc, None, &schema, &Variables::new(), &()) + let (result, errs) = execute(doc, None, &schema, &graphql_vars! {}, &()) .await .expect("Execution failed"); @@ -299,7 +299,7 @@ async fn scalar_description_introspection() { assert_eq!( type_info.get_field_value("description"), Some(&graphql_value!( - "A sample scalar, represented as an integer" + "A sample scalar, represented as an integer", )), ); }) @@ -341,7 +341,7 @@ async fn resolves_with_custom_scalar_value() { ); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok((graphql_value!({"withCustomScalarValue": 0}), vec![])), ); } diff --git a/integration_tests/juniper_tests/src/codegen/interface_attr.rs b/integration_tests/juniper_tests/src/codegen/interface_attr.rs index c4bc4c8e5..d8869a04a 100644 --- a/integration_tests/juniper_tests/src/codegen/interface_attr.rs +++ b/integration_tests/juniper_tests/src/codegen/interface_attr.rs @@ -1,9 +1,9 @@ //! Tests for `#[graphql_interface]` macro. use juniper::{ - execute, graphql_interface, graphql_object, graphql_value, DefaultScalarValue, EmptyMutation, - EmptySubscription, Executor, FieldError, FieldResult, GraphQLInputObject, GraphQLObject, - GraphQLType, IntoFieldError, RootNode, ScalarValue, Variables, + execute, graphql_interface, graphql_object, graphql_value, graphql_vars, DefaultScalarValue, + EmptyMutation, EmptySubscription, Executor, FieldError, FieldResult, GraphQLInputObject, + GraphQLObject, GraphQLType, IntoFieldError, RootNode, ScalarValue, }; fn schema<'q, C, Q>(query_root: Q) -> RootNode<'q, Q, EmptyMutation, EmptySubscription> @@ -72,7 +72,7 @@ mod no_implers { ); assert_eq!( - execute(&doc, None, &schema, &Variables::new(), &()).await, + execute(&doc, None, &schema, &graphql_vars! {}, &()).await, Ok((graphql_value!({"__type": {"kind": "INTERFACE"}}), vec![])), ); } @@ -94,7 +94,7 @@ mod no_implers { let expected_name: &str = *interface; assert_eq!( - execute(&doc, None, &schema, &Variables::new(), &()).await, + execute(&doc, None, &schema, &graphql_vars! {}, &()).await, Ok((graphql_value!({"__type": {"name": expected_name}}), vec![])), ); } @@ -115,7 +115,7 @@ mod no_implers { ); assert_eq!( - execute(&doc, None, &schema, &Variables::new(), &()).await, + execute(&doc, None, &schema, &graphql_vars! {}, &()).await, Ok((graphql_value!({"__type": {"description": null}}), vec![])), ); } @@ -229,7 +229,7 @@ mod trivial { let schema = schema(QueryRoot::Human); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"character": {"humanId": "human-32", "homePlanet": "earth"}}), vec![], @@ -251,7 +251,7 @@ mod trivial { let schema = schema(QueryRoot::Droid); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"character": {"droidId": "droid-99", "primaryFunction": "run"}}), vec![], @@ -273,7 +273,7 @@ mod trivial { let schema = schema(QueryRoot::Human); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"hero": {"humanId": "human-32", "homePlanet": "earth"}}), vec![], @@ -295,7 +295,7 @@ mod trivial { let schema = schema(QueryRoot::Droid); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"hero": {"droidId": "droid-99", "primaryFunction": "run"}}), vec![], @@ -319,7 +319,7 @@ mod trivial { let expected_id: &str = *expected_id; assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok((graphql_value!({"character": {"id": expected_id}}), vec![])), ); } @@ -338,7 +338,7 @@ mod trivial { let expected_info: &str = *expected_info; assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok((graphql_value!({"hero": {"info": expected_info}}), vec![])), ); } @@ -359,7 +359,7 @@ mod trivial { ); assert_eq!( - execute(&doc, None, &schema, &Variables::new(), &()).await, + execute(&doc, None, &schema, &graphql_vars! {}, &()).await, Ok((graphql_value!({"__type": {"kind": "INTERFACE"}}), vec![])), ); } @@ -383,7 +383,7 @@ mod trivial { ); assert_eq!( - execute(&doc, None, &schema, &Variables::new(), &()).await, + execute(&doc, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"__type": {"possibleTypes": [ {"kind": "OBJECT", "name": "Droid"}, @@ -413,7 +413,7 @@ mod trivial { ); assert_eq!( - execute(&doc, None, &schema, &Variables::new(), &()).await, + execute(&doc, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"__type": {"interfaces": [ {"kind": "INTERFACE", "name": "Character"}, @@ -441,7 +441,7 @@ mod trivial { let expected_name: &str = *interface; assert_eq!( - execute(&doc, None, &schema, &Variables::new(), &()).await, + execute(&doc, None, &schema, &graphql_vars! {}, &()).await, Ok((graphql_value!({"__type": {"name": expected_name}}), vec![])), ); } @@ -462,7 +462,7 @@ mod trivial { ); assert_eq!( - execute(&doc, None, &schema, &Variables::new(), &()).await, + execute(&doc, None, &schema, &graphql_vars! {}, &()).await, Ok((graphql_value!({"__type": {"description": null}}), vec![])), ); } @@ -543,7 +543,7 @@ mod explicit_alias { let schema = schema(QueryRoot::Human); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"character": {"humanId": "human-32", "homePlanet": "earth"}}), vec![], @@ -565,7 +565,7 @@ mod explicit_alias { let schema = schema(QueryRoot::Droid); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"character": {"droidId": "droid-99", "primaryFunction": "run"}}), vec![], @@ -589,7 +589,7 @@ mod explicit_alias { let expected_id: &str = *expected_id; assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok((graphql_value!({"character": {"id": expected_id}}), vec![])), ); } @@ -606,7 +606,7 @@ mod explicit_alias { let schema = schema(QueryRoot::Human); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok((graphql_value!({"__type": {"kind": "INTERFACE"}}), vec![])), ); } @@ -622,7 +622,7 @@ mod explicit_alias { let schema = schema(QueryRoot::Human); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok((graphql_value!({"__type": {"name": "Character"}}), vec![])), ); } @@ -638,7 +638,7 @@ mod explicit_alias { let schema = schema(QueryRoot::Human); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok((graphql_value!({"__type": {"description": null}}), vec![])), ); } @@ -751,7 +751,7 @@ mod trivial_async { let schema = schema(QueryRoot::Human); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"character": {"humanId": "human-32", "homePlanet": "earth"}}), vec![], @@ -773,7 +773,7 @@ mod trivial_async { let schema = schema(QueryRoot::Droid); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"character": {"droidId": "droid-99", "primaryFunction": "run"}}), vec![], @@ -795,7 +795,7 @@ mod trivial_async { let schema = schema(QueryRoot::Human); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"hero": {"humanId": "human-32", "homePlanet": "earth"}}), vec![], @@ -817,7 +817,7 @@ mod trivial_async { let schema = schema(QueryRoot::Droid); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"hero": {"droidId": "droid-99", "primaryFunction": "run"}}), vec![], @@ -841,7 +841,7 @@ mod trivial_async { let expected_id: &str = *expected_id; assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok((graphql_value!({"character": {"id": expected_id}}), vec![])), ); } @@ -860,7 +860,7 @@ mod trivial_async { let expected_info: &str = *expected_info; assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok((graphql_value!({"hero": {"info": expected_info}}), vec![])), ); } @@ -881,7 +881,7 @@ mod trivial_async { ); assert_eq!( - execute(&doc, None, &schema, &Variables::new(), &()).await, + execute(&doc, None, &schema, &graphql_vars! {}, &()).await, Ok((graphql_value!({"__type": {"kind": "INTERFACE"}}), vec![])), ); } @@ -905,7 +905,7 @@ mod trivial_async { ); assert_eq!( - execute(&doc, None, &schema, &Variables::new(), &()).await, + execute(&doc, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"__type": {"possibleTypes": [ {"kind": "OBJECT", "name": "Droid"}, @@ -935,7 +935,7 @@ mod trivial_async { ); assert_eq!( - execute(&doc, None, &schema, &Variables::new(), &()).await, + execute(&doc, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"__type": {"interfaces": [ {"kind": "INTERFACE", "name": "Character"}, @@ -963,7 +963,7 @@ mod trivial_async { let expected_name: &str = *interface; assert_eq!( - execute(&doc, None, &schema, &Variables::new(), &()).await, + execute(&doc, None, &schema, &graphql_vars! {}, &()).await, Ok((graphql_value!({"__type": {"name": expected_name}}), vec![])), ); } @@ -984,7 +984,7 @@ mod trivial_async { ); assert_eq!( - execute(&doc, None, &schema, &Variables::new(), &()).await, + execute(&doc, None, &schema, &graphql_vars! {}, &()).await, Ok((graphql_value!({"__type": {"description": null}}), vec![])), ); } @@ -1114,7 +1114,7 @@ mod explicit_async { let schema = schema(QueryRoot::Human); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"character": {"humanId": "human-32", "homePlanet": "earth"}}), vec![], @@ -1136,7 +1136,7 @@ mod explicit_async { let schema = schema(QueryRoot::Droid); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"character": {"droidId": "droid-99", "primaryFunction": "run"}}), vec![], @@ -1158,7 +1158,7 @@ mod explicit_async { let schema = schema(QueryRoot::Human); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"hero": {"humanId": "human-32", "homePlanet": "earth"}}), vec![], @@ -1180,7 +1180,7 @@ mod explicit_async { let schema = schema(QueryRoot::Droid); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"hero": {"droidId": "droid-99", "primaryFunction": "run"}}), vec![], @@ -1206,7 +1206,7 @@ mod explicit_async { let expected_id: &str = *expected_id; let expected_info: &str = *expected_info; assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"character": { "id": expected_id, @@ -1236,7 +1236,7 @@ mod explicit_async { let expected_id: &str = *expected_id; let expected_info: &str = *expected_info; assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"hero": { "id": expected_id, @@ -1364,7 +1364,7 @@ mod fallible_field { let schema = schema(QueryRoot::Human); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"character": {"humanId": "human-32", "homePlanet": "earth"}}), vec![], @@ -1386,7 +1386,7 @@ mod fallible_field { let schema = schema(QueryRoot::Droid); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"character": {"droidId": "droid-99", "primaryFunction": "run"}}), vec![], @@ -1408,7 +1408,7 @@ mod fallible_field { let schema = schema(QueryRoot::Human); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"hero": {"humanId": "human-32", "homePlanet": "earth"}}), vec![], @@ -1430,7 +1430,7 @@ mod fallible_field { let schema = schema(QueryRoot::Droid); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"hero": {"droidId": "droid-99", "primaryFunction": "run"}}), vec![], @@ -1454,7 +1454,7 @@ mod fallible_field { let expected_id: &str = *expected_id; assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok((graphql_value!({"character": {"id": expected_id}}), vec![])), ); } @@ -1473,7 +1473,7 @@ mod fallible_field { let expected_info: &str = *expected_info; assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok((graphql_value!({"hero": {"info": expected_info}}), vec![])), ); } @@ -1506,7 +1506,7 @@ mod fallible_field { let expected_name: &str = *interface; let expected_field_name: &str = *field; assert_eq!( - execute(&doc, None, &schema, &Variables::new(), &()).await, + execute(&doc, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"__type": { "name": expected_name, @@ -1630,7 +1630,7 @@ mod generic { let schema = schema(QueryRoot::Human); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"character": {"humanId": "human-32", "homePlanet": "earth"}}), vec![], @@ -1652,7 +1652,7 @@ mod generic { let schema = schema(QueryRoot::Droid); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"character": {"droidId": "droid-99", "primaryFunction": "run"}}), vec![], @@ -1674,7 +1674,7 @@ mod generic { let schema = schema(QueryRoot::Human); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"hero": {"humanId": "human-32", "homePlanet": "earth"}}), vec![], @@ -1696,7 +1696,7 @@ mod generic { let schema = schema(QueryRoot::Droid); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"hero": {"droidId": "droid-99", "primaryFunction": "run"}}), vec![], @@ -1720,7 +1720,7 @@ mod generic { let expected_id: &str = *expected_id; assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok((graphql_value!({"character": {"id": expected_id}}), vec![])), ); } @@ -1739,7 +1739,7 @@ mod generic { let expected_info: &str = *expected_info; assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok((graphql_value!({"hero": {"info": expected_info}}), vec![])), ); } @@ -1761,7 +1761,7 @@ mod generic { let expected_name: &str = *interface; assert_eq!( - execute(&doc, None, &schema, &Variables::new(), &()).await, + execute(&doc, None, &schema, &graphql_vars! {}, &()).await, Ok((graphql_value!({"__type": {"name": expected_name}}), vec![])), ); } @@ -1875,7 +1875,7 @@ mod generic_async { let schema = schema(QueryRoot::Human); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"character": {"humanId": "human-32", "homePlanet": "earth"}}), vec![], @@ -1897,7 +1897,7 @@ mod generic_async { let schema = schema(QueryRoot::Droid); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"character": {"droidId": "droid-99", "primaryFunction": "run"}}), vec![], @@ -1919,7 +1919,7 @@ mod generic_async { let schema = schema(QueryRoot::Human); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"hero": {"humanId": "human-32", "homePlanet": "earth"}}), vec![], @@ -1941,7 +1941,7 @@ mod generic_async { let schema = schema(QueryRoot::Droid); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"hero": {"droidId": "droid-99", "primaryFunction": "run"}}), vec![], @@ -1965,7 +1965,7 @@ mod generic_async { let expected_id: &str = *expected_id; assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok((graphql_value!({"character": {"id": expected_id}}), vec![])), ); } @@ -1984,7 +1984,7 @@ mod generic_async { let expected_info: &str = *expected_info; assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok((graphql_value!({"hero": {"info": expected_info}}), vec![])), ); } @@ -2006,7 +2006,7 @@ mod generic_async { let expected_name: &str = *interface; assert_eq!( - execute(&doc, None, &schema, &Variables::new(), &()).await, + execute(&doc, None, &schema, &graphql_vars! {}, &()).await, Ok((graphql_value!({"__type": {"name": expected_name}}), vec![])), ); } @@ -2120,7 +2120,7 @@ mod generic_lifetime_async { let schema = schema(QueryRoot::Human); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"character": {"humanId": "human-32", "homePlanet": "earth"}}), vec![], @@ -2142,7 +2142,7 @@ mod generic_lifetime_async { let schema = schema(QueryRoot::Droid); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"character": {"droidId": "droid-99", "primaryFunction": "run"}}), vec![], @@ -2164,7 +2164,7 @@ mod generic_lifetime_async { let schema = schema(QueryRoot::Human); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"hero": {"humanId": "human-32", "homePlanet": "earth"}}), vec![], @@ -2186,7 +2186,7 @@ mod generic_lifetime_async { let schema = schema(QueryRoot::Droid); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"hero": {"droidId": "droid-99", "primaryFunction": "run"}}), vec![], @@ -2210,7 +2210,7 @@ mod generic_lifetime_async { let expected_id: &str = *expected_id; assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok((graphql_value!({"character": {"id": expected_id}}), vec![])), ); } @@ -2229,7 +2229,7 @@ mod generic_lifetime_async { let expected_info: &str = *expected_info; assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok((graphql_value!({"hero": {"info": expected_info}}), vec![])), ); } @@ -2251,7 +2251,7 @@ mod generic_lifetime_async { let expected_name: &str = *interface; assert_eq!( - execute(&doc, None, &schema, &Variables::new(), &()).await, + execute(&doc, None, &schema, &graphql_vars! {}, &()).await, Ok((graphql_value!({"__type": {"name": expected_name}}), vec![])), ); } @@ -2357,7 +2357,7 @@ mod argument { let expected: &str = *expected; assert_eq!( - execute(*input, None, &schema, &Variables::new(), &()).await, + execute(*input, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"character": { "idWide": expected, @@ -2386,7 +2386,7 @@ mod argument { let expected: &str = *expected; assert_eq!( - execute(*input, None, &schema, &Variables::new(), &()).await, + execute(*input, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"hero": { "infoWide": expected, @@ -2424,7 +2424,7 @@ mod argument { let expected_field_name2: &str = &format!("{}2", field); let expected_arg_name: &str = *arg; assert_eq!( - execute(&doc, None, &schema, &Variables::new(), &()).await, + execute(&doc, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"__type": {"fields": [{ "name": expected_field_name, @@ -2463,7 +2463,7 @@ mod argument { ); assert_eq!( - execute(&doc, None, &schema, &Variables::new(), &()).await, + execute(&doc, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"__type": {"fields": [ {"args": [{"description": null}]}, @@ -2494,7 +2494,7 @@ mod argument { ); assert_eq!( - execute(&doc, None, &schema, &Variables::new(), &()).await, + execute(&doc, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"__type": {"fields": [ {"args": [{"defaultValue": null}]}, @@ -2576,7 +2576,7 @@ mod default_argument { let expected: &str = *expected; assert_eq!( - execute(*input, None, &schema, &Variables::new(), &()).await, + execute(*input, None, &schema, &graphql_vars! {}, &()).await, Ok((graphql_value!({"character": {"id": expected}}), vec![])), ); } @@ -2593,7 +2593,7 @@ mod default_argument { let expected: i32 = *expected; assert_eq!( - execute(*input, None, &schema, &Variables::new(), &()).await, + execute(*input, None, &schema, &graphql_vars! {}, &()).await, Ok((graphql_value!({"character": {"info": expected}}), vec![])), ); } @@ -2621,7 +2621,7 @@ mod default_argument { let schema = schema(QueryRoot); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"__type": {"fields": [{ "args": [{ @@ -2702,7 +2702,7 @@ mod description_from_doc_comment { let schema = schema(QueryRoot); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"__type": { "description": "Rust docs.", @@ -2770,7 +2770,7 @@ mod deprecation_from_attr { let schema = schema(QueryRoot); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok((graphql_value!({"character": {"id": "human-32"}}), vec![])), ); } @@ -2787,7 +2787,7 @@ mod deprecation_from_attr { let schema = schema(QueryRoot); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok((graphql_value!({"character": {"a": "a", "b": "b"}}), vec![])), ); } @@ -2806,7 +2806,7 @@ mod deprecation_from_attr { let schema = schema(QueryRoot); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"__type": {"fields": [ {"name": "id", "isDeprecated": false}, @@ -2832,7 +2832,7 @@ mod deprecation_from_attr { let schema = schema(QueryRoot); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"__type": {"fields": [ {"name": "id", "deprecationReason": null}, @@ -2907,7 +2907,7 @@ mod explicit_name_description_and_deprecation { let schema = schema(QueryRoot); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"character": {"myId": "human-32", "a": "a", "b": "b"}}), vec![], @@ -2932,7 +2932,7 @@ mod explicit_name_description_and_deprecation { let schema = schema(QueryRoot); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"__type": { "name": "MyChar", @@ -2965,7 +2965,7 @@ mod explicit_name_description_and_deprecation { let schema = schema(QueryRoot); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"__type": { "description": "My character.", @@ -3003,7 +3003,7 @@ mod explicit_name_description_and_deprecation { let schema = schema(QueryRoot); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"__type": { "fields": [{ @@ -3086,7 +3086,7 @@ mod renamed_all_fields_and_args { let schema = schema(QueryRoot); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"character": { "id": "human-32", @@ -3114,7 +3114,7 @@ mod renamed_all_fields_and_args { let schema = schema(QueryRoot); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"__type": {"fields": [ {"name": "id", "args": []}, @@ -3236,7 +3236,7 @@ mod explicit_scalar { let schema = schema(QueryRoot::Human); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"character": {"humanId": "human-32", "homePlanet": "earth"}}), vec![], @@ -3258,7 +3258,7 @@ mod explicit_scalar { let schema = schema(QueryRoot::Droid); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"character": {"droidId": "droid-99", "primaryFunction": "run"}}), vec![], @@ -3280,7 +3280,7 @@ mod explicit_scalar { let schema = schema(QueryRoot::Human); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"hero": {"humanId": "human-32", "homePlanet": "earth"}}), vec![], @@ -3302,7 +3302,7 @@ mod explicit_scalar { let schema = schema(QueryRoot::Droid); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"hero": {"droidId": "droid-99", "primaryFunction": "run"}}), vec![], @@ -3326,7 +3326,7 @@ mod explicit_scalar { let expected_id: &str = *expected_id; assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok((graphql_value!({"character": {"id": expected_id}}), vec![])), ); } @@ -3345,7 +3345,7 @@ mod explicit_scalar { let expected_info: &str = *expected_info; assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok((graphql_value!({"hero": {"info": expected_info}}), vec![])), ); } @@ -3462,7 +3462,7 @@ mod custom_scalar { let schema = schema_with_scalar::(QueryRoot::Human); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"character": {"humanId": "human-32", "homePlanet": "earth"}}), vec![], @@ -3484,7 +3484,7 @@ mod custom_scalar { let schema = schema_with_scalar::(QueryRoot::Droid); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"character": {"droidId": "droid-99", "primaryFunction": "run"}}), vec![], @@ -3506,7 +3506,7 @@ mod custom_scalar { let schema = schema_with_scalar::(QueryRoot::Human); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"hero": {"humanId": "human-32", "homePlanet": "earth"}}), vec![], @@ -3528,7 +3528,7 @@ mod custom_scalar { let schema = schema_with_scalar::(QueryRoot::Droid); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"hero": {"droidId": "droid-99", "primaryFunction": "run"}}), vec![], @@ -3552,7 +3552,7 @@ mod custom_scalar { let expected_id: &str = *expected_id; assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok((graphql_value!({"character": {"id": expected_id}}), vec![])), ); } @@ -3571,7 +3571,7 @@ mod custom_scalar { let expected_info: &str = *expected_info; assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok((graphql_value!({"hero": {"info": expected_info}}), vec![])), ); } @@ -3685,7 +3685,7 @@ mod explicit_generic_scalar { let schema = schema(QueryRoot::Human); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"character": {"humanId": "human-32", "homePlanet": "earth"}}), vec![], @@ -3707,7 +3707,7 @@ mod explicit_generic_scalar { let schema = schema(QueryRoot::Droid); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"character": {"droidId": "droid-99", "primaryFunction": "run"}}), vec![], @@ -3729,7 +3729,7 @@ mod explicit_generic_scalar { let schema = schema(QueryRoot::Human); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"hero": {"humanId": "human-32", "homePlanet": "earth"}}), vec![], @@ -3751,7 +3751,7 @@ mod explicit_generic_scalar { let schema = schema(QueryRoot::Droid); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"hero": {"droidId": "droid-99", "primaryFunction": "run"}}), vec![], @@ -3775,7 +3775,7 @@ mod explicit_generic_scalar { let expected_id: &str = *expected_id; assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok((graphql_value!({"character": {"id": expected_id}}), vec![])), ); } @@ -3794,7 +3794,7 @@ mod explicit_generic_scalar { let expected_info: &str = *expected_info; assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok((graphql_value!({"hero": {"info": expected_info}}), vec![])), ); } @@ -3908,7 +3908,7 @@ mod bounded_generic_scalar { let schema = schema(QueryRoot::Human); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"character": {"humanId": "human-32", "homePlanet": "earth"}}), vec![], @@ -3930,7 +3930,7 @@ mod bounded_generic_scalar { let schema = schema(QueryRoot::Droid); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"character": {"droidId": "droid-99", "primaryFunction": "run"}}), vec![], @@ -3952,7 +3952,7 @@ mod bounded_generic_scalar { let schema = schema(QueryRoot::Human); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"hero": {"humanId": "human-32", "homePlanet": "earth"}}), vec![], @@ -3974,7 +3974,7 @@ mod bounded_generic_scalar { let schema = schema(QueryRoot::Droid); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"hero": {"droidId": "droid-99", "primaryFunction": "run"}}), vec![], @@ -3998,7 +3998,7 @@ mod bounded_generic_scalar { let expected_id: &str = *expected_id; assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok((graphql_value!({"character": {"id": expected_id}}), vec![])), ); } @@ -4017,7 +4017,7 @@ mod bounded_generic_scalar { let expected_info: &str = *expected_info; assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok((graphql_value!({"hero": {"info": expected_info}}), vec![])), ); } @@ -4176,7 +4176,7 @@ mod explicit_custom_context { let schema = schema(QueryRoot::Human); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &CustomContext).await, + execute(DOC, None, &schema, &graphql_vars! {}, &CustomContext).await, Ok(( graphql_value!({"character": {"humanId": "human-32", "homePlanet": "earth"}}), vec![], @@ -4198,7 +4198,7 @@ mod explicit_custom_context { let schema = schema(QueryRoot::Droid); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &CustomContext).await, + execute(DOC, None, &schema, &graphql_vars! {}, &CustomContext).await, Ok(( graphql_value!({"character": {"droidId": "droid-99", "primaryFunction": "run"}}), vec![], @@ -4220,7 +4220,7 @@ mod explicit_custom_context { let schema = schema(QueryRoot::Human); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &CustomContext).await, + execute(DOC, None, &schema, &graphql_vars! {}, &CustomContext).await, Ok(( graphql_value!({"hero": {"humanId": "human-32", "homePlanet": "earth"}}), vec![], @@ -4242,7 +4242,7 @@ mod explicit_custom_context { let schema = schema(QueryRoot::Droid); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &CustomContext).await, + execute(DOC, None, &schema, &graphql_vars! {}, &CustomContext).await, Ok(( graphql_value!({"hero": {"droidId": "droid-99", "primaryFunction": "run"}}), vec![], @@ -4276,7 +4276,7 @@ mod explicit_custom_context { let expected_info: &str = *expected_info; let expexted_more: &str = *expexted_more; assert_eq!( - execute(&doc, None, &schema, &Variables::new(), &CustomContext).await, + execute(&doc, None, &schema, &graphql_vars! {}, &CustomContext).await, Ok(( graphql_value!({expected_interface: { "id": expected_id, @@ -4423,7 +4423,7 @@ mod inferred_custom_context_from_field { let ctx = CustomContext("in-ctx".into()); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &ctx).await, + execute(DOC, None, &schema, &graphql_vars! {}, &ctx).await, Ok(( graphql_value!({"character": {"humanId": "human-32", "homePlanet": "earth"}}), vec![], @@ -4446,7 +4446,7 @@ mod inferred_custom_context_from_field { let ctx = CustomContext("in-droid".into()); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &ctx).await, + execute(DOC, None, &schema, &graphql_vars! {}, &ctx).await, Ok(( graphql_value!({"character": {"droidId": "droid-99", "primaryFunction": "run"}}), vec![], @@ -4469,7 +4469,7 @@ mod inferred_custom_context_from_field { let ctx = CustomContext("in-ctx".into()); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &ctx).await, + execute(DOC, None, &schema, &graphql_vars! {}, &ctx).await, Ok(( graphql_value!({"hero": {"humanId": "human-32", "homePlanet": "earth"}}), vec![], @@ -4492,7 +4492,7 @@ mod inferred_custom_context_from_field { let ctx = CustomContext("in-droid".into()); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &ctx).await, + execute(DOC, None, &schema, &graphql_vars! {}, &ctx).await, Ok(( graphql_value!({"hero": {"droidId": "droid-99", "primaryFunction": "run"}}), vec![], @@ -4525,7 +4525,7 @@ mod inferred_custom_context_from_field { let expected_id: &str = *expected_id; let expected_info: &str = *expected_info; assert_eq!( - execute(&doc, None, &schema, &Variables::new(), &ctx).await, + execute(&doc, None, &schema, &graphql_vars! {}, &ctx).await, Ok(( graphql_value!({expected_interface: { "id": expected_id, @@ -4675,7 +4675,7 @@ mod inferred_custom_context_from_downcast { let db = Database { droid: None }; assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &db).await, + execute(DOC, None, &schema, &graphql_vars! {}, &db).await, Ok(( graphql_value!({"character": {"humanId": "human-32", "homePlanet": "earth"}}), vec![], @@ -4703,7 +4703,7 @@ mod inferred_custom_context_from_downcast { }; assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &db).await, + execute(DOC, None, &schema, &graphql_vars! {}, &db).await, Ok(( graphql_value!({"character": {"droidId": "droid-99", "primaryFunction": "run"}}), vec![], @@ -4726,7 +4726,7 @@ mod inferred_custom_context_from_downcast { let db = Database { droid: None }; assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &db).await, + execute(DOC, None, &schema, &graphql_vars! {}, &db).await, Ok(( graphql_value!({"hero": {"humanId": "human-32", "homePlanet": "earth"}}), vec![], @@ -4754,7 +4754,7 @@ mod inferred_custom_context_from_downcast { }; assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &db).await, + execute(DOC, None, &schema, &graphql_vars! {}, &db).await, Ok(( graphql_value!({"hero": {"droidId": "droid-88", "primaryFunction": "sit"}}), vec![], @@ -4779,7 +4779,7 @@ mod inferred_custom_context_from_downcast { let expected_id: &str = *expected_id; assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &db).await, + execute(DOC, None, &schema, &graphql_vars! {}, &db).await, Ok((graphql_value!({"character": {"id": expected_id}}), vec![])), ); } @@ -4799,7 +4799,7 @@ mod inferred_custom_context_from_downcast { let expected_info: &str = *expected_info; assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &db).await, + execute(DOC, None, &schema, &graphql_vars! {}, &db).await, Ok((graphql_value!({"hero": {"info": expected_info}}), vec![])), ); } @@ -4953,7 +4953,7 @@ mod executor { let schema = schema(QueryRoot::Human); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"character": {"humanId": "human-32", "homePlanet": "earth"}}), vec![], @@ -4975,7 +4975,7 @@ mod executor { let schema = schema(QueryRoot::Droid); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"character": {"droidId": "droid-99", "primaryFunction": "run"}}), vec![], @@ -4997,7 +4997,7 @@ mod executor { let schema = schema(QueryRoot::Human); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"hero": {"humanId": "human-32", "homePlanet": "earth"}}), vec![], @@ -5019,7 +5019,7 @@ mod executor { let schema = schema(QueryRoot::Droid); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"hero": {"droidId": "droid-99", "primaryFunction": "run"}}), vec![], @@ -5047,7 +5047,7 @@ mod executor { let expected_info: &str = *expected_info; assert_eq!( - execute(&doc, None, &schema, &Variables::new(), &()).await, + execute(&doc, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({expected_interface: {"id": "id", "info": expected_info}}), vec![], @@ -5077,7 +5077,7 @@ mod executor { let schema = schema(QueryRoot::Human); assert_eq!( - execute(&doc, None, &schema, &Variables::new(), &()).await, + execute(&doc, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"__type": {"fields": [ {"name": "id", "args": []}, @@ -5147,7 +5147,7 @@ mod ignored_method { let schema = schema(QueryRoot); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"character": {"humanId": "human-32", "homePlanet": "earth"}}), vec![], @@ -5166,7 +5166,7 @@ mod ignored_method { let schema = schema(QueryRoot); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok((graphql_value!({"character": {"id": "human-32"}}), vec![])), ); } @@ -5184,7 +5184,7 @@ mod ignored_method { let schema = schema(QueryRoot); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"__type": {"fields": [{"name": "id"}]}}), vec![], @@ -5318,7 +5318,7 @@ mod downcast_method { let schema = schema(QueryRoot::Human); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"character": {"humanId": "human-32", "homePlanet": "earth"}}), vec![], @@ -5340,7 +5340,7 @@ mod downcast_method { let schema = schema(QueryRoot::Droid); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"character": {"droidId": "droid-99", "primaryFunction": "run"}}), vec![], @@ -5362,7 +5362,7 @@ mod downcast_method { let schema = schema(QueryRoot::Human); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"hero": {"humanId": "human-32", "homePlanet": "earth"}}), vec![], @@ -5384,7 +5384,7 @@ mod downcast_method { let schema = schema(QueryRoot::Droid); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"hero": {"droidId": "droid-99", "primaryFunction": "run"}}), vec![], @@ -5408,7 +5408,7 @@ mod downcast_method { let expected_id: &str = *expected_id; assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok((graphql_value!({"character": {"id": expected_id}}), vec![])), ); } @@ -5427,7 +5427,7 @@ mod downcast_method { let expected_info: &str = *expected_info; assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok((graphql_value!({"hero": {"info": expected_info}}), vec![])), ); } @@ -5444,7 +5444,7 @@ mod downcast_method { let expected_field: &str = *field; assert_eq!( - execute(*doc, None, &schema, &Variables::new(), &()).await, + execute(*doc, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"__type": {"fields": [{"name": expected_field}]}}), vec![], @@ -5590,7 +5590,7 @@ mod external_downcast { }; assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &db).await, + execute(DOC, None, &schema, &graphql_vars! {}, &db).await, Ok(( graphql_value!({"character": {"humanId": "human-64", "homePlanet": "mars"}}), vec![], @@ -5616,7 +5616,7 @@ mod external_downcast { }; assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &db).await, + execute(DOC, None, &schema, &graphql_vars! {}, &db).await, Ok(( graphql_value!({"character": {"droidId": "droid-99", "primaryFunction": "run"}}), vec![], @@ -5642,7 +5642,7 @@ mod external_downcast { }; assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &db).await, + execute(DOC, None, &schema, &graphql_vars! {}, &db).await, Ok(( graphql_value!({"hero": {"humanId": "human-32", "homePlanet": "earth"}}), vec![], @@ -5671,7 +5671,7 @@ mod external_downcast { }; assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &db).await, + execute(DOC, None, &schema, &graphql_vars! {}, &db).await, Ok(( graphql_value!({"hero": {"droidId": "droid-01", "primaryFunction": "swim"}}), vec![], @@ -5703,7 +5703,7 @@ mod external_downcast { let expected_id: &str = *expected_id; assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &db).await, + execute(DOC, None, &schema, &graphql_vars! {}, &db).await, Ok((graphql_value!({"character": {"id": expected_id}}), vec![])), ); } @@ -5730,7 +5730,7 @@ mod external_downcast { let expected_info: &str = *expected_info; assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &db).await, + execute(DOC, None, &schema, &graphql_vars! {}, &db).await, Ok((graphql_value!({"hero": {"info": expected_info}}), vec![])), ); } diff --git a/integration_tests/juniper_tests/src/codegen/object_attr.rs b/integration_tests/juniper_tests/src/codegen/object_attr.rs index c896523d0..9161cc55d 100644 --- a/integration_tests/juniper_tests/src/codegen/object_attr.rs +++ b/integration_tests/juniper_tests/src/codegen/object_attr.rs @@ -1,9 +1,9 @@ //! Tests for `#[graphql_object]` macro. use juniper::{ - execute, graphql_object, graphql_value, DefaultScalarValue, EmptyMutation, EmptySubscription, - Executor, FieldError, FieldResult, GraphQLInputObject, GraphQLObject, GraphQLType, - IntoFieldError, RootNode, ScalarValue, Variables, + execute, graphql_object, graphql_value, graphql_vars, DefaultScalarValue, EmptyMutation, + EmptySubscription, Executor, FieldError, FieldResult, GraphQLInputObject, GraphQLObject, + GraphQLType, IntoFieldError, RootNode, ScalarValue, }; fn schema<'q, C, Q>(query_root: Q) -> RootNode<'q, Q, EmptyMutation, EmptySubscription> @@ -63,7 +63,7 @@ mod trivial { let schema = schema(QueryRoot); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok((graphql_value!({"human": {"id": "human-32"}}), vec![])), ); } @@ -79,7 +79,7 @@ mod trivial { let schema = schema(QueryRoot); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok((graphql_value!({"__type": {"kind": "OBJECT"}}), vec![])), ); } @@ -95,7 +95,7 @@ mod trivial { let schema = schema(QueryRoot); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok((graphql_value!({"__type": {"name": "Human"}}), vec![])), ); } @@ -111,7 +111,7 @@ mod trivial { let schema = schema(QueryRoot); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok((graphql_value!({"__type": {"description": null}}), vec![])), ); } @@ -151,7 +151,7 @@ mod trivial_async { let schema = schema(QueryRoot); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok((graphql_value!({"human": {"id": "human-32"}}), vec![])), ); } @@ -167,7 +167,7 @@ mod trivial_async { let schema = schema(QueryRoot); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok((graphql_value!({"__type": {"kind": "OBJECT"}}), vec![])), ); } @@ -183,7 +183,7 @@ mod trivial_async { let schema = schema(QueryRoot); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok((graphql_value!({"__type": {"name": "Human"}}), vec![])), ); } @@ -199,7 +199,7 @@ mod trivial_async { let schema = schema(QueryRoot); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok((graphql_value!({"__type": {"description": null}}), vec![])), ); } @@ -242,7 +242,7 @@ mod raw_method { let schema = schema(QueryRoot); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"human": {"myId": "human-32", "async": "async-32"}}), vec![], @@ -265,7 +265,7 @@ mod raw_method { let schema = schema(QueryRoot); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"__type": { "name": "Human", @@ -316,7 +316,7 @@ mod ignored_method { let schema = schema(QueryRoot); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok((graphql_value!({"human": {"id": "human-32"}}), vec![])), ); } @@ -334,7 +334,7 @@ mod ignored_method { let schema = schema(QueryRoot); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"__type": {"fields": [{"name": "id"}]}}), vec![], @@ -393,7 +393,7 @@ mod fallible_method { let schema = schema(QueryRoot); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"human": {"id": "human-32", "homePlanet": "earth"}}), vec![], @@ -422,7 +422,7 @@ mod fallible_method { let schema = schema(QueryRoot); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"__type": { "name": "Human", @@ -494,7 +494,7 @@ mod generic { let schema = schema(QueryRoot); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok((graphql_value!({"human": {"id": 32}}), vec![])), ); } @@ -510,7 +510,7 @@ mod generic { let schema = schema(QueryRoot); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok((graphql_value!({"humanString": {"id": "human-32"}}), vec![])), ); } @@ -526,7 +526,7 @@ mod generic { let schema = schema(QueryRoot); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok((graphql_value!({"__type": {"name": "Human"}}), vec![])), ); } @@ -585,7 +585,7 @@ mod generic_async { let schema = schema(QueryRoot); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok((graphql_value!({"human": {"id": 32}}), vec![])), ); } @@ -601,7 +601,7 @@ mod generic_async { let schema = schema(QueryRoot); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok((graphql_value!({"humanString": {"id": "human-32"}}), vec![])), ); } @@ -617,7 +617,7 @@ mod generic_async { let schema = schema(QueryRoot); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok((graphql_value!({"__type": {"name": "Human"}}), vec![])), ); } @@ -685,7 +685,7 @@ mod generic_lifetime_async { let schema = schema(QueryRoot("mars".into())); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"human": {"id": 32, "planet": "earth"}}), vec![], @@ -705,7 +705,7 @@ mod generic_lifetime_async { let schema = schema(QueryRoot("mars".into())); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"humanString": {"id": "mars", "planet": "mars"}}), vec![], @@ -724,7 +724,7 @@ mod generic_lifetime_async { let schema = schema(QueryRoot("mars".into())); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok((graphql_value!({"__type": {"name": "Human"}}), vec![])), ); } @@ -837,7 +837,7 @@ mod nested_generic_lifetime_async { let schema = schema(QueryRoot("mars".into())); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"human": { "id": 32, @@ -868,7 +868,7 @@ mod nested_generic_lifetime_async { let schema = schema(QueryRoot("mars".into())); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"humanString": { "id": "mars", @@ -899,7 +899,7 @@ mod nested_generic_lifetime_async { let expected_name: &str = *object; assert_eq!( - execute(&doc, None, &schema, &Variables::new(), &()).await, + execute(&doc, None, &schema, &graphql_vars! {}, &()).await, Ok((graphql_value!({"__type": {"name": expected_name}}), vec![])), ); } @@ -943,7 +943,7 @@ mod argument { let schema = schema(QueryRoot); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"human": {"id": "human-32", "homePlanet": "earth,None"}}), vec![], @@ -967,7 +967,7 @@ mod argument { let schema = schema(QueryRoot); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"__type": {"fields": [ {"name": "id", "args": [{"name": "arg"}]}, @@ -993,7 +993,7 @@ mod argument { let schema = schema(QueryRoot); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"__type": {"fields": [ {"args": [{"description": null}]}, @@ -1019,7 +1019,7 @@ mod argument { let schema = schema(QueryRoot); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"__type": {"fields": [ {"args": [{"defaultValue": null}]}, @@ -1082,7 +1082,7 @@ mod default_argument { let expected: &str = *expected; assert_eq!( - execute(*input, None, &schema, &Variables::new(), &()).await, + execute(*input, None, &schema, &graphql_vars! {}, &()).await, Ok((graphql_value!({"human": {"id": expected}}), vec![])), ); } @@ -1099,7 +1099,7 @@ mod default_argument { let expected: i32 = *expected; assert_eq!( - execute(*input, None, &schema, &Variables::new(), &()).await, + execute(*input, None, &schema, &graphql_vars! {}, &()).await, Ok((graphql_value!({"human": {"info": expected}}), vec![])), ); } @@ -1127,7 +1127,7 @@ mod default_argument { let schema = schema(QueryRoot); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"__type": {"fields": [{ "args": [{ @@ -1193,7 +1193,7 @@ mod description_from_doc_comment { let schema = schema(QueryRoot); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"__type": { "description": "Rust docs.", @@ -1247,7 +1247,7 @@ mod deprecation_from_attr { let schema = schema(QueryRoot); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok((graphql_value!({"human": {"id": "human-32"}}), vec![])), ); } @@ -1264,7 +1264,7 @@ mod deprecation_from_attr { let schema = schema(QueryRoot); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok((graphql_value!({"human": {"a": "a", "b": "b"}}), vec![])), ); } @@ -1283,7 +1283,7 @@ mod deprecation_from_attr { let schema = schema(QueryRoot); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"__type": {"fields": [ {"name": "id", "isDeprecated": false}, @@ -1309,7 +1309,7 @@ mod deprecation_from_attr { let schema = schema(QueryRoot); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"__type": {"fields": [ {"name": "id", "deprecationReason": null}, @@ -1372,7 +1372,7 @@ mod explicit_name_description_and_deprecation { let schema = schema(QueryRoot); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"human": {"myId": "human-32", "a": "a", "b": "b"}}), vec![], @@ -1397,7 +1397,7 @@ mod explicit_name_description_and_deprecation { let schema = schema(QueryRoot); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"__type": { "name": "MyHuman", @@ -1430,7 +1430,7 @@ mod explicit_name_description_and_deprecation { let schema = schema(QueryRoot); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"__type": { "description": "My human.", @@ -1468,7 +1468,7 @@ mod explicit_name_description_and_deprecation { let schema = schema(QueryRoot); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"__type": { "fields": [{ @@ -1533,7 +1533,7 @@ mod renamed_all_fields_and_args { let schema = schema(QueryRoot); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"human": { "id": "human-32", @@ -1561,7 +1561,7 @@ mod renamed_all_fields_and_args { let schema = schema(QueryRoot); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"__type": {"fields": [ {"name": "id", "args": []}, @@ -1611,7 +1611,7 @@ mod explicit_scalar { let schema = schema(QueryRoot); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"human": {"id": "human-32", "homePlanet": "earth"}}), vec![], @@ -1659,7 +1659,7 @@ mod custom_scalar { let schema = schema_with_scalar::(QueryRoot); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"human": {"id": "human-32", "homePlanet": "earth"}}), vec![], @@ -1709,7 +1709,7 @@ mod explicit_generic_scalar { let schema = schema(QueryRoot); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"human": { "id": "human-32", @@ -1760,7 +1760,7 @@ mod bounded_generic_scalar { let schema = schema(QueryRoot); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"human": { "id": "human-32", @@ -1819,7 +1819,7 @@ mod explicit_custom_context { let ctx = CustomContext("ctx!".into()); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &ctx).await, + execute(DOC, None, &schema, &graphql_vars! {}, &ctx).await, Ok(( graphql_value!({"human": { "id": "ctx!", @@ -1879,7 +1879,7 @@ mod inferred_custom_context_from_field { let ctx = CustomContext("ctx!".into()); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &ctx).await, + execute(DOC, None, &schema, &graphql_vars! {}, &ctx).await, Ok(( graphql_value!({"human": { "id": "ctx!", @@ -1943,7 +1943,7 @@ mod executor { let schema = schema(QueryRoot); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"human": { "id": "id", @@ -1971,7 +1971,7 @@ mod executor { let schema = schema(QueryRoot); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"__type": {"fields": [ {"name": "id", "args": []}, @@ -2052,7 +2052,7 @@ mod switched_context { let ctx = CustomContext; assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &ctx).await, + execute(DOC, None, &schema, &graphql_vars! {}, &ctx).await, Ok(( graphql_value!({"human": { "switchAlways": {"id": 0}, @@ -2086,7 +2086,7 @@ mod switched_context { let ctx = CustomContext; assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &ctx).await, + execute(DOC, None, &schema, &graphql_vars! {}, &ctx).await, Ok(( graphql_value!({"__type": {"fields": [{ "name": "switchAlways", diff --git a/integration_tests/juniper_tests/src/codegen/object_derive.rs b/integration_tests/juniper_tests/src/codegen/object_derive.rs index 2be660679..126c315a4 100644 --- a/integration_tests/juniper_tests/src/codegen/object_derive.rs +++ b/integration_tests/juniper_tests/src/codegen/object_derive.rs @@ -1,8 +1,8 @@ //! Tests for `#[derive(GraphQLObject)]` macro. use juniper::{ - execute, graphql_object, graphql_value, DefaultScalarValue, EmptyMutation, EmptySubscription, - GraphQLObject, GraphQLType, RootNode, ScalarValue, Variables, + execute, graphql_object, graphql_value, graphql_vars, DefaultScalarValue, EmptyMutation, + EmptySubscription, GraphQLObject, GraphQLType, RootNode, ScalarValue, }; fn schema<'q, C, Q>(query_root: Q) -> RootNode<'q, Q, EmptyMutation, EmptySubscription> @@ -58,7 +58,7 @@ mod trivial { let schema = schema(QueryRoot); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok((graphql_value!({"human": {"id": "human-32"}}), vec![])), ); } @@ -74,7 +74,7 @@ mod trivial { let schema = schema(QueryRoot); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok((graphql_value!({"__type": {"kind": "OBJECT"}}), vec![])), ); } @@ -90,7 +90,7 @@ mod trivial { let schema = schema(QueryRoot); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok((graphql_value!({"__type": {"name": "Human"}}), vec![])), ); } @@ -106,7 +106,7 @@ mod trivial { let schema = schema(QueryRoot); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok((graphql_value!({"__type": {"description": null}}), vec![])), ); } @@ -142,7 +142,7 @@ mod raw_field { let schema = schema(QueryRoot); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok((graphql_value!({"human": {"async": "human-32"}}), vec![])), ); } @@ -162,7 +162,7 @@ mod raw_field { let schema = schema(QueryRoot); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"__type": { "name": "Human", @@ -209,7 +209,7 @@ mod ignored_field { let schema = schema(QueryRoot); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok((graphql_value!({"human": {"id": "human-32"}}), vec![])), ); } @@ -227,7 +227,7 @@ mod ignored_field { let schema = schema(QueryRoot); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"__type": {"fields": [{"name": "id"}]}}), vec![], @@ -269,7 +269,7 @@ mod generic { let schema = schema(QueryRoot); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok((graphql_value!({"human": {"id": "human-32"}}), vec![])), ); } @@ -285,7 +285,7 @@ mod generic { let schema = schema(QueryRoot); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok((graphql_value!({"__type": {"name": "Human"}}), vec![])), ); } @@ -324,7 +324,7 @@ mod generic_lifetime { let schema = schema(QueryRoot("mars".into())); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok((graphql_value!({"human": {"id": "mars"}}), vec![])), ); } @@ -340,7 +340,7 @@ mod generic_lifetime { let schema = schema(QueryRoot("mars".into())); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok((graphql_value!({"__type": {"name": "Human"}}), vec![])), ); } @@ -391,7 +391,7 @@ mod nested_generic_lifetime_async { let schema = schema(QueryRoot("mars".into())); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"human": { "id": 32, @@ -420,7 +420,7 @@ mod nested_generic_lifetime_async { let expected_name: &str = *object; assert_eq!( - execute(&doc, None, &schema, &Variables::new(), &()).await, + execute(&doc, None, &schema, &graphql_vars! {}, &()).await, Ok((graphql_value!({"__type": {"name": expected_name}}), vec![])), ); } @@ -464,7 +464,7 @@ mod description_from_doc_comment { let schema = schema(QueryRoot); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"__type": { "description": "Rust docs. Here.", @@ -513,7 +513,7 @@ mod deprecation_from_attr { let schema = schema(QueryRoot); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok((graphql_value!({"human": {"id": "human-32"}}), vec![])), ); } @@ -530,7 +530,7 @@ mod deprecation_from_attr { let schema = schema(QueryRoot); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok((graphql_value!({"human": {"a": "a", "b": "b"}}), vec![])), ); } @@ -549,7 +549,7 @@ mod deprecation_from_attr { let schema = schema(QueryRoot); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"__type": {"fields": [ {"name": "id", "isDeprecated": false}, @@ -575,7 +575,7 @@ mod deprecation_from_attr { let schema = schema(QueryRoot); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"__type": {"fields": [ {"name": "id", "deprecationReason": null}, @@ -632,7 +632,7 @@ mod explicit_name_description_and_deprecation { let schema = schema(QueryRoot); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"human": {"myId": "human-32", "a": "a", "b": "b"}}), vec![], @@ -654,7 +654,7 @@ mod explicit_name_description_and_deprecation { let schema = schema(QueryRoot); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"__type": { "name": "MyHuman", @@ -684,7 +684,7 @@ mod explicit_name_description_and_deprecation { let schema = schema(QueryRoot); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"__type": { "description": "My human.", @@ -719,7 +719,7 @@ mod explicit_name_description_and_deprecation { let schema = schema(QueryRoot); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"__type": { "fields": [{ @@ -779,7 +779,7 @@ mod renamed_all_fields { let schema = schema(QueryRoot); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"human": { "id": "human-32", @@ -804,7 +804,7 @@ mod renamed_all_fields { let schema = schema(QueryRoot); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"__type": {"fields": [ {"name": "id"}, @@ -846,7 +846,7 @@ mod explicit_scalar { let schema = schema(QueryRoot); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok((graphql_value!({"human": {"id": "human-32"}}), vec![])), ); } @@ -883,7 +883,7 @@ mod custom_scalar { let schema = schema_with_scalar::(QueryRoot); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok((graphql_value!({"human": {"id": "human-32"}}), vec![])), ); } @@ -925,7 +925,7 @@ mod explicit_generic_scalar { let schema = schema(QueryRoot); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok((graphql_value!({"human": {"id": "human-32"}}), vec![])), ); } @@ -960,7 +960,7 @@ mod bounded_generic_scalar { let schema = schema(QueryRoot); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok((graphql_value!({"human": {"id": "human-32"}}), vec![])), ); } @@ -1000,7 +1000,7 @@ mod explicit_custom_context { let ctx = CustomContext("ctx!".into()); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &ctx).await, + execute(DOC, None, &schema, &graphql_vars! {}, &ctx).await, Ok((graphql_value!({"human": {"id": "ctx!"}}), vec![])), ); } diff --git a/integration_tests/juniper_tests/src/codegen/scalar_value_transparent.rs b/integration_tests/juniper_tests/src/codegen/scalar_value_transparent.rs index 510a71f11..f2a45af1f 100644 --- a/integration_tests/juniper_tests/src/codegen/scalar_value_transparent.rs +++ b/integration_tests/juniper_tests/src/codegen/scalar_value_transparent.rs @@ -50,7 +50,7 @@ fn test_scalar_value_simple() { let id = UserId("111".into()); let output = ToInputValue::::to_input_value(&id); - assert_eq!(output, graphql_input_value!("111"),); + assert_eq!(output, graphql_input_value!("111")); } #[test] @@ -71,7 +71,7 @@ fn test_scalar_value_custom() { let id = CustomUserId("111".into()); let output = ToInputValue::::to_input_value(&id); - assert_eq!(output, graphql_input_value!("111"),); + assert_eq!(output, graphql_input_value!("111")); } #[test] diff --git a/integration_tests/juniper_tests/src/codegen/subscription_attr.rs b/integration_tests/juniper_tests/src/codegen/subscription_attr.rs index cd3ae4ab3..306b8c8e3 100644 --- a/integration_tests/juniper_tests/src/codegen/subscription_attr.rs +++ b/integration_tests/juniper_tests/src/codegen/subscription_attr.rs @@ -4,9 +4,9 @@ use std::pin::Pin; use futures::{future, stream, FutureExt as _}; use juniper::{ - execute, graphql_object, graphql_subscription, graphql_value, resolve_into_stream, - DefaultScalarValue, EmptyMutation, Executor, FieldError, FieldResult, GraphQLInputObject, - GraphQLType, IntoFieldError, RootNode, ScalarValue, Variables, + execute, graphql_object, graphql_subscription, graphql_value, graphql_vars, + resolve_into_stream, DefaultScalarValue, EmptyMutation, Executor, FieldError, FieldResult, + GraphQLInputObject, GraphQLType, IntoFieldError, RootNode, ScalarValue, }; use crate::util::extract_next; @@ -71,7 +71,7 @@ mod trivial { let schema = schema(Query, Human); assert_eq!( - resolve_into_stream(DOC, None, &schema, &Variables::new(), &()) + resolve_into_stream(DOC, None, &schema, &graphql_vars! {}, &()) .then(|s| extract_next(s)) .await, Ok((graphql_value!({"id": "human-32"}), vec![])), @@ -87,7 +87,7 @@ mod trivial { let schema = schema(Query, Human); assert_eq!( - resolve_into_stream(DOC, None, &schema, &Variables::new(), &()) + resolve_into_stream(DOC, None, &schema, &graphql_vars! {}, &()) .then(|s| extract_next(s)) .await, Ok((graphql_value!({"homePlanet": "earth"}), vec![])), @@ -105,7 +105,7 @@ mod trivial { let schema = schema(Query, Human); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok((graphql_value!({"__type": {"kind": "OBJECT"}}), vec![])), ); } @@ -121,7 +121,7 @@ mod trivial { let schema = schema(Query, Human); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok((graphql_value!({"__type": {"name": "Human"}}), vec![])), ); } @@ -137,7 +137,7 @@ mod trivial { let schema = schema(Query, Human); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok((graphql_value!({"__type": {"description": null}}), vec![])), ); } @@ -168,7 +168,7 @@ mod raw_method { let schema = schema(Query, Human); assert_eq!( - resolve_into_stream(DOC, None, &schema, &Variables::new(), &()) + resolve_into_stream(DOC, None, &schema, &graphql_vars! {}, &()) .then(|s| extract_next(s)) .await, Ok((graphql_value!({"myId": "human-32"}), vec![])), @@ -184,7 +184,7 @@ mod raw_method { let schema = schema(Query, Human); assert_eq!( - resolve_into_stream(DOC, None, &schema, &Variables::new(), &()) + resolve_into_stream(DOC, None, &schema, &graphql_vars! {}, &()) .then(|s| extract_next(s)) .await, Ok((graphql_value!({"async": "async-32"}), vec![])), @@ -206,7 +206,7 @@ mod raw_method { let schema = schema(Query, Human); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"__type": { "name": "Human", @@ -246,7 +246,7 @@ mod ignored_method { let schema = schema(Query, Human); assert_eq!( - resolve_into_stream(DOC, None, &schema, &Variables::new(), &()) + resolve_into_stream(DOC, None, &schema, &graphql_vars! {}, &()) .then(|s| extract_next(s)) .await, Ok((graphql_value!({"id": "human-32"}), vec![])), @@ -266,7 +266,7 @@ mod ignored_method { let schema = schema(Query, Human); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"__type": {"fields": [{"name": "id"}]}}), vec![], @@ -308,7 +308,7 @@ mod fallible_method { let schema = schema(Query, Human); assert_eq!( - resolve_into_stream(DOC, None, &schema, &Variables::new(), &()) + resolve_into_stream(DOC, None, &schema, &graphql_vars! {}, &()) .then(|s| extract_next(s)) .await, Ok((graphql_value!({"id": "human-32"}), vec![])), @@ -324,7 +324,7 @@ mod fallible_method { let schema = schema(Query, Human); assert_eq!( - resolve_into_stream(DOC, None, &schema, &Variables::new(), &()) + resolve_into_stream(DOC, None, &schema, &graphql_vars! {}, &()) .then(|s| extract_next(s)) .await, Ok((graphql_value!({"homePlanet": "earth"}), vec![])), @@ -352,7 +352,7 @@ mod fallible_method { let schema = schema(Query, Human); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"__type": { "name": "Human", @@ -403,7 +403,7 @@ mod argument { let schema = schema(Query, Human); assert_eq!( - resolve_into_stream(DOC, None, &schema, &Variables::new(), &()) + resolve_into_stream(DOC, None, &schema, &graphql_vars! {}, &()) .then(|s| extract_next(s)) .await, Ok((graphql_value!({"id": "human-32"}), vec![])), @@ -419,7 +419,7 @@ mod argument { let schema = schema(Query, Human); assert_eq!( - resolve_into_stream(DOC, None, &schema, &Variables::new(), &()) + resolve_into_stream(DOC, None, &schema, &graphql_vars! {}, &()) .then(|s| extract_next(s)) .await, Ok((graphql_value!({"homePlanet": "earth,None"}), vec![])), @@ -442,7 +442,7 @@ mod argument { let schema = schema(Query, Human); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"__type": {"fields": [ {"name": "id", "args": [{"name": "arg"}]}, @@ -468,7 +468,7 @@ mod argument { let schema = schema(Query, Human); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"__type": {"fields": [ {"args": [{"description": null}]}, @@ -494,7 +494,7 @@ mod argument { let schema = schema(Query, Human); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"__type": {"fields": [ {"args": [{"defaultValue": null}]}, @@ -552,7 +552,7 @@ mod default_argument { let expected: &str = *expected; assert_eq!( - resolve_into_stream(*input, None, &schema, &Variables::new(), &()) + resolve_into_stream(*input, None, &schema, &graphql_vars! {}, &()) .then(|s| extract_next(s)) .await, Ok((graphql_value!({ "id": expected }), vec![])), @@ -571,7 +571,7 @@ mod default_argument { let expected: i32 = *expected; assert_eq!( - resolve_into_stream(*input, None, &schema, &Variables::new(), &()) + resolve_into_stream(*input, None, &schema, &graphql_vars! {}, &()) .then(|s| extract_next(s)) .await, Ok((graphql_value!({ "info": expected }), vec![])), @@ -601,7 +601,7 @@ mod default_argument { let schema = schema(Query, Human); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"__type": {"fields": [{ "args": [{ @@ -667,7 +667,7 @@ mod generic { ); assert_eq!( - resolve_into_stream(DOC, None, &schema, &Variables::new(), &()) + resolve_into_stream(DOC, None, &schema, &graphql_vars! {}, &()) .then(|s| extract_next(s)) .await, Ok((graphql_value!({"id": 34}), vec![])), @@ -689,7 +689,7 @@ mod generic { ); assert_eq!( - resolve_into_stream(DOC, None, &schema, &Variables::new(), &()) + resolve_into_stream(DOC, None, &schema, &graphql_vars! {}, &()) .then(|s| extract_next(s)) .await, Ok((graphql_value!({"id": "human-32"}), vec![])), @@ -713,7 +713,7 @@ mod generic { ); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok((graphql_value!({"__type": {"name": "Human"}}), vec![])), ); } @@ -767,7 +767,7 @@ mod generic_lifetime { ); assert_eq!( - resolve_into_stream(DOC, None, &schema, &Variables::new(), &()) + resolve_into_stream(DOC, None, &schema, &graphql_vars! {}, &()) .then(|s| extract_next(s)) .await, Ok((graphql_value!({"id": 34}), vec![])), @@ -789,7 +789,7 @@ mod generic_lifetime { ); assert_eq!( - resolve_into_stream(DOC, None, &schema, &Variables::new(), &()) + resolve_into_stream(DOC, None, &schema, &graphql_vars! {}, &()) .then(|s| extract_next(s)) .await, Ok((graphql_value!({"planet": "earth"}), vec![])), @@ -811,7 +811,7 @@ mod generic_lifetime { ); assert_eq!( - resolve_into_stream(DOC, None, &schema, &Variables::new(), &()) + resolve_into_stream(DOC, None, &schema, &graphql_vars! {}, &()) .then(|s| extract_next(s)) .await, Ok((graphql_value!({"id": "human-32"}), vec![])), @@ -833,7 +833,7 @@ mod generic_lifetime { ); assert_eq!( - resolve_into_stream(DOC, None, &schema, &Variables::new(), &()) + resolve_into_stream(DOC, None, &schema, &graphql_vars! {}, &()) .then(|s| extract_next(s)) .await, Ok((graphql_value!({"planet": "mars"}), vec![])), @@ -857,7 +857,7 @@ mod generic_lifetime { ); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok((graphql_value!({"__type": {"name": "Human"}}), vec![])), ); } @@ -892,7 +892,7 @@ mod description_from_doc_comment { let schema = schema(Query, Human); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"__type": { "description": "Rust docs.", @@ -935,7 +935,7 @@ mod deprecation_from_attr { let schema = schema(Query, Human); assert_eq!( - resolve_into_stream(DOC, None, &schema, &Variables::new(), &()) + resolve_into_stream(DOC, None, &schema, &graphql_vars! {}, &()) .then(|s| extract_next(s)) .await, Ok((graphql_value!({"id": "human-32"}), vec![])), @@ -951,7 +951,7 @@ mod deprecation_from_attr { let schema = schema(Query, Human); assert_eq!( - resolve_into_stream(DOC, None, &schema, &Variables::new(), &()) + resolve_into_stream(DOC, None, &schema, &graphql_vars! {}, &()) .then(|s| extract_next(s)) .await, Ok((graphql_value!({"a": "a"}), vec![])), @@ -967,7 +967,7 @@ mod deprecation_from_attr { let schema = schema(Query, Human); assert_eq!( - resolve_into_stream(DOC, None, &schema, &Variables::new(), &()) + resolve_into_stream(DOC, None, &schema, &graphql_vars! {}, &()) .then(|s| extract_next(s)) .await, Ok((graphql_value!({"b": "b"}), vec![])), @@ -988,7 +988,7 @@ mod deprecation_from_attr { let schema = schema(Query, Human); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"__type": {"fields": [ {"name": "id", "isDeprecated": false}, @@ -1014,7 +1014,7 @@ mod deprecation_from_attr { let schema = schema(Query, Human); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"__type": {"fields": [ {"name": "id", "deprecationReason": null}, @@ -1064,7 +1064,7 @@ mod explicit_name_description_and_deprecation { let schema = schema(Query, Human); assert_eq!( - resolve_into_stream(DOC, None, &schema, &Variables::new(), &()) + resolve_into_stream(DOC, None, &schema, &graphql_vars! {}, &()) .then(|s| extract_next(s)) .await, Ok((graphql_value!({"myId": "human-32"}), vec![])), @@ -1080,7 +1080,7 @@ mod explicit_name_description_and_deprecation { let schema = schema(Query, Human); assert_eq!( - resolve_into_stream(DOC, None, &schema, &Variables::new(), &()) + resolve_into_stream(DOC, None, &schema, &graphql_vars! {}, &()) .then(|s| extract_next(s)) .await, Ok((graphql_value!({"a": "a"}), vec![])), @@ -1096,7 +1096,7 @@ mod explicit_name_description_and_deprecation { let schema = schema(Query, Human); assert_eq!( - resolve_into_stream(DOC, None, &schema, &Variables::new(), &()) + resolve_into_stream(DOC, None, &schema, &graphql_vars! {}, &()) .then(|s| extract_next(s)) .await, Ok((graphql_value!({"b": "b"}), vec![])), @@ -1120,7 +1120,7 @@ mod explicit_name_description_and_deprecation { let schema = schema(Query, Human); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"__type": { "name": "MyHuman", @@ -1153,7 +1153,7 @@ mod explicit_name_description_and_deprecation { let schema = schema(Query, Human); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"__type": { "description": "My human.", @@ -1191,7 +1191,7 @@ mod explicit_name_description_and_deprecation { let schema = schema(Query, Human); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"__type": { "fields": [{ @@ -1243,7 +1243,7 @@ mod renamed_all_fields_and_args { let schema = schema(Query, Human); assert_eq!( - resolve_into_stream(DOC, None, &schema, &Variables::new(), &()) + resolve_into_stream(DOC, None, &schema, &graphql_vars! {}, &()) .then(|s| extract_next(s)) .await, Ok((graphql_value!({"id": "human-32"}), vec![])), @@ -1259,7 +1259,7 @@ mod renamed_all_fields_and_args { let schema = schema(Query, Human); assert_eq!( - resolve_into_stream(DOC, None, &schema, &Variables::new(), &()) + resolve_into_stream(DOC, None, &schema, &graphql_vars! {}, &()) .then(|s| extract_next(s)) .await, Ok((graphql_value!({"home_planet": "earth"}), vec![])), @@ -1275,7 +1275,7 @@ mod renamed_all_fields_and_args { let schema = schema(Query, Human); assert_eq!( - resolve_into_stream(DOC, None, &schema, &Variables::new(), &()) + resolve_into_stream(DOC, None, &schema, &graphql_vars! {}, &()) .then(|s| extract_next(s)) .await, Ok((graphql_value!({"async_info": 3}), vec![])), @@ -1298,7 +1298,7 @@ mod renamed_all_fields_and_args { let schema = schema(Query, Human); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"__type": {"fields": [ {"name": "id", "args": []}, @@ -1336,7 +1336,7 @@ mod explicit_scalar { let schema = schema(Query, Human); assert_eq!( - resolve_into_stream(DOC, None, &schema, &Variables::new(), &()) + resolve_into_stream(DOC, None, &schema, &graphql_vars! {}, &()) .then(|s| extract_next(s)) .await, Ok((graphql_value!({"id": "human-32"}), vec![])), @@ -1352,7 +1352,7 @@ mod explicit_scalar { let schema = schema(Query, Human); assert_eq!( - resolve_into_stream(DOC, None, &schema, &Variables::new(), &()) + resolve_into_stream(DOC, None, &schema, &graphql_vars! {}, &()) .then(|s| extract_next(s)) .await, Ok((graphql_value!({"homePlanet": "earth"}), vec![])), @@ -1387,7 +1387,7 @@ mod custom_scalar { let schema = schema_with_scalar::(Query, Human); assert_eq!( - resolve_into_stream(DOC, None, &schema, &Variables::new(), &()) + resolve_into_stream(DOC, None, &schema, &graphql_vars! {}, &()) .then(|s| extract_next(s)) .await, Ok((graphql_value!({"id": "human-32"}), vec![])), @@ -1403,7 +1403,7 @@ mod custom_scalar { let schema = schema_with_scalar::(Query, Human); assert_eq!( - resolve_into_stream(DOC, None, &schema, &Variables::new(), &()) + resolve_into_stream(DOC, None, &schema, &graphql_vars! {}, &()) .then(|s| extract_next(s)) .await, Ok((graphql_value!({"homePlanet": "earth"}), vec![])), @@ -1438,7 +1438,7 @@ mod explicit_generic_scalar { let schema = schema(Query, Human::(PhantomData)); assert_eq!( - resolve_into_stream(DOC, None, &schema, &Variables::new(), &()) + resolve_into_stream(DOC, None, &schema, &graphql_vars! {}, &()) .then(|s| extract_next(s)) .await, Ok((graphql_value!({"id": "human-32"}), vec![])), @@ -1454,7 +1454,7 @@ mod explicit_generic_scalar { let schema = schema(Query, Human::(PhantomData)); assert_eq!( - resolve_into_stream(DOC, None, &schema, &Variables::new(), &()) + resolve_into_stream(DOC, None, &schema, &graphql_vars! {}, &()) .then(|s| extract_next(s)) .await, Ok((graphql_value!({"homePlanet": "earth"}), vec![])), @@ -1489,7 +1489,7 @@ mod bounded_generic_scalar { let schema = schema(Query, Human); assert_eq!( - resolve_into_stream(DOC, None, &schema, &Variables::new(), &()) + resolve_into_stream(DOC, None, &schema, &graphql_vars! {}, &()) .then(|s| extract_next(s)) .await, Ok((graphql_value!({"id": "human-32"}), vec![])), @@ -1505,7 +1505,7 @@ mod bounded_generic_scalar { let schema = schema(Query, Human); assert_eq!( - resolve_into_stream(DOC, None, &schema, &Variables::new(), &()) + resolve_into_stream(DOC, None, &schema, &graphql_vars! {}, &()) .then(|s| extract_next(s)) .await, Ok((graphql_value!({"homePlanet": "earth"}), vec![])), @@ -1558,7 +1558,7 @@ mod explicit_custom_context { let ctx = CustomContext("ctx!".into()); assert_eq!( - resolve_into_stream(DOC, None, &schema, &Variables::new(), &ctx) + resolve_into_stream(DOC, None, &schema, &graphql_vars! {}, &ctx) .then(|s| extract_next(s)) .await, Ok((graphql_value!({"id": "ctx!"}), vec![])), @@ -1575,7 +1575,7 @@ mod explicit_custom_context { let ctx = CustomContext("ctx!".into()); assert_eq!( - resolve_into_stream(DOC, None, &schema, &Variables::new(), &ctx) + resolve_into_stream(DOC, None, &schema, &graphql_vars! {}, &ctx) .then(|s| extract_next(s)) .await, Ok((graphql_value!({"info": "human being"}), vec![])), @@ -1592,7 +1592,7 @@ mod explicit_custom_context { let ctx = CustomContext("ctx!".into()); assert_eq!( - resolve_into_stream(DOC, None, &schema, &Variables::new(), &ctx) + resolve_into_stream(DOC, None, &schema, &graphql_vars! {}, &ctx) .then(|s| extract_next(s)) .await, Ok((graphql_value!({"more": "ctx!"}), vec![])), @@ -1645,7 +1645,7 @@ mod inferred_custom_context_from_field { let ctx = CustomContext("ctx!".into()); assert_eq!( - resolve_into_stream(DOC, None, &schema, &Variables::new(), &ctx) + resolve_into_stream(DOC, None, &schema, &graphql_vars! {}, &ctx) .then(|s| extract_next(s)) .await, Ok((graphql_value!({"id": "ctx!"}), vec![])), @@ -1662,7 +1662,7 @@ mod inferred_custom_context_from_field { let ctx = CustomContext("ctx!".into()); assert_eq!( - resolve_into_stream(DOC, None, &schema, &Variables::new(), &ctx) + resolve_into_stream(DOC, None, &schema, &graphql_vars! {}, &ctx) .then(|s| extract_next(s)) .await, Ok((graphql_value!({"info": "human being"}), vec![])), @@ -1679,7 +1679,7 @@ mod inferred_custom_context_from_field { let ctx = CustomContext("ctx!".into()); assert_eq!( - resolve_into_stream(DOC, None, &schema, &Variables::new(), &ctx) + resolve_into_stream(DOC, None, &schema, &graphql_vars! {}, &ctx) .then(|s| extract_next(s)) .await, Ok((graphql_value!({"more": "ctx!"}), vec![])), @@ -1731,7 +1731,7 @@ mod executor { let schema = schema(Query, Human); assert_eq!( - resolve_into_stream(DOC, None, &schema, &Variables::new(), &()) + resolve_into_stream(DOC, None, &schema, &graphql_vars! {}, &()) .then(|s| extract_next(s)) .await, Ok((graphql_value!({"id": "id"}), vec![])), @@ -1747,7 +1747,7 @@ mod executor { let schema = schema(Query, Human); assert_eq!( - resolve_into_stream(DOC, None, &schema, &Variables::new(), &()) + resolve_into_stream(DOC, None, &schema, &graphql_vars! {}, &()) .then(|s| extract_next(s)) .await, Ok((graphql_value!({"info": "input!"}), vec![])), @@ -1763,7 +1763,7 @@ mod executor { let schema = schema(Query, Human); assert_eq!( - resolve_into_stream(DOC, None, &schema, &Variables::new(), &()) + resolve_into_stream(DOC, None, &schema, &graphql_vars! {}, &()) .then(|s| extract_next(s)) .await, Ok((graphql_value!({"info2": "no info"}), vec![])), @@ -1786,7 +1786,7 @@ mod executor { let schema = schema(Query, Human); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"__type": {"fields": [ {"name": "id", "args": []}, diff --git a/integration_tests/juniper_tests/src/codegen/union_attr.rs b/integration_tests/juniper_tests/src/codegen/union_attr.rs index 456014ca7..9f032c4c8 100644 --- a/integration_tests/juniper_tests/src/codegen/union_attr.rs +++ b/integration_tests/juniper_tests/src/codegen/union_attr.rs @@ -1,8 +1,8 @@ //! Tests for `#[graphql_union]` macro. use juniper::{ - execute, graphql_object, graphql_union, graphql_value, DefaultScalarValue, EmptyMutation, - EmptySubscription, GraphQLObject, GraphQLType, RootNode, ScalarValue, Variables, + execute, graphql_object, graphql_union, graphql_value, graphql_vars, DefaultScalarValue, + EmptyMutation, EmptySubscription, GraphQLObject, GraphQLType, RootNode, ScalarValue, }; #[derive(GraphQLObject)] @@ -143,7 +143,7 @@ mod trivial { let schema = schema(QueryRoot::Human); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"character": {"humanId": "human-32", "homePlanet": "earth"}}), vec![], @@ -156,7 +156,7 @@ mod trivial { let schema = schema(QueryRoot::Droid); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"character": {"droidId": "droid-99", "primaryFunction": "run"}}), vec![], @@ -175,7 +175,7 @@ mod trivial { let schema = schema(QueryRoot::Human); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok((graphql_value!({"__type": {"kind": "UNION"}}), vec![])), ); } @@ -191,7 +191,7 @@ mod trivial { let schema = schema(QueryRoot::Human); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok((graphql_value!({"__type": {"name": "Character"}}), vec![])), ); } @@ -207,7 +207,7 @@ mod trivial { let schema = schema(QueryRoot::Human); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok((graphql_value!({"__type": {"description": null}}), vec![])), ); } @@ -280,7 +280,7 @@ mod generic { let schema = schema(QueryRoot::Human); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"character": {"humanId": "human-32", "homePlanet": "earth"}}), vec![], @@ -293,7 +293,7 @@ mod generic { let schema = schema(QueryRoot::Droid); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"character": {"droidId": "droid-99", "primaryFunction": "run"}}), vec![], @@ -312,7 +312,7 @@ mod generic { let schema = schema(QueryRoot::Human); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok((graphql_value!({"__type": {"name": "Character"}}), vec![])), ); } @@ -363,7 +363,7 @@ mod description_from_doc_comment { let schema = schema(QueryRoot); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"character": {"humanId": "human-32", "homePlanet": "earth"}}), vec![], @@ -382,7 +382,7 @@ mod description_from_doc_comment { let schema = schema(QueryRoot); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"__type": {"description": "Rust docs."}}), vec![], @@ -436,7 +436,7 @@ mod explicit_name_and_description { let schema = schema(QueryRoot); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"character": {"humanId": "human-32", "homePlanet": "earth"}}), vec![], @@ -455,7 +455,7 @@ mod explicit_name_and_description { let schema = schema(QueryRoot); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok((graphql_value!({"__type": {"name": "MyChar"}}), vec![])), ); } @@ -471,7 +471,7 @@ mod explicit_name_and_description { let schema = schema(QueryRoot); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"__type": {"description": "My character."}}), vec![], @@ -547,7 +547,7 @@ mod explicit_scalar { let schema = schema(QueryRoot::Human); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"character": {"humanId": "human-32", "homePlanet": "earth"}}), vec![], @@ -560,7 +560,7 @@ mod explicit_scalar { let schema = schema(QueryRoot::Droid); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"character": {"droidId": "droid-99", "primaryFunction": "run"}}), vec![], @@ -638,7 +638,7 @@ mod custom_scalar { let schema = schema_with_scalar::(QueryRoot::Human); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"character": {"humanId": "human-32", "homePlanet": "earth"}}), vec![], @@ -651,7 +651,7 @@ mod custom_scalar { let schema = schema_with_scalar::(QueryRoot::Droid); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"character": {"droidId": "droid-99", "primaryFunction": "run"}}), vec![], @@ -727,7 +727,7 @@ mod explicit_generic_scalar { let schema = schema(QueryRoot::Human); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"character": {"humanId": "human-32", "homePlanet": "earth"}}), vec![], @@ -740,7 +740,7 @@ mod explicit_generic_scalar { let schema = schema(QueryRoot::Droid); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"character": {"droidId": "droid-99", "primaryFunction": "run"}}), vec![], @@ -816,7 +816,7 @@ mod bounded_generic_scalar { let schema = schema(QueryRoot::Human); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"character": {"humanId": "human-32", "homePlanet": "earth"}}), vec![], @@ -829,7 +829,7 @@ mod bounded_generic_scalar { let schema = schema(QueryRoot::Droid); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"character": {"droidId": "droid-99", "primaryFunction": "run"}}), vec![], @@ -903,7 +903,7 @@ mod explicit_custom_context { let schema = schema(QueryRoot); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &CustomContext::Human).await, + execute(DOC, None, &schema, &graphql_vars! {}, &CustomContext::Human).await, Ok(( graphql_value!({"character": {"humanId": "human-32", "homePlanet": "earth"}}), vec![], @@ -916,7 +916,7 @@ mod explicit_custom_context { let schema = schema(QueryRoot); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &CustomContext::Droid).await, + execute(DOC, None, &schema, &graphql_vars! {}, &CustomContext::Droid).await, Ok(( graphql_value!({"character": {"droidId": "droid-99", "primaryFunction": "run"}}), vec![], @@ -990,7 +990,7 @@ mod inferred_custom_context { let schema = schema(QueryRoot); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &CustomContext::Human).await, + execute(DOC, None, &schema, &graphql_vars! {}, &CustomContext::Human).await, Ok(( graphql_value!({"character": {"humanId": "human-32", "homePlanet": "earth"}}), vec![], @@ -1003,7 +1003,7 @@ mod inferred_custom_context { let schema = schema(QueryRoot); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &CustomContext::Droid).await, + execute(DOC, None, &schema, &graphql_vars! {}, &CustomContext::Droid).await, Ok(( graphql_value!({"character": {"droidId": "droid-99", "primaryFunction": "run"}}), vec![], @@ -1062,7 +1062,7 @@ mod ignored_method { let schema = schema(QueryRoot); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"character": {"humanId": "human-32", "homePlanet": "earth"}}), vec![], @@ -1083,7 +1083,7 @@ mod ignored_method { let schema = schema(QueryRoot); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"__type": {"possibleTypes": [{"name": "Human"}]}}), vec![], @@ -1165,7 +1165,7 @@ mod external_resolver { let db = Database { droid: None }; assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &db).await, + execute(DOC, None, &schema, &graphql_vars! {}, &db).await, Ok(( graphql_value!({"character": {"humanId": "human-32", "homePlanet": "earth"}}), vec![], @@ -1184,7 +1184,7 @@ mod external_resolver { }; assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &db).await, + execute(DOC, None, &schema, &graphql_vars! {}, &db).await, Ok(( graphql_value!({"character": {"droidId": "droid-99", "primaryFunction": "run"}}), vec![], @@ -1288,7 +1288,7 @@ mod full_featured { let schema = schema(QueryRoot); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &CustomContext::Human).await, + execute(DOC, None, &schema, &graphql_vars! {}, &CustomContext::Human).await, Ok(( graphql_value!({"character": {"humanId": "human-32", "homePlanet": "earth"}}), vec![], @@ -1301,7 +1301,7 @@ mod full_featured { let schema = schema(QueryRoot); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &CustomContext::Droid).await, + execute(DOC, None, &schema, &graphql_vars! {}, &CustomContext::Droid).await, Ok(( graphql_value!({"character": {"droidId": "droid-99", "primaryFunction": "run"}}), vec![], @@ -1314,7 +1314,7 @@ mod full_featured { let schema = schema(QueryRoot); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &CustomContext::Ewok).await, + execute(DOC, None, &schema, &graphql_vars! {}, &CustomContext::Ewok).await, Ok(( graphql_value!({"character": {"ewokId": "ewok-1", "funny": true}}), vec![], @@ -1333,7 +1333,7 @@ mod full_featured { let schema = schema(QueryRoot); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &CustomContext::Ewok).await, + execute(DOC, None, &schema, &graphql_vars! {}, &CustomContext::Ewok).await, Ok((graphql_value!({"__type": {"name": "MyChar"}}), vec![])), ); } @@ -1349,7 +1349,7 @@ mod full_featured { let schema = schema(QueryRoot); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &CustomContext::Ewok).await, + execute(DOC, None, &schema, &graphql_vars! {}, &CustomContext::Ewok).await, Ok(( graphql_value!({"__type": {"description": "My character."}}), vec![], diff --git a/integration_tests/juniper_tests/src/codegen/union_derive.rs b/integration_tests/juniper_tests/src/codegen/union_derive.rs index dd654d9d2..be6577e2b 100644 --- a/integration_tests/juniper_tests/src/codegen/union_derive.rs +++ b/integration_tests/juniper_tests/src/codegen/union_derive.rs @@ -3,8 +3,8 @@ use std::marker::PhantomData; use juniper::{ - execute, graphql_object, graphql_value, DefaultScalarValue, EmptyMutation, EmptySubscription, - GraphQLObject, GraphQLType, GraphQLUnion, RootNode, ScalarValue, Variables, + execute, graphql_object, graphql_value, graphql_vars, DefaultScalarValue, EmptyMutation, + EmptySubscription, GraphQLObject, GraphQLType, GraphQLUnion, RootNode, ScalarValue, }; #[derive(GraphQLObject)] @@ -126,7 +126,7 @@ mod trivial_enum { let schema = schema(QueryRoot::Human); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"character": {"humanId": "human-32", "homePlanet": "earth"}}), vec![], @@ -139,7 +139,7 @@ mod trivial_enum { let schema = schema(QueryRoot::Droid); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"character": {"droidId": "droid-99", "primaryFunction": "run"}}), vec![], @@ -158,7 +158,7 @@ mod trivial_enum { let schema = schema(QueryRoot::Human); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok((graphql_value!({"__type": {"kind": "UNION"}}), vec![])), ); } @@ -174,7 +174,7 @@ mod trivial_enum { let schema = schema(QueryRoot::Human); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok((graphql_value!({"__type": {"name": "Character"}}), vec![])), ); } @@ -190,7 +190,7 @@ mod trivial_enum { let schema = schema(QueryRoot::Human); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok((graphql_value!({"__type": {"description": null}}), vec![])), ); } @@ -246,7 +246,7 @@ mod generic_enum { let schema = schema(QueryRoot::Human); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"character": {"humanId": "human-32", "homePlanet": "earth"}}), vec![], @@ -259,7 +259,7 @@ mod generic_enum { let schema = schema(QueryRoot::Droid); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"character": {"droidId": "droid-99", "primaryFunction": "run"}}), vec![], @@ -278,7 +278,7 @@ mod generic_enum { let schema = schema(QueryRoot::Human); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok((graphql_value!({"__type": {"name": "Character"}}), vec![])), ); } @@ -340,7 +340,7 @@ mod generic_lifetime_enum { let schema = schema(QueryRoot::Human); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"character": {"humanId": "human-32"}}), vec![], @@ -353,7 +353,7 @@ mod generic_lifetime_enum { let schema = schema(QueryRoot::Droid); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"character": {"droidId": "droid-99"}}), vec![], @@ -372,7 +372,7 @@ mod generic_lifetime_enum { let schema = schema(QueryRoot::Human); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok((graphql_value!({"__type": {"name": "Character"}}), vec![])), ); } @@ -414,7 +414,7 @@ mod description_from_doc_comments { let schema = schema(QueryRoot); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"character": {"humanId": "human-32", "homePlanet": "earth"}}), vec![], @@ -433,7 +433,7 @@ mod description_from_doc_comments { let schema = schema(QueryRoot); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"__type": {"description": "Rust docs."}}), vec![], @@ -478,7 +478,7 @@ mod explicit_name_and_description { let schema = schema(QueryRoot); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"character": {"humanId": "human-32", "homePlanet": "earth"}}), vec![], @@ -497,7 +497,7 @@ mod explicit_name_and_description { let schema = schema(QueryRoot); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok((graphql_value!({"__type": {"name": "MyChar"}}), vec![])), ); } @@ -513,7 +513,7 @@ mod explicit_name_and_description { let schema = schema(QueryRoot); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"__type": {"description": "My character."}}), vec![], @@ -571,7 +571,7 @@ mod explicit_scalar { let schema = schema(QueryRoot::Human); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"character": {"humanId": "human-32", "homePlanet": "earth"}}), vec![], @@ -584,7 +584,7 @@ mod explicit_scalar { let schema = schema(QueryRoot::Droid); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"character": {"droidId": "droid-99", "primaryFunction": "run"}}), vec![], @@ -644,7 +644,7 @@ mod custom_scalar { let schema = schema_with_scalar::(QueryRoot::Human); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"character": {"humanId": "human-32", "homePlanet": "earth"}}), vec![], @@ -657,7 +657,7 @@ mod custom_scalar { let schema = schema_with_scalar::(QueryRoot::Droid); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"character": {"droidId": "droid-99", "primaryFunction": "run"}}), vec![], @@ -717,7 +717,7 @@ mod explicit_generic_scalar { let schema = schema(QueryRoot::Human); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"character": {"humanId": "human-32", "homePlanet": "earth"}}), vec![], @@ -730,7 +730,7 @@ mod explicit_generic_scalar { let schema = schema(QueryRoot::Droid); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"character": {"droidId": "droid-99", "primaryFunction": "run"}}), vec![], @@ -788,7 +788,7 @@ mod bounded_generic_scalar { let schema = schema(QueryRoot::Human); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"character": {"humanId": "human-32", "homePlanet": "earth"}}), vec![], @@ -801,7 +801,7 @@ mod bounded_generic_scalar { let schema = schema(QueryRoot::Droid); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"character": {"droidId": "droid-99", "primaryFunction": "run"}}), vec![], @@ -857,7 +857,7 @@ mod custom_context { let schema = schema(QueryRoot); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &CustomContext::Human).await, + execute(DOC, None, &schema, &graphql_vars! {}, &CustomContext::Human).await, Ok(( graphql_value!({"character": {"humanId": "human-32", "homePlanet": "earth"}}), vec![], @@ -870,7 +870,7 @@ mod custom_context { let schema = schema(QueryRoot); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &CustomContext::Droid).await, + execute(DOC, None, &schema, &graphql_vars! {}, &CustomContext::Droid).await, Ok(( graphql_value!({"character": {"droidId": "droid-99", "primaryFunction": "run"}}), vec![], @@ -926,7 +926,7 @@ mod different_context { let schema = schema(QueryRoot); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &CustomContext::Human).await, + execute(DOC, None, &schema, &graphql_vars! {}, &CustomContext::Human).await, Ok(( graphql_value!({"character": {"humanId": "human-32", "homePlanet": "earth"}}), vec![], @@ -939,7 +939,7 @@ mod different_context { let schema = schema(QueryRoot); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &CustomContext::Droid).await, + execute(DOC, None, &schema, &graphql_vars! {}, &CustomContext::Droid).await, Ok(( graphql_value!({"character": {"droidId": "droid-99", "primaryFunction": "run"}}), vec![], @@ -986,7 +986,7 @@ mod ignored_enum_variants { let schema = schema(QueryRoot); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"character": {"humanId": "human-32", "homePlanet": "earth"}}), vec![], @@ -1007,7 +1007,7 @@ mod ignored_enum_variants { let schema = schema(QueryRoot); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"__type": {"possibleTypes": [{"name": "Human"}]}}), vec![], @@ -1080,7 +1080,7 @@ mod external_resolver_enum { let db = Database { droid: None }; assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &db).await, + execute(DOC, None, &schema, &graphql_vars! {}, &db).await, Ok(( graphql_value!({"character": {"humanId": "human-32", "homePlanet": "earth"}}), vec![], @@ -1099,7 +1099,7 @@ mod external_resolver_enum { }; assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &db).await, + execute(DOC, None, &schema, &graphql_vars! {}, &db).await, Ok(( graphql_value!({"character": {"droidId": "droid-99", "primaryFunction": "run"}}), vec![], @@ -1174,7 +1174,7 @@ mod external_resolver_enum_variant { let db = Database { droid: None }; assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &db).await, + execute(DOC, None, &schema, &graphql_vars! {}, &db).await, Ok(( graphql_value!({"character": {"humanId": "human-32", "homePlanet": "earth"}}), vec![], @@ -1193,7 +1193,7 @@ mod external_resolver_enum_variant { }; assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &db).await, + execute(DOC, None, &schema, &graphql_vars! {}, &db).await, Ok(( graphql_value!({"character": {"droidId": "droid-99", "primaryFunction": "run"}}), vec![], @@ -1287,7 +1287,7 @@ mod full_featured_enum { let schema = schema(QueryRoot); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &CustomContext::Human).await, + execute(DOC, None, &schema, &graphql_vars! {}, &CustomContext::Human).await, Ok(( graphql_value!({"character": {"humanId": "human-32", "homePlanet": "earth"}}), vec![], @@ -1300,7 +1300,7 @@ mod full_featured_enum { let schema = schema(QueryRoot); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &CustomContext::Droid).await, + execute(DOC, None, &schema, &graphql_vars! {}, &CustomContext::Droid).await, Ok(( graphql_value!({"character": {"droidId": "droid-99", "primaryFunction": "run"}}), vec![], @@ -1313,7 +1313,7 @@ mod full_featured_enum { let schema = schema(QueryRoot); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &CustomContext::Ewok).await, + execute(DOC, None, &schema, &graphql_vars! {}, &CustomContext::Ewok).await, Ok(( graphql_value!({"character": {"ewokId": "ewok-1", "funny": true}}), vec![], @@ -1332,7 +1332,7 @@ mod full_featured_enum { let schema = schema(QueryRoot); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &CustomContext::Ewok).await, + execute(DOC, None, &schema, &graphql_vars! {}, &CustomContext::Ewok).await, Ok((graphql_value!({"__type": {"name": "MyChar"}}), vec![])), ); } @@ -1348,7 +1348,7 @@ mod full_featured_enum { let schema = schema(QueryRoot); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &CustomContext::Ewok).await, + execute(DOC, None, &schema, &graphql_vars! {}, &CustomContext::Ewok).await, Ok(( graphql_value!({"__type": {"description": "My character."}}), vec![], @@ -1439,7 +1439,7 @@ mod trivial_struct { }; assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &db).await, + execute(DOC, None, &schema, &graphql_vars! {}, &db).await, Ok(( graphql_value!({"character": {"humanId": "human-32", "homePlanet": "earth"}}), vec![], @@ -1459,7 +1459,7 @@ mod trivial_struct { }; assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &db).await, + execute(DOC, None, &schema, &graphql_vars! {}, &db).await, Ok(( graphql_value!({"character": {"droidId": "droid-99", "primaryFunction": "run"}}), vec![], @@ -1485,7 +1485,7 @@ mod trivial_struct { }; assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &db).await, + execute(DOC, None, &schema, &graphql_vars! {}, &db).await, Ok((graphql_value!({"__type": {"kind": "UNION"}}), vec![])), ); } @@ -1508,7 +1508,7 @@ mod trivial_struct { }; assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &db).await, + execute(DOC, None, &schema, &graphql_vars! {}, &db).await, Ok((graphql_value!({"__type": {"name": "Character"}}), vec![])), ); } @@ -1531,7 +1531,7 @@ mod trivial_struct { }; assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &db).await, + execute(DOC, None, &schema, &graphql_vars! {}, &db).await, Ok((graphql_value!({"__type": {"description": null}}), vec![])), ); } @@ -1596,7 +1596,7 @@ mod generic_struct { }; assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &db).await, + execute(DOC, None, &schema, &graphql_vars! {}, &db).await, Ok(( graphql_value!({"character": {"humanId": "human-32", "homePlanet": "earth"}}), vec![], @@ -1616,7 +1616,7 @@ mod generic_struct { let db = Database { human: None }; assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &db).await, + execute(DOC, None, &schema, &graphql_vars! {}, &db).await, Ok((graphql_value!({"__type": {"name": "Character"}}), vec![])), ); } @@ -1709,7 +1709,7 @@ mod full_featured_struct { }; assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &db).await, + execute(DOC, None, &schema, &graphql_vars! {}, &db).await, Ok(( graphql_value!({"character": {"humanId": "human-32", "homePlanet": "earth"}}), vec![], @@ -1729,7 +1729,7 @@ mod full_featured_struct { }; assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &db).await, + execute(DOC, None, &schema, &graphql_vars! {}, &db).await, Ok(( graphql_value!({"character": {"droidId": "droid-99", "primaryFunction": "run"}}), vec![], @@ -1752,7 +1752,7 @@ mod full_featured_struct { }; assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &db).await, + execute(DOC, None, &schema, &graphql_vars! {}, &db).await, Ok((graphql_value!({"__type": {"name": "MyChar"}}), vec![])), ); } @@ -1772,7 +1772,7 @@ mod full_featured_struct { }; assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &db).await, + execute(DOC, None, &schema, &graphql_vars! {}, &db).await, Ok(( graphql_value!({"__type": {"description": "My character."}}), vec![], @@ -1833,7 +1833,7 @@ mod issue_845 { let schema = schema(QueryRoot::Human); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"character": {"humanId": "human-32", "homePlanet": "earth"}}), vec![], @@ -1846,7 +1846,7 @@ mod issue_845 { let schema = schema(QueryRoot::Droid); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok(( graphql_value!({"character": {"droidId": "droid-99", "primaryFunction": "run"}}), vec![], @@ -1865,7 +1865,7 @@ mod issue_845 { let schema = schema(QueryRoot::Human); assert_eq!( - execute(DOC, None, &schema, &Variables::new(), &()).await, + execute(DOC, None, &schema, &graphql_vars! {}, &()).await, Ok((graphql_value!({"__type": {"kind": "UNION"}}), vec![])), ); } diff --git a/integration_tests/juniper_tests/src/custom_scalar.rs b/integration_tests/juniper_tests/src/custom_scalar.rs index 4fda813e8..13da9ec91 100644 --- a/integration_tests/juniper_tests/src/custom_scalar.rs +++ b/integration_tests/juniper_tests/src/custom_scalar.rs @@ -232,13 +232,14 @@ async fn querying_long_arg() { #[tokio::test] async fn querying_long_variable() { + let num = i64::from(i32::MAX) + 42; run_variable_query( "query q($test: Long!){ longWithArg(longArg: $test) }", - graphql_vars! {"test": MyScalarValue::Long(i64::from(i32::MAX) + 42)}, + graphql_vars! {"test": InputValue::<_>::scalar(num)}, |result| { assert_eq!( result.get_field_value("longWithArg"), - Some(&Value::scalar(i64::from(i32::MAX) + 42)), + Some(&Value::scalar(num)), ); }, ) @@ -252,7 +253,7 @@ fn deserialize_variable() { assert_eq!( serde_json::from_str::>(&json).unwrap(), graphql_input_value!({ - "field": MyScalarValue::Long(i64::from(i32::MAX) + 42), + "field": InputValue::<_>::scalar(i64::from(i32::MAX) + 42), }), ); } diff --git a/integration_tests/juniper_tests/src/explicit_null.rs b/integration_tests/juniper_tests/src/explicit_null.rs index 89e6dc2c7..99fb58880 100644 --- a/integration_tests/juniper_tests/src/explicit_null.rs +++ b/integration_tests/juniper_tests/src/explicit_null.rs @@ -48,27 +48,25 @@ async fn explicit_null() { EmptySubscription::::new(), ); - let vars: Variables = graphql_vars!({ - "emptyObj": [], + let vars: Variables = graphql_vars! { + "emptyObj": {}, "literalNullObj": {"field": null}, - }); + }; - let (data, errors) = juniper::execute(query, None, &schema, &vars, &Context) - .await - .unwrap(); - - assert_eq!(errors.len(), 0); assert_eq!( - data, - graphql_value!({ - "literalOneIsExplicitNull": false, - "literalNullIsExplicitNull": true, - "noArgIsExplicitNull": false, - "literalOneFieldIsExplicitNull": false, - "literalNullFieldIsExplicitNull": true, - "noFieldIsExplicitNull": false, - "emptyVariableObjectFieldIsExplicitNull": false, - "literalNullVariableObjectFieldIsExplicitNull": true, - }), + juniper::execute(query, None, &schema, &vars, &Context).await, + Ok(( + graphql_value!({ + "literalOneIsExplicitNull": false, + "literalNullIsExplicitNull": true, + "noArgIsExplicitNull": false, + "literalOneFieldIsExplicitNull": false, + "literalNullFieldIsExplicitNull": true, + "noFieldIsExplicitNull": false, + "emptyVariableObjectFieldIsExplicitNull": false, + "literalNullVariableObjectFieldIsExplicitNull": true, + }), + vec![], + )), ); } diff --git a/juniper/src/ast.rs b/juniper/src/ast.rs index fca336480..b0f856579 100644 --- a/juniper/src/ast.rs +++ b/juniper/src/ast.rs @@ -490,6 +490,12 @@ impl<'a, S: From> From<&'a str> for InputValue { } } +impl<'a, S: From> From> for InputValue { + fn from(s: Cow<'a, str>) -> Self { + Self::scalar(s.into_owned()) + } +} + impl> From for InputValue { fn from(s: String) -> Self { Self::scalar(s) diff --git a/juniper/src/macros/graphql_input_value.rs b/juniper/src/macros/graphql_input_value.rs index a977708ef..69641e376 100644 --- a/juniper/src/macros/graphql_input_value.rs +++ b/juniper/src/macros/graphql_input_value.rs @@ -348,15 +348,15 @@ macro_rules! graphql_input_value { // Defaults // ////////////// - ([ $($arr:tt)* ]) => { + ([ $($arr:tt)* ]$(,)?) => { $crate::graphql_input_value!(@@array [] $($arr)*) }; - ({}) => { + ({}$(,)?) => { $crate::InputValue::parsed_object(vec![]) }; - ({ $($map:tt)+ }) => { + ({ $($map:tt)+ }$(,)?) => { $crate::InputValue::parsed_object({ let mut object = vec![]; $crate::graphql_input_value!(@@object object () ($($map)*) ($($map)*)); @@ -364,21 +364,21 @@ macro_rules! graphql_input_value { }) }; - (null) => ($crate::InputValue::null()); + (null$(,)?) => ($crate::InputValue::null()); - (None) => ($crate::InputValue::null()); + (None$(,)?) => ($crate::InputValue::null()); - (true) => ($crate::InputValue::from(true)); + (true$(,)?) => ($crate::InputValue::from(true)); - (false) => ($crate::InputValue::from(false)); + (false$(,)?) => ($crate::InputValue::from(false)); - (@$var:ident) => ($crate::InputValue::variable(stringify!($var))); + (@$var:ident$(,)?) => ($crate::InputValue::variable(stringify!($var))); - ($enum:ident) => ($crate::InputValue::enum_value(stringify!($enum))); + ($enum:ident$(,)?) => ($crate::InputValue::enum_value(stringify!($enum))); - (($e:expr)) => ($crate::InputValue::from($e)); + (($e:expr)$(,)?) => ($crate::InputValue::from($e)); - ($e:expr) => ($crate::InputValue::from($e)); + ($e:expr$(,)?) => ($crate::InputValue::from($e)); } #[cfg(test)] diff --git a/juniper/src/macros/graphql_value.rs b/juniper/src/macros/graphql_value.rs index af61b8922..cc4e34d38 100644 --- a/juniper/src/macros/graphql_value.rs +++ b/juniper/src/macros/graphql_value.rs @@ -248,15 +248,15 @@ macro_rules! graphql_value { // Defaults // ////////////// - ([ $($arr:tt)* ]) => { + ([ $($arr:tt)* ]$(,)?) => { $crate::graphql_value!(@array [] $($arr)*) }; - ({}) => { + ({}$(,)?) => { $crate::Value::object($crate::Object::with_capacity(0)) }; - ({ $($map:tt)+ }) => { + ({ $($map:tt)+ }$(,)?) => { $crate::Value::object({ let mut object = $crate::Object::with_capacity(0); $crate::graphql_value!(@object object () ($($map)*) ($($map)*)); @@ -264,11 +264,11 @@ macro_rules! graphql_value { }) }; - (null) => ($crate::Value::null()); + (null$(,)?) => ($crate::Value::null()); - (None) => ($crate::Value::null()); + (None$(,)?) => ($crate::Value::null()); - ($e:expr) => ($crate::Value::from($e)); + ($e:expr$(,)?) => ($crate::Value::from($e)); } #[cfg(test)] diff --git a/juniper/src/value/mod.rs b/juniper/src/value/mod.rs index a1bf8b748..64e299ee9 100644 --- a/juniper/src/value/mod.rs +++ b/juniper/src/value/mod.rs @@ -1,11 +1,7 @@ mod object; mod scalar; -use std::{ - any::TypeId, - fmt::{self, Display, Formatter}, - mem, -}; +use std::{any::TypeId, borrow::Cow, fmt, mem}; use crate::{ ast::{InputValue, ToInputValue}, @@ -194,8 +190,8 @@ impl ToInputValue for Value { } } -impl Display for Value { - fn fmt(&self, f: &mut Formatter) -> fmt::Result { +impl fmt::Display for Value { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { Self::Null => write!(f, "null"), Self::Scalar(s) => { @@ -252,6 +248,12 @@ impl<'a, S: From> From<&'a str> for Value { } } +impl<'a, S: From> From> for Value { + fn from(s: Cow<'a, str>) -> Self { + Self::scalar(s.into_owned()) + } +} + impl> From for Value { fn from(s: String) -> Self { Self::scalar(s) diff --git a/juniper/src/value/scalar.rs b/juniper/src/value/scalar.rs index 499db2f8e..d50172206 100644 --- a/juniper/src/value/scalar.rs +++ b/juniper/src/value/scalar.rs @@ -1,4 +1,4 @@ -use std::fmt; +use std::{borrow::Cow, fmt}; use serde::{de::DeserializeOwned, Serialize}; @@ -352,3 +352,9 @@ impl<'a> From<&'a str> for DefaultScalarValue { Self::String(s.into()) } } + +impl<'a> From> for DefaultScalarValue { + fn from(s: Cow<'a, str>) -> Self { + Self::String(s.into()) + } +} From 1d81186a3a301b79ecb73e914faf3533018bd9ea Mon Sep 17 00:00:00 2001 From: tyranron Date: Fri, 26 Nov 2021 16:51:26 +0100 Subject: [PATCH 21/22] Final code replaces --- integration_tests/juniper_tests/src/array.rs | 26 +++++++++---------- .../codegen/derive_object_with_raw_idents.rs | 6 ++--- .../juniper_tests/src/custom_scalar.rs | 2 +- .../juniper_tests/src/issue_371.rs | 12 ++++----- .../juniper_tests/src/issue_372.rs | 18 ++++++------- .../juniper_tests/src/issue_398.rs | 4 +-- .../juniper_tests/src/issue_407.rs | 11 ++++---- .../juniper_tests/src/issue_500.rs | 6 +++-- .../juniper_tests/src/issue_798.rs | 12 ++++----- .../juniper_tests/src/issue_914.rs | 6 ++--- .../juniper_tests/src/issue_922.rs | 8 +++--- .../juniper_tests/src/issue_925.rs | 6 ++--- .../juniper_tests/src/issue_945.rs | 8 +++--- .../juniper_tests/src/pre_parse.rs | 10 +++---- juniper/benches/bench.rs | 8 +++--- .../src/executor_tests/introspection/enums.rs | 5 ++-- .../introspection/input_object.rs | 5 ++-- .../src/executor_tests/introspection/mod.rs | 13 +++++----- juniper/src/integrations/chrono_tz.rs | 4 +-- juniper/src/integrations/url.rs | 4 +-- juniper/src/integrations/uuid.rs | 7 ++--- juniper/src/parser/tests/document.rs | 3 ++- juniper/src/tests/introspection_tests.rs | 16 ++++++------ juniper/src/tests/type_info_tests.rs | 6 ++--- juniper_graphql_ws/src/client_message.rs | 2 +- juniper_graphql_ws/src/lib.rs | 20 +++++++------- 26 files changed, 115 insertions(+), 113 deletions(-) diff --git a/integration_tests/juniper_tests/src/array.rs b/integration_tests/juniper_tests/src/array.rs index aa1606511..1686e5197 100644 --- a/integration_tests/juniper_tests/src/array.rs +++ b/integration_tests/juniper_tests/src/array.rs @@ -1,6 +1,6 @@ use juniper::{ - graphql_object, graphql_value, EmptyMutation, EmptySubscription, GraphQLInputObject, RootNode, - Variables, + graphql_object, graphql_value, graphql_vars, EmptyMutation, EmptySubscription, + GraphQLInputObject, RootNode, }; mod as_output_field { @@ -24,7 +24,7 @@ mod as_output_field { "#; let schema = RootNode::new(Query, EmptyMutation::new(), EmptySubscription::new()); - let (res, errors) = juniper::execute(query, None, &schema, &Variables::new(), &()) + let (res, errors) = juniper::execute(query, None, &schema, &graphql_vars! {}, &()) .await .unwrap(); @@ -68,7 +68,7 @@ mod as_input_field { "#; let schema = RootNode::new(Query, EmptyMutation::new(), EmptySubscription::new()); - let (res, errors) = juniper::execute(query, None, &schema, &Variables::new(), &()) + let (res, errors) = juniper::execute(query, None, &schema, &graphql_vars! {}, &()) .await .unwrap(); @@ -85,7 +85,7 @@ mod as_input_field { "#; let schema = RootNode::new(Query, EmptyMutation::new(), EmptySubscription::new()); - let res = juniper::execute(query, None, &schema, &Variables::new(), &()).await; + let res = juniper::execute(query, None, &schema, &graphql_vars! {}, &()).await; assert!(res.is_err()); assert!(res @@ -103,7 +103,7 @@ mod as_input_field { "#; let schema = RootNode::new(Query, EmptyMutation::new(), EmptySubscription::new()); - let res = juniper::execute(query, None, &schema, &Variables::new(), &()).await; + let res = juniper::execute(query, None, &schema, &graphql_vars! {}, &()).await; assert!(res.is_err()); assert!(res @@ -121,7 +121,7 @@ mod as_input_field { "#; let schema = RootNode::new(Query, EmptyMutation::new(), EmptySubscription::new()); - let (res, errors) = juniper::execute(query, None, &schema, &Variables::new(), &()) + let (res, errors) = juniper::execute(query, None, &schema, &graphql_vars! {}, &()) .await .unwrap(); @@ -159,7 +159,7 @@ mod as_input_argument { "#; let schema = RootNode::new(Query, EmptyMutation::new(), EmptySubscription::new()); - let (res, errors) = juniper::execute(query, None, &schema, &Variables::new(), &()) + let (res, errors) = juniper::execute(query, None, &schema, &graphql_vars! {}, &()) .await .unwrap(); @@ -176,7 +176,7 @@ mod as_input_argument { "#; let schema = RootNode::new(Query, EmptyMutation::new(), EmptySubscription::new()); - let res = juniper::execute(query, None, &schema, &Variables::new(), &()).await; + let res = juniper::execute(query, None, &schema, &graphql_vars! {}, &()).await; assert!(res.is_err()); assert!(res @@ -194,7 +194,7 @@ mod as_input_argument { "#; let schema = RootNode::new(Query, EmptyMutation::new(), EmptySubscription::new()); - let res = juniper::execute(query, None, &schema, &Variables::new(), &()).await; + let res = juniper::execute(query, None, &schema, &graphql_vars! {}, &()).await; assert!(res.is_err()); assert!(res @@ -212,7 +212,7 @@ mod as_input_argument { "#; let schema = RootNode::new(Query, EmptyMutation::new(), EmptySubscription::new()); - let (res, errors) = juniper::execute(query, None, &schema, &Variables::new(), &()) + let (res, errors) = juniper::execute(query, None, &schema, &graphql_vars! {}, &()) .await .unwrap(); @@ -229,7 +229,7 @@ mod as_input_argument { "#; let schema = RootNode::new(Query, EmptyMutation::new(), EmptySubscription::new()); - let (res, errors) = juniper::execute(query, None, &schema, &Variables::new(), &()) + let (res, errors) = juniper::execute(query, None, &schema, &graphql_vars! {}, &()) .await .unwrap(); @@ -246,7 +246,7 @@ mod as_input_argument { "#; let schema = RootNode::new(Query, EmptyMutation::new(), EmptySubscription::new()); - let (res, errors) = juniper::execute(query, None, &schema, &Variables::new(), &()) + let (res, errors) = juniper::execute(query, None, &schema, &graphql_vars! {}, &()) .await .unwrap(); diff --git a/integration_tests/juniper_tests/src/codegen/derive_object_with_raw_idents.rs b/integration_tests/juniper_tests/src/codegen/derive_object_with_raw_idents.rs index 241a2ab83..c1c5dea7f 100644 --- a/integration_tests/juniper_tests/src/codegen/derive_object_with_raw_idents.rs +++ b/integration_tests/juniper_tests/src/codegen/derive_object_with_raw_idents.rs @@ -1,6 +1,6 @@ use juniper::{ - execute, graphql_object, graphql_value, EmptyMutation, EmptySubscription, GraphQLInputObject, - RootNode, Value, Variables, + execute, graphql_object, graphql_value, graphql_vars, EmptyMutation, EmptySubscription, + GraphQLInputObject, RootNode, Value, }; pub struct Query; @@ -93,7 +93,7 @@ async fn run_type_info_query(doc: &str) -> Value { EmptySubscription::<()>::new(), ); - let (result, errs) = execute(doc, None, &schema, &Variables::new(), &()) + let (result, errs) = execute(doc, None, &schema, &graphql_vars! {}, &()) .await .expect("Execution failed"); diff --git a/integration_tests/juniper_tests/src/custom_scalar.rs b/integration_tests/juniper_tests/src/custom_scalar.rs index 13da9ec91..64fe39980 100644 --- a/integration_tests/juniper_tests/src/custom_scalar.rs +++ b/integration_tests/juniper_tests/src/custom_scalar.rs @@ -202,7 +202,7 @@ async fn run_query(query: &str, f: F) where F: Fn(&Object) -> (), { - run_variable_query(query, Variables::new(), f).await; + run_variable_query(query, graphql_vars! {}, f).await; } #[tokio::test] diff --git a/integration_tests/juniper_tests/src/issue_371.rs b/integration_tests/juniper_tests/src/issue_371.rs index 571a1587e..26c1903b2 100644 --- a/integration_tests/juniper_tests/src/issue_371.rs +++ b/integration_tests/juniper_tests/src/issue_371.rs @@ -5,8 +5,8 @@ //! Original author of this test is [@davidpdrsn](https://github.com/davidpdrsn). use juniper::{ - graphql_object, EmptyMutation, EmptySubscription, Executor, LookAheadMethods as _, RootNode, - ScalarValue, Variables, + graphql_object, graphql_vars, EmptyMutation, EmptySubscription, Executor, + LookAheadMethods as _, RootNode, ScalarValue, }; pub struct Context; @@ -57,7 +57,7 @@ async fn users() { let query = "{ users { id } }"; let schema = Schema::new(Query, EmptyMutation::new(), EmptySubscription::new()); - let (_, errors) = juniper::execute(query, None, &schema, &Variables::new(), &Context) + let (_, errors) = juniper::execute(query, None, &schema, &graphql_vars! {}, &Context) .await .unwrap(); @@ -69,7 +69,7 @@ async fn countries() { let query = "{ countries { id } }"; let schema = Schema::new(Query, EmptyMutation::new(), EmptySubscription::new()); - let (_, errors) = juniper::execute(query, None, &schema, &Variables::new(), &Context) + let (_, errors) = juniper::execute(query, None, &schema, &graphql_vars! {}, &Context) .await .unwrap(); @@ -84,7 +84,7 @@ async fn both() { }"; let schema = Schema::new(Query, EmptyMutation::new(), EmptySubscription::new()); - let (_, errors) = juniper::execute(query, None, &schema, &Variables::new(), &Context) + let (_, errors) = juniper::execute(query, None, &schema, &graphql_vars! {}, &Context) .await .unwrap(); @@ -99,7 +99,7 @@ async fn both_in_different_order() { }"; let schema = Schema::new(Query, EmptyMutation::new(), EmptySubscription::new()); - let (_, errors) = juniper::execute(query, None, &schema, &Variables::new(), &Context) + let (_, errors) = juniper::execute(query, None, &schema, &graphql_vars! {}, &Context) .await .unwrap(); diff --git a/integration_tests/juniper_tests/src/issue_372.rs b/integration_tests/juniper_tests/src/issue_372.rs index d982282f0..8d765176a 100644 --- a/integration_tests/juniper_tests/src/issue_372.rs +++ b/integration_tests/juniper_tests/src/issue_372.rs @@ -3,8 +3,8 @@ use futures::{stream, FutureExt as _}; use juniper::{ - execute, graphql_object, graphql_subscription, graphql_value, resolve_into_stream, RootNode, - Variables, + execute, graphql_object, graphql_subscription, graphql_value, graphql_vars, + resolve_into_stream, RootNode, }; use crate::util::extract_next; @@ -43,7 +43,7 @@ async fn implicit_query_typename() { let schema = RootNode::new(Query, Mutation, Subscription); assert_eq!( - execute(query, None, &schema, &Variables::new(), &()).await, + execute(query, None, &schema, &graphql_vars! {}, &()).await, Ok((graphql_value!({"__typename": "Query"}), vec![])), ); } @@ -55,7 +55,7 @@ async fn query_typename() { let schema = RootNode::new(Query, Mutation, Subscription); assert_eq!( - execute(query, None, &schema, &Variables::new(), &()).await, + execute(query, None, &schema, &graphql_vars! {}, &()).await, Ok((graphql_value!({"__typename": "Query"}), vec![])), ); } @@ -67,7 +67,7 @@ async fn explicit_query_typename() { let schema = RootNode::new(Query, Mutation, Subscription); assert_eq!( - execute(query, None, &schema, &Variables::new(), &()).await, + execute(query, None, &schema, &graphql_vars! {}, &()).await, Ok((graphql_value!({"__typename": "Query"}), vec![])), ); } @@ -79,7 +79,7 @@ async fn mutation_typename() { let schema = RootNode::new(Query, Mutation, Subscription); assert_eq!( - execute(query, None, &schema, &Variables::new(), &()).await, + execute(query, None, &schema, &graphql_vars! {}, &()).await, Ok((graphql_value!({"__typename": "Mutation"}), vec![])), ); } @@ -91,7 +91,7 @@ async fn explicit_mutation_typename() { let schema = RootNode::new(Query, Mutation, Subscription); assert_eq!( - execute(query, None, &schema, &Variables::new(), &()).await, + execute(query, None, &schema, &graphql_vars! {}, &()).await, Ok((graphql_value!({"__typename": "Mutation"}), vec![])), ); } @@ -103,7 +103,7 @@ async fn subscription_typename() { let schema = RootNode::new(Query, Mutation, Subscription); assert_eq!( - resolve_into_stream(query, None, &schema, &Variables::new(), &()) + resolve_into_stream(query, None, &schema, &graphql_vars! {}, &()) .then(|s| extract_next(s)) .await, Ok((graphql_value!({"__typename": "Subscription"}), vec![])), @@ -117,7 +117,7 @@ async fn explicit_subscription_typename() { let schema = RootNode::new(Query, Mutation, Subscription); assert_eq!( - resolve_into_stream(query, None, &schema, &Variables::new(), &()) + resolve_into_stream(query, None, &schema, &graphql_vars! {}, &()) .then(|s| extract_next(s)) .await, Ok((graphql_value!({"__typename": "Subscription"}), vec![])), diff --git a/integration_tests/juniper_tests/src/issue_398.rs b/integration_tests/juniper_tests/src/issue_398.rs index 0d5557411..31df9aeea 100644 --- a/integration_tests/juniper_tests/src/issue_398.rs +++ b/integration_tests/juniper_tests/src/issue_398.rs @@ -4,7 +4,7 @@ //! Original author of this test is [@davidpdrsn](https://github.com/davidpdrsn). use juniper::{ - graphql_object, EmptyMutation, EmptySubscription, Executor, RootNode, ScalarValue, Variables, + graphql_object, graphql_vars, EmptyMutation, EmptySubscription, Executor, RootNode, ScalarValue, }; struct Query; @@ -66,7 +66,7 @@ async fn lookahead_from_fragment_with_nested_type() { "#, None, &Schema::new(Query, EmptyMutation::new(), EmptySubscription::new()), - &Variables::new(), + &graphql_vars! {}, &(), ) .await diff --git a/integration_tests/juniper_tests/src/issue_407.rs b/integration_tests/juniper_tests/src/issue_407.rs index 11c6075c9..51bf4211a 100644 --- a/integration_tests/juniper_tests/src/issue_407.rs +++ b/integration_tests/juniper_tests/src/issue_407.rs @@ -2,7 +2,8 @@ //! See [#407](https://github.com/graphql-rust/juniper/issues/407) for details. use juniper::{ - graphql_interface, graphql_object, EmptyMutation, EmptySubscription, GraphQLObject, Variables, + graphql_interface, graphql_object, graphql_vars, EmptyMutation, EmptySubscription, + GraphQLObject, }; struct Query; @@ -78,12 +79,12 @@ async fn fragments_in_interface() { let schema = Schema::new(Query, EmptyMutation::new(), EmptySubscription::new()); - let (_, errors) = juniper::execute(query, None, &schema, &Variables::new(), &()) + let (_, errors) = juniper::execute(query, None, &schema, &graphql_vars! {}, &()) .await .unwrap(); assert_eq!(errors.len(), 0); - let (_, errors) = juniper::execute_sync(query, None, &schema, &Variables::new(), &()).unwrap(); + let (_, errors) = juniper::execute_sync(query, None, &schema, &graphql_vars! {}, &()).unwrap(); assert_eq!(errors.len(), 0); } @@ -112,11 +113,11 @@ async fn inline_fragments_in_interface() { let schema = Schema::new(Query, EmptyMutation::new(), EmptySubscription::new()); - let (_, errors) = juniper::execute(query, None, &schema, &Variables::new(), &()) + let (_, errors) = juniper::execute(query, None, &schema, &graphql_vars! {}, &()) .await .unwrap(); assert_eq!(errors.len(), 0); - let (_, errors) = juniper::execute_sync(query, None, &schema, &Variables::new(), &()).unwrap(); + let (_, errors) = juniper::execute_sync(query, None, &schema, &graphql_vars! {}, &()).unwrap(); assert_eq!(errors.len(), 0); } diff --git a/integration_tests/juniper_tests/src/issue_500.rs b/integration_tests/juniper_tests/src/issue_500.rs index 221b1720e..1fcafb79f 100644 --- a/integration_tests/juniper_tests/src/issue_500.rs +++ b/integration_tests/juniper_tests/src/issue_500.rs @@ -1,7 +1,9 @@ //! Checks that using nested fragments works okay. //! See [#500](https://github.com/graphql-rust/juniper/issues/500) for details. -use juniper::{graphql_object, EmptyMutation, EmptySubscription, Executor, ScalarValue, Variables}; +use juniper::{ + graphql_object, graphql_vars, EmptyMutation, EmptySubscription, Executor, ScalarValue, +}; struct Query; @@ -82,7 +84,7 @@ async fn nested_fragments() { "#; let schema = Schema::new(Query, EmptyMutation::new(), EmptySubscription::new()); - let (_, errors) = juniper::execute(query, None, &schema, &Variables::new(), &()) + let (_, errors) = juniper::execute(query, None, &schema, &graphql_vars! {}, &()) .await .unwrap(); diff --git a/integration_tests/juniper_tests/src/issue_798.rs b/integration_tests/juniper_tests/src/issue_798.rs index a8f7ec0de..fc23bbd6e 100644 --- a/integration_tests/juniper_tests/src/issue_798.rs +++ b/integration_tests/juniper_tests/src/issue_798.rs @@ -2,8 +2,8 @@ //! See [#798](https://github.com/graphql-rust/juniper/issues/798) for details. use juniper::{ - graphql_interface, graphql_object, graphql_value, EmptyMutation, EmptySubscription, - GraphQLObject, GraphQLUnion, RootNode, Variables, + graphql_interface, graphql_object, graphql_value, graphql_vars, EmptyMutation, + EmptySubscription, GraphQLObject, GraphQLUnion, RootNode, }; #[graphql_interface(for = [Human, Droid])] @@ -89,7 +89,7 @@ async fn interface_inline_fragment_on_union() { "#; let schema = Schema::new(Query::Human, EmptyMutation::new(), EmptySubscription::new()); - let (res, errors) = juniper::execute(query, None, &schema, &Variables::new(), &()) + let (res, errors) = juniper::execute(query, None, &schema, &graphql_vars! {}, &()) .await .unwrap(); @@ -107,7 +107,7 @@ async fn interface_inline_fragment_on_union() { let schema = Schema::new(Query::Droid, EmptyMutation::new(), EmptySubscription::new()); let (res, errors) = - juniper::execute_sync(query, None, &schema, &Variables::new(), &()).unwrap(); + juniper::execute_sync(query, None, &schema, &graphql_vars! {}, &()).unwrap(); assert_eq!(errors.len(), 0); assert_eq!( @@ -144,7 +144,7 @@ async fn interface_fragment_on_union() { "#; let schema = Schema::new(Query::Human, EmptyMutation::new(), EmptySubscription::new()); - let (res, errors) = juniper::execute(query, None, &schema, &Variables::new(), &()) + let (res, errors) = juniper::execute(query, None, &schema, &graphql_vars! {}, &()) .await .unwrap(); @@ -162,7 +162,7 @@ async fn interface_fragment_on_union() { let schema = Schema::new(Query::Droid, EmptyMutation::new(), EmptySubscription::new()); let (res, errors) = - juniper::execute_sync(query, None, &schema, &Variables::new(), &()).unwrap(); + juniper::execute_sync(query, None, &schema, &graphql_vars! {}, &()).unwrap(); assert_eq!(errors.len(), 0); assert_eq!( diff --git a/integration_tests/juniper_tests/src/issue_914.rs b/integration_tests/juniper_tests/src/issue_914.rs index aa9b86c38..bebede511 100644 --- a/integration_tests/juniper_tests/src/issue_914.rs +++ b/integration_tests/juniper_tests/src/issue_914.rs @@ -1,7 +1,7 @@ //! Checks that multiple fragments on sub types don't override each other. //! See [#914](https://github.com/graphql-rust/juniper/issues/914) for details. -use juniper::{graphql_object, EmptyMutation, EmptySubscription, GraphQLObject, Variables}; +use juniper::{graphql_object, graphql_vars, EmptyMutation, EmptySubscription, GraphQLObject}; struct Query; @@ -77,13 +77,13 @@ async fn fragments_with_nested_objects_dont_override_previous_selections() { let schema = Schema::new(Query, EmptyMutation::new(), EmptySubscription::new()); - let (async_value, errors) = juniper::execute(query, None, &schema, &Variables::new(), &()) + let (async_value, errors) = juniper::execute(query, None, &schema, &graphql_vars! {}, &()) .await .unwrap(); assert_eq!(errors.len(), 0); let (sync_value, errors) = - juniper::execute_sync(query, None, &schema, &Variables::new(), &()).unwrap(); + juniper::execute_sync(query, None, &schema, &graphql_vars! {}, &()).unwrap(); assert_eq!(errors.len(), 0); assert_eq!(async_value, sync_value); diff --git a/integration_tests/juniper_tests/src/issue_922.rs b/integration_tests/juniper_tests/src/issue_922.rs index b99803fb3..60418de4a 100644 --- a/integration_tests/juniper_tests/src/issue_922.rs +++ b/integration_tests/juniper_tests/src/issue_922.rs @@ -2,8 +2,8 @@ //! See [#922](https://github.com/graphql-rust/juniper/issues/922) for details. use juniper::{ - graphql_interface, graphql_object, graphql_value, EmptyMutation, EmptySubscription, - GraphQLObject, Variables, + graphql_interface, graphql_object, graphql_value, graphql_vars, EmptyMutation, + EmptySubscription, GraphQLObject, }; struct Query; @@ -93,7 +93,7 @@ async fn fragment_on_interface() { let schema = Schema::new(Query, EmptyMutation::new(), EmptySubscription::new()); - let (res, errors) = juniper::execute(query, None, &schema, &Variables::new(), &()) + let (res, errors) = juniper::execute(query, None, &schema, &graphql_vars! {}, &()) .await .unwrap(); @@ -109,7 +109,7 @@ async fn fragment_on_interface() { ); let (res, errors) = - juniper::execute_sync(query, None, &schema, &Variables::new(), &()).unwrap(); + juniper::execute_sync(query, None, &schema, &graphql_vars! {}, &()).unwrap(); assert_eq!(errors.len(), 0); assert_eq!( diff --git a/integration_tests/juniper_tests/src/issue_925.rs b/integration_tests/juniper_tests/src/issue_925.rs index 435cb2a7b..6c1487c42 100644 --- a/integration_tests/juniper_tests/src/issue_925.rs +++ b/integration_tests/juniper_tests/src/issue_925.rs @@ -4,8 +4,8 @@ use futures::stream::BoxStream; use juniper::{ - graphql_object, graphql_subscription, graphql_value, EmptyMutation, FieldError, GraphQLObject, - IntoFieldError, Object, ScalarValue, Value, Variables, + graphql_object, graphql_subscription, graphql_value, graphql_vars, EmptyMutation, FieldError, + GraphQLObject, IntoFieldError, Object, ScalarValue, Value, }; #[derive(GraphQLObject)] @@ -59,7 +59,7 @@ async fn error_extensions() { "#; let schema = Schema::new(Query, EmptyMutation::new(), SubscriptionsRoot); - let (_, errors) = juniper::resolve_into_stream(sub, None, &schema, &Variables::new(), &()) + let (_, errors) = juniper::resolve_into_stream(sub, None, &schema, &graphql_vars! {}, &()) .await .unwrap(); diff --git a/integration_tests/juniper_tests/src/issue_945.rs b/integration_tests/juniper_tests/src/issue_945.rs index 9d8c0db85..369e660ba 100644 --- a/integration_tests/juniper_tests/src/issue_945.rs +++ b/integration_tests/juniper_tests/src/issue_945.rs @@ -2,8 +2,8 @@ //! See [#945](https://github.com/graphql-rust/juniper/issues/945) for details. use juniper::{ - graphql_object, graphql_value, EmptyMutation, EmptySubscription, GraphQLObject, GraphQLUnion, - Variables, + graphql_object, graphql_value, graphql_vars, EmptyMutation, EmptySubscription, GraphQLObject, + GraphQLUnion, }; struct Query; @@ -66,7 +66,7 @@ async fn fragment_on_union() { let schema = Schema::new(Query, EmptyMutation::new(), EmptySubscription::new()); - let (res, errors) = juniper::execute(query, None, &schema, &Variables::new(), &()) + let (res, errors) = juniper::execute(query, None, &schema, &graphql_vars! {}, &()) .await .unwrap(); @@ -79,7 +79,7 @@ async fn fragment_on_union() { ); let (res, errors) = - juniper::execute_sync(query, None, &schema, &Variables::new(), &()).unwrap(); + juniper::execute_sync(query, None, &schema, &graphql_vars! {}, &()).unwrap(); assert_eq!(errors.len(), 0); assert_eq!( diff --git a/integration_tests/juniper_tests/src/pre_parse.rs b/integration_tests/juniper_tests/src/pre_parse.rs index c18b1e32a..ec987eca2 100644 --- a/integration_tests/juniper_tests/src/pre_parse.rs +++ b/integration_tests/juniper_tests/src/pre_parse.rs @@ -1,10 +1,10 @@ use futures::{Stream, StreamExt, TryFutureExt}; use juniper::{ executor::{execute_validated_query_async, get_operation, resolve_validated_subscription}, - graphql_object, graphql_subscription, + graphql_object, graphql_subscription, graphql_vars, parser::parse_document_source, validation::{validate_input_values, visit_all_rules, ValidatorContext}, - EmptyMutation, FieldError, OperationType, RootNode, Variables, + EmptyMutation, FieldError, OperationType, RootNode, }; use std::pin::Pin; @@ -61,14 +61,14 @@ async fn query_document_can_be_pre_parsed() { let operation = get_operation(&document, None).unwrap(); assert!(operation.item.operation_type == OperationType::Query); - let errors = validate_input_values(&juniper::Variables::new(), operation, &root_node.schema); + let errors = validate_input_values(&graphql_vars! {}, operation, &root_node.schema); assert!(errors.is_empty()); let (_, errors) = execute_validated_query_async( &document, operation, root_node, - &Variables::new(), + &graphql_vars! {}, &Context {}, ) .await @@ -91,7 +91,7 @@ async fn subscription_document_can_be_pre_parsed() { &document, &operation, &root_node, - &Variables::new(), + &graphql_vars! {}, &Context {}, ) .map_ok(|(stream, errors)| juniper_subscriptions::Connection::from_stream(stream, errors)) diff --git a/juniper/benches/bench.rs b/juniper/benches/bench.rs index 860e96229..c3fde3c74 100644 --- a/juniper/benches/bench.rs +++ b/juniper/benches/bench.rs @@ -1,8 +1,8 @@ use bencher::{benchmark_group, benchmark_main, Bencher}; use juniper::{ - execute_sync, + execute_sync, graphql_vars, tests::fixtures::starwars::schema::{Database, Query}, - DefaultScalarValue, EmptyMutation, EmptySubscription, RootNode, Variables, + DefaultScalarValue, EmptyMutation, EmptySubscription, RootNode, }; fn query_type_name(b: &mut Bencher) { @@ -27,7 +27,7 @@ fn query_type_name(b: &mut Bencher) { } }"#; - b.iter(|| execute_sync(doc, None, &schema, &Variables::new(), &database)); + b.iter(|| execute_sync(doc, None, &schema, &graphql_vars! {}, &database)); } fn introspection_query(b: &mut Bencher) { @@ -137,7 +137,7 @@ fn introspection_query(b: &mut Bencher) { } "#; - b.iter(|| execute_sync(doc, None, &schema, &Variables::new(), &database)); + b.iter(|| execute_sync(doc, None, &schema, &graphql_vars! {}, &database)); } benchmark_group!(queries, query_type_name, introspection_query); diff --git a/juniper/src/executor_tests/introspection/enums.rs b/juniper/src/executor_tests/introspection/enums.rs index b2ba2d3c3..127f45ab2 100644 --- a/juniper/src/executor_tests/introspection/enums.rs +++ b/juniper/src/executor_tests/introspection/enums.rs @@ -1,6 +1,5 @@ use crate::{ - executor::Variables, - graphql_value, + graphql_value, graphql_vars, schema::model::RootNode, types::scalars::{EmptyMutation, EmptySubscription}, value::{DefaultScalarValue, Object, Value}, @@ -98,7 +97,7 @@ where EmptySubscription::<()>::new(), ); - let (result, errs) = crate::execute(doc, None, &schema, &Variables::new(), &()) + let (result, errs) = crate::execute(doc, None, &schema, &graphql_vars! {}, &()) .await .expect("Execution failed"); diff --git a/juniper/src/executor_tests/introspection/input_object.rs b/juniper/src/executor_tests/introspection/input_object.rs index b00401fe8..b7e673351 100644 --- a/juniper/src/executor_tests/introspection/input_object.rs +++ b/juniper/src/executor_tests/introspection/input_object.rs @@ -2,8 +2,7 @@ use crate::{ ast::{FromInputValue, InputValue}, - executor::Variables, - graphql_input_value, graphql_object, graphql_value, + graphql_input_value, graphql_object, graphql_value, graphql_vars, schema::model::RootNode, types::scalars::{EmptyMutation, EmptySubscription}, value::{DefaultScalarValue, Object, Value}, @@ -123,7 +122,7 @@ where EmptySubscription::<()>::new(), ); - let (result, errs) = crate::execute(doc, None, &schema, &Variables::new(), &()) + let (result, errs) = crate::execute(doc, None, &schema, &graphql_vars! {}, &()) .await .expect("Execution failed"); diff --git a/juniper/src/executor_tests/introspection/mod.rs b/juniper/src/executor_tests/introspection/mod.rs index 47b70f5c7..5778d8cb6 100644 --- a/juniper/src/executor_tests/introspection/mod.rs +++ b/juniper/src/executor_tests/introspection/mod.rs @@ -6,8 +6,7 @@ mod input_object; use self::input_object::{NamedPublic, NamedPublicWithDescription}; use crate::{ - executor::Variables, - graphql_interface, graphql_object, graphql_scalar, graphql_value, + graphql_interface, graphql_object, graphql_scalar, graphql_value, graphql_vars, schema::model::RootNode, types::scalars::{EmptyMutation, EmptySubscription}, value::{ParseScalarResult, ParseScalarValue, ScalarValue, Value}, @@ -83,7 +82,7 @@ async fn test_execution() { EmptySubscription::<()>::new(), ); - let (result, errs) = crate::execute(doc, None, &schema, &Variables::new(), &()) + let (result, errs) = crate::execute(doc, None, &schema, &graphql_vars! {}, &()) .await .expect("Execution failed"); @@ -128,7 +127,7 @@ async fn enum_introspection() { EmptySubscription::<()>::new(), ); - let (result, errs) = crate::execute(doc, None, &schema, &Variables::new(), &()) + let (result, errs) = crate::execute(doc, None, &schema, &graphql_vars! {}, &()) .await .expect("Execution failed"); @@ -237,7 +236,7 @@ async fn interface_introspection() { EmptySubscription::<()>::new(), ); - let (result, errs) = crate::execute(doc, None, &schema, &Variables::new(), &()) + let (result, errs) = crate::execute(doc, None, &schema, &graphql_vars! {}, &()) .await .expect("Execution failed"); @@ -369,7 +368,7 @@ async fn object_introspection() { EmptySubscription::<()>::new(), ); - let (result, errs) = crate::execute(doc, None, &schema, &Variables::new(), &()) + let (result, errs) = crate::execute(doc, None, &schema, &graphql_vars! {}, &()) .await .expect("Execution failed"); @@ -506,7 +505,7 @@ async fn scalar_introspection() { EmptySubscription::<()>::new(), ); - let (result, errs) = crate::execute(doc, None, &schema, &Variables::new(), &()) + let (result, errs) = crate::execute(doc, None, &schema, &graphql_vars! {}, &()) .await .expect("Execution failed"); diff --git a/juniper/src/integrations/chrono_tz.rs b/juniper/src/integrations/chrono_tz.rs index 8f5becda1..14963e83b 100644 --- a/juniper/src/integrations/chrono_tz.rs +++ b/juniper/src/integrations/chrono_tz.rs @@ -39,10 +39,10 @@ mod test { mod from_input_value { use chrono_tz::Tz; - use crate::{DefaultScalarValue, FromInputValue, InputValue}; + use crate::{graphql_input_value, FromInputValue, InputValue}; fn tz_input_test(raw: &'static str, expected: Option) { - let input = >::scalar(raw.to_string()); + let input: InputValue = graphql_input_value!((raw)); let parsed: Option = FromInputValue::from_input_value(&input); assert_eq!(parsed, expected); diff --git a/juniper/src/integrations/url.rs b/juniper/src/integrations/url.rs index 844a9c029..659cba1f2 100644 --- a/juniper/src/integrations/url.rs +++ b/juniper/src/integrations/url.rs @@ -29,12 +29,12 @@ where mod test { use url::Url; - use crate::{DefaultScalarValue, InputValue}; + use crate::{graphql_input_value, InputValue}; #[test] fn url_from_input_value() { let raw = "https://example.net/"; - let input = >::scalar(raw.to_string()); + let input: InputValue = graphql_input_value!((raw)); let parsed: Url = crate::FromInputValue::from_input_value(&input).unwrap(); let url = Url::parse(raw).unwrap(); diff --git a/juniper/src/integrations/uuid.rs b/juniper/src/integrations/uuid.rs index 0dee5bc02..43f716b6f 100644 --- a/juniper/src/integrations/uuid.rs +++ b/juniper/src/integrations/uuid.rs @@ -34,15 +34,16 @@ where #[cfg(test)] mod test { - use crate::{value::DefaultScalarValue, InputValue}; use uuid::Uuid; + use crate::{graphql_input_value, FromInputValue, InputValue}; + #[test] fn uuid_from_input_value() { let raw = "123e4567-e89b-12d3-a456-426655440000"; - let input = >::scalar(raw.to_string()); + let input: InputValue = graphql_input_value!((raw)); - let parsed: Uuid = crate::FromInputValue::from_input_value(&input).unwrap(); + let parsed: Uuid = FromInputValue::from_input_value(&input).unwrap(); let id = Uuid::parse_str(raw).unwrap(); assert_eq!(parsed, id); diff --git a/juniper/src/parser/tests/document.rs b/juniper/src/parser/tests/document.rs index 52ad0bbd4..29959265f 100644 --- a/juniper/src/parser/tests/document.rs +++ b/juniper/src/parser/tests/document.rs @@ -3,6 +3,7 @@ use crate::{ Arguments, Definition, Field, InputValue, Operation, OperationType, OwnedDocument, Selection, }, + graphql_input_value, parser::{document::parse_document_source, ParseError, SourcePosition, Spanning, Token}, schema::model::SchemaType, types::scalars::{EmptyMutation, EmptySubscription}, @@ -78,7 +79,7 @@ fn simple_ast() { Spanning::start_end( &SourcePosition::new(40, 2, 25), &SourcePosition::new(41, 2, 26), - InputValue::scalar(4), + graphql_input_value!(4), ), )], }, diff --git a/juniper/src/tests/introspection_tests.rs b/juniper/src/tests/introspection_tests.rs index 38259eead..0ab33da50 100644 --- a/juniper/src/tests/introspection_tests.rs +++ b/juniper/src/tests/introspection_tests.rs @@ -1,7 +1,7 @@ use std::collections::HashSet; use crate::{ - executor::Variables, + graphql_vars, introspection::IntrospectionFormat, schema::model::RootNode, tests::fixtures::starwars::schema::{Database, Query}, @@ -28,7 +28,7 @@ async fn test_introspection_query_type_name() { ); assert_eq!( - crate::execute(doc, None, &schema, &Variables::new(), &database).await, + crate::execute(doc, None, &schema, &graphql_vars! {}, &database).await, Ok(( graphql_value!({ "__schema": { @@ -59,7 +59,7 @@ async fn test_introspection_type_name() { ); assert_eq!( - crate::execute(doc, None, &schema, &Variables::new(), &database).await, + crate::execute(doc, None, &schema, &graphql_vars! {}, &database).await, Ok(( graphql_value!({ "__type": { @@ -89,7 +89,7 @@ async fn test_introspection_specific_object_type_name_and_kind() { ); assert_eq!( - crate::execute(doc, None, &schema, &Variables::new(), &database).await, + crate::execute(doc, None, &schema, &graphql_vars! {}, &database).await, Ok(( graphql_value!({ "__type": { @@ -120,7 +120,7 @@ async fn test_introspection_specific_interface_type_name_and_kind() { ); assert_eq!( - crate::execute(doc, None, &schema, &Variables::new(), &database).await, + crate::execute(doc, None, &schema, &graphql_vars! {}, &database).await, Ok(( graphql_value!({ "__type": { @@ -151,7 +151,7 @@ async fn test_introspection_documentation() { ); assert_eq!( - crate::execute(doc, None, &schema, &Variables::new(), &database).await, + crate::execute(doc, None, &schema, &graphql_vars! {}, &database).await, Ok(( graphql_value!({ "__type": { @@ -184,7 +184,7 @@ async fn test_introspection_directives() { EmptySubscription::::new(), ); - let mut result = crate::execute(q, None, &schema, &Variables::new(), &database) + let mut result = crate::execute(q, None, &schema, &graphql_vars! {}, &database) .await .unwrap(); sort_schema_value(&mut result.0); @@ -234,7 +234,7 @@ async fn test_introspection_possible_types() { EmptySubscription::::new(), ); - let result = crate::execute(doc, None, &schema, &Variables::new(), &database).await; + let result = crate::execute(doc, None, &schema, &graphql_vars! {}, &database).await; let (result, errors) = result.ok().expect("Query returned error"); diff --git a/juniper/src/tests/type_info_tests.rs b/juniper/src/tests/type_info_tests.rs index 4b8a22d03..61e7662bc 100644 --- a/juniper/src/tests/type_info_tests.rs +++ b/juniper/src/tests/type_info_tests.rs @@ -1,8 +1,8 @@ use indexmap::IndexMap; use crate::{ - executor::{ExecutionResult, Executor, Registry, Variables}, - graphql_value, + executor::{ExecutionResult, Executor, Registry}, + graphql_value, graphql_vars, schema::{meta::MetaType, model::RootNode}, types::{ base::{Arguments, GraphQLType, GraphQLValue}, @@ -94,7 +94,7 @@ fn test_node() { ); assert_eq!( - crate::execute_sync(doc, None, &schema, &Variables::new(), &()), + crate::execute_sync(doc, None, &schema, &graphql_vars! {}, &()), Ok(( graphql_value!({ "foo": "1", diff --git a/juniper_graphql_ws/src/client_message.rs b/juniper_graphql_ws/src/client_message.rs index c24f4d5b2..c893f6da3 100644 --- a/juniper_graphql_ws/src/client_message.rs +++ b/juniper_graphql_ws/src/client_message.rs @@ -71,7 +71,7 @@ mod test { assert_eq!( ClientMessage::ConnectionInit { - payload: Variables::default(), + payload: graphql_vars! {}, }, serde_json::from_str(r##"{"type": "connection_init"}"##).unwrap(), ); diff --git a/juniper_graphql_ws/src/lib.rs b/juniper_graphql_ws/src/lib.rs index 0c47bc474..bf68869fd 100644 --- a/juniper_graphql_ws/src/lib.rs +++ b/juniper_graphql_ws/src/lib.rs @@ -633,7 +633,7 @@ mod test { use juniper::{ futures::sink::SinkExt, - graphql_object, graphql_subscription, graphql_value, graphql_vars, + graphql_input_value, graphql_object, graphql_subscription, graphql_value, graphql_vars, parser::{ParseError, Spanning, Token}, DefaultScalarValue, EmptyMutation, FieldError, FieldResult, InputValue, RootNode, }; @@ -707,7 +707,7 @@ mod test { ); conn.send(ClientMessage::ConnectionInit { - payload: Variables::default(), + payload: graphql_vars! {}, }) .await .unwrap(); @@ -718,7 +718,7 @@ mod test { id: "foo".to_string(), payload: StartPayload { query: "{context}".to_string(), - variables: Variables::default(), + variables: graphql_vars! {}, operation_name: None, }, }) @@ -752,7 +752,7 @@ mod test { ); conn.send(ClientMessage::ConnectionInit { - payload: Variables::default(), + payload: graphql_vars! {}, }) .await .unwrap(); @@ -763,7 +763,7 @@ mod test { id: "foo".to_string(), payload: StartPayload { query: "subscription Foo {context}".to_string(), - variables: Variables::default(), + variables: graphql_vars! {}, operation_name: None, }, }) @@ -785,7 +785,7 @@ mod test { id: "bar".to_string(), payload: StartPayload { query: "subscription Bar {context}".to_string(), - variables: Variables::default(), + variables: graphql_vars! {}, operation_name: None, }, }) @@ -820,7 +820,7 @@ mod test { #[tokio::test] async fn test_init_params_ok() { let mut conn = Connection::new(new_test_schema(), |params: Variables| async move { - assert_eq!(params.get("foo"), Some(&InputValue::scalar("bar"))); + assert_eq!(params.get("foo"), Some(&graphql_input_value!("bar"))); Ok(ConnectionConfig::new(Context(1))) as Result<_, Infallible> }); @@ -836,7 +836,7 @@ mod test { #[tokio::test] async fn test_init_params_error() { let mut conn = Connection::new(new_test_schema(), |params: Variables| async move { - assert_eq!(params.get("foo"), Some(&InputValue::scalar("bar"))); + assert_eq!(params.get("foo"), Some(&graphql_input_value!("bar"))); Err(io::Error::new(io::ErrorKind::Other, "init error")) }); @@ -952,7 +952,7 @@ mod test { ); conn.send(ClientMessage::ConnectionInit { - payload: Variables::default(), + payload: graphql_vars! {}, }) .await .unwrap(); @@ -975,7 +975,7 @@ mod test { ); conn.send(ClientMessage::ConnectionInit { - payload: Variables::default(), + payload: graphql_vars! {}, }) .await .unwrap(); From e5ce7bb51680b5aec5d90a2afb0291210048ef62 Mon Sep 17 00:00:00 2001 From: tyranron Date: Fri, 26 Nov 2021 17:10:39 +0100 Subject: [PATCH 22/22] Fix lint --- juniper_graphql_ws/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/juniper_graphql_ws/src/lib.rs b/juniper_graphql_ws/src/lib.rs index bf68869fd..f1fe9bd3b 100644 --- a/juniper_graphql_ws/src/lib.rs +++ b/juniper_graphql_ws/src/lib.rs @@ -635,7 +635,7 @@ mod test { futures::sink::SinkExt, graphql_input_value, graphql_object, graphql_subscription, graphql_value, graphql_vars, parser::{ParseError, Spanning, Token}, - DefaultScalarValue, EmptyMutation, FieldError, FieldResult, InputValue, RootNode, + DefaultScalarValue, EmptyMutation, FieldError, FieldResult, RootNode, }; use super::*;