diff --git a/examples/actix_subscriptions/src/main.rs b/examples/actix_subscriptions/src/main.rs index c5021ae6..6da5ad56 100644 --- a/examples/actix_subscriptions/src/main.rs +++ b/examples/actix_subscriptions/src/main.rs @@ -9,9 +9,9 @@ use actix_web::{ }; use juniper::{ - graphql_object, graphql_subscription, + graphql_object, graphql_subscription, graphql_value, tests::fixtures::starwars::schema::{Character as _, Database, Query}, - DefaultScalarValue, EmptyMutation, FieldError, RootNode, Value, + EmptyMutation, FieldError, RootNode, }; use juniper_actix::{graphql_handler, playground_handler, subscriptions::subscriptions_handler}; use juniper_graphql_ws::ConnectionConfig; @@ -77,9 +77,7 @@ impl Subscription { if counter == 2 { yield Err(FieldError::new( "some field error from handler", - Value::Scalar(DefaultScalarValue::String( - "some additional string".to_string(), - )), + graphql_value!("some additional string"), )) } else { let random_id = rng.gen_range(1000..1005).to_string(); diff --git a/examples/warp_subscriptions/src/main.rs b/examples/warp_subscriptions/src/main.rs index c7a6f855..abac06a5 100644 --- a/examples/warp_subscriptions/src/main.rs +++ b/examples/warp_subscriptions/src/main.rs @@ -4,8 +4,8 @@ use std::{env, pin::Pin, sync::Arc, time::Duration}; use futures::{FutureExt as _, Stream}; use juniper::{ - graphql_object, graphql_subscription, DefaultScalarValue, EmptyMutation, FieldError, - GraphQLEnum, RootNode, Value, + graphql_object, graphql_subscription, graphql_value, EmptyMutation, FieldError, GraphQLEnum, + RootNode, }; use juniper_graphql_ws::ConnectionConfig; use juniper_warp::{playground_filter, subscriptions::serve_graphql_ws}; @@ -117,9 +117,7 @@ impl Subscription { if counter == 2 { yield Err(FieldError::new( "some field error from handler", - Value::Scalar(DefaultScalarValue::String( - "some additional string".to_string(), - )), + graphql_value!("some additional string"), )) } else { yield Ok(User { diff --git a/integration_tests/juniper_tests/src/codegen/derive_scalar.rs b/integration_tests/juniper_tests/src/codegen/derive_scalar.rs index 6ed5f29d..8010cbea 100644 --- a/integration_tests/juniper_tests/src/codegen/derive_scalar.rs +++ b/integration_tests/juniper_tests/src/codegen/derive_scalar.rs @@ -1,9 +1,10 @@ -use crate::custom_scalar::MyScalarValue; use juniper::{ - execute, EmptyMutation, EmptySubscription, FromInputValue, InputValue, RootNode, ToInputValue, - Value, Variables, + execute, graphql_value, EmptyMutation, EmptySubscription, FromInputValue, InputValue, RootNode, + ToInputValue, Value, Variables, }; +use crate::custom_scalar::MyScalarValue; + #[derive(Debug, PartialEq, Eq, Hash, juniper::GraphQLScalarValue)] #[graphql(transparent, scalar = MyScalarValue)] pub struct LargeId(i64); @@ -56,28 +57,14 @@ async fn test_scalar_value_large_query() { EmptySubscription::<()>::new(), ); - let doc = r#" - query { - user { id } - }"#; + let doc = r#"{ + user { id } + }"#; + let val = Value::::scalar(0_i64); assert_eq!( execute(doc, None, &schema, &Variables::::new(), &()).await, - Ok(( - Value::object( - vec![( - "user", - Value::object( - vec![("id", Value::::scalar(0_i64)),] - .into_iter() - .collect(), - ), - )] - .into_iter() - .collect() - ), - vec![] - )) + Ok((graphql_value!({"user": {"id": val}}), vec![])), ); } @@ -89,51 +76,23 @@ async fn test_scalar_value_large_mutation() { EmptySubscription::<()>::new(), ); - let doc = r#" - mutation { - changeUser(id: 1) { id } - }"#; + let doc = r#"mutation { + changeUser(id: 1) { id } + }"#; + let val = Value::::scalar(1_i64); assert_eq!( execute(doc, None, &schema, &Variables::::new(), &()).await, - Ok(( - Value::object( - vec![( - "changeUser", - Value::object( - vec![("id", Value::::scalar(1_i64)),] - .into_iter() - .collect(), - ), - )] - .into_iter() - .collect() - ), - vec![] - )) + Ok((graphql_value!({"changeUser": {"id": val}}), vec![])), ); - let doc = r#" - mutation { - changeUser(id: 4294967297) { id } - }"#; + let doc = r#"mutation { + changeUser(id: 4294967297) { id } + }"#; + let val = Value::::scalar(4294967297_i64); assert_eq!( execute(doc, None, &schema, &Variables::::new(), &()).await, - Ok(( - Value::object( - vec![( - "changeUser", - Value::object( - vec![("id", Value::::scalar(4294967297_i64)),] - .into_iter() - .collect(), - ), - )] - .into_iter() - .collect() - ), - vec![] - )) + Ok((graphql_value!({"changeUser": {"id": val}}), vec![])), ); } diff --git a/integration_tests/juniper_tests/src/codegen/impl_scalar.rs b/integration_tests/juniper_tests/src/codegen/impl_scalar.rs index 9da7de8e..42059817 100644 --- a/integration_tests/juniper_tests/src/codegen/impl_scalar.rs +++ b/integration_tests/juniper_tests/src/codegen/impl_scalar.rs @@ -222,11 +222,11 @@ async fn default_name_introspection() { run_type_info_query(doc, |type_info| { assert_eq!( type_info.get_field_value("name"), - Some(&Value::scalar("DefaultName")) + Some(&graphql_value!("DefaultName")), ); assert_eq!( type_info.get_field_value("description"), - Some(&Value::null()) + Some(&graphql_value!(None)), ); }) .await; @@ -246,11 +246,11 @@ async fn other_order_introspection() { run_type_info_query(doc, |type_info| { assert_eq!( type_info.get_field_value("name"), - Some(&Value::scalar("OtherOrder")) + Some(&graphql_value!("OtherOrder")), ); assert_eq!( type_info.get_field_value("description"), - Some(&Value::null()) + Some(&graphql_value!(None)), ); }) .await; @@ -270,11 +270,11 @@ async fn named_introspection() { run_type_info_query(doc, |type_info| { assert_eq!( type_info.get_field_value("name"), - Some(&Value::scalar("ANamedScalar")) + Some(&graphql_value!("ANamedScalar")), ); assert_eq!( type_info.get_field_value("description"), - Some(&Value::null()) + Some(&graphql_value!(None)), ); }) .await; @@ -294,11 +294,13 @@ async fn scalar_description_introspection() { run_type_info_query(doc, |type_info| { assert_eq!( type_info.get_field_value("name"), - Some(&Value::scalar("ScalarDescription")) + Some(&graphql_value!("ScalarDescription")), ); assert_eq!( type_info.get_field_value("description"), - Some(&Value::scalar("A sample scalar, represented as an integer")) + Some(&graphql_value!( + "A sample scalar, represented as an integer" + )), ); }) .await; @@ -318,11 +320,11 @@ async fn generated_scalar_introspection() { run_type_info_query(doc, |type_info| { assert_eq!( type_info.get_field_value("name"), - Some(&Value::scalar("Generated")) + Some(&graphql_value!("Generated")), ); assert_eq!( type_info.get_field_value("description"), - Some(&Value::null()) + Some(&graphql_value!(None)), ); }) .await; diff --git a/integration_tests/juniper_tests/src/codegen/subscription_attr.rs b/integration_tests/juniper_tests/src/codegen/subscription_attr.rs index f2357ca1..5b69da15 100644 --- a/integration_tests/juniper_tests/src/codegen/subscription_attr.rs +++ b/integration_tests/juniper_tests/src/codegen/subscription_attr.rs @@ -2,14 +2,15 @@ use std::pin::Pin; -use futures::{future, stream, FutureExt as _, StreamExt as _}; +use futures::{future, stream, FutureExt as _}; use juniper::{ execute, graphql_object, graphql_subscription, graphql_value, resolve_into_stream, - DefaultScalarValue, EmptyMutation, ExecutionError, Executor, FieldError, FieldResult, - GraphQLError, GraphQLInputObject, GraphQLType, IntoFieldError, RootNode, ScalarValue, Value, - ValuesStream, Variables, + DefaultScalarValue, EmptyMutation, Executor, FieldError, FieldResult, GraphQLInputObject, + GraphQLType, IntoFieldError, RootNode, ScalarValue, Variables, }; +use crate::util::extract_next; + struct Query; #[graphql_object] @@ -44,29 +45,6 @@ where type Stream<'a, I> = Pin + Send + 'a>>; -async fn extract_next<'a, S: ScalarValue>( - input: Result<(Value>, Vec>), GraphQLError<'a>>, -) -> Result<(Value, Vec>), GraphQLError<'a>> { - let (stream, errs) = input?; - if !errs.is_empty() { - return Ok((Value::Null, errs)); - } - - if let Value::Object(obj) = stream { - for (name, mut val) in obj { - if let Value::Scalar(ref mut stream) = val { - return match stream.next().await { - Some(Ok(val)) => Ok((graphql_value!({ name: val }), vec![])), - Some(Err(e)) => Ok((Value::Null, vec![e])), - None => Ok((Value::Null, vec![])), - }; - } - } - } - - panic!("Expected to get Value::Object containing a Stream") -} - mod trivial { use super::*; diff --git a/integration_tests/juniper_tests/src/custom_scalar.rs b/integration_tests/juniper_tests/src/custom_scalar.rs index fcd9b5bd..a1703a6f 100644 --- a/integration_tests/juniper_tests/src/custom_scalar.rs +++ b/integration_tests/juniper_tests/src/custom_scalar.rs @@ -218,7 +218,7 @@ async fn querying_long() { run_query("{ longField }", |result| { assert_eq!( result.get_field_value("longField"), - Some(&Value::scalar(i64::from(i32::max_value()) + 1)) + Some(&Value::scalar(i64::from(i32::MAX) + 1)) ); }) .await; @@ -227,14 +227,11 @@ async fn querying_long() { #[tokio::test] async fn querying_long_arg() { run_query( - &format!( - "{{ longWithArg(longArg: {}) }}", - i64::from(i32::max_value()) + 3 - ), + &format!("{{ longWithArg(longArg: {}) }}", i64::from(i32::MAX) + 3), |result| { assert_eq!( result.get_field_value("longWithArg"), - Some(&Value::scalar(i64::from(i32::max_value()) + 3)) + Some(&Value::scalar(i64::from(i32::MAX) + 3)) ); }, ) @@ -247,14 +244,14 @@ async fn querying_long_variable() { "query q($test: Long!){ longWithArg(longArg: $test) }", vec![( "test".to_owned(), - InputValue::Scalar(MyScalarValue::Long(i64::from(i32::max_value()) + 42)), + InputValue::Scalar(MyScalarValue::Long(i64::from(i32::MAX) + 42)), )] .into_iter() .collect(), |result| { assert_eq!( result.get_field_value("longWithArg"), - Some(&Value::scalar(i64::from(i32::max_value()) + 42)) + Some(&Value::scalar(i64::from(i32::MAX) + 42)) ); }, ) @@ -263,7 +260,7 @@ async fn querying_long_variable() { #[test] fn deserialize_variable() { - let json = format!("{{\"field\": {}}}", i64::from(i32::max_value()) + 42); + let json = format!("{{\"field\": {}}}", i64::from(i32::MAX) + 42); let input_value: InputValue = serde_json::from_str(&json).unwrap(); assert_eq!( @@ -271,7 +268,7 @@ fn deserialize_variable() { InputValue::Object(vec![( Spanning::unlocated("field".into()), Spanning::unlocated(InputValue::Scalar(MyScalarValue::Long( - i64::from(i32::max_value()) + 42 + i64::from(i32::MAX) + 42 ))) )]) ); diff --git a/integration_tests/juniper_tests/src/issue_372.rs b/integration_tests/juniper_tests/src/issue_372.rs index 661c90db..d982282f 100644 --- a/integration_tests/juniper_tests/src/issue_372.rs +++ b/integration_tests/juniper_tests/src/issue_372.rs @@ -1,8 +1,13 @@ //! Checks that `__typename` field queries okay on root types. //! See [#372](https://github.com/graphql-rust/juniper/issues/372) for details. -use futures::{stream, StreamExt as _}; -use juniper::{graphql_object, graphql_subscription, graphql_value, RootNode, Value, Variables}; +use futures::{stream, FutureExt as _}; +use juniper::{ + execute, graphql_object, graphql_subscription, graphql_value, resolve_into_stream, RootNode, + Variables, +}; + +use crate::util::extract_next; pub struct Query; @@ -36,12 +41,11 @@ async fn implicit_query_typename() { let query = r#"{ __typename }"#; let schema = RootNode::new(Query, Mutation, Subscription); - let (res, errors) = juniper::execute(query, None, &schema, &Variables::new(), &()) - .await - .unwrap(); - assert_eq!(errors.len(), 0); - assert_eq!(res, graphql_value!({"__typename": "Query"})); + assert_eq!( + execute(query, None, &schema, &Variables::new(), &()).await, + Ok((graphql_value!({"__typename": "Query"}), vec![])), + ); } #[tokio::test] @@ -49,12 +53,11 @@ async fn query_typename() { let query = r#"query { __typename }"#; let schema = RootNode::new(Query, Mutation, Subscription); - let (res, errors) = juniper::execute(query, None, &schema, &Variables::new(), &()) - .await - .unwrap(); - assert_eq!(errors.len(), 0); - assert_eq!(res, graphql_value!({"__typename": "Query"})); + assert_eq!( + execute(query, None, &schema, &Variables::new(), &()).await, + Ok((graphql_value!({"__typename": "Query"}), vec![])), + ); } #[tokio::test] @@ -62,12 +65,11 @@ async fn explicit_query_typename() { let query = r#"query Query { __typename }"#; let schema = RootNode::new(Query, Mutation, Subscription); - let (res, errors) = juniper::execute(query, None, &schema, &Variables::new(), &()) - .await - .unwrap(); - assert_eq!(errors.len(), 0); - assert_eq!(res, graphql_value!({"__typename": "Query"})); + assert_eq!( + execute(query, None, &schema, &Variables::new(), &()).await, + Ok((graphql_value!({"__typename": "Query"}), vec![])), + ); } #[tokio::test] @@ -75,12 +77,11 @@ async fn mutation_typename() { let query = r#"mutation { __typename }"#; let schema = RootNode::new(Query, Mutation, Subscription); - let (res, errors) = juniper::execute(query, None, &schema, &Variables::new(), &()) - .await - .unwrap(); - assert_eq!(errors.len(), 0); - assert_eq!(res, graphql_value!({"__typename": "Mutation"})); + assert_eq!( + execute(query, None, &schema, &Variables::new(), &()).await, + Ok((graphql_value!({"__typename": "Mutation"}), vec![])), + ); } #[tokio::test] @@ -88,12 +89,11 @@ async fn explicit_mutation_typename() { let query = r#"mutation Mutation { __typename }"#; let schema = RootNode::new(Query, Mutation, Subscription); - let (res, errors) = juniper::execute(query, None, &schema, &Variables::new(), &()) - .await - .unwrap(); - assert_eq!(errors.len(), 0); - assert_eq!(res, graphql_value!({"__typename": "Mutation"})); + assert_eq!( + execute(query, None, &schema, &Variables::new(), &()).await, + Ok((graphql_value!({"__typename": "Mutation"}), vec![])), + ); } #[tokio::test] @@ -101,24 +101,13 @@ async fn subscription_typename() { let query = r#"subscription { __typename }"#; let schema = RootNode::new(Query, Mutation, Subscription); - let (res, errors) = juniper::resolve_into_stream(query, None, &schema, &Variables::new(), &()) - .await - .unwrap(); - assert_eq!(errors.len(), 0); - assert!(matches!(res, Value::Object(_))); - if let Value::Object(mut obj) = res { - assert!(obj.contains_field("__typename")); - - let val = obj.get_mut_field_value("__typename").unwrap(); - assert!(matches!(val, Value::Scalar(_))); - if let Value::Scalar(ref mut stream) = val { - assert_eq!( - stream.next().await, - Some(Ok(graphql_value!("Subscription"))), - ); - } - } + assert_eq!( + resolve_into_stream(query, None, &schema, &Variables::new(), &()) + .then(|s| extract_next(s)) + .await, + Ok((graphql_value!({"__typename": "Subscription"}), vec![])), + ); } #[tokio::test] @@ -126,22 +115,11 @@ async fn explicit_subscription_typename() { let query = r#"subscription Subscription { __typename }"#; let schema = RootNode::new(Query, Mutation, Subscription); - let (res, errors) = juniper::resolve_into_stream(query, None, &schema, &Variables::new(), &()) - .await - .unwrap(); - assert_eq!(errors.len(), 0); - assert!(matches!(res, Value::Object(_))); - if let Value::Object(mut obj) = res { - assert!(obj.contains_field("__typename")); - - let val = obj.get_mut_field_value("__typename").unwrap(); - assert!(matches!(val, Value::Scalar(_))); - if let Value::Scalar(ref mut stream) = val { - assert_eq!( - stream.next().await, - Some(Ok(graphql_value!("Subscription"))), - ); - } - } + assert_eq!( + resolve_into_stream(query, None, &schema, &Variables::new(), &()) + .then(|s| extract_next(s)) + .await, + Ok((graphql_value!({"__typename": "Subscription"}), vec![])), + ); } diff --git a/integration_tests/juniper_tests/src/lib.rs b/integration_tests/juniper_tests/src/lib.rs index 5fe40091..0d166d2b 100644 --- a/integration_tests/juniper_tests/src/lib.rs +++ b/integration_tests/juniper_tests/src/lib.rs @@ -32,3 +32,36 @@ mod issue_925; mod issue_945; #[cfg(test)] mod pre_parse; + +#[cfg(test)] +/// Common utilities used across tests. +pub(crate) mod util { + use futures::StreamExt as _; + use juniper::{graphql_value, ExecutionError, GraphQLError, ScalarValue, Value, ValuesStream}; + + /// Extracts a single next value from the result returned by + /// [`juniper::resolve_into_stream()`] and transforms it into a regular + /// [`Value`]. + pub(crate) async fn extract_next<'a, S: ScalarValue>( + input: Result<(Value>, Vec>), GraphQLError<'a>>, + ) -> Result<(Value, Vec>), GraphQLError<'a>> { + let (stream, errs) = input?; + if !errs.is_empty() { + return Ok((Value::Null, errs)); + } + + if let Value::Object(obj) = stream { + for (name, mut val) in obj { + if let Value::Scalar(ref mut stream) = val { + return match stream.next().await { + Some(Ok(val)) => Ok((graphql_value!({ name: val }), vec![])), + Some(Err(e)) => Ok((Value::Null, vec![e])), + None => Ok((Value::Null, vec![])), + }; + } + } + } + + panic!("Expected to get Value::Object containing a Stream") + } +} diff --git a/juniper/src/executor_tests/async_await/mod.rs b/juniper/src/executor_tests/async_await/mod.rs index 06750bab..277c0197 100644 --- a/juniper/src/executor_tests/async_await/mod.rs +++ b/juniper/src/executor_tests/async_await/mod.rs @@ -1,4 +1,6 @@ -use crate::{graphql_object, EmptyMutation, EmptySubscription, GraphQLEnum, RootNode, Value}; +use crate::{ + graphql_object, graphql_value, EmptyMutation, EmptySubscription, GraphQLEnum, RootNode, Value, +}; #[derive(GraphQLEnum)] enum UserKind { @@ -74,10 +76,10 @@ impl Query { async fn async_simple() { let schema = RootNode::new(Query, EmptyMutation::new(), EmptySubscription::new()); let doc = r#" - query { + query { fieldSync - fieldAsyncPlain - delayed + fieldAsyncPlain + delayed user(id: "user1") { name } @@ -96,7 +98,7 @@ async fn async_simple() { assert_eq!( value, - crate::graphql_value!({ + graphql_value!({ "delayed": true, "fieldAsyncPlain": "field_async_plain", "fieldSync": "field_sync", diff --git a/juniper/src/executor_tests/directives.rs b/juniper/src/executor_tests/directives.rs index 50cc5a0e..adc05594 100644 --- a/juniper/src/executor_tests/directives.rs +++ b/juniper/src/executor_tests/directives.rs @@ -1,8 +1,9 @@ use crate::{ executor::Variables, + graphql_value, schema::model::RootNode, types::scalars::{EmptyMutation, EmptySubscription}, - value::{DefaultScalarValue, Object, Value}, + value::{DefaultScalarValue, Object}, }; struct TestType; @@ -51,8 +52,8 @@ where #[tokio::test] async fn scalar_include_true() { run_query("{ a, b @include(if: true) }", |result| { - assert_eq!(result.get_field_value("a"), Some(&Value::scalar("a"))); - assert_eq!(result.get_field_value("b"), Some(&Value::scalar("b"))); + assert_eq!(result.get_field_value("a"), Some(&graphql_value!("a"))); + assert_eq!(result.get_field_value("b"), Some(&graphql_value!("b"))); }) .await; } @@ -60,7 +61,7 @@ async fn scalar_include_true() { #[tokio::test] async fn scalar_include_false() { run_query("{ a, b @include(if: false) }", |result| { - assert_eq!(result.get_field_value("a"), Some(&Value::scalar("a"))); + assert_eq!(result.get_field_value("a"), Some(&graphql_value!("a"))); assert_eq!(result.get_field_value("b"), None); }) .await; @@ -69,8 +70,8 @@ async fn scalar_include_false() { #[tokio::test] async fn scalar_skip_false() { run_query("{ a, b @skip(if: false) }", |result| { - assert_eq!(result.get_field_value("a"), Some(&Value::scalar("a"))); - assert_eq!(result.get_field_value("b"), Some(&Value::scalar("b"))); + assert_eq!(result.get_field_value("a"), Some(&graphql_value!("a"))); + assert_eq!(result.get_field_value("b"), Some(&graphql_value!("b"))); }) .await; } @@ -78,7 +79,7 @@ async fn scalar_skip_false() { #[tokio::test] async fn scalar_skip_true() { run_query("{ a, b @skip(if: true) }", |result| { - assert_eq!(result.get_field_value("a"), Some(&Value::scalar("a"))); + assert_eq!(result.get_field_value("a"), Some(&graphql_value!("a"))); assert_eq!(result.get_field_value("b"), None); }) .await; @@ -89,8 +90,8 @@ async fn fragment_spread_include_true() { run_query( "{ a, ...Frag @include(if: true) } fragment Frag on TestType { b }", |result| { - assert_eq!(result.get_field_value("a"), Some(&Value::scalar("a"))); - assert_eq!(result.get_field_value("b"), Some(&Value::scalar("b"))); + assert_eq!(result.get_field_value("a"), Some(&graphql_value!("a"))); + assert_eq!(result.get_field_value("b"), Some(&graphql_value!("b"))); }, ) .await; @@ -101,7 +102,7 @@ async fn fragment_spread_include_false() { run_query( "{ a, ...Frag @include(if: false) } fragment Frag on TestType { b }", |result| { - assert_eq!(result.get_field_value("a"), Some(&Value::scalar("a"))); + assert_eq!(result.get_field_value("a"), Some(&graphql_value!("a"))); assert_eq!(result.get_field_value("b"), None); }, ) @@ -113,8 +114,8 @@ async fn fragment_spread_skip_false() { run_query( "{ a, ...Frag @skip(if: false) } fragment Frag on TestType { b }", |result| { - assert_eq!(result.get_field_value("a"), Some(&Value::scalar("a"))); - assert_eq!(result.get_field_value("b"), Some(&Value::scalar("b"))); + assert_eq!(result.get_field_value("a"), Some(&graphql_value!("a"))); + assert_eq!(result.get_field_value("b"), Some(&graphql_value!("b"))); }, ) .await; @@ -125,7 +126,7 @@ async fn fragment_spread_skip_true() { run_query( "{ a, ...Frag @skip(if: true) } fragment Frag on TestType { b }", |result| { - assert_eq!(result.get_field_value("a"), Some(&Value::scalar("a"))); + assert_eq!(result.get_field_value("a"), Some(&graphql_value!("a"))); assert_eq!(result.get_field_value("b"), None); }, ) @@ -137,8 +138,8 @@ async fn inline_fragment_include_true() { run_query( "{ a, ... on TestType @include(if: true) { b } }", |result| { - assert_eq!(result.get_field_value("a"), Some(&Value::scalar("a"))); - assert_eq!(result.get_field_value("b"), Some(&Value::scalar("b"))); + assert_eq!(result.get_field_value("a"), Some(&graphql_value!("a"))); + assert_eq!(result.get_field_value("b"), Some(&graphql_value!("b"))); }, ) .await; @@ -149,7 +150,7 @@ async fn inline_fragment_include_false() { run_query( "{ a, ... on TestType @include(if: false) { b } }", |result| { - assert_eq!(result.get_field_value("a"), Some(&Value::scalar("a"))); + assert_eq!(result.get_field_value("a"), Some(&graphql_value!("a"))); assert_eq!(result.get_field_value("b"), None); }, ) @@ -159,8 +160,8 @@ async fn inline_fragment_include_false() { #[tokio::test] async fn inline_fragment_skip_false() { run_query("{ a, ... on TestType @skip(if: false) { b } }", |result| { - assert_eq!(result.get_field_value("a"), Some(&Value::scalar("a"))); - assert_eq!(result.get_field_value("b"), Some(&Value::scalar("b"))); + assert_eq!(result.get_field_value("a"), Some(&graphql_value!("a"))); + assert_eq!(result.get_field_value("b"), Some(&graphql_value!("b"))); }) .await; } @@ -168,7 +169,7 @@ async fn inline_fragment_skip_false() { #[tokio::test] async fn inline_fragment_skip_true() { run_query("{ a, ... on TestType @skip(if: true) { b } }", |result| { - assert_eq!(result.get_field_value("a"), Some(&Value::scalar("a"))); + assert_eq!(result.get_field_value("a"), Some(&graphql_value!("a"))); assert_eq!(result.get_field_value("b"), None); }) .await; @@ -177,8 +178,8 @@ async fn inline_fragment_skip_true() { #[tokio::test] async fn anonymous_inline_fragment_include_true() { run_query("{ a, ... @include(if: true) { b } }", |result| { - assert_eq!(result.get_field_value("a"), Some(&Value::scalar("a"))); - assert_eq!(result.get_field_value("b"), Some(&Value::scalar("b"))); + assert_eq!(result.get_field_value("a"), Some(&graphql_value!("a"))); + assert_eq!(result.get_field_value("b"), Some(&graphql_value!("b"))); }) .await; } @@ -186,7 +187,7 @@ async fn anonymous_inline_fragment_include_true() { #[tokio::test] async fn anonymous_inline_fragment_include_false() { run_query("{ a, ... @include(if: false) { b } }", |result| { - assert_eq!(result.get_field_value("a"), Some(&Value::scalar("a"))); + assert_eq!(result.get_field_value("a"), Some(&graphql_value!("a"))); assert_eq!(result.get_field_value("b"), None); }) .await; @@ -195,8 +196,8 @@ async fn anonymous_inline_fragment_include_false() { #[tokio::test] async fn anonymous_inline_fragment_skip_false() { run_query("{ a, ... @skip(if: false) { b } }", |result| { - assert_eq!(result.get_field_value("a"), Some(&Value::scalar("a"))); - assert_eq!(result.get_field_value("b"), Some(&Value::scalar("b"))); + assert_eq!(result.get_field_value("a"), Some(&graphql_value!("a"))); + assert_eq!(result.get_field_value("b"), Some(&graphql_value!("b"))); }) .await; } @@ -204,7 +205,7 @@ async fn anonymous_inline_fragment_skip_false() { #[tokio::test] async fn anonymous_inline_fragment_skip_true() { run_query("{ a, ... @skip(if: true) { b } }", |result| { - assert_eq!(result.get_field_value("a"), Some(&Value::scalar("a"))); + assert_eq!(result.get_field_value("a"), Some(&graphql_value!("a"))); assert_eq!(result.get_field_value("b"), None); }) .await; @@ -213,7 +214,7 @@ async fn anonymous_inline_fragment_skip_true() { #[tokio::test] async fn scalar_include_true_skip_true() { run_query("{ a, b @include(if: true) @skip(if: true) }", |result| { - assert_eq!(result.get_field_value("a"), Some(&Value::scalar("a"))); + assert_eq!(result.get_field_value("a"), Some(&graphql_value!("a"))); assert_eq!(result.get_field_value("b"), None); }) .await; @@ -222,8 +223,8 @@ async fn scalar_include_true_skip_true() { #[tokio::test] async fn scalar_include_true_skip_false() { run_query("{ a, b @include(if: true) @skip(if: false) }", |result| { - assert_eq!(result.get_field_value("a"), Some(&Value::scalar("a"))); - assert_eq!(result.get_field_value("b"), Some(&Value::scalar("b"))); + assert_eq!(result.get_field_value("a"), Some(&graphql_value!("a"))); + assert_eq!(result.get_field_value("b"), Some(&graphql_value!("b"))); }) .await; } @@ -231,7 +232,7 @@ async fn scalar_include_true_skip_false() { #[tokio::test] async fn scalar_include_false_skip_true() { run_query("{ a, b @include(if: false) @skip(if: true) }", |result| { - assert_eq!(result.get_field_value("a"), Some(&Value::scalar("a"))); + assert_eq!(result.get_field_value("a"), Some(&graphql_value!("a"))); assert_eq!(result.get_field_value("b"), None); }) .await; @@ -240,7 +241,7 @@ async fn scalar_include_false_skip_true() { #[tokio::test] async fn scalar_include_false_skip_false() { run_query("{ a, b @include(if: false) @skip(if: false) }", |result| { - assert_eq!(result.get_field_value("a"), Some(&Value::scalar("a"))); + assert_eq!(result.get_field_value("a"), Some(&graphql_value!("a"))); assert_eq!(result.get_field_value("b"), None); }) .await; diff --git a/juniper/src/executor_tests/enums.rs b/juniper/src/executor_tests/enums.rs index bdd7ddcf..8528aa11 100644 --- a/juniper/src/executor_tests/enums.rs +++ b/juniper/src/executor_tests/enums.rs @@ -5,7 +5,7 @@ use crate::{ schema::model::RootNode, types::scalars::{EmptyMutation, EmptySubscription}, validation::RuleError, - value::{DefaultScalarValue, Object, Value}, + value::{DefaultScalarValue, Object}, GraphQLEnum, GraphQLError::ValidationError, }; @@ -64,7 +64,7 @@ async fn accepts_enum_literal() { run_query("{ toString(color: RED) }", |result| { assert_eq!( result.get_field_value("toString"), - Some(&Value::scalar("Color::Red")) + Some(&graphql_value!("Color::Red")), ); }) .await; @@ -75,7 +75,7 @@ async fn serializes_as_output() { run_query("{ aColor }", |result| { assert_eq!( result.get_field_value("aColor"), - Some(&Value::scalar("RED")) + Some(&graphql_value!("RED")), ); }) .await; @@ -115,7 +115,7 @@ async fn accepts_strings_in_variables() { |result| { assert_eq!( result.get_field_value("toString"), - Some(&Value::scalar("Color::Red")) + Some(&graphql_value!("Color::Red")), ); }, ) diff --git a/juniper/src/executor_tests/executor.rs b/juniper/src/executor_tests/executor.rs index 3d6f098d..c9245fe5 100644 --- a/juniper/src/executor_tests/executor.rs +++ b/juniper/src/executor_tests/executor.rs @@ -385,7 +385,6 @@ mod dynamic_context_switching { parser::SourcePosition, schema::model::RootNode, types::scalars::{EmptyMutation, EmptySubscription}, - value::Value, Executor, ScalarValue, }; @@ -485,21 +484,10 @@ mod dynamic_context_switching { assert_eq!( result, - Value::object( - vec![ - ( - "first", - Value::object( - vec![("value", Value::scalar("First value"))] - .into_iter() - .collect(), - ), - ), - ("missing", Value::null()), - ] - .into_iter() - .collect() - ) + graphql_value!({ + "first": {"value": "First value"}, + "missing": None, + }), ); } @@ -545,21 +533,7 @@ mod dynamic_context_switching { println!("Result: {:#?}", result); - assert_eq!( - result, - Value::object( - vec![( - "first", - Value::object( - vec![("value", Value::scalar("First value"))] - .into_iter() - .collect(), - ), - )] - .into_iter() - .collect() - ) - ); + assert_eq!(result, graphql_value!({"first": {"value": "First value"}})); } #[tokio::test] @@ -603,13 +577,13 @@ mod dynamic_context_switching { vec![ExecutionError::new( SourcePosition::new(14, 1, 12), &["missing"], - FieldError::new("Could not find key 2", Value::null()), + FieldError::new("Could not find key 2", graphql_value!(None)), )] ); println!("Result: {:#?}", result); - assert_eq!(result, Value::null()); + assert_eq!(result, graphql_value!(None)); } #[tokio::test] @@ -657,7 +631,7 @@ mod dynamic_context_switching { [ExecutionError::new( SourcePosition::new(123, 4, 12), &["tooLarge"], - FieldError::new("Key too large: 200", Value::null()), + FieldError::new("Key too large: 200", graphql_value!(None)), )] ); @@ -665,22 +639,11 @@ mod dynamic_context_switching { assert_eq!( result, - Value::object( - vec![ - ( - "first", - Value::object( - vec![("value", Value::scalar("First value"))] - .into_iter() - .collect(), - ), - ), - ("missing", Value::null()), - ("tooLarge", Value::null()), - ] - .into_iter() - .collect() - ) + graphql_value!({ + "first": {"value": "First value"}, + "missing": None, + "tooLarge": None, + }), ); } @@ -722,21 +685,7 @@ mod dynamic_context_switching { println!("Result: {:#?}", result); - assert_eq!( - result, - Value::object( - vec![( - "first", - Value::object( - vec![("value", Value::scalar("First value"))] - .into_iter() - .collect(), - ), - )] - .into_iter() - .collect() - ) - ); + assert_eq!(result, graphql_value!({"first": {"value": "First value"}})); } } @@ -832,7 +781,7 @@ mod propagates_errors_to_nullable_fields { vec![ExecutionError::new( SourcePosition::new(10, 0, 10), &["inner", "nullableErrorField"], - FieldError::new("Error for nullableErrorField", Value::null()), + FieldError::new("Error for nullableErrorField", graphql_value!(None)), )] ); } @@ -861,7 +810,7 @@ mod propagates_errors_to_nullable_fields { vec![ExecutionError::new( SourcePosition::new(10, 0, 10), &["inner", "nonNullableErrorField"], - FieldError::new("Error for nonNullableErrorField", Value::null()), + FieldError::new("Error for nonNullableErrorField", graphql_value!(None)), )] ); } @@ -922,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", Value::null()), + FieldError::new("Error for nonNullableErrorField", graphql_value!(None)), )] ); } @@ -951,7 +900,7 @@ mod propagates_errors_to_nullable_fields { vec![ExecutionError::new( SourcePosition::new(29, 0, 29), &["inner", "nonNullableField", "nonNullableErrorField"], - FieldError::new("Error for nonNullableErrorField", Value::null()), + FieldError::new("Error for nonNullableErrorField", graphql_value!(None)), )] ); } @@ -983,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", Value::null()), + FieldError::new("Error for nullableErrorField", graphql_value!(None)), )] ); } @@ -1012,7 +961,7 @@ mod propagates_errors_to_nullable_fields { vec![ExecutionError::new( SourcePosition::new(11, 0, 11), &["inners", "nonNullableErrorField"], - FieldError::new("Error for nonNullableErrorField", Value::null()), + FieldError::new("Error for nonNullableErrorField", graphql_value!(None)), )] ); } @@ -1045,27 +994,27 @@ mod propagates_errors_to_nullable_fields { ExecutionError::new( SourcePosition::new(19, 0, 19), &["nullableInners", "nonNullableErrorField"], - FieldError::new("Error for nonNullableErrorField", Value::null()), + FieldError::new("Error for nonNullableErrorField", graphql_value!(None)), ), ExecutionError::new( SourcePosition::new(19, 0, 19), &["nullableInners", "nonNullableErrorField"], - FieldError::new("Error for nonNullableErrorField", Value::null()), + FieldError::new("Error for nonNullableErrorField", graphql_value!(None)), ), ExecutionError::new( SourcePosition::new(19, 0, 19), &["nullableInners", "nonNullableErrorField"], - FieldError::new("Error for nonNullableErrorField", Value::null()), + FieldError::new("Error for nonNullableErrorField", graphql_value!(None)), ), ExecutionError::new( SourcePosition::new(19, 0, 19), &["nullableInners", "nonNullableErrorField"], - FieldError::new("Error for nonNullableErrorField", Value::null()), + FieldError::new("Error for nonNullableErrorField", graphql_value!(None)), ), ExecutionError::new( SourcePosition::new(19, 0, 19), &["nullableInners", "nonNullableErrorField"], - FieldError::new("Error for nonNullableErrorField", Value::null()), + FieldError::new("Error for nonNullableErrorField", graphql_value!(None)), ), ] ); diff --git a/juniper/src/executor_tests/interfaces_unions.rs b/juniper/src/executor_tests/interfaces_unions.rs index e7fbb902..02787ce5 100644 --- a/juniper/src/executor_tests/interfaces_unions.rs +++ b/juniper/src/executor_tests/interfaces_unions.rs @@ -3,7 +3,6 @@ mod interface { graphql_interface, graphql_object, schema::model::RootNode, types::scalars::{EmptyMutation, EmptySubscription}, - value::Value, }; #[graphql_interface(for = [Cat, Dog])] @@ -126,31 +125,15 @@ mod interface { assert_eq!( result, - Value::object( - vec![( - "pets", - Value::list(vec![ - Value::object( - vec![ - ("name", Value::scalar("Odie")), - ("woofs", Value::scalar(true)), - ] - .into_iter() - .collect(), - ), - Value::object( - vec![ - ("name", Value::scalar("Garfield")), - ("meows", Value::scalar(false)), - ] - .into_iter() - .collect(), - ), - ]), - )] - .into_iter() - .collect() - ) + graphql_value!({ + "pets": [{ + "name": "Odie", + "woofs": true, + }, { + "name": "Garfield", + "meows": false, + }], + }), ); } } @@ -160,7 +143,6 @@ mod union { graphql_object, graphql_union, schema::model::RootNode, types::scalars::{EmptyMutation, EmptySubscription}, - value::Value, }; #[graphql_union] @@ -271,33 +253,17 @@ mod union { assert_eq!( result, - Value::object( - vec![( - "pets", - Value::list(vec![ - Value::object( - vec![ - ("__typename", Value::scalar("Dog")), - ("name", Value::scalar("Odie")), - ("woofs", Value::scalar(true)), - ] - .into_iter() - .collect(), - ), - Value::object( - vec![ - ("__typename", Value::scalar("Cat")), - ("name", Value::scalar("Garfield")), - ("meows", Value::scalar(false)), - ] - .into_iter() - .collect(), - ), - ]), - )] - .into_iter() - .collect() - ) + graphql_value!({ + "pets": [{ + "__typename": "Dog", + "name": "Odie", + "woofs": true, + }, { + "__typename": "Cat", + "name": "Garfield", + "meows": false, + }], + }), ); } } diff --git a/juniper/src/executor_tests/introspection/enums.rs b/juniper/src/executor_tests/introspection/enums.rs index eed50501..1b861523 100644 --- a/juniper/src/executor_tests/introspection/enums.rs +++ b/juniper/src/executor_tests/introspection/enums.rs @@ -1,5 +1,6 @@ use crate::{ executor::Variables, + graphql_value, schema::model::RootNode, types::scalars::{EmptyMutation, EmptySubscription}, value::{DefaultScalarValue, Object, Value}, @@ -142,36 +143,28 @@ async fn default_name_introspection() { run_type_info_query(doc, |(type_info, values)| { assert_eq!( type_info.get_field_value("name"), - Some(&Value::scalar("DefaultName")) + Some(&graphql_value!("DefaultName")), ); assert_eq!( type_info.get_field_value("description"), - Some(&Value::null()) + Some(&graphql_value!(None)), ); assert_eq!(values.len(), 2); - assert!(values.contains(&Value::object( - vec![ - ("name", Value::scalar("FOO")), - ("description", Value::null()), - ("isDeprecated", Value::scalar(false)), - ("deprecationReason", Value::null()), - ] - .into_iter() - .collect(), - ))); + assert!(values.contains(&graphql_value!({ + "name": "FOO", + "description": None, + "isDeprecated": false, + "deprecationReason": None, + }))); - assert!(values.contains(&Value::object( - vec![ - ("name", Value::scalar("BAR")), - ("description", Value::null()), - ("isDeprecated", Value::scalar(false)), - ("deprecationReason", Value::null()), - ] - .into_iter() - .collect(), - ))); + assert!(values.contains(&graphql_value!({ + "name": "BAR", + "description": None, + "isDeprecated": false, + "deprecationReason": None, + }))); }) .await; } @@ -196,36 +189,28 @@ async fn named_introspection() { run_type_info_query(doc, |(type_info, values)| { assert_eq!( type_info.get_field_value("name"), - Some(&Value::scalar("ANamedEnum")) + Some(&graphql_value!("ANamedEnum")), ); assert_eq!( type_info.get_field_value("description"), - Some(&Value::null()) + Some(&graphql_value!(None)), ); assert_eq!(values.len(), 2); - assert!(values.contains(&Value::object( - vec![ - ("name", Value::scalar("FOO")), - ("description", Value::null()), - ("isDeprecated", Value::scalar(false)), - ("deprecationReason", Value::null()), - ] - .into_iter() - .collect(), - ))); + assert!(values.contains(&graphql_value!({ + "name": "FOO", + "description": None, + "isDeprecated": false, + "deprecationReason": None, + }))); - assert!(values.contains(&Value::object( - vec![ - ("name", Value::scalar("BAR")), - ("description", Value::null()), - ("isDeprecated", Value::scalar(false)), - ("deprecationReason", Value::null()), - ] - .into_iter() - .collect(), - ))); + assert!(values.contains(&graphql_value!({ + "name": "BAR", + "description": None, + "isDeprecated": false, + "deprecationReason": None, + }))); }) .await; } @@ -250,36 +235,28 @@ async fn no_trailing_comma_introspection() { run_type_info_query(doc, |(type_info, values)| { assert_eq!( type_info.get_field_value("name"), - Some(&Value::scalar("NoTrailingComma")) + Some(&graphql_value!("NoTrailingComma")), ); assert_eq!( type_info.get_field_value("description"), - Some(&Value::null()) + Some(&graphql_value!(None)), ); assert_eq!(values.len(), 2); - assert!(values.contains(&Value::object( - vec![ - ("name", Value::scalar("FOO")), - ("description", Value::null()), - ("isDeprecated", Value::scalar(false)), - ("deprecationReason", Value::null()), - ] - .into_iter() - .collect(), - ))); + assert!(values.contains(&graphql_value!({ + "name": "FOO", + "description": None, + "isDeprecated": false, + "deprecationReason": None, + }))); - assert!(values.contains(&Value::object( - vec![ - ("name", Value::scalar("BAR")), - ("description", Value::null()), - ("isDeprecated", Value::scalar(false)), - ("deprecationReason", Value::null()), - ] - .into_iter() - .collect(), - ))); + assert!(values.contains(&graphql_value!({ + "name": "BAR", + "description": None, + "isDeprecated": false, + "deprecationReason": None, + }))); }) .await; } @@ -304,36 +281,28 @@ async fn enum_description_introspection() { run_type_info_query(doc, |(type_info, values)| { assert_eq!( type_info.get_field_value("name"), - Some(&Value::scalar("EnumDescription")) + Some(&graphql_value!("EnumDescription")), ); assert_eq!( type_info.get_field_value("description"), - Some(&Value::scalar("A description of the enum itself")) + Some(&graphql_value!("A description of the enum itself")), ); assert_eq!(values.len(), 2); - assert!(values.contains(&Value::object( - vec![ - ("name", Value::scalar("FOO")), - ("description", Value::null()), - ("isDeprecated", Value::scalar(false)), - ("deprecationReason", Value::null()), - ] - .into_iter() - .collect(), - ))); + assert!(values.contains(&graphql_value!({ + "name": "FOO", + "description": None, + "isDeprecated": false, + "deprecationReason": None, + }))); - assert!(values.contains(&Value::object( - vec![ - ("name", Value::scalar("BAR")), - ("description", Value::null()), - ("isDeprecated", Value::scalar(false)), - ("deprecationReason", Value::null()), - ] - .into_iter() - .collect(), - ))); + assert!(values.contains(&graphql_value!({ + "name": "BAR", + "description": None, + "isDeprecated": false, + "deprecationReason": None, + }))); }) .await; } @@ -358,36 +327,28 @@ async fn enum_value_description_introspection() { run_type_info_query(doc, |(type_info, values)| { assert_eq!( type_info.get_field_value("name"), - Some(&Value::scalar("EnumValueDescription")) + Some(&graphql_value!("EnumValueDescription")), ); assert_eq!( type_info.get_field_value("description"), - Some(&Value::null()) + Some(&graphql_value!(None)), ); assert_eq!(values.len(), 2); - assert!(values.contains(&Value::object( - vec![ - ("name", Value::scalar("FOO")), - ("description", Value::scalar("The FOO value")), - ("isDeprecated", Value::scalar(false)), - ("deprecationReason", Value::null()), - ] - .into_iter() - .collect(), - ))); + assert!(values.contains(&graphql_value!({ + "name": "FOO", + "description": "The FOO value", + "isDeprecated": false, + "deprecationReason": None, + }))); - assert!(values.contains(&Value::object( - vec![ - ("name", Value::scalar("BAR")), - ("description", Value::scalar("The BAR value")), - ("isDeprecated", Value::scalar(false)), - ("deprecationReason", Value::null()), - ] - .into_iter() - .collect(), - ))); + assert!(values.contains(&graphql_value!({ + "name": "BAR", + "description": "The BAR value", + "isDeprecated": false, + "deprecationReason": None, + }))); }) .await; } @@ -412,42 +373,28 @@ async fn enum_deprecation_introspection() { run_type_info_query(doc, |(type_info, values)| { assert_eq!( type_info.get_field_value("name"), - Some(&Value::scalar("EnumDeprecation")) + Some(&graphql_value!("EnumDeprecation")), ); assert_eq!( type_info.get_field_value("description"), - Some(&Value::null()) + Some(&graphql_value!(None)), ); assert_eq!(values.len(), 2); - assert!(values.contains(&Value::object( - vec![ - ("name", Value::scalar("FOO")), - ("description", Value::null()), - ("isDeprecated", Value::scalar(true)), - ( - "deprecationReason", - Value::scalar("Please don't use FOO any more"), - ), - ] - .into_iter() - .collect(), - ))); + assert!(values.contains(&graphql_value!({ + "name": "FOO", + "description": None, + "isDeprecated": true, + "deprecationReason": "Please don't use FOO any more", + }))); - assert!(values.contains(&Value::object( - vec![ - ("name", Value::scalar("BAR")), - ("description", Value::scalar("The BAR value")), - ("isDeprecated", Value::scalar(true)), - ( - "deprecationReason", - Value::scalar("Please don't use BAR any more"), - ), - ] - .into_iter() - .collect(), - ))); + assert!(values.contains(&graphql_value!({ + "name": "BAR", + "description": "The BAR value", + "isDeprecated": true, + "deprecationReason": "Please don't use BAR any more", + }))); }) .await; } @@ -472,11 +419,11 @@ async fn enum_deprecation_no_values_introspection() { run_type_info_query(doc, |(type_info, values)| { assert_eq!( type_info.get_field_value("name"), - Some(&Value::scalar("EnumDeprecation")) + Some(&graphql_value!("EnumDeprecation")), ); assert_eq!( type_info.get_field_value("description"), - Some(&Value::null()) + Some(&graphql_value!(None)), ); assert_eq!(values.len(), 0); diff --git a/juniper/src/executor_tests/introspection/mod.rs b/juniper/src/executor_tests/introspection/mod.rs index 8bf6a14e..be6ec7ac 100644 --- a/juniper/src/executor_tests/introspection/mod.rs +++ b/juniper/src/executor_tests/introspection/mod.rs @@ -7,7 +7,7 @@ use self::input_object::{NamedPublic, NamedPublicWithDescription}; use crate::{ executor::Variables, - graphql_interface, graphql_object, graphql_scalar, + graphql_interface, graphql_object, graphql_scalar, graphql_value, schema::model::RootNode, types::scalars::{EmptyMutation, EmptySubscription}, value::{ParseScalarResult, ParseScalarValue, ScalarValue, Value}, @@ -93,15 +93,11 @@ async fn test_execution() { assert_eq!( result, - Value::object( - vec![ - ("sampleEnum", Value::scalar("ONE")), - ("first", Value::scalar(123)), - ("second", Value::scalar(30)), - ] - .into_iter() - .collect() - ) + graphql_value!({ + "sampleEnum": "ONE", + "first": 123, + "second": 30, + }), ); } @@ -150,29 +146,32 @@ async fn enum_introspection() { assert_eq!( type_info.get_field_value("name"), - Some(&Value::scalar("SampleEnum")) + Some(&graphql_value!("SampleEnum")), ); assert_eq!( type_info.get_field_value("kind"), - Some(&Value::scalar("ENUM")) + Some(&graphql_value!("ENUM")), ); assert_eq!( type_info.get_field_value("description"), - Some(&Value::null()) + Some(&graphql_value!(None)), ); assert_eq!( type_info.get_field_value("interfaces"), - Some(&Value::null()) + Some(&graphql_value!(None)), ); assert_eq!( type_info.get_field_value("possibleTypes"), - Some(&Value::null()) + Some(&graphql_value!(None)), ); assert_eq!( type_info.get_field_value("inputFields"), - Some(&Value::null()) + Some(&graphql_value!(None)), + ); + assert_eq!( + type_info.get_field_value("ofType"), + Some(&graphql_value!(None)) ); - assert_eq!(type_info.get_field_value("ofType"), Some(&Value::null())); let values = type_info .get_field_value("enumValues") @@ -182,27 +181,19 @@ async fn enum_introspection() { assert_eq!(values.len(), 2); - assert!(values.contains(&Value::object( - vec![ - ("name", Value::scalar("ONE")), - ("description", Value::null()), - ("isDeprecated", Value::scalar(false)), - ("deprecationReason", Value::null()), - ] - .into_iter() - .collect(), - ))); + assert!(values.contains(&graphql_value!({ + "name": "ONE", + "description": None, + "isDeprecated": false, + "deprecationReason": None, + }))); - assert!(values.contains(&Value::object( - vec![ - ("name", Value::scalar("TWO")), - ("description", Value::null()), - ("isDeprecated", Value::scalar(false)), - ("deprecationReason", Value::null()), - ] - .into_iter() - .collect(), - ))); + assert!(values.contains(&graphql_value!({ + "name": "TWO", + "description": None, + "isDeprecated": false, + "deprecationReason": None, + }))); } #[tokio::test] @@ -264,29 +255,32 @@ async fn interface_introspection() { assert_eq!( type_info.get_field_value("name"), - Some(&Value::scalar("SampleInterface")) + Some(&graphql_value!("SampleInterface")), ); assert_eq!( type_info.get_field_value("kind"), - Some(&Value::scalar("INTERFACE")) + Some(&graphql_value!("INTERFACE")), ); assert_eq!( type_info.get_field_value("description"), - Some(&Value::scalar("A sample interface")) + Some(&graphql_value!("A sample interface")), ); assert_eq!( type_info.get_field_value("interfaces"), - Some(&Value::null()) + Some(&graphql_value!(None)), ); assert_eq!( type_info.get_field_value("enumValues"), - Some(&Value::null()) + Some(&graphql_value!(None)), ); assert_eq!( type_info.get_field_value("inputFields"), - Some(&Value::null()) + Some(&graphql_value!(None)), + ); + assert_eq!( + type_info.get_field_value("ofType"), + Some(&graphql_value!(None)) ); - assert_eq!(type_info.get_field_value("ofType"), Some(&Value::null())); let possible_types = type_info .get_field_value("possibleTypes") @@ -296,9 +290,7 @@ async fn interface_introspection() { assert_eq!(possible_types.len(), 1); - assert!(possible_types.contains(&Value::object( - vec![("name", Value::scalar("Root"))].into_iter().collect() - ))); + assert!(possible_types.contains(&graphql_value!({"name": "Root"}))); let fields = type_info .get_field_value("fields") @@ -308,42 +300,21 @@ async fn interface_introspection() { assert_eq!(fields.len(), 1); - assert!(fields.contains(&Value::object( - vec![ - ("name", Value::scalar("sampleEnum")), - ( - "description", - Value::scalar("A sample field in the interface"), - ), - ("args", Value::list(vec![])), - ( - "type", - Value::object( - vec![ - ("name", Value::null()), - ("kind", Value::scalar("NON_NULL")), - ( - "ofType", - Value::object( - vec![ - ("name", Value::scalar("SampleEnum")), - ("kind", Value::scalar("ENUM")), - ] - .into_iter() - .collect(), - ), - ), - ] - .into_iter() - .collect(), - ), - ), - ("isDeprecated", Value::scalar(false)), - ("deprecationReason", Value::null()), - ] - .into_iter() - .collect(), - ))); + assert!(fields.contains(&graphql_value!({ + "name": "sampleEnum", + "description": "A sample field in the interface", + "args": [], + "type": { + "name": None, + "kind": "NON_NULL", + "ofType": { + "name": "SampleEnum", + "kind": "ENUM", + }, + }, + "isDeprecated": false, + "deprecationReason": None, + }))); } #[tokio::test] @@ -416,36 +387,35 @@ async fn object_introspection() { assert_eq!( type_info.get_field_value("name"), - Some(&Value::scalar("Root")) + Some(&graphql_value!("Root")), ); assert_eq!( type_info.get_field_value("kind"), - Some(&Value::scalar("OBJECT")) + Some(&graphql_value!("OBJECT")), ); assert_eq!( type_info.get_field_value("description"), - Some(&Value::scalar("The root query object in the schema")) + Some(&graphql_value!("The root query object in the schema")), ); assert_eq!( type_info.get_field_value("interfaces"), - Some(&Value::list(vec![Value::object( - vec![("name", Value::scalar("SampleInterface"))] - .into_iter() - .collect(), - )])) + Some(&graphql_value!([{"name": "SampleInterface"}])), ); assert_eq!( type_info.get_field_value("enumValues"), - Some(&Value::null()) + Some(&graphql_value!(None)), ); assert_eq!( type_info.get_field_value("inputFields"), - Some(&Value::null()) + Some(&graphql_value!(None)), + ); + assert_eq!( + type_info.get_field_value("ofType"), + Some(&graphql_value!(None)) ); - assert_eq!(type_info.get_field_value("ofType"), Some(&Value::null())); assert_eq!( type_info.get_field_value("possibleTypes"), - Some(&Value::null()) + Some(&graphql_value!(None)), ); let fields = type_info @@ -458,133 +428,59 @@ async fn object_introspection() { println!("Fields: {:#?}", fields); - assert!(fields.contains(&Value::object( - vec![ - ("name", Value::scalar("sampleEnum")), - ("description", Value::null()), - ("args", Value::list(vec![])), - ( - "type", - Value::object( - vec![ - ("name", Value::null()), - ("kind", Value::scalar("NON_NULL")), - ( - "ofType", - Value::object( - vec![ - ("name", Value::scalar("SampleEnum")), - ("kind", Value::scalar("ENUM")), - ] - .into_iter() - .collect(), - ), - ), - ] - .into_iter() - .collect(), - ), - ), - ("isDeprecated", Value::scalar(false)), - ("deprecationReason", Value::null()), - ] - .into_iter() - .collect(), - ))); + assert!(fields.contains(&graphql_value!({ + "name": "sampleEnum", + "description": None, + "args": [], + "type": { + "name": None, + "kind": "NON_NULL", + "ofType": { + "name": "SampleEnum", + "kind": "ENUM", + }, + }, + "isDeprecated": false, + "deprecationReason": None, + }))); - assert!(fields.contains(&Value::object( - vec![ - ("name", Value::scalar("sampleScalar")), - ( - "description", - Value::scalar("A sample scalar field on the object"), - ), - ( - "args", - Value::list(vec![ - Value::object( - vec![ - ("name", Value::scalar("first")), - ("description", Value::scalar("The first number")), - ( - "type", - Value::object( - vec![ - ("name", Value::null()), - ("kind", Value::scalar("NON_NULL")), - ( - "ofType", - Value::object( - vec![ - ("name", Value::scalar("Int")), - ("kind", Value::scalar("SCALAR")), - ("ofType", Value::null()), - ] - .into_iter() - .collect(), - ), - ), - ] - .into_iter() - .collect(), - ), - ), - ("defaultValue", Value::null()), - ] - .into_iter() - .collect(), - ), - Value::object( - vec![ - ("name", Value::scalar("second")), - ("description", Value::scalar("The second number")), - ( - "type", - Value::object( - vec![ - ("name", Value::scalar("Int")), - ("kind", Value::scalar("SCALAR")), - ("ofType", Value::null()), - ] - .into_iter() - .collect(), - ), - ), - ("defaultValue", Value::scalar("123")), - ] - .into_iter() - .collect(), - ), - ]), - ), - ( - "type", - Value::object( - vec![ - ("name", Value::null()), - ("kind", Value::scalar("NON_NULL")), - ( - "ofType", - Value::object( - vec![ - ("name", Value::scalar("SampleScalar")), - ("kind", Value::scalar("SCALAR")), - ] - .into_iter() - .collect(), - ), - ), - ] - .into_iter() - .collect(), - ), - ), - ("isDeprecated", Value::scalar(false)), - ("deprecationReason", Value::null()), - ] - .into_iter() - .collect(), - ))); + assert!(fields.contains(&graphql_value!({ + "name": "sampleScalar", + "description": "A sample scalar field on the object", + "args": [{ + "name": "first", + "description": "The first number", + "type": { + "name": None, + "kind": "NON_NULL", + "ofType": { + "name": "Int", + "kind": "SCALAR", + "ofType": None, + }, + }, + "defaultValue": None, + }, { + "name": "second", + "description": "The second number", + "type": { + "name": "Int", + "kind": "SCALAR", + "ofType": None, + }, + "defaultValue": "123", + }], + "type": { + "name": None, + "kind": "NON_NULL", + "ofType": { + "name": "SampleScalar", + "kind": "SCALAR", + }, + }, + "isDeprecated": false, + "deprecationReason": None, + }))); } #[tokio::test] @@ -626,20 +522,16 @@ async fn scalar_introspection() { assert_eq!( type_info, - &Value::object( - vec![ - ("name", Value::scalar("SampleScalar")), - ("kind", Value::scalar("SCALAR")), - ("description", Value::null()), - ("fields", Value::null()), - ("interfaces", Value::null()), - ("possibleTypes", Value::null()), - ("enumValues", Value::null()), - ("inputFields", Value::null()), - ("ofType", Value::null()), - ] - .into_iter() - .collect() - ) + &graphql_value!({ + "name": "SampleScalar", + "kind": "SCALAR", + "description": None, + "fields": None, + "interfaces": None, + "possibleTypes": None, + "enumValues": None, + "inputFields": None, + "ofType": None, + }), ); } diff --git a/juniper/src/executor_tests/variables.rs b/juniper/src/executor_tests/variables.rs index 1cefcb83..fa8739fd 100644 --- a/juniper/src/executor_tests/variables.rs +++ b/juniper/src/executor_tests/variables.rs @@ -1,12 +1,12 @@ use crate::{ ast::InputValue, executor::Variables, - graphql_object, graphql_scalar, + graphql_object, graphql_scalar, graphql_value, parser::SourcePosition, schema::model::RootNode, types::scalars::{EmptyMutation, EmptySubscription}, validation::RuleError, - value::{DefaultScalarValue, Object, ParseScalarResult, ParseScalarValue, ScalarValue, Value}, + value::{DefaultScalarValue, Object, ParseScalarResult, ParseScalarValue, ScalarValue}, GraphQLError::ValidationError, GraphQLInputObject, }; @@ -17,7 +17,7 @@ struct TestComplexScalar; #[graphql_scalar] impl GraphQLScalar for TestComplexScalar { fn resolve(&self) -> Value { - Value::scalar(String::from("SerializedValue")) + graphql_value!("SerializedValue") } fn from_input_value(v: &InputValue) -> Option { @@ -157,7 +157,7 @@ async fn inline_complex_input() { |result: &Object| { assert_eq!( result.get_field_value("fieldWithObjectInput"), - Some(&Value::scalar( + Some(&graphql_value!( r#"Some(TestInputObject { a: Some("foo"), b: Some([Some("bar")]), c: "baz", d: None })"# )) ); @@ -172,7 +172,7 @@ async fn inline_parse_single_value_to_list() { |result: &Object| { assert_eq!( result.get_field_value("fieldWithObjectInput"), - Some(&Value::scalar( + Some(&graphql_value!( r#"Some(TestInputObject { a: Some("foo"), b: Some([Some("bar")]), c: "baz", d: None })"# )) ); @@ -187,7 +187,7 @@ async fn inline_runs_from_input_value_on_scalar() { |result: &Object| { assert_eq!( result.get_field_value("fieldWithObjectInput"), - Some(&Value::scalar( + Some(&graphql_value!( r#"Some(TestInputObject { a: None, b: None, c: "baz", d: Some(TestComplexScalar) })"# )) ); @@ -216,7 +216,7 @@ async fn variable_complex_input() { |result: &Object| { assert_eq!( result.get_field_value("fieldWithObjectInput"), - Some(&Value::scalar( + Some(&graphql_value!( r#"Some(TestInputObject { a: Some("foo"), b: Some([Some("bar")]), c: "baz", d: None })"# )) ); @@ -245,7 +245,7 @@ async fn variable_parse_single_value_to_list() { |result: &Object| { assert_eq!( result.get_field_value("fieldWithObjectInput"), - Some(&Value::scalar( + Some(&graphql_value!( r#"Some(TestInputObject { a: Some("foo"), b: Some([Some("bar")]), c: "baz", d: None })"# )) ); @@ -273,7 +273,7 @@ async fn variable_runs_from_input_value_on_scalar() { |result: &Object| { assert_eq!( result.get_field_value("fieldWithObjectInput"), - Some(&Value::scalar( + Some(&graphql_value!( r#"Some(TestInputObject { a: None, b: None, c: "baz", d: Some(TestComplexScalar) })"# )) ); @@ -468,7 +468,7 @@ async fn allow_nullable_inputs_to_be_omitted() { |result: &Object| { assert_eq!( result.get_field_value("fieldWithNullableStringInput"), - Some(&Value::scalar(r#"None"#)) + Some(&graphql_value!(r#"None"#)) ); }, ) @@ -482,7 +482,7 @@ async fn allow_nullable_inputs_to_be_omitted_in_variable() { |result: &Object| { assert_eq!( result.get_field_value("fieldWithNullableStringInput"), - Some(&Value::scalar(r#"None"#)) + Some(&graphql_value!(r#"None"#)) ); }, ) @@ -496,7 +496,7 @@ async fn allow_nullable_inputs_to_be_explicitly_null() { |result: &Object| { assert_eq!( result.get_field_value("fieldWithNullableStringInput"), - Some(&Value::scalar(r#"None"#)) + Some(&graphql_value!(r#"None"#)) ); }, ) @@ -513,7 +513,7 @@ async fn allow_nullable_inputs_to_be_set_to_null_in_variable() { |result: &Object| { assert_eq!( result.get_field_value("fieldWithNullableStringInput"), - Some(&Value::scalar(r#"None"#)) + Some(&graphql_value!(r#"None"#)) ); }, ) @@ -530,7 +530,7 @@ async fn allow_nullable_inputs_to_be_set_to_value_in_variable() { |result: &Object| { assert_eq!( result.get_field_value("fieldWithNullableStringInput"), - Some(&Value::scalar(r#"Some("a")"#)) + Some(&graphql_value!(r#"Some("a")"#)) ); }, ) @@ -544,7 +544,7 @@ async fn allow_nullable_inputs_to_be_set_to_value_directly() { |result: &Object| { assert_eq!( result.get_field_value("fieldWithNullableStringInput"), - Some(&Value::scalar(r#"Some("a")"#)) + Some(&graphql_value!(r#"Some("a")"#)) ); }, ) @@ -611,7 +611,7 @@ async fn allow_non_nullable_inputs_to_be_set_to_value_in_variable() { |result| { assert_eq!( result.get_field_value("fieldWithNonNullableStringInput"), - Some(&Value::scalar(r#""a""#)) + Some(&graphql_value!(r#""a""#)) ); }, ) @@ -625,7 +625,7 @@ async fn allow_non_nullable_inputs_to_be_set_to_value_directly() { |result: &Object| { assert_eq!( result.get_field_value("fieldWithNonNullableStringInput"), - Some(&Value::scalar(r#""a""#)) + Some(&graphql_value!(r#""a""#)) ); }, ) @@ -642,7 +642,7 @@ async fn allow_lists_to_be_null() { |result: &Object| { assert_eq!( result.get_field_value("list"), - Some(&Value::scalar(r#"None"#)) + Some(&graphql_value!(r#"None"#)) ); }, ) @@ -662,7 +662,7 @@ async fn allow_lists_to_contain_values() { |result| { assert_eq!( result.get_field_value("list"), - Some(&Value::scalar(r#"Some([Some("A")])"#)) + Some(&graphql_value!(r#"Some([Some("A")])"#)) ); }, ) @@ -686,7 +686,7 @@ async fn allow_lists_to_contain_null() { |result| { assert_eq!( result.get_field_value("list"), - Some(&Value::scalar(r#"Some([Some("A"), None, Some("B")])"#)) + Some(&graphql_value!(r#"Some([Some("A"), None, Some("B")])"#)) ); }, ) @@ -732,7 +732,7 @@ async fn allow_non_null_lists_to_contain_values() { |result| { assert_eq!( result.get_field_value("nnList"), - Some(&Value::scalar(r#"[Some("A")]"#)) + Some(&graphql_value!(r#"[Some("A")]"#)) ); }, ) @@ -755,7 +755,7 @@ async fn allow_non_null_lists_to_contain_null() { |result| { assert_eq!( result.get_field_value("nnList"), - Some(&Value::scalar(r#"[Some("A"), None, Some("B")]"#)) + Some(&graphql_value!(r#"[Some("A"), None, Some("B")]"#)) ); }, ) @@ -772,7 +772,7 @@ async fn allow_lists_of_non_null_to_be_null() { |result| { assert_eq!( result.get_field_value("listNn"), - Some(&Value::scalar(r#"None"#)) + Some(&graphql_value!(r#"None"#)), ); }, ) @@ -792,7 +792,7 @@ async fn allow_lists_of_non_null_to_contain_values() { |result| { assert_eq!( result.get_field_value("listNn"), - Some(&Value::scalar(r#"Some(["A"])"#)) + Some(&graphql_value!(r#"Some(["A"])"#)), ); }, ) @@ -904,7 +904,7 @@ async fn allow_non_null_lists_of_non_null_to_contain_values() { |result| { assert_eq!( result.get_field_value("nnListNn"), - Some(&Value::scalar(r#"["A"]"#)) + Some(&graphql_value!(r#"["A"]"#)), ); }, ) @@ -916,7 +916,7 @@ async fn default_argument_when_not_provided() { run_query(r#"{ fieldWithDefaultArgumentValue }"#, |result| { assert_eq!( result.get_field_value("fieldWithDefaultArgumentValue"), - Some(&Value::scalar(r#""Hello World""#)) + Some(&graphql_value!(r#""Hello World""#)), ); }) .await; @@ -929,7 +929,7 @@ async fn default_argument_when_nullable_variable_not_provided() { |result| { assert_eq!( result.get_field_value("fieldWithDefaultArgumentValue"), - Some(&Value::scalar(r#""Hello World""#)) + Some(&graphql_value!(r#""Hello World""#)), ); }, ) @@ -946,7 +946,7 @@ async fn default_argument_when_nullable_variable_set_to_null() { |result| { assert_eq!( result.get_field_value("fieldWithDefaultArgumentValue"), - Some(&Value::scalar(r#""Hello World""#)) + Some(&graphql_value!(r#""Hello World""#)), ); }, ) @@ -958,7 +958,7 @@ async fn nullable_input_object_arguments_successful_without_variables() { run_query(r#"{ exampleInput(arg: {a: "abc", b: 123}) }"#, |result| { assert_eq!( result.get_field_value("exampleInput"), - Some(&Value::scalar(r#"a: Some("abc"), b: 123"#)) + Some(&graphql_value!(r#"a: Some("abc"), b: 123"#)), ); }) .await; @@ -966,7 +966,7 @@ async fn nullable_input_object_arguments_successful_without_variables() { run_query(r#"{ exampleInput(arg: {a: null, b: 1}) }"#, |result| { assert_eq!( result.get_field_value("exampleInput"), - Some(&Value::scalar(r#"a: None, b: 1"#)) + Some(&graphql_value!(r#"a: None, b: 1"#)), ); }) .await; @@ -982,7 +982,7 @@ async fn nullable_input_object_arguments_successful_with_variables() { |result| { assert_eq!( result.get_field_value("exampleInput"), - Some(&Value::scalar(r#"a: None, b: 123"#)) + Some(&graphql_value!(r#"a: None, b: 123"#)), ); }, ) @@ -996,7 +996,7 @@ async fn nullable_input_object_arguments_successful_with_variables() { |result| { assert_eq!( result.get_field_value("exampleInput"), - Some(&Value::scalar(r#"a: None, b: 1"#)) + Some(&graphql_value!(r#"a: None, b: 1"#)), ); }, ) @@ -1008,7 +1008,7 @@ async fn nullable_input_object_arguments_successful_with_variables() { |result| { assert_eq!( result.get_field_value("exampleInput"), - Some(&Value::scalar(r#"a: None, b: 1"#)) + Some(&graphql_value!(r#"a: None, b: 1"#)), ); }, ) @@ -1118,7 +1118,7 @@ async fn input_object_with_default_values() { run_query(r#"{ inputWithDefaults(arg: {a: 1}) }"#, |result| { assert_eq!( result.get_field_value("inputWithDefaults"), - Some(&Value::scalar(r#"a: 1"#)) + Some(&graphql_value!(r#"a: 1"#)), ); }) .await; @@ -1131,7 +1131,7 @@ async fn input_object_with_default_values() { |result| { assert_eq!( result.get_field_value("inputWithDefaults"), - Some(&Value::scalar(r#"a: 1"#)) + Some(&graphql_value!(r#"a: 1"#)), ); }, ) @@ -1143,7 +1143,7 @@ async fn input_object_with_default_values() { |result| { assert_eq!( result.get_field_value("inputWithDefaults"), - Some(&Value::scalar(r#"a: 1"#)) + Some(&graphql_value!(r#"a: 1"#)), ); }, ) @@ -1157,7 +1157,7 @@ async fn input_object_with_default_values() { |result| { assert_eq!( result.get_field_value("inputWithDefaults"), - Some(&Value::scalar(r#"a: 2"#)) + Some(&graphql_value!(r#"a: 2"#)), ); }, ) @@ -1177,7 +1177,7 @@ mod integers { |result| { assert_eq!( result.get_field_value("integerInput"), - Some(&Value::scalar(r#"value: 1"#)) + Some(&graphql_value!(r#"value: 1"#)), ); }, ) @@ -1191,7 +1191,7 @@ mod integers { |result| { assert_eq!( result.get_field_value("integerInput"), - Some(&Value::scalar(r#"value: -1"#)) + Some(&graphql_value!(r#"value: -1"#)), ); }, ) @@ -1264,7 +1264,7 @@ mod floats { |result| { assert_eq!( result.get_field_value("floatInput"), - Some(&Value::scalar(r#"value: 10"#)) + Some(&graphql_value!(r#"value: 10"#)), ); }, ) @@ -1281,7 +1281,7 @@ mod floats { |result| { assert_eq!( result.get_field_value("floatInput"), - Some(&Value::scalar(r#"value: -1"#)) + Some(&graphql_value!(r#"value: -1"#)), ); }, ) diff --git a/juniper/src/integrations/chrono.rs b/juniper/src/integrations/chrono.rs index 56613fdd..dec58f14 100644 --- a/juniper/src/integrations/chrono.rs +++ b/juniper/src/integrations/chrono.rs @@ -177,7 +177,7 @@ mod test { } fn datetime_utc_test(raw: &'static str) { - let input: crate::InputValue = InputValue::scalar(raw.to_string()); + let input = >::scalar(raw.to_string()); let parsed: DateTime = crate::FromInputValue::from_input_value(&input).unwrap(); let expected = DateTime::parse_from_rfc3339(raw) @@ -237,7 +237,7 @@ mod test { #[test] fn naivedatetime_from_input_value() { let raw = 1_000_000_000_f64; - let input: InputValue = InputValue::scalar(raw); + let input = >::scalar(raw); let parsed: NaiveDateTime = crate::FromInputValue::from_input_value(&input).unwrap(); let expected = NaiveDateTime::from_timestamp_opt(raw as i64, 0).unwrap(); diff --git a/juniper/src/integrations/url.rs b/juniper/src/integrations/url.rs index 492626bd..844a9c02 100644 --- a/juniper/src/integrations/url.rs +++ b/juniper/src/integrations/url.rs @@ -27,13 +27,14 @@ where #[cfg(test)] mod test { - use crate::InputValue; use url::Url; + use crate::{DefaultScalarValue, InputValue}; + #[test] fn url_from_input_value() { let raw = "https://example.net/"; - let input: InputValue = InputValue::scalar(raw.to_string()); + let input = >::scalar(raw.to_string()); 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 1f677d65..0dee5bc0 100644 --- a/juniper/src/integrations/uuid.rs +++ b/juniper/src/integrations/uuid.rs @@ -40,7 +40,7 @@ mod test { #[test] fn uuid_from_input_value() { let raw = "123e4567-e89b-12d3-a456-426655440000"; - let input: InputValue = InputValue::scalar(raw.to_string()); + let input = >::scalar(raw.to_string()); let parsed: Uuid = crate::FromInputValue::from_input_value(&input).unwrap(); let id = Uuid::parse_str(raw).unwrap(); diff --git a/juniper/src/tests/query_tests.rs b/juniper/src/tests/query_tests.rs index 32d79c1c..3091a1ea 100644 --- a/juniper/src/tests/query_tests.rs +++ b/juniper/src/tests/query_tests.rs @@ -5,17 +5,15 @@ use crate::{ schema::model::RootNode, tests::fixtures::starwars::schema::{Database, Query}, types::scalars::{EmptyMutation, EmptySubscription}, - value::Value, }; #[tokio::test] async fn test_hero_name() { - let doc = r#" - { - hero { - name - } - }"#; + let doc = r#"{ + hero { + name + } + }"#; let database = Database::new(); let schema = RootNode::new( Query, @@ -25,17 +23,7 @@ async fn test_hero_name() { assert_eq!( crate::execute(doc, None, &schema, &Variables::new(), &database).await, - Ok(( - Value::object( - vec![( - "hero", - Value::object(vec![("name", Value::scalar("R2-D2"))].into_iter().collect()), - )] - .into_iter() - .collect() - ), - vec![] - )) + Ok((graphql_value!({"hero": {"name": "R2-D2"}}), vec![])), ); } @@ -48,77 +36,46 @@ async fn test_hero_field_order() { EmptySubscription::::new(), ); - let doc = r#" - { - hero { - id - name - } - }"#; + let doc = r#"{ + hero { + id + name + } + }"#; assert_eq!( crate::execute(doc, None, &schema, &Variables::new(), &database).await, Ok(( - Value::object( - vec![( - "hero", - Value::object( - vec![ - ("id", Value::scalar("2001")), - ("name", Value::scalar("R2-D2")), - ] - .into_iter() - .collect(), - ), - )] - .into_iter() - .collect() - ), - vec![] - )) + graphql_value!({"hero": {"id": "2001", "name": "R2-D2"}}), + vec![], + )), ); - let doc_reversed = r#" - { - hero { - name - id - } - }"#; + let doc_reversed = r#"{ + hero { + name + id + } + }"#; assert_eq!( crate::execute(doc_reversed, None, &schema, &Variables::new(), &database).await, Ok(( - Value::object( - vec![( - "hero", - Value::object( - vec![ - ("name", Value::scalar("R2-D2")), - ("id", Value::scalar("2001")), - ] - .into_iter() - .collect(), - ), - )] - .into_iter() - .collect() - ), - vec![] - )) + graphql_value!({"hero": {"name": "R2-D2", "id": "2001"}}), + vec![], + )), ); } #[tokio::test] async fn test_hero_name_and_friends() { - let doc = r#" - { - hero { - id + let doc = r#"{ + hero { + id + name + friends { name - friends { - name - } } - }"#; + } + }"#; let database = Database::new(); let schema = RootNode::new( Query, @@ -129,62 +86,35 @@ async fn test_hero_name_and_friends() { assert_eq!( crate::execute(doc, None, &schema, &Variables::new(), &database).await, Ok(( - Value::object( - vec![( - "hero", - Value::object( - vec![ - ("id", Value::scalar("2001")), - ("name", Value::scalar("R2-D2")), - ( - "friends", - Value::list(vec![ - Value::object( - vec![("name", Value::scalar("Luke Skywalker"))] - .into_iter() - .collect(), - ), - Value::object( - vec![("name", Value::scalar("Han Solo"))] - .into_iter() - .collect(), - ), - Value::object( - vec![("name", Value::scalar("Leia Organa"))] - .into_iter() - .collect(), - ), - ]), - ), - ] - .into_iter() - .collect(), - ), - )] - .into_iter() - .collect() - ), - vec![] - )) + graphql_value!({"hero": { + "id": "2001", + "name": "R2-D2", + "friends": [ + {"name": "Luke Skywalker"}, + {"name": "Han Solo"}, + {"name": "Leia Organa"}, + ], + }}), + vec![], + )), ); } #[tokio::test] async fn test_hero_name_and_friends_and_friends_of_friends() { - let doc = r#" - { - hero { - id + let doc = r#"{ + hero { + id + name + friends { name + appearsIn friends { - name - appearsIn - friends { - name - } + name } } - }"#; + } + }"#; let database = Database::new(); let schema = RootNode::new( Query, @@ -195,155 +125,39 @@ async fn test_hero_name_and_friends_and_friends_of_friends() { assert_eq!( crate::execute(doc, None, &schema, &Variables::new(), &database).await, Ok(( - Value::object( - vec![( - "hero", - Value::object( - vec![ - ("id", Value::scalar("2001")), - ("name", Value::scalar("R2-D2")), - ( - "friends", - Value::list(vec![ - Value::object( - vec![ - ("name", Value::scalar("Luke Skywalker")), - ( - "appearsIn", - Value::list(vec![ - Value::scalar("NEW_HOPE"), - Value::scalar("EMPIRE"), - Value::scalar("JEDI"), - ]), - ), - ( - "friends", - Value::list(vec![ - Value::object( - vec![("name", Value::scalar("Han Solo"))] - .into_iter() - .collect(), - ), - Value::object( - vec![( - "name", - Value::scalar("Leia Organa"), - )] - .into_iter() - .collect(), - ), - Value::object( - vec![("name", Value::scalar("C-3PO"))] - .into_iter() - .collect(), - ), - Value::object( - vec![("name", Value::scalar("R2-D2"))] - .into_iter() - .collect(), - ), - ]), - ), - ] - .into_iter() - .collect(), - ), - Value::object( - vec![ - ("name", Value::scalar("Han Solo")), - ( - "appearsIn", - Value::list(vec![ - Value::scalar("NEW_HOPE"), - Value::scalar("EMPIRE"), - Value::scalar("JEDI"), - ]), - ), - ( - "friends", - Value::list(vec![ - Value::object( - vec![( - "name", - Value::scalar("Luke Skywalker"), - )] - .into_iter() - .collect(), - ), - Value::object( - vec![( - "name", - Value::scalar("Leia Organa"), - )] - .into_iter() - .collect(), - ), - Value::object( - vec![("name", Value::scalar("R2-D2"))] - .into_iter() - .collect(), - ), - ]), - ), - ] - .into_iter() - .collect(), - ), - Value::object( - vec![ - ("name", Value::scalar("Leia Organa")), - ( - "appearsIn", - Value::list(vec![ - Value::scalar("NEW_HOPE"), - Value::scalar("EMPIRE"), - Value::scalar("JEDI"), - ]), - ), - ( - "friends", - Value::list(vec![ - Value::object( - vec![( - "name", - Value::scalar("Luke Skywalker"), - )] - .into_iter() - .collect(), - ), - Value::object( - vec![("name", Value::scalar("Han Solo"))] - .into_iter() - .collect(), - ), - Value::object( - vec![("name", Value::scalar("C-3PO"))] - .into_iter() - .collect(), - ), - Value::object( - vec![("name", Value::scalar("R2-D2"))] - .into_iter() - .collect(), - ), - ]), - ), - ] - .into_iter() - .collect(), - ), - ]), - ), - ] - .into_iter() - .collect(), - ), - )] - .into_iter() - .collect() - ), - vec![] - )) + graphql_value!({"hero": { + "id": "2001", + "name": "R2-D2", + "friends": [{ + "name": "Luke Skywalker", + "appearsIn": ["NEW_HOPE", "EMPIRE", "JEDI"], + "friends": [ + {"name": "Han Solo"}, + {"name": "Leia Organa"}, + {"name": "C-3PO"}, + {"name": "R2-D2"}, + ], + }, { + "name": "Han Solo", + "appearsIn": ["NEW_HOPE", "EMPIRE", "JEDI"], + "friends": [ + {"name": "Luke Skywalker"}, + {"name": "Leia Organa"}, + {"name": "R2-D2"}, + ], + }, { + "name": "Leia Organa", + "appearsIn": ["NEW_HOPE", "EMPIRE", "JEDI"], + "friends": [ + {"name": "Luke Skywalker"}, + {"name": "Han Solo"}, + {"name": "C-3PO"}, + {"name": "R2-D2"}, + ], + }], + }}), + vec![], + )), ); } @@ -360,20 +174,9 @@ async fn test_query_name() { assert_eq!( crate::execute(doc, None, &schema, &Variables::new(), &database).await, Ok(( - Value::object( - vec![( - "human", - Value::object( - vec![("name", Value::scalar("Luke Skywalker"))] - .into_iter() - .collect(), - ), - )] - .into_iter() - .collect() - ), - vec![] - )) + graphql_value!({"human": {"name": "Luke Skywalker"}}), + vec![], + )), ); } @@ -389,31 +192,16 @@ async fn test_query_alias_single() { assert_eq!( crate::execute(doc, None, &schema, &Variables::new(), &database).await, - Ok(( - Value::object( - vec![( - "luke", - Value::object( - vec![("name", Value::scalar("Luke Skywalker"))] - .into_iter() - .collect(), - ), - )] - .into_iter() - .collect() - ), - vec![] - )) + Ok((graphql_value!({"luke": {"name": "Luke Skywalker"}}), vec![])), ); } #[tokio::test] async fn test_query_alias_multiple() { - let doc = r#" - { - luke: human(id: "1000") { name } - leia: human(id: "1003") { name } - }"#; + let doc = r#"{ + luke: human(id: "1000") { name } + leia: human(id: "1003") { name } + }"#; let database = Database::new(); let schema = RootNode::new( Query, @@ -424,30 +212,12 @@ async fn test_query_alias_multiple() { assert_eq!( crate::execute(doc, None, &schema, &Variables::new(), &database).await, Ok(( - Value::object( - vec![ - ( - "luke", - Value::object( - vec![("name", Value::scalar("Luke Skywalker"))] - .into_iter() - .collect(), - ), - ), - ( - "leia", - Value::object( - vec![("name", Value::scalar("Leia Organa"))] - .into_iter() - .collect(), - ), - ), - ] - .into_iter() - .collect() - ), - vec![] - )) + graphql_value!({ + "luke": {"name": "Luke Skywalker"}, + "leia": {"name": "Leia Organa"}, + }), + vec![], + )), ); } @@ -473,36 +243,12 @@ async fn test_query_alias_multiple_with_fragment() { assert_eq!( crate::execute(doc, None, &schema, &Variables::new(), &database).await, Ok(( - Value::object( - vec![ - ( - "luke", - Value::object( - vec![ - ("name", Value::scalar("Luke Skywalker")), - ("homePlanet", Value::scalar("Tatooine")), - ] - .into_iter() - .collect(), - ), - ), - ( - "leia", - Value::object( - vec![ - ("name", Value::scalar("Leia Organa")), - ("homePlanet", Value::scalar("Alderaan")), - ] - .into_iter() - .collect(), - ), - ), - ] - .into_iter() - .collect() - ), - vec![] - )) + graphql_value!({ + "luke": {"name": "Luke Skywalker", "homePlanet": "Tatooine"}, + "leia": {"name": "Leia Organa", "homePlanet": "Alderaan"}, + }), + vec![], + )), ); } @@ -523,20 +269,9 @@ async fn test_query_name_variable() { assert_eq!( crate::execute(doc, None, &schema, &vars, &database).await, Ok(( - Value::object( - vec![( - "human", - Value::object( - vec![("name", Value::scalar("Luke Skywalker"))] - .into_iter() - .collect(), - ), - )] - .into_iter() - .collect() - ), - vec![] - )) + graphql_value!({"human": {"name": "Luke Skywalker"}}), + vec![], + )), ); } @@ -556,10 +291,7 @@ async fn test_query_name_invalid_variable() { assert_eq!( crate::execute(doc, None, &schema, &vars, &database).await, - Ok(( - Value::object(vec![("human", Value::null())].into_iter().collect()), - vec![] - )) + Ok((graphql_value!({ "human": None }), vec![])), ); } @@ -576,57 +308,31 @@ async fn test_query_friends_names() { assert_eq!( crate::execute(doc, None, &schema, &Variables::new(), &database).await, Ok(( - Value::object( - vec![( - "human", - Value::object( - vec![( - "friends", - Value::list(vec![ - Value::object( - vec![("name", Value::scalar("Han Solo"))] - .into_iter() - .collect(), - ), - Value::object( - vec![("name", Value::scalar("Leia Organa"))] - .into_iter() - .collect(), - ), - Value::object( - vec![("name", Value::scalar("C-3PO"))].into_iter().collect(), - ), - Value::object( - vec![("name", Value::scalar("R2-D2"))].into_iter().collect(), - ), - ]), - )] - .into_iter() - .collect(), - ), - )] - .into_iter() - .collect() - ), - vec![] - )) + graphql_value!({"human": { + "friends": [ + {"name": "Han Solo"}, + {"name": "Leia Organa"}, + {"name": "C-3PO"}, + {"name": "R2-D2"}, + ], + }}), + vec![], + )), ); } #[tokio::test] async fn test_query_inline_fragments_droid() { - let doc = r#" - query InlineFragments { - hero { - name - __typename + let doc = r#"query InlineFragments { + hero { + name + __typename - ...on Droid { - primaryFunction - } + ...on Droid { + primaryFunction } } - "#; + }"#; let database = Database::new(); let schema = RootNode::new( Query, @@ -637,37 +343,24 @@ async fn test_query_inline_fragments_droid() { assert_eq!( crate::execute(doc, None, &schema, &Variables::new(), &database).await, Ok(( - Value::object( - vec![( - "hero", - Value::object( - vec![ - ("__typename", Value::scalar("Droid")), - ("name", Value::scalar("R2-D2")), - ("primaryFunction", Value::scalar("Astromech")), - ] - .into_iter() - .collect(), - ), - )] - .into_iter() - .collect() - ), - vec![] - )) + graphql_value!({"hero": { + "__typename": "Droid", + "name": "R2-D2", + "primaryFunction": "Astromech", + }}), + vec![], + )), ); } #[tokio::test] async fn test_query_inline_fragments_human() { - let doc = r#" - query InlineFragments { - hero(episode: EMPIRE) { - __typename - name - } + let doc = r#"query InlineFragments { + hero(episode: EMPIRE) { + __typename + name } - "#; + }"#; let database = Database::new(); let schema = RootNode::new( Query, @@ -678,34 +371,22 @@ async fn test_query_inline_fragments_human() { assert_eq!( crate::execute(doc, None, &schema, &Variables::new(), &database).await, Ok(( - Value::object( - vec![( - "hero", - Value::object( - vec![ - ("__typename", Value::scalar("Human")), - ("name", Value::scalar("Luke Skywalker")), - ] - .into_iter() - .collect(), - ), - )] - .into_iter() - .collect() - ), - vec![] - )) + graphql_value!({"hero": { + "__typename": "Human", + "name": "Luke Skywalker", + }}), + vec![], + )), ); } #[tokio::test] async fn test_object_typename() { - let doc = r#" - { - human(id: "1000") { - __typename - } - }"#; + let doc = r#"{ + human(id: "1000") { + __typename + } + }"#; let database = Database::new(); let schema = RootNode::new( Query, @@ -715,21 +396,7 @@ async fn test_object_typename() { assert_eq!( crate::execute(doc, None, &schema, &Variables::new(), &database).await, - Ok(( - Value::object( - vec![( - "human", - Value::object( - vec![("__typename", Value::scalar("Human"))] - .into_iter() - .collect(), - ), - )] - .into_iter() - .collect() - ), - vec![] - )) + Ok((graphql_value!({"human": {"__typename": "Human"}}), vec![])), ); } diff --git a/juniper/src/tests/schema_introspection.rs b/juniper/src/tests/schema_introspection.rs index 4303c676..683b19d3 100644 --- a/juniper/src/tests/schema_introspection.rs +++ b/juniper/src/tests/schema_introspection.rs @@ -1,7 +1,4 @@ -use crate::value::{ - self, - Value::{self, Null}, -}; +use crate::value::Value; // Sort a nested schema Value. // In particular, lists are sorted by the "name" key of children, if present. @@ -36,14 +33,14 @@ pub(super) fn sort_schema_value(value: &mut Value) { } } -pub(crate) fn schema_introspection_result() -> value::Value { +pub(crate) fn schema_introspection_result() -> Value { let mut v = graphql_value!({ "__schema": { "queryType": { "name": "Query" }, - "mutationType": Null, - "subscriptionType": Null, + "mutationType": None, + "subscriptionType": None, "types": [ { "kind": "OBJECT", @@ -56,15 +53,15 @@ pub(crate) fn schema_introspection_result() -> value::Value { "args": [], "type": { "kind": "NON_NULL", - "name": Null, + "name": None, "ofType": { "kind": "SCALAR", "name": "String", - "ofType": Null + "ofType": None } }, "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None }, { "name": "name", @@ -73,10 +70,10 @@ pub(crate) fn schema_introspection_result() -> value::Value { "type": { "kind": "SCALAR", "name": "String", - "ofType": Null + "ofType": None }, "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None }, { "name": "friends", @@ -84,23 +81,23 @@ pub(crate) fn schema_introspection_result() -> value::Value { "args": [], "type": { "kind": "NON_NULL", - "name": Null, + "name": None, "ofType": { "kind": "LIST", - "name": Null, + "name": None, "ofType": { "kind": "NON_NULL", - "name": Null, + "name": None, "ofType": { "kind": "INTERFACE", "name": "Character", - "ofType": Null + "ofType": None } } } }, "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None }, { "name": "appearsIn", @@ -108,23 +105,23 @@ pub(crate) fn schema_introspection_result() -> value::Value { "args": [], "type": { "kind": "NON_NULL", - "name": Null, + "name": None, "ofType": { "kind": "LIST", - "name": Null, + "name": None, "ofType": { "kind": "NON_NULL", - "name": Null, + "name": None, "ofType": { "kind": "ENUM", "name": "Episode", - "ofType": Null + "ofType": None } } } }, "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None }, { "name": "homePlanet", @@ -133,559 +130,559 @@ pub(crate) fn schema_introspection_result() -> value::Value { "type": { "kind": "SCALAR", "name": "String", - "ofType": Null + "ofType": None }, "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None } ], - "inputFields": Null, + "inputFields": None, "interfaces": [ { "kind": "INTERFACE", "name": "Character", - "ofType": Null + "ofType": None } ], - "enumValues": Null, - "possibleTypes": Null + "enumValues": None, + "possibleTypes": None }, { "kind": "SCALAR", "name": "Boolean", - "description": Null, - "fields": Null, - "inputFields": Null, - "interfaces": Null, - "enumValues": Null, - "possibleTypes": Null + "description": None, + "fields": None, + "inputFields": None, + "interfaces": None, + "enumValues": None, + "possibleTypes": None }, { "kind": "OBJECT", "name": "__InputValue", - "description": Null, + "description": None, "fields": [ { "name": "name", - "description": Null, + "description": None, "args": [], "type": { "kind": "NON_NULL", - "name": Null, + "name": None, "ofType": { "kind": "SCALAR", "name": "String", - "ofType": Null + "ofType": None } }, "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None }, { "name": "description", - "description": Null, + "description": None, "args": [], "type": { "kind": "SCALAR", "name": "String", - "ofType": Null + "ofType": None }, "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None }, { "name": "type", - "description": Null, + "description": None, "args": [], "type": { "kind": "NON_NULL", - "name": Null, + "name": None, "ofType": { "kind": "OBJECT", "name": "__Type", - "ofType": Null + "ofType": None } }, "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None }, { "name": "defaultValue", - "description": Null, + "description": None, "args": [], "type": { "kind": "SCALAR", "name": "String", - "ofType": Null + "ofType": None }, "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None } ], - "inputFields": Null, + "inputFields": None, "interfaces": [], - "enumValues": Null, - "possibleTypes": Null + "enumValues": None, + "possibleTypes": None }, { "kind": "SCALAR", "name": "String", - "description": Null, - "fields": Null, - "inputFields": Null, - "interfaces": Null, - "enumValues": Null, - "possibleTypes": Null + "description": None, + "fields": None, + "inputFields": None, + "interfaces": None, + "enumValues": None, + "possibleTypes": None }, { "kind": "OBJECT", "name": "__Field", - "description": Null, + "description": None, "fields": [ { "name": "name", - "description": Null, + "description": None, "args": [], "type": { "kind": "NON_NULL", - "name": Null, + "name": None, "ofType": { "kind": "SCALAR", "name": "String", - "ofType": Null + "ofType": None } }, "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None }, { "name": "description", - "description": Null, + "description": None, "args": [], "type": { "kind": "SCALAR", "name": "String", - "ofType": Null + "ofType": None }, "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None }, { "name": "args", - "description": Null, + "description": None, "args": [], "type": { "kind": "NON_NULL", - "name": Null, + "name": None, "ofType": { "kind": "LIST", - "name": Null, + "name": None, "ofType": { "kind": "NON_NULL", - "name": Null, + "name": None, "ofType": { "kind": "OBJECT", "name": "__InputValue", - "ofType": Null + "ofType": None } } } }, "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None }, { "name": "type", - "description": Null, + "description": None, "args": [], "type": { "kind": "NON_NULL", - "name": Null, + "name": None, "ofType": { "kind": "OBJECT", "name": "__Type", - "ofType": Null + "ofType": None } }, "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None }, { "name": "isDeprecated", - "description": Null, + "description": None, "args": [], "type": { "kind": "NON_NULL", - "name": Null, + "name": None, "ofType": { "kind": "SCALAR", "name": "Boolean", - "ofType": Null + "ofType": None } }, "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None }, { "name": "deprecationReason", - "description": Null, + "description": None, "args": [], "type": { "kind": "SCALAR", "name": "String", - "ofType": Null + "ofType": None }, "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None } ], - "inputFields": Null, + "inputFields": None, "interfaces": [], - "enumValues": Null, - "possibleTypes": Null + "enumValues": None, + "possibleTypes": None }, { "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": Null, - "inputFields": Null, - "interfaces": Null, + "fields": None, + "inputFields": None, + "interfaces": None, "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": Null + "deprecationReason": None }, { "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": Null + "deprecationReason": None }, { "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": Null + "deprecationReason": None }, { "name": "UNION", "description": "## Union types\n\nUnions are similar to interfaces but can not contain any fields on their own.", "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None }, { "name": "ENUM", "description": "## Enum types\n\nLike scalars, enum types appear as the leaf nodes of GraphQL queries.", "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None }, { "name": "INPUT_OBJECT", "description": "## Input objects\n\nRepresents complex values provided in queries _into_ the system.", "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None }, { "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": Null + "deprecationReason": None }, { "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": Null + "deprecationReason": None } ], - "possibleTypes": Null + "possibleTypes": None }, { "kind": "OBJECT", "name": "__Type", - "description": Null, + "description": None, "fields": [ { "name": "name", - "description": Null, + "description": None, "args": [], "type": { "kind": "SCALAR", "name": "String", - "ofType": Null + "ofType": None }, "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None }, { "name": "description", - "description": Null, + "description": None, "args": [], "type": { "kind": "SCALAR", "name": "String", - "ofType": Null + "ofType": None }, "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None }, { "name": "kind", - "description": Null, + "description": None, "args": [], "type": { "kind": "NON_NULL", - "name": Null, + "name": None, "ofType": { "kind": "ENUM", "name": "__TypeKind", - "ofType": Null + "ofType": None } }, "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None }, { "name": "fields", - "description": Null, + "description": None, "args": [ { "name": "includeDeprecated", - "description": Null, + "description": None, "type": { "kind": "SCALAR", "name": "Boolean", - "ofType": Null + "ofType": None }, "defaultValue": "false" } ], "type": { "kind": "LIST", - "name": Null, + "name": None, "ofType": { "kind": "NON_NULL", - "name": Null, + "name": None, "ofType": { "kind": "OBJECT", "name": "__Field", - "ofType": Null + "ofType": None } } }, "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None }, { "name": "ofType", - "description": Null, + "description": None, "args": [], "type": { "kind": "OBJECT", "name": "__Type", - "ofType": Null + "ofType": None }, "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None }, { "name": "inputFields", - "description": Null, + "description": None, "args": [], "type": { "kind": "LIST", - "name": Null, + "name": None, "ofType": { "kind": "NON_NULL", - "name": Null, + "name": None, "ofType": { "kind": "OBJECT", "name": "__InputValue", - "ofType": Null + "ofType": None } } }, "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None }, { "name": "interfaces", - "description": Null, + "description": None, "args": [], "type": { "kind": "LIST", - "name": Null, + "name": None, "ofType": { "kind": "NON_NULL", - "name": Null, + "name": None, "ofType": { "kind": "OBJECT", "name": "__Type", - "ofType": Null + "ofType": None } } }, "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None }, { "name": "possibleTypes", - "description": Null, + "description": None, "args": [], "type": { "kind": "LIST", - "name": Null, + "name": None, "ofType": { "kind": "NON_NULL", - "name": Null, + "name": None, "ofType": { "kind": "OBJECT", "name": "__Type", - "ofType": Null + "ofType": None } } }, "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None }, { "name": "enumValues", - "description": Null, + "description": None, "args": [ { "name": "includeDeprecated", - "description": Null, + "description": None, "type": { "kind": "SCALAR", "name": "Boolean", - "ofType": Null + "ofType": None }, "defaultValue": "false" } ], "type": { "kind": "LIST", - "name": Null, + "name": None, "ofType": { "kind": "NON_NULL", - "name": Null, + "name": None, "ofType": { "kind": "OBJECT", "name": "__EnumValue", - "ofType": Null + "ofType": None } } }, "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None } ], - "inputFields": Null, + "inputFields": None, "interfaces": [], - "enumValues": Null, - "possibleTypes": Null + "enumValues": None, + "possibleTypes": None }, { "kind": "OBJECT", "name": "__Schema", - "description": Null, + "description": None, "fields": [ { "name": "types", - "description": Null, + "description": None, "args": [], "type": { "kind": "NON_NULL", - "name": Null, + "name": None, "ofType": { "kind": "LIST", - "name": Null, + "name": None, "ofType": { "kind": "NON_NULL", - "name": Null, + "name": None, "ofType": { "kind": "OBJECT", "name": "__Type", - "ofType": Null + "ofType": None } } } }, "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None }, { "name": "queryType", - "description": Null, + "description": None, "args": [], "type": { "kind": "NON_NULL", - "name": Null, + "name": None, "ofType": { "kind": "OBJECT", "name": "__Type", - "ofType": Null + "ofType": None } }, "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None }, { "name": "mutationType", - "description": Null, + "description": None, "args": [], "type": { "kind": "OBJECT", "name": "__Type", - "ofType": Null + "ofType": None }, "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None }, { "name": "subscriptionType", - "description": Null, + "description": None, "args": [], "type": { "kind": "OBJECT", "name": "__Type", - "ofType": Null + "ofType": None }, "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None }, { "name": "directives", - "description": Null, + "description": None, "args": [], "type": { "kind": "NON_NULL", - "name": Null, + "name": None, "ofType": { "kind": "LIST", - "name": Null, + "name": None, "ofType": { "kind": "NON_NULL", - "name": Null, + "name": None, "ofType": { "kind": "OBJECT", "name": "__Directive", - "ofType": Null + "ofType": None } } } }, "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None } ], - "inputFields": Null, + "inputFields": None, "interfaces": [], - "enumValues": Null, - "possibleTypes": Null + "enumValues": None, + "possibleTypes": None }, { "kind": "OBJECT", @@ -698,15 +695,15 @@ pub(crate) fn schema_introspection_result() -> value::Value { "args": [], "type": { "kind": "NON_NULL", - "name": Null, + "name": None, "ofType": { "kind": "SCALAR", "name": "String", - "ofType": Null + "ofType": None } }, "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None }, { "name": "name", @@ -715,10 +712,10 @@ pub(crate) fn schema_introspection_result() -> value::Value { "type": { "kind": "SCALAR", "name": "String", - "ofType": Null + "ofType": None }, "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None }, { "name": "friends", @@ -726,23 +723,23 @@ pub(crate) fn schema_introspection_result() -> value::Value { "args": [], "type": { "kind": "NON_NULL", - "name": Null, + "name": None, "ofType": { "kind": "LIST", - "name": Null, + "name": None, "ofType": { "kind": "NON_NULL", - "name": Null, + "name": None, "ofType": { "kind": "INTERFACE", "name": "Character", - "ofType": Null + "ofType": None } } } }, "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None }, { "name": "appearsIn", @@ -750,23 +747,23 @@ pub(crate) fn schema_introspection_result() -> value::Value { "args": [], "type": { "kind": "NON_NULL", - "name": Null, + "name": None, "ofType": { "kind": "LIST", - "name": Null, + "name": None, "ofType": { "kind": "NON_NULL", - "name": Null, + "name": None, "ofType": { "kind": "ENUM", "name": "Episode", - "ofType": Null + "ofType": None } } } }, "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None }, { "name": "primaryFunction", @@ -775,22 +772,22 @@ pub(crate) fn schema_introspection_result() -> value::Value { "type": { "kind": "SCALAR", "name": "String", - "ofType": Null + "ofType": None }, "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None } ], - "inputFields": Null, + "inputFields": None, "interfaces": [ { "kind": "INTERFACE", "name": "Character", - "ofType": Null + "ofType": None } ], - "enumValues": Null, - "possibleTypes": Null + "enumValues": None, + "possibleTypes": None }, { "kind": "OBJECT", @@ -799,62 +796,62 @@ pub(crate) fn schema_introspection_result() -> value::Value { "fields": [ { "name": "human", - "description": Null, + "description": None, "args": [ { "name": "id", "description": "id of the human", "type": { "kind": "NON_NULL", - "name": Null, + "name": None, "ofType": { "kind": "SCALAR", "name": "String", - "ofType": Null + "ofType": None } }, - "defaultValue": Null + "defaultValue": None } ], "type": { "kind": "OBJECT", "name": "Human", - "ofType": Null + "ofType": None }, "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None }, { "name": "droid", - "description": Null, + "description": None, "args": [ { "name": "id", - "description": Null, + "description": None, "description": "id of the droid", "type": { "kind": "NON_NULL", - "name": Null, + "name": None, "ofType": { "kind": "SCALAR", "name": "String", - "ofType": Null + "ofType": None } }, - "defaultValue": Null + "defaultValue": None } ], "type": { "kind": "OBJECT", "name": "Droid", - "ofType": Null + "ofType": None }, "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None }, { "name": "hero", - "description": Null, + "description": None, "args": [ { "name": "episode", @@ -862,173 +859,173 @@ pub(crate) fn schema_introspection_result() -> value::Value { "type": { "kind": "ENUM", "name": "Episode", - "ofType": Null + "ofType": None }, - "defaultValue": Null + "defaultValue": None } ], "type": { "kind": "INTERFACE", "name": "Character", - "ofType": Null + "ofType": None }, "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None } ], - "inputFields": Null, + "inputFields": None, "interfaces": [], - "enumValues": Null, - "possibleTypes": Null + "enumValues": None, + "possibleTypes": None }, { "kind": "OBJECT", "name": "__EnumValue", - "description": Null, + "description": None, "fields": [ { "name": "name", - "description": Null, + "description": None, "args": [], "type": { "kind": "NON_NULL", - "name": Null, + "name": None, "ofType": { "kind": "SCALAR", "name": "String", - "ofType": Null + "ofType": None } }, "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None }, { "name": "description", - "description": Null, + "description": None, "args": [], "type": { "kind": "SCALAR", "name": "String", - "ofType": Null + "ofType": None }, "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None }, { "name": "isDeprecated", - "description": Null, + "description": None, "args": [], "type": { "kind": "NON_NULL", - "name": Null, + "name": None, "ofType": { "kind": "SCALAR", "name": "Boolean", - "ofType": Null + "ofType": None } }, "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None }, { "name": "deprecationReason", - "description": Null, + "description": None, "args": [], "type": { "kind": "SCALAR", "name": "String", - "ofType": Null + "ofType": None }, "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None } ], - "inputFields": Null, + "inputFields": None, "interfaces": [], - "enumValues": Null, - "possibleTypes": Null + "enumValues": None, + "possibleTypes": None }, { "kind": "ENUM", "name": "Episode", - "description": Null, - "fields": Null, - "inputFields": Null, - "interfaces": Null, + "description": None, + "fields": None, + "inputFields": None, + "interfaces": None, "enumValues": [ { "name": "NEW_HOPE", - "description": Null, + "description": None, "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None }, { "name": "EMPIRE", - "description": Null, + "description": None, "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None }, { "name": "JEDI", - "description": Null, + "description": None, "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None } ], - "possibleTypes": Null + "possibleTypes": None }, { "kind": "ENUM", "name": "__DirectiveLocation", - "description": Null, - "fields": Null, - "inputFields": Null, - "interfaces": Null, + "description": None, + "fields": None, + "inputFields": None, + "interfaces": None, "enumValues": [ { "name": "QUERY", - "description": Null, + "description": None, "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None }, { "name": "MUTATION", - "description": Null, + "description": None, "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None }, { "name": "SUBSCRIPTION", - "description": Null, + "description": None, "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None }, { "name": "FIELD", - "description": Null, + "description": None, "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None }, { "name": "FRAGMENT_DEFINITION", - "description": Null, + "description": None, "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None }, { "name": "FRAGMENT_SPREAD", - "description": Null, + "description": None, "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None }, { "name": "INLINE_FRAGMENT", - "description": Null, + "description": None, "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None } ], - "possibleTypes": Null + "possibleTypes": None }, { "kind": "INTERFACE", @@ -1041,15 +1038,15 @@ pub(crate) fn schema_introspection_result() -> value::Value { "args": [], "type": { "kind": "NON_NULL", - "name": Null, + "name": None, "ofType": { "kind": "SCALAR", "name": "String", - "ofType": Null + "ofType": None } }, "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None }, { "name": "name", @@ -1058,10 +1055,10 @@ pub(crate) fn schema_introspection_result() -> value::Value { "type": { "kind": "SCALAR", "name": "String", - "ofType": Null + "ofType": None }, "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None }, { "name": "friends", @@ -1069,23 +1066,23 @@ pub(crate) fn schema_introspection_result() -> value::Value { "args": [], "type": { "kind": "NON_NULL", - "name": Null, + "name": None, "ofType": { "kind": "LIST", - "name": Null, + "name": None, "ofType": { "kind": "NON_NULL", - "name": Null, + "name": None, "ofType": { "kind": "INTERFACE", "name": "Character", - "ofType": Null + "ofType": None } } } }, "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None }, { "name": "appearsIn", @@ -1093,133 +1090,133 @@ pub(crate) fn schema_introspection_result() -> value::Value { "args": [], "type": { "kind": "NON_NULL", - "name": Null, + "name": None, "ofType": { "kind": "LIST", - "name": Null, + "name": None, "ofType": { "kind": "NON_NULL", - "name": Null, + "name": None, "ofType": { "kind": "ENUM", "name": "Episode", - "ofType": Null + "ofType": None } } } }, "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None } ], - "inputFields": Null, - "interfaces": Null, - "enumValues": Null, + "inputFields": None, + "interfaces": None, + "enumValues": None, "possibleTypes": [ { "kind": "OBJECT", "name": "Human", - "ofType": Null + "ofType": None }, { "kind": "OBJECT", "name": "Droid", - "ofType": Null + "ofType": None } ] }, { "kind": "OBJECT", "name": "__Directive", - "description": Null, + "description": None, "fields": [ { "name": "name", - "description": Null, + "description": None, "args": [], "type": { "kind": "NON_NULL", - "name": Null, + "name": None, "ofType": { "kind": "SCALAR", "name": "String", - "ofType": Null + "ofType": None } }, "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None }, { "name": "description", - "description": Null, + "description": None, "args": [], "type": { "kind": "SCALAR", "name": "String", - "ofType": Null + "ofType": None }, "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None }, { "name": "locations", - "description": Null, + "description": None, "args": [], "type": { "kind": "NON_NULL", - "name": Null, + "name": None, "ofType": { "kind": "LIST", - "name": Null, + "name": None, "ofType": { "kind": "NON_NULL", - "name": Null, + "name": None, "ofType": { "kind": "ENUM", "name": "__DirectiveLocation", - "ofType": Null + "ofType": None } } } }, "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None }, { "name": "args", - "description": Null, + "description": None, "args": [], "type": { "kind": "NON_NULL", - "name": Null, + "name": None, "ofType": { "kind": "LIST", - "name": Null, + "name": None, "ofType": { "kind": "NON_NULL", - "name": Null, + "name": None, "ofType": { "kind": "OBJECT", "name": "__InputValue", - "ofType": Null + "ofType": None } } } }, "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None }, { "name": "onOperation", - "description": Null, + "description": None, "args": [], "type": { "kind": "NON_NULL", - "name": Null, + "name": None, "ofType": { "kind": "SCALAR", "name": "Boolean", - "ofType": Null + "ofType": None } }, "isDeprecated": true, @@ -1227,15 +1224,15 @@ pub(crate) fn schema_introspection_result() -> value::Value { }, { "name": "onFragment", - "description": Null, + "description": None, "args": [], "type": { "kind": "NON_NULL", - "name": Null, + "name": None, "ofType": { "kind": "SCALAR", "name": "Boolean", - "ofType": Null + "ofType": None } }, "isDeprecated": true, @@ -1243,31 +1240,31 @@ pub(crate) fn schema_introspection_result() -> value::Value { }, { "name": "onField", - "description": Null, + "description": None, "args": [], "type": { "kind": "NON_NULL", - "name": Null, + "name": None, "ofType": { "kind": "SCALAR", "name": "Boolean", - "ofType": Null + "ofType": None } }, "isDeprecated": true, "deprecationReason": "Use the locations array instead" } ], - "inputFields": Null, + "inputFields": None, "interfaces": [], - "enumValues": Null, - "possibleTypes": Null + "enumValues": None, + "possibleTypes": None } ], "directives": [ { "name": "skip", - "description": Null, + "description": None, "locations": [ "FIELD", "FRAGMENT_SPREAD", @@ -1276,23 +1273,23 @@ pub(crate) fn schema_introspection_result() -> value::Value { "args": [ { "name": "if", - "description": Null, + "description": None, "type": { "kind": "NON_NULL", - "name": Null, + "name": None, "ofType": { "kind": "SCALAR", "name": "Boolean", - "ofType": Null + "ofType": None } }, - "defaultValue": Null + "defaultValue": None } ] }, { "name": "include", - "description": Null, + "description": None, "locations": [ "FIELD", "FRAGMENT_SPREAD", @@ -1301,17 +1298,17 @@ pub(crate) fn schema_introspection_result() -> value::Value { "args": [ { "name": "if", - "description": Null, + "description": None, "type": { "kind": "NON_NULL", - "name": Null, + "name": None, "ofType": { "kind": "SCALAR", "name": "Boolean", - "ofType": Null + "ofType": None } }, - "defaultValue": Null + "defaultValue": None } ] } @@ -1322,14 +1319,14 @@ pub(crate) fn schema_introspection_result() -> value::Value { v } -pub(crate) fn schema_introspection_result_without_descriptions() -> value::Value { +pub(crate) fn schema_introspection_result_without_descriptions() -> Value { let mut v = graphql_value!({ "__schema": { "queryType": { "name": "Query" }, - "mutationType": Null, - "subscriptionType": Null, + "mutationType": None, + "subscriptionType": None, "types": [ { "kind": "OBJECT", @@ -1340,15 +1337,15 @@ pub(crate) fn schema_introspection_result_without_descriptions() -> value::Value "args": [], "type": { "kind": "NON_NULL", - "name": Null, + "name": None, "ofType": { "kind": "SCALAR", "name": "String", - "ofType": Null + "ofType": None } }, "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None }, { "name": "name", @@ -1356,56 +1353,56 @@ pub(crate) fn schema_introspection_result_without_descriptions() -> value::Value "type": { "kind": "SCALAR", "name": "String", - "ofType": Null + "ofType": None }, "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None }, { "name": "friends", "args": [], "type": { "kind": "NON_NULL", - "name": Null, + "name": None, "ofType": { "kind": "LIST", - "name": Null, + "name": None, "ofType": { "kind": "NON_NULL", - "name": Null, + "name": None, "ofType": { "kind": "INTERFACE", "name": "Character", - "ofType": Null + "ofType": None } } } }, "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None }, { "name": "appearsIn", "args": [], "type": { "kind": "NON_NULL", - "name": Null, + "name": None, "ofType": { "kind": "LIST", - "name": Null, + "name": None, "ofType": { "kind": "NON_NULL", - "name": Null, + "name": None, "ofType": { "kind": "ENUM", "name": "Episode", - "ofType": Null + "ofType": None } } } }, "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None }, { "name": "homePlanet", @@ -1413,31 +1410,31 @@ pub(crate) fn schema_introspection_result_without_descriptions() -> value::Value "type": { "kind": "SCALAR", "name": "String", - "ofType": Null + "ofType": None }, "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None } ], - "inputFields": Null, + "inputFields": None, "interfaces": [ { "kind": "INTERFACE", "name": "Character", - "ofType": Null + "ofType": None } ], - "enumValues": Null, - "possibleTypes": Null + "enumValues": None, + "possibleTypes": None }, { "kind": "SCALAR", "name": "Boolean", - "fields": Null, - "inputFields": Null, - "interfaces": Null, - "enumValues": Null, - "possibleTypes": Null + "fields": None, + "inputFields": None, + "interfaces": None, + "enumValues": None, + "possibleTypes": None }, { "kind": "OBJECT", @@ -1448,15 +1445,15 @@ pub(crate) fn schema_introspection_result_without_descriptions() -> value::Value "args": [], "type": { "kind": "NON_NULL", - "name": Null, + "name": None, "ofType": { "kind": "SCALAR", "name": "String", - "ofType": Null + "ofType": None } }, "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None }, { "name": "description", @@ -1464,25 +1461,25 @@ pub(crate) fn schema_introspection_result_without_descriptions() -> value::Value "type": { "kind": "SCALAR", "name": "String", - "ofType": Null + "ofType": None }, "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None }, { "name": "type", "args": [], "type": { "kind": "NON_NULL", - "name": Null, + "name": None, "ofType": { "kind": "OBJECT", "name": "__Type", - "ofType": Null + "ofType": None } }, "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None }, { "name": "defaultValue", @@ -1490,25 +1487,25 @@ pub(crate) fn schema_introspection_result_without_descriptions() -> value::Value "type": { "kind": "SCALAR", "name": "String", - "ofType": Null + "ofType": None }, "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None } ], - "inputFields": Null, + "inputFields": None, "interfaces": [], - "enumValues": Null, - "possibleTypes": Null + "enumValues": None, + "possibleTypes": None }, { "kind": "SCALAR", "name": "String", - "fields": Null, - "inputFields": Null, - "interfaces": Null, - "enumValues": Null, - "possibleTypes": Null + "fields": None, + "inputFields": None, + "interfaces": None, + "enumValues": None, + "possibleTypes": None }, { "kind": "OBJECT", @@ -1519,15 +1516,15 @@ pub(crate) fn schema_introspection_result_without_descriptions() -> value::Value "args": [], "type": { "kind": "NON_NULL", - "name": Null, + "name": None, "ofType": { "kind": "SCALAR", "name": "String", - "ofType": Null + "ofType": None } }, "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None }, { "name": "description", @@ -1535,63 +1532,63 @@ pub(crate) fn schema_introspection_result_without_descriptions() -> value::Value "type": { "kind": "SCALAR", "name": "String", - "ofType": Null + "ofType": None }, "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None }, { "name": "args", "args": [], "type": { "kind": "NON_NULL", - "name": Null, + "name": None, "ofType": { "kind": "LIST", - "name": Null, + "name": None, "ofType": { "kind": "NON_NULL", - "name": Null, + "name": None, "ofType": { "kind": "OBJECT", "name": "__InputValue", - "ofType": Null + "ofType": None } } } }, "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None }, { "name": "type", "args": [], "type": { "kind": "NON_NULL", - "name": Null, + "name": None, "ofType": { "kind": "OBJECT", "name": "__Type", - "ofType": Null + "ofType": None } }, "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None }, { "name": "isDeprecated", "args": [], "type": { "kind": "NON_NULL", - "name": Null, + "name": None, "ofType": { "kind": "SCALAR", "name": "Boolean", - "ofType": Null + "ofType": None } }, "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None }, { "name": "deprecationReason", @@ -1599,66 +1596,66 @@ pub(crate) fn schema_introspection_result_without_descriptions() -> value::Value "type": { "kind": "SCALAR", "name": "String", - "ofType": Null + "ofType": None }, "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None } ], - "inputFields": Null, + "inputFields": None, "interfaces": [], - "enumValues": Null, - "possibleTypes": Null + "enumValues": None, + "possibleTypes": None }, { "kind": "ENUM", "name": "__TypeKind", - "fields": Null, - "inputFields": Null, - "interfaces": Null, + "fields": None, + "inputFields": None, + "interfaces": None, "enumValues": [ { "name": "SCALAR", "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None }, { "name": "OBJECT", "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None }, { "name": "INTERFACE", "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None }, { "name": "UNION", "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None }, { "name": "ENUM", "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None }, { "name": "INPUT_OBJECT", "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None }, { "name": "LIST", "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None }, { "name": "NON_NULL", "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None } ], - "possibleTypes": Null + "possibleTypes": None }, { "kind": "OBJECT", @@ -1670,10 +1667,10 @@ pub(crate) fn schema_introspection_result_without_descriptions() -> value::Value "type": { "kind": "SCALAR", "name": "String", - "ofType": Null + "ofType": None }, "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None }, { "name": "description", @@ -1681,25 +1678,25 @@ pub(crate) fn schema_introspection_result_without_descriptions() -> value::Value "type": { "kind": "SCALAR", "name": "String", - "ofType": Null + "ofType": None }, "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None }, { "name": "kind", "args": [], "type": { "kind": "NON_NULL", - "name": Null, + "name": None, "ofType": { "kind": "ENUM", "name": "__TypeKind", - "ofType": Null + "ofType": None } }, "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None }, { "name": "fields", @@ -1709,26 +1706,26 @@ pub(crate) fn schema_introspection_result_without_descriptions() -> value::Value "type": { "kind": "SCALAR", "name": "Boolean", - "ofType": Null + "ofType": None }, "defaultValue": "false" } ], "type": { "kind": "LIST", - "name": Null, + "name": None, "ofType": { "kind": "NON_NULL", - "name": Null, + "name": None, "ofType": { "kind": "OBJECT", "name": "__Field", - "ofType": Null + "ofType": None } } }, "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None }, { "name": "ofType", @@ -1736,67 +1733,67 @@ pub(crate) fn schema_introspection_result_without_descriptions() -> value::Value "type": { "kind": "OBJECT", "name": "__Type", - "ofType": Null + "ofType": None }, "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None }, { "name": "inputFields", "args": [], "type": { "kind": "LIST", - "name": Null, + "name": None, "ofType": { "kind": "NON_NULL", - "name": Null, + "name": None, "ofType": { "kind": "OBJECT", "name": "__InputValue", - "ofType": Null + "ofType": None } } }, "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None }, { "name": "interfaces", "args": [], "type": { "kind": "LIST", - "name": Null, + "name": None, "ofType": { "kind": "NON_NULL", - "name": Null, + "name": None, "ofType": { "kind": "OBJECT", "name": "__Type", - "ofType": Null + "ofType": None } } }, "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None }, { "name": "possibleTypes", "args": [], "type": { "kind": "LIST", - "name": Null, + "name": None, "ofType": { "kind": "NON_NULL", - "name": Null, + "name": None, "ofType": { "kind": "OBJECT", "name": "__Type", - "ofType": Null + "ofType": None } } }, "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None }, { "name": "enumValues", @@ -1806,32 +1803,32 @@ pub(crate) fn schema_introspection_result_without_descriptions() -> value::Value "type": { "kind": "SCALAR", "name": "Boolean", - "ofType": Null + "ofType": None }, "defaultValue": "false" } ], "type": { "kind": "LIST", - "name": Null, + "name": None, "ofType": { "kind": "NON_NULL", - "name": Null, + "name": None, "ofType": { "kind": "OBJECT", "name": "__EnumValue", - "ofType": Null + "ofType": None } } }, "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None } ], - "inputFields": Null, + "inputFields": None, "interfaces": [], - "enumValues": Null, - "possibleTypes": Null + "enumValues": None, + "possibleTypes": None }, { "kind": "OBJECT", @@ -1842,38 +1839,38 @@ pub(crate) fn schema_introspection_result_without_descriptions() -> value::Value "args": [], "type": { "kind": "NON_NULL", - "name": Null, + "name": None, "ofType": { "kind": "LIST", - "name": Null, + "name": None, "ofType": { "kind": "NON_NULL", - "name": Null, + "name": None, "ofType": { "kind": "OBJECT", "name": "__Type", - "ofType": Null + "ofType": None } } } }, "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None }, { "name": "queryType", "args": [], "type": { "kind": "NON_NULL", - "name": Null, + "name": None, "ofType": { "kind": "OBJECT", "name": "__Type", - "ofType": Null + "ofType": None } }, "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None }, { "name": "mutationType", @@ -1881,10 +1878,10 @@ pub(crate) fn schema_introspection_result_without_descriptions() -> value::Value "type": { "kind": "OBJECT", "name": "__Type", - "ofType": Null + "ofType": None }, "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None }, { "name": "subscriptionType", @@ -1892,39 +1889,39 @@ pub(crate) fn schema_introspection_result_without_descriptions() -> value::Value "type": { "kind": "OBJECT", "name": "__Type", - "ofType": Null + "ofType": None }, "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None }, { "name": "directives", "args": [], "type": { "kind": "NON_NULL", - "name": Null, + "name": None, "ofType": { "kind": "LIST", - "name": Null, + "name": None, "ofType": { "kind": "NON_NULL", - "name": Null, + "name": None, "ofType": { "kind": "OBJECT", "name": "__Directive", - "ofType": Null + "ofType": None } } } }, "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None } ], - "inputFields": Null, + "inputFields": None, "interfaces": [], - "enumValues": Null, - "possibleTypes": Null + "enumValues": None, + "possibleTypes": None }, { "kind": "OBJECT", @@ -1935,15 +1932,15 @@ pub(crate) fn schema_introspection_result_without_descriptions() -> value::Value "args": [], "type": { "kind": "NON_NULL", - "name": Null, + "name": None, "ofType": { "kind": "SCALAR", "name": "String", - "ofType": Null + "ofType": None } }, "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None }, { "name": "name", @@ -1951,56 +1948,56 @@ pub(crate) fn schema_introspection_result_without_descriptions() -> value::Value "type": { "kind": "SCALAR", "name": "String", - "ofType": Null + "ofType": None }, "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None }, { "name": "friends", "args": [], "type": { "kind": "NON_NULL", - "name": Null, + "name": None, "ofType": { "kind": "LIST", - "name": Null, + "name": None, "ofType": { "kind": "NON_NULL", - "name": Null, + "name": None, "ofType": { "kind": "INTERFACE", "name": "Character", - "ofType": Null + "ofType": None } } } }, "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None }, { "name": "appearsIn", "args": [], "type": { "kind": "NON_NULL", - "name": Null, + "name": None, "ofType": { "kind": "LIST", - "name": Null, + "name": None, "ofType": { "kind": "NON_NULL", - "name": Null, + "name": None, "ofType": { "kind": "ENUM", "name": "Episode", - "ofType": Null + "ofType": None } } } }, "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None }, { "name": "primaryFunction", @@ -2008,22 +2005,22 @@ pub(crate) fn schema_introspection_result_without_descriptions() -> value::Value "type": { "kind": "SCALAR", "name": "String", - "ofType": Null + "ofType": None }, "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None } ], - "inputFields": Null, + "inputFields": None, "interfaces": [ { "kind": "INTERFACE", "name": "Character", - "ofType": Null + "ofType": None } ], - "enumValues": Null, - "possibleTypes": Null + "enumValues": None, + "possibleTypes": None }, { "kind": "OBJECT", @@ -2036,23 +2033,23 @@ pub(crate) fn schema_introspection_result_without_descriptions() -> value::Value "name": "id", "type": { "kind": "NON_NULL", - "name": Null, + "name": None, "ofType": { "kind": "SCALAR", "name": "String", - "ofType": Null + "ofType": None } }, - "defaultValue": Null + "defaultValue": None } ], "type": { "kind": "OBJECT", "name": "Human", - "ofType": Null + "ofType": None }, "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None }, { "name": "droid", @@ -2061,23 +2058,23 @@ pub(crate) fn schema_introspection_result_without_descriptions() -> value::Value "name": "id", "type": { "kind": "NON_NULL", - "name": Null, + "name": None, "ofType": { "kind": "SCALAR", "name": "String", - "ofType": Null + "ofType": None } }, - "defaultValue": Null + "defaultValue": None } ], "type": { "kind": "OBJECT", "name": "Droid", - "ofType": Null + "ofType": None }, "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None }, { "name": "hero", @@ -2087,24 +2084,24 @@ pub(crate) fn schema_introspection_result_without_descriptions() -> value::Value "type": { "kind": "ENUM", "name": "Episode", - "ofType": Null + "ofType": None }, - "defaultValue": Null + "defaultValue": None } ], "type": { "kind": "INTERFACE", "name": "Character", - "ofType": Null + "ofType": None }, "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None } ], - "inputFields": Null, + "inputFields": None, "interfaces": [], - "enumValues": Null, - "possibleTypes": Null + "enumValues": None, + "possibleTypes": None }, { "kind": "OBJECT", @@ -2115,15 +2112,15 @@ pub(crate) fn schema_introspection_result_without_descriptions() -> value::Value "args": [], "type": { "kind": "NON_NULL", - "name": Null, + "name": None, "ofType": { "kind": "SCALAR", "name": "String", - "ofType": Null + "ofType": None } }, "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None }, { "name": "description", @@ -2131,25 +2128,25 @@ pub(crate) fn schema_introspection_result_without_descriptions() -> value::Value "type": { "kind": "SCALAR", "name": "String", - "ofType": Null + "ofType": None }, "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None }, { "name": "isDeprecated", "args": [], "type": { "kind": "NON_NULL", - "name": Null, + "name": None, "ofType": { "kind": "SCALAR", "name": "Boolean", - "ofType": Null + "ofType": None } }, "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None }, { "name": "deprecationReason", @@ -2157,86 +2154,86 @@ pub(crate) fn schema_introspection_result_without_descriptions() -> value::Value "type": { "kind": "SCALAR", "name": "String", - "ofType": Null + "ofType": None }, "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None } ], - "inputFields": Null, + "inputFields": None, "interfaces": [], - "enumValues": Null, - "possibleTypes": Null + "enumValues": None, + "possibleTypes": None }, { "kind": "ENUM", "name": "Episode", - "fields": Null, - "inputFields": Null, - "interfaces": Null, + "fields": None, + "inputFields": None, + "interfaces": None, "enumValues": [ { "name": "NEW_HOPE", "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None }, { "name": "EMPIRE", "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None }, { "name": "JEDI", "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None } ], - "possibleTypes": Null + "possibleTypes": None }, { "kind": "ENUM", "name": "__DirectiveLocation", - "fields": Null, - "inputFields": Null, - "interfaces": Null, + "fields": None, + "inputFields": None, + "interfaces": None, "enumValues": [ { "name": "QUERY", "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None }, { "name": "MUTATION", "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None }, { "name": "SUBSCRIPTION", "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None }, { "name": "FIELD", "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None }, { "name": "FRAGMENT_DEFINITION", "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None }, { "name": "FRAGMENT_SPREAD", "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None }, { "name": "INLINE_FRAGMENT", "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None } ], - "possibleTypes": Null + "possibleTypes": None }, { "kind": "INTERFACE", @@ -2247,15 +2244,15 @@ pub(crate) fn schema_introspection_result_without_descriptions() -> value::Value "args": [], "type": { "kind": "NON_NULL", - "name": Null, + "name": None, "ofType": { "kind": "SCALAR", "name": "String", - "ofType": Null + "ofType": None } }, "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None }, { "name": "name", @@ -2263,71 +2260,71 @@ pub(crate) fn schema_introspection_result_without_descriptions() -> value::Value "type": { "kind": "SCALAR", "name": "String", - "ofType": Null + "ofType": None }, "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None }, { "name": "friends", "args": [], "type": { "kind": "NON_NULL", - "name": Null, + "name": None, "ofType": { "kind": "LIST", - "name": Null, + "name": None, "ofType": { "kind": "NON_NULL", - "name": Null, + "name": None, "ofType": { "kind": "INTERFACE", "name": "Character", - "ofType": Null + "ofType": None } } } }, "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None }, { "name": "appearsIn", "args": [], "type": { "kind": "NON_NULL", - "name": Null, + "name": None, "ofType": { "kind": "LIST", - "name": Null, + "name": None, "ofType": { "kind": "NON_NULL", - "name": Null, + "name": None, "ofType": { "kind": "ENUM", "name": "Episode", - "ofType": Null + "ofType": None } } } }, "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None } ], - "inputFields": Null, - "interfaces": Null, - "enumValues": Null, + "inputFields": None, + "interfaces": None, + "enumValues": None, "possibleTypes": [ { "kind": "OBJECT", "name": "Human", - "ofType": Null + "ofType": None }, { "kind": "OBJECT", "name": "Droid", - "ofType": Null + "ofType": None } ] }, @@ -2340,15 +2337,15 @@ pub(crate) fn schema_introspection_result_without_descriptions() -> value::Value "args": [], "type": { "kind": "NON_NULL", - "name": Null, + "name": None, "ofType": { "kind": "SCALAR", "name": "String", - "ofType": Null + "ofType": None } }, "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None }, { "name": "description", @@ -2356,67 +2353,67 @@ pub(crate) fn schema_introspection_result_without_descriptions() -> value::Value "type": { "kind": "SCALAR", "name": "String", - "ofType": Null + "ofType": None }, "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None }, { "name": "locations", "args": [], "type": { "kind": "NON_NULL", - "name": Null, + "name": None, "ofType": { "kind": "LIST", - "name": Null, + "name": None, "ofType": { "kind": "NON_NULL", - "name": Null, + "name": None, "ofType": { "kind": "ENUM", "name": "__DirectiveLocation", - "ofType": Null + "ofType": None } } } }, "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None }, { "name": "args", "args": [], "type": { "kind": "NON_NULL", - "name": Null, + "name": None, "ofType": { "kind": "LIST", - "name": Null, + "name": None, "ofType": { "kind": "NON_NULL", - "name": Null, + "name": None, "ofType": { "kind": "OBJECT", "name": "__InputValue", - "ofType": Null + "ofType": None } } } }, "isDeprecated": false, - "deprecationReason": Null + "deprecationReason": None }, { "name": "onOperation", "args": [], "type": { "kind": "NON_NULL", - "name": Null, + "name": None, "ofType": { "kind": "SCALAR", "name": "Boolean", - "ofType": Null + "ofType": None } }, "isDeprecated": true, @@ -2427,11 +2424,11 @@ pub(crate) fn schema_introspection_result_without_descriptions() -> value::Value "args": [], "type": { "kind": "NON_NULL", - "name": Null, + "name": None, "ofType": { "kind": "SCALAR", "name": "Boolean", - "ofType": Null + "ofType": None } }, "isDeprecated": true, @@ -2442,21 +2439,21 @@ pub(crate) fn schema_introspection_result_without_descriptions() -> value::Value "args": [], "type": { "kind": "NON_NULL", - "name": Null, + "name": None, "ofType": { "kind": "SCALAR", "name": "Boolean", - "ofType": Null + "ofType": None } }, "isDeprecated": true, "deprecationReason": "Use the locations array instead" } ], - "inputFields": Null, + "inputFields": None, "interfaces": [], - "enumValues": Null, - "possibleTypes": Null + "enumValues": None, + "possibleTypes": None } ], "directives": [ @@ -2472,14 +2469,14 @@ pub(crate) fn schema_introspection_result_without_descriptions() -> value::Value "name": "if", "type": { "kind": "NON_NULL", - "name": Null, + "name": None, "ofType": { "kind": "SCALAR", "name": "Boolean", - "ofType": Null + "ofType": None } }, - "defaultValue": Null + "defaultValue": None } ] }, @@ -2495,14 +2492,14 @@ pub(crate) fn schema_introspection_result_without_descriptions() -> value::Value "name": "if", "type": { "kind": "NON_NULL", - "name": Null, + "name": None, "ofType": { "kind": "SCALAR", "name": "Boolean", - "ofType": Null + "ofType": None } }, - "defaultValue": Null + "defaultValue": None } ] } diff --git a/juniper/src/tests/subscriptions.rs b/juniper/src/tests/subscriptions.rs index ac61d504..6ba01a76 100644 --- a/juniper/src/tests/subscriptions.rs +++ b/juniper/src/tests/subscriptions.rs @@ -3,8 +3,9 @@ use std::{iter, iter::FromIterator as _, pin::Pin}; use futures::{stream, StreamExt as _}; use crate::{ - graphql_object, graphql_subscription, http::GraphQLRequest, Context, DefaultScalarValue, - EmptyMutation, ExecutionError, FieldError, GraphQLObject, Object, RootNode, Value, + graphql_object, graphql_subscription, graphql_value, http::GraphQLRequest, Context, + DefaultScalarValue, EmptyMutation, ExecutionError, FieldError, GraphQLObject, Object, RootNode, + Value, }; #[derive(Debug, Clone)] @@ -57,7 +58,7 @@ impl MySubscription { async fn error_human() -> Result { Err(FieldError::new( "handler error", - Value::Scalar(DefaultScalarValue::String("more details".to_string())), + graphql_value!("more details"), )) } @@ -163,14 +164,8 @@ fn returns_requested_object() { std::iter::from_fn(move || { iterator_count += 1; match iterator_count { - 1 => Some(( - "id", - Value::Scalar(DefaultScalarValue::String("stream id".to_string())), - )), - 2 => Some(( - "name", - Value::Scalar(DefaultScalarValue::String("stream name".to_string())), - )), + 1 => Some(("id", graphql_value!("stream id"))), + 2 => Some(("name", graphql_value!("stream name"))), _ => None, } }), @@ -199,10 +194,7 @@ fn returns_error() { let expected_error = ExecutionError::new( crate::parser::SourcePosition::new(23, 1, 8), &vec!["errorHuman"], - FieldError::new( - "handler error", - Value::Scalar(DefaultScalarValue::String("more details".to_string())), - ), + FieldError::new("handler error", graphql_value!("more details")), ); assert_eq!(returned_errors, vec![expected_error]); @@ -224,10 +216,7 @@ fn can_access_context() { move || { iterator_count += 1; match iterator_count { - 1 => Some(( - "id", - Value::Scalar(DefaultScalarValue::String("2".to_string())), - )), + 1 => Some(("id", graphql_value!("2"))), _ => None, } }, @@ -255,10 +244,7 @@ fn resolves_typed_inline_fragments() { move || { iterator_count += 1; match iterator_count { - 1 => Some(( - "id", - Value::Scalar(DefaultScalarValue::String("stream id".to_string())), - )), + 1 => Some(("id", graphql_value!("stream id"))), _ => None, } }, @@ -286,10 +272,7 @@ fn resolves_nontyped_inline_fragments() { move || { iterator_count += 1; match iterator_count { - 1 => Some(( - "id", - Value::Scalar(DefaultScalarValue::String("stream id".to_string())), - )), + 1 => Some(("id", graphql_value!("stream id"))), _ => None, } }, @@ -316,14 +299,8 @@ fn can_access_arguments() { move || { iterator_count += 1; match iterator_count { - 1 => Some(( - "id", - Value::Scalar(DefaultScalarValue::String("123".to_string())), - )), - 2 => Some(( - "name", - Value::Scalar(DefaultScalarValue::String("args name".to_string())), - )), + 1 => Some(("id", graphql_value!("123"))), + 2 => Some(("name", graphql_value!("args name"))), _ => None, } }, @@ -350,14 +327,8 @@ fn type_alias() { move || { iterator_count += 1; match iterator_count { - 1 => Some(( - "id", - Value::Scalar(DefaultScalarValue::String("stream id".to_string())), - )), - 2 => Some(( - "name", - Value::Scalar(DefaultScalarValue::String("stream name".to_string())), - )), + 1 => Some(("id", graphql_value!("stream id"))), + 2 => Some(("name", graphql_value!("stream name"))), _ => None, } }, diff --git a/juniper/src/tests/type_info_tests.rs b/juniper/src/tests/type_info_tests.rs index fdacbc61..4b8a22d0 100644 --- a/juniper/src/tests/type_info_tests.rs +++ b/juniper/src/tests/type_info_tests.rs @@ -2,12 +2,13 @@ use indexmap::IndexMap; use crate::{ executor::{ExecutionResult, Executor, Registry, Variables}, + graphql_value, schema::{meta::MetaType, model::RootNode}, types::{ base::{Arguments, GraphQLType, GraphQLValue}, scalars::{EmptyMutation, EmptySubscription}, }, - value::{ScalarValue, Value}, + value::ScalarValue, }; pub struct NodeTypeInfo { @@ -95,16 +96,12 @@ fn test_node() { assert_eq!( crate::execute_sync(doc, None, &schema, &Variables::new(), &()), Ok(( - Value::object( - vec![ - ("foo", Value::scalar("1")), - ("bar", Value::scalar("2")), - ("baz", Value::scalar("3")), - ] - .into_iter() - .collect() - ), - vec![] - )) + graphql_value!({ + "foo": "1", + "bar": "2", + "baz": "3", + }), + vec![], + )), ); } diff --git a/juniper/src/value/object.rs b/juniper/src/value/object.rs index 3c359c93..909abe3f 100644 --- a/juniper/src/value/object.rs +++ b/juniper/src/value/object.rs @@ -78,7 +78,7 @@ impl IntoIterator for Object { impl From> for Value { fn from(o: Object) -> Self { - Value::Object(o) + Self::Object(o) } } diff --git a/juniper_graphql_ws/src/lib.rs b/juniper_graphql_ws/src/lib.rs index f5627596..675f9cff 100644 --- a/juniper_graphql_ws/src/lib.rs +++ b/juniper_graphql_ws/src/lib.rs @@ -633,9 +633,9 @@ mod test { use juniper::{ futures::sink::SinkExt, - graphql_object, graphql_subscription, + graphql_object, graphql_subscription, graphql_value, parser::{ParseError, Spanning, Token}, - DefaultScalarValue, EmptyMutation, FieldError, FieldResult, InputValue, RootNode, Value, + DefaultScalarValue, EmptyMutation, FieldError, FieldResult, InputValue, RootNode, }; use super::*; @@ -681,7 +681,7 @@ mod test { async fn error(_context: &Context) -> BoxStream<'static, FieldResult> { stream::once(future::ready(Err(FieldError::new( "field error", - Value::null(), + graphql_value!(None), )))) .chain( tokio::time::sleep(Duration::from_secs(10000)) @@ -729,12 +729,7 @@ mod test { ServerMessage::Data { id: "foo".to_string(), payload: DataPayload { - data: Value::Object( - [("context", Value::Scalar(DefaultScalarValue::Int(1)))] - .iter() - .cloned() - .collect() - ), + data: graphql_value!({"context": 1}), errors: vec![], }, }, @@ -779,7 +774,7 @@ mod test { ServerMessage::Data { id: "foo".to_string(), payload: DataPayload { - data: Value::Object([("context", Value::scalar(1))].iter().cloned().collect()), + data: graphql_value!({"context": 1}), errors: vec![], }, }, @@ -801,7 +796,7 @@ mod test { ServerMessage::Data { id: "bar".to_string(), payload: DataPayload { - data: Value::Object([("context", Value::scalar(1))].iter().cloned().collect()), + data: graphql_value!({"context": 1}), errors: vec![], }, }, @@ -1009,12 +1004,7 @@ mod test { ServerMessage::Data { id: "foo".to_string(), payload: DataPayload { - data: Value::Object( - [("context", Value::Scalar(DefaultScalarValue::Int(1)))] - .iter() - .cloned() - .collect() - ), + data: graphql_value!({"context": 1}), errors: vec![], }, }, @@ -1054,10 +1044,7 @@ mod test { payload: DataPayload { data, errors }, } => { assert_eq!(id, "foo"); - assert_eq!( - data, - Value::Object([("error", Value::null())].iter().cloned().collect()) - ); + assert_eq!(data, graphql_value!({ "error": None }),); 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 252681e1..5bcc5111 100644 --- a/juniper_graphql_ws/src/server_message.rs +++ b/juniper_graphql_ws/src/server_message.rs @@ -134,8 +134,9 @@ pub enum ServerMessage { #[cfg(test)] mod test { + use juniper::{graphql_value, DefaultScalarValue}; + use super::*; - use juniper::DefaultScalarValue; #[test] fn test_serialization() { @@ -160,7 +161,7 @@ mod test { serde_json::to_string(&ServerMessage::Data { id: "foo".to_string(), payload: DataPayload { - data: Value::null(), + data: graphql_value!(None), errors: vec![], }, }) diff --git a/juniper_subscriptions/src/lib.rs b/juniper_subscriptions/src/lib.rs index 6541e892..ada8449d 100644 --- a/juniper_subscriptions/src/lib.rs +++ b/juniper_subscriptions/src/lib.rs @@ -254,17 +254,17 @@ where #[cfg(test)] mod whole_responses_stream { use futures::{stream, StreamExt as _}; - use juniper::{DefaultScalarValue, ExecutionError, FieldError}; + use juniper::{graphql_value, DefaultScalarValue, ExecutionError, FieldError}; use super::*; #[tokio::test] async fn with_error() { - let expected = vec![ExecutionOutput { - data: Value::::Null, + let expected: Vec> = vec![ExecutionOutput { + data: graphql_value!(None), errors: vec![ExecutionError::at_origin(FieldError::new( "field error", - Value::Null, + graphql_value!(None), ))], }]; 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", - Value::Null, + graphql_value!(None), ))], ) .collect::>() @@ -285,9 +285,8 @@ mod whole_responses_stream { #[tokio::test] async fn value_null() { - let expected = vec![ExecutionOutput::from_data( - Value::::Null, - )]; + let expected: Vec> = + vec![ExecutionOutput::from_data(graphql_value!(None))]; let expected = serde_json::to_string(&expected).unwrap(); let result = whole_responses_stream::(Value::Null, vec![]) @@ -302,12 +301,12 @@ mod whole_responses_stream { #[tokio::test] async fn value_scalar() { - let expected = vec![ - ExecutionOutput::from_data(Value::Scalar(DefaultScalarValue::Int(1i32))), - ExecutionOutput::from_data(Value::Scalar(DefaultScalarValue::Int(2i32))), - ExecutionOutput::from_data(Value::Scalar(DefaultScalarValue::Int(3i32))), - ExecutionOutput::from_data(Value::Scalar(DefaultScalarValue::Int(4i32))), - ExecutionOutput::from_data(Value::Scalar(DefaultScalarValue::Int(5i32))), + let expected: Vec> = vec![ + ExecutionOutput::from_data(graphql_value!(1)), + ExecutionOutput::from_data(graphql_value!(2)), + ExecutionOutput::from_data(graphql_value!(3)), + ExecutionOutput::from_data(graphql_value!(4)), + ExecutionOutput::from_data(graphql_value!(5)), ]; let expected = serde_json::to_string(&expected).unwrap(); @@ -317,7 +316,7 @@ mod whole_responses_stream { return Poll::Ready(None); } counter += 1; - Poll::Ready(Some(Ok(Value::Scalar(DefaultScalarValue::Int(counter))))) + Poll::Ready(Some(Ok(graphql_value!(counter)))) }); let result = @@ -331,24 +330,24 @@ mod whole_responses_stream { #[tokio::test] async fn value_list() { - let expected = vec![ - ExecutionOutput::from_data(Value::Scalar(DefaultScalarValue::Int(1i32))), - ExecutionOutput::from_data(Value::Scalar(DefaultScalarValue::Int(2i32))), - ExecutionOutput::from_data(Value::null()), - ExecutionOutput::from_data(Value::Scalar(DefaultScalarValue::Int(4i32))), + 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!(4)), ]; let expected = serde_json::to_string(&expected).unwrap(); let streams: Vec> = vec![ Value::Scalar(Box::pin(stream::once(async { - PollResult::Ok(Value::Scalar(DefaultScalarValue::Int(1i32))) + PollResult::Ok(graphql_value!(1)) }))), Value::Scalar(Box::pin(stream::once(async { - PollResult::Ok(Value::Scalar(DefaultScalarValue::Int(2i32))) + PollResult::Ok(graphql_value!(2)) }))), Value::Null, Value::Scalar(Box::pin(stream::once(async { - PollResult::Ok(Value::Scalar(DefaultScalarValue::Int(4i32))) + PollResult::Ok(graphql_value!(4)) }))), ]; @@ -362,21 +361,9 @@ mod whole_responses_stream { #[tokio::test] async fn value_object() { - let expected = vec![ - ExecutionOutput::from_data(Value::Object(Object::from_iter( - vec![ - ("one", Value::Scalar(DefaultScalarValue::Int(1i32))), - ("two", Value::Scalar(DefaultScalarValue::Int(1i32))), - ] - .into_iter(), - ))), - ExecutionOutput::from_data(Value::Object(Object::from_iter( - vec![ - ("one", Value::Scalar(DefaultScalarValue::Int(2i32))), - ("two", Value::Scalar(DefaultScalarValue::Int(2i32))), - ] - .into_iter(), - ))), + let expected: Vec> = vec![ + ExecutionOutput::from_data(graphql_value!({"one": 1, "two": 1})), + ExecutionOutput::from_data(graphql_value!({"one": 2, "two": 2})), ]; let expected = serde_json::to_string(&expected).unwrap(); @@ -386,7 +373,7 @@ mod whole_responses_stream { return Poll::Ready(None); } counter += 1; - Poll::Ready(Some(Ok(Value::Scalar(DefaultScalarValue::Int(counter))))) + Poll::Ready(Some(Ok(graphql_value!(counter)))) }); let mut counter = 0; @@ -395,7 +382,7 @@ mod whole_responses_stream { return Poll::Ready(None); } counter += 1; - Poll::Ready(Some(Ok(Value::Scalar(DefaultScalarValue::Int(counter))))) + Poll::Ready(Some(Ok(graphql_value!(counter)))) }); let vals: Vec<(&str, Value)> = vec![