Use graphql_value!() macro in tests asap

This commit is contained in:
tyranron 2021-08-13 02:12:01 +03:00
parent a3fda7363d
commit 74afe4c04a
No known key found for this signature in database
GPG key ID: 762E144FB230A4F0
27 changed files with 1253 additions and 1945 deletions

View file

@ -9,9 +9,9 @@ use actix_web::{
}; };
use juniper::{ use juniper::{
graphql_object, graphql_subscription, graphql_object, graphql_subscription, graphql_value,
tests::fixtures::starwars::schema::{Character as _, Database, Query}, 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_actix::{graphql_handler, playground_handler, subscriptions::subscriptions_handler};
use juniper_graphql_ws::ConnectionConfig; use juniper_graphql_ws::ConnectionConfig;
@ -77,9 +77,7 @@ impl Subscription {
if counter == 2 { if counter == 2 {
yield Err(FieldError::new( yield Err(FieldError::new(
"some field error from handler", "some field error from handler",
Value::Scalar(DefaultScalarValue::String( graphql_value!("some additional string"),
"some additional string".to_string(),
)),
)) ))
} else { } else {
let random_id = rng.gen_range(1000..1005).to_string(); let random_id = rng.gen_range(1000..1005).to_string();

View file

@ -4,8 +4,8 @@ use std::{env, pin::Pin, sync::Arc, time::Duration};
use futures::{FutureExt as _, Stream}; use futures::{FutureExt as _, Stream};
use juniper::{ use juniper::{
graphql_object, graphql_subscription, DefaultScalarValue, EmptyMutation, FieldError, graphql_object, graphql_subscription, graphql_value, EmptyMutation, FieldError, GraphQLEnum,
GraphQLEnum, RootNode, Value, RootNode,
}; };
use juniper_graphql_ws::ConnectionConfig; use juniper_graphql_ws::ConnectionConfig;
use juniper_warp::{playground_filter, subscriptions::serve_graphql_ws}; use juniper_warp::{playground_filter, subscriptions::serve_graphql_ws};
@ -117,9 +117,7 @@ impl Subscription {
if counter == 2 { if counter == 2 {
yield Err(FieldError::new( yield Err(FieldError::new(
"some field error from handler", "some field error from handler",
Value::Scalar(DefaultScalarValue::String( graphql_value!("some additional string"),
"some additional string".to_string(),
)),
)) ))
} else { } else {
yield Ok(User { yield Ok(User {

View file

@ -1,9 +1,10 @@
use crate::custom_scalar::MyScalarValue;
use juniper::{ use juniper::{
execute, EmptyMutation, EmptySubscription, FromInputValue, InputValue, RootNode, ToInputValue, execute, graphql_value, EmptyMutation, EmptySubscription, FromInputValue, InputValue, RootNode,
Value, Variables, ToInputValue, Value, Variables,
}; };
use crate::custom_scalar::MyScalarValue;
#[derive(Debug, PartialEq, Eq, Hash, juniper::GraphQLScalarValue)] #[derive(Debug, PartialEq, Eq, Hash, juniper::GraphQLScalarValue)]
#[graphql(transparent, scalar = MyScalarValue)] #[graphql(transparent, scalar = MyScalarValue)]
pub struct LargeId(i64); pub struct LargeId(i64);
@ -56,28 +57,14 @@ async fn test_scalar_value_large_query() {
EmptySubscription::<()>::new(), EmptySubscription::<()>::new(),
); );
let doc = r#" let doc = r#"{
query { user { id }
user { id } }"#;
}"#;
let val = Value::<MyScalarValue>::scalar(0_i64);
assert_eq!( assert_eq!(
execute(doc, None, &schema, &Variables::<MyScalarValue>::new(), &()).await, execute(doc, None, &schema, &Variables::<MyScalarValue>::new(), &()).await,
Ok(( Ok((graphql_value!({"user": {"id": val}}), vec![])),
Value::object(
vec![(
"user",
Value::object(
vec![("id", Value::<MyScalarValue>::scalar(0_i64)),]
.into_iter()
.collect(),
),
)]
.into_iter()
.collect()
),
vec![]
))
); );
} }
@ -89,51 +76,23 @@ async fn test_scalar_value_large_mutation() {
EmptySubscription::<()>::new(), EmptySubscription::<()>::new(),
); );
let doc = r#" let doc = r#"mutation {
mutation { changeUser(id: 1) { id }
changeUser(id: 1) { id } }"#;
}"#;
let val = Value::<MyScalarValue>::scalar(1_i64);
assert_eq!( assert_eq!(
execute(doc, None, &schema, &Variables::<MyScalarValue>::new(), &()).await, execute(doc, None, &schema, &Variables::<MyScalarValue>::new(), &()).await,
Ok(( Ok((graphql_value!({"changeUser": {"id": val}}), vec![])),
Value::object(
vec![(
"changeUser",
Value::object(
vec![("id", Value::<MyScalarValue>::scalar(1_i64)),]
.into_iter()
.collect(),
),
)]
.into_iter()
.collect()
),
vec![]
))
); );
let doc = r#" let doc = r#"mutation {
mutation { changeUser(id: 4294967297) { id }
changeUser(id: 4294967297) { id } }"#;
}"#;
let val = Value::<MyScalarValue>::scalar(4294967297_i64);
assert_eq!( assert_eq!(
execute(doc, None, &schema, &Variables::<MyScalarValue>::new(), &()).await, execute(doc, None, &schema, &Variables::<MyScalarValue>::new(), &()).await,
Ok(( Ok((graphql_value!({"changeUser": {"id": val}}), vec![])),
Value::object(
vec![(
"changeUser",
Value::object(
vec![("id", Value::<MyScalarValue>::scalar(4294967297_i64)),]
.into_iter()
.collect(),
),
)]
.into_iter()
.collect()
),
vec![]
))
); );
} }

View file

@ -222,11 +222,11 @@ async fn default_name_introspection() {
run_type_info_query(doc, |type_info| { run_type_info_query(doc, |type_info| {
assert_eq!( assert_eq!(
type_info.get_field_value("name"), type_info.get_field_value("name"),
Some(&Value::scalar("DefaultName")) Some(&graphql_value!("DefaultName")),
); );
assert_eq!( assert_eq!(
type_info.get_field_value("description"), type_info.get_field_value("description"),
Some(&Value::null()) Some(&graphql_value!(None)),
); );
}) })
.await; .await;
@ -246,11 +246,11 @@ async fn other_order_introspection() {
run_type_info_query(doc, |type_info| { run_type_info_query(doc, |type_info| {
assert_eq!( assert_eq!(
type_info.get_field_value("name"), type_info.get_field_value("name"),
Some(&Value::scalar("OtherOrder")) Some(&graphql_value!("OtherOrder")),
); );
assert_eq!( assert_eq!(
type_info.get_field_value("description"), type_info.get_field_value("description"),
Some(&Value::null()) Some(&graphql_value!(None)),
); );
}) })
.await; .await;
@ -270,11 +270,11 @@ async fn named_introspection() {
run_type_info_query(doc, |type_info| { run_type_info_query(doc, |type_info| {
assert_eq!( assert_eq!(
type_info.get_field_value("name"), type_info.get_field_value("name"),
Some(&Value::scalar("ANamedScalar")) Some(&graphql_value!("ANamedScalar")),
); );
assert_eq!( assert_eq!(
type_info.get_field_value("description"), type_info.get_field_value("description"),
Some(&Value::null()) Some(&graphql_value!(None)),
); );
}) })
.await; .await;
@ -294,11 +294,13 @@ async fn scalar_description_introspection() {
run_type_info_query(doc, |type_info| { run_type_info_query(doc, |type_info| {
assert_eq!( assert_eq!(
type_info.get_field_value("name"), type_info.get_field_value("name"),
Some(&Value::scalar("ScalarDescription")) Some(&graphql_value!("ScalarDescription")),
); );
assert_eq!( assert_eq!(
type_info.get_field_value("description"), 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; .await;
@ -318,11 +320,11 @@ async fn generated_scalar_introspection() {
run_type_info_query(doc, |type_info| { run_type_info_query(doc, |type_info| {
assert_eq!( assert_eq!(
type_info.get_field_value("name"), type_info.get_field_value("name"),
Some(&Value::scalar("Generated")) Some(&graphql_value!("Generated")),
); );
assert_eq!( assert_eq!(
type_info.get_field_value("description"), type_info.get_field_value("description"),
Some(&Value::null()) Some(&graphql_value!(None)),
); );
}) })
.await; .await;

View file

@ -2,14 +2,15 @@
use std::pin::Pin; use std::pin::Pin;
use futures::{future, stream, FutureExt as _, StreamExt as _}; use futures::{future, stream, FutureExt as _};
use juniper::{ use juniper::{
execute, graphql_object, graphql_subscription, graphql_value, resolve_into_stream, execute, graphql_object, graphql_subscription, graphql_value, resolve_into_stream,
DefaultScalarValue, EmptyMutation, ExecutionError, Executor, FieldError, FieldResult, DefaultScalarValue, EmptyMutation, Executor, FieldError, FieldResult, GraphQLInputObject,
GraphQLError, GraphQLInputObject, GraphQLType, IntoFieldError, RootNode, ScalarValue, Value, GraphQLType, IntoFieldError, RootNode, ScalarValue, Variables,
ValuesStream, Variables,
}; };
use crate::util::extract_next;
struct Query; struct Query;
#[graphql_object] #[graphql_object]
@ -44,29 +45,6 @@ where
type Stream<'a, I> = Pin<Box<dyn futures::Stream<Item = I> + Send + 'a>>; type Stream<'a, I> = Pin<Box<dyn futures::Stream<Item = I> + Send + 'a>>;
async fn extract_next<'a, S: ScalarValue>(
input: Result<(Value<ValuesStream<'a, S>>, Vec<ExecutionError<S>>), GraphQLError<'a>>,
) -> Result<(Value<S>, Vec<ExecutionError<S>>), 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 { mod trivial {
use super::*; use super::*;

View file

@ -218,7 +218,7 @@ async fn querying_long() {
run_query("{ longField }", |result| { run_query("{ longField }", |result| {
assert_eq!( assert_eq!(
result.get_field_value("longField"), result.get_field_value("longField"),
Some(&Value::scalar(i64::from(i32::max_value()) + 1)) Some(&Value::scalar(i64::from(i32::MAX) + 1))
); );
}) })
.await; .await;
@ -227,14 +227,11 @@ async fn querying_long() {
#[tokio::test] #[tokio::test]
async fn querying_long_arg() { async fn querying_long_arg() {
run_query( run_query(
&format!( &format!("{{ longWithArg(longArg: {}) }}", i64::from(i32::MAX) + 3),
"{{ longWithArg(longArg: {}) }}",
i64::from(i32::max_value()) + 3
),
|result| { |result| {
assert_eq!( assert_eq!(
result.get_field_value("longWithArg"), 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) }", "query q($test: Long!){ longWithArg(longArg: $test) }",
vec![( vec![(
"test".to_owned(), "test".to_owned(),
InputValue::Scalar(MyScalarValue::Long(i64::from(i32::max_value()) + 42)), InputValue::Scalar(MyScalarValue::Long(i64::from(i32::MAX) + 42)),
)] )]
.into_iter() .into_iter()
.collect(), .collect(),
|result| { |result| {
assert_eq!( assert_eq!(
result.get_field_value("longWithArg"), 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] #[test]
fn deserialize_variable() { 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<MyScalarValue> = serde_json::from_str(&json).unwrap(); let input_value: InputValue<MyScalarValue> = serde_json::from_str(&json).unwrap();
assert_eq!( assert_eq!(
@ -271,7 +268,7 @@ fn deserialize_variable() {
InputValue::Object(vec![( InputValue::Object(vec![(
Spanning::unlocated("field".into()), Spanning::unlocated("field".into()),
Spanning::unlocated(InputValue::Scalar(MyScalarValue::Long( Spanning::unlocated(InputValue::Scalar(MyScalarValue::Long(
i64::from(i32::max_value()) + 42 i64::from(i32::MAX) + 42
))) )))
)]) )])
); );

View file

@ -1,8 +1,13 @@
//! Checks that `__typename` field queries okay on root types. //! Checks that `__typename` field queries okay on root types.
//! See [#372](https://github.com/graphql-rust/juniper/issues/372) for details. //! See [#372](https://github.com/graphql-rust/juniper/issues/372) for details.
use futures::{stream, StreamExt as _}; use futures::{stream, FutureExt as _};
use juniper::{graphql_object, graphql_subscription, graphql_value, RootNode, Value, Variables}; use juniper::{
execute, graphql_object, graphql_subscription, graphql_value, resolve_into_stream, RootNode,
Variables,
};
use crate::util::extract_next;
pub struct Query; pub struct Query;
@ -36,12 +41,11 @@ async fn implicit_query_typename() {
let query = r#"{ __typename }"#; let query = r#"{ __typename }"#;
let schema = RootNode::new(Query, Mutation, Subscription); 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!(
assert_eq!(res, graphql_value!({"__typename": "Query"})); execute(query, None, &schema, &Variables::new(), &()).await,
Ok((graphql_value!({"__typename": "Query"}), vec![])),
);
} }
#[tokio::test] #[tokio::test]
@ -49,12 +53,11 @@ async fn query_typename() {
let query = r#"query { __typename }"#; let query = r#"query { __typename }"#;
let schema = RootNode::new(Query, Mutation, Subscription); 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!(
assert_eq!(res, graphql_value!({"__typename": "Query"})); execute(query, None, &schema, &Variables::new(), &()).await,
Ok((graphql_value!({"__typename": "Query"}), vec![])),
);
} }
#[tokio::test] #[tokio::test]
@ -62,12 +65,11 @@ async fn explicit_query_typename() {
let query = r#"query Query { __typename }"#; let query = r#"query Query { __typename }"#;
let schema = RootNode::new(Query, Mutation, Subscription); 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!(
assert_eq!(res, graphql_value!({"__typename": "Query"})); execute(query, None, &schema, &Variables::new(), &()).await,
Ok((graphql_value!({"__typename": "Query"}), vec![])),
);
} }
#[tokio::test] #[tokio::test]
@ -75,12 +77,11 @@ async fn mutation_typename() {
let query = r#"mutation { __typename }"#; let query = r#"mutation { __typename }"#;
let schema = RootNode::new(Query, Mutation, Subscription); 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!(
assert_eq!(res, graphql_value!({"__typename": "Mutation"})); execute(query, None, &schema, &Variables::new(), &()).await,
Ok((graphql_value!({"__typename": "Mutation"}), vec![])),
);
} }
#[tokio::test] #[tokio::test]
@ -88,12 +89,11 @@ async fn explicit_mutation_typename() {
let query = r#"mutation Mutation { __typename }"#; let query = r#"mutation Mutation { __typename }"#;
let schema = RootNode::new(Query, Mutation, Subscription); 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!(
assert_eq!(res, graphql_value!({"__typename": "Mutation"})); execute(query, None, &schema, &Variables::new(), &()).await,
Ok((graphql_value!({"__typename": "Mutation"}), vec![])),
);
} }
#[tokio::test] #[tokio::test]
@ -101,24 +101,13 @@ async fn subscription_typename() {
let query = r#"subscription { __typename }"#; let query = r#"subscription { __typename }"#;
let schema = RootNode::new(Query, Mutation, Subscription); 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_eq!(
assert!(matches!(res, Value::Object(_))); resolve_into_stream(query, None, &schema, &Variables::new(), &())
if let Value::Object(mut obj) = res { .then(|s| extract_next(s))
assert!(obj.contains_field("__typename")); .await,
Ok((graphql_value!({"__typename": "Subscription"}), vec![])),
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"))),
);
}
}
} }
#[tokio::test] #[tokio::test]
@ -126,22 +115,11 @@ async fn explicit_subscription_typename() {
let query = r#"subscription Subscription { __typename }"#; let query = r#"subscription Subscription { __typename }"#;
let schema = RootNode::new(Query, Mutation, Subscription); 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_eq!(
assert!(matches!(res, Value::Object(_))); resolve_into_stream(query, None, &schema, &Variables::new(), &())
if let Value::Object(mut obj) = res { .then(|s| extract_next(s))
assert!(obj.contains_field("__typename")); .await,
Ok((graphql_value!({"__typename": "Subscription"}), vec![])),
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"))),
);
}
}
} }

View file

@ -32,3 +32,36 @@ mod issue_925;
mod issue_945; mod issue_945;
#[cfg(test)] #[cfg(test)]
mod pre_parse; 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<ValuesStream<'a, S>>, Vec<ExecutionError<S>>), GraphQLError<'a>>,
) -> Result<(Value<S>, Vec<ExecutionError<S>>), 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")
}
}

View file

@ -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)] #[derive(GraphQLEnum)]
enum UserKind { enum UserKind {
@ -74,10 +76,10 @@ impl Query {
async fn async_simple() { async fn async_simple() {
let schema = RootNode::new(Query, EmptyMutation::new(), EmptySubscription::new()); let schema = RootNode::new(Query, EmptyMutation::new(), EmptySubscription::new());
let doc = r#" let doc = r#"
query { query {
fieldSync fieldSync
fieldAsyncPlain fieldAsyncPlain
delayed delayed
user(id: "user1") { user(id: "user1") {
name name
} }
@ -96,7 +98,7 @@ async fn async_simple() {
assert_eq!( assert_eq!(
value, value,
crate::graphql_value!({ graphql_value!({
"delayed": true, "delayed": true,
"fieldAsyncPlain": "field_async_plain", "fieldAsyncPlain": "field_async_plain",
"fieldSync": "field_sync", "fieldSync": "field_sync",

View file

@ -1,8 +1,9 @@
use crate::{ use crate::{
executor::Variables, executor::Variables,
graphql_value,
schema::model::RootNode, schema::model::RootNode,
types::scalars::{EmptyMutation, EmptySubscription}, types::scalars::{EmptyMutation, EmptySubscription},
value::{DefaultScalarValue, Object, Value}, value::{DefaultScalarValue, Object},
}; };
struct TestType; struct TestType;
@ -51,8 +52,8 @@ where
#[tokio::test] #[tokio::test]
async fn scalar_include_true() { async fn scalar_include_true() {
run_query("{ a, b @include(if: true) }", |result| { 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("a"), Some(&graphql_value!("a")));
assert_eq!(result.get_field_value("b"), Some(&Value::scalar("b"))); assert_eq!(result.get_field_value("b"), Some(&graphql_value!("b")));
}) })
.await; .await;
} }
@ -60,7 +61,7 @@ async fn scalar_include_true() {
#[tokio::test] #[tokio::test]
async fn scalar_include_false() { async fn scalar_include_false() {
run_query("{ a, b @include(if: false) }", |result| { 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); assert_eq!(result.get_field_value("b"), None);
}) })
.await; .await;
@ -69,8 +70,8 @@ async fn scalar_include_false() {
#[tokio::test] #[tokio::test]
async fn scalar_skip_false() { async fn scalar_skip_false() {
run_query("{ a, b @skip(if: false) }", |result| { 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("a"), Some(&graphql_value!("a")));
assert_eq!(result.get_field_value("b"), Some(&Value::scalar("b"))); assert_eq!(result.get_field_value("b"), Some(&graphql_value!("b")));
}) })
.await; .await;
} }
@ -78,7 +79,7 @@ async fn scalar_skip_false() {
#[tokio::test] #[tokio::test]
async fn scalar_skip_true() { async fn scalar_skip_true() {
run_query("{ a, b @skip(if: true) }", |result| { 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); assert_eq!(result.get_field_value("b"), None);
}) })
.await; .await;
@ -89,8 +90,8 @@ async fn fragment_spread_include_true() {
run_query( run_query(
"{ a, ...Frag @include(if: true) } fragment Frag on TestType { b }", "{ a, ...Frag @include(if: true) } fragment Frag on TestType { b }",
|result| { |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"), Some(&Value::scalar("b"))); assert_eq!(result.get_field_value("b"), Some(&graphql_value!("b")));
}, },
) )
.await; .await;
@ -101,7 +102,7 @@ async fn fragment_spread_include_false() {
run_query( run_query(
"{ a, ...Frag @include(if: false) } fragment Frag on TestType { b }", "{ a, ...Frag @include(if: false) } fragment Frag on TestType { b }",
|result| { |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); assert_eq!(result.get_field_value("b"), None);
}, },
) )
@ -113,8 +114,8 @@ async fn fragment_spread_skip_false() {
run_query( run_query(
"{ a, ...Frag @skip(if: false) } fragment Frag on TestType { b }", "{ a, ...Frag @skip(if: false) } fragment Frag on TestType { b }",
|result| { |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"), Some(&Value::scalar("b"))); assert_eq!(result.get_field_value("b"), Some(&graphql_value!("b")));
}, },
) )
.await; .await;
@ -125,7 +126,7 @@ async fn fragment_spread_skip_true() {
run_query( run_query(
"{ a, ...Frag @skip(if: true) } fragment Frag on TestType { b }", "{ a, ...Frag @skip(if: true) } fragment Frag on TestType { b }",
|result| { |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); assert_eq!(result.get_field_value("b"), None);
}, },
) )
@ -137,8 +138,8 @@ async fn inline_fragment_include_true() {
run_query( run_query(
"{ a, ... on TestType @include(if: true) { b } }", "{ a, ... on TestType @include(if: true) { b } }",
|result| { |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"), Some(&Value::scalar("b"))); assert_eq!(result.get_field_value("b"), Some(&graphql_value!("b")));
}, },
) )
.await; .await;
@ -149,7 +150,7 @@ async fn inline_fragment_include_false() {
run_query( run_query(
"{ a, ... on TestType @include(if: false) { b } }", "{ a, ... on TestType @include(if: false) { b } }",
|result| { |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); assert_eq!(result.get_field_value("b"), None);
}, },
) )
@ -159,8 +160,8 @@ async fn inline_fragment_include_false() {
#[tokio::test] #[tokio::test]
async fn inline_fragment_skip_false() { async fn inline_fragment_skip_false() {
run_query("{ a, ... on TestType @skip(if: false) { b } }", |result| { 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("a"), Some(&graphql_value!("a")));
assert_eq!(result.get_field_value("b"), Some(&Value::scalar("b"))); assert_eq!(result.get_field_value("b"), Some(&graphql_value!("b")));
}) })
.await; .await;
} }
@ -168,7 +169,7 @@ async fn inline_fragment_skip_false() {
#[tokio::test] #[tokio::test]
async fn inline_fragment_skip_true() { async fn inline_fragment_skip_true() {
run_query("{ a, ... on TestType @skip(if: true) { b } }", |result| { 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); assert_eq!(result.get_field_value("b"), None);
}) })
.await; .await;
@ -177,8 +178,8 @@ async fn inline_fragment_skip_true() {
#[tokio::test] #[tokio::test]
async fn anonymous_inline_fragment_include_true() { async fn anonymous_inline_fragment_include_true() {
run_query("{ a, ... @include(if: true) { b } }", |result| { 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("a"), Some(&graphql_value!("a")));
assert_eq!(result.get_field_value("b"), Some(&Value::scalar("b"))); assert_eq!(result.get_field_value("b"), Some(&graphql_value!("b")));
}) })
.await; .await;
} }
@ -186,7 +187,7 @@ async fn anonymous_inline_fragment_include_true() {
#[tokio::test] #[tokio::test]
async fn anonymous_inline_fragment_include_false() { async fn anonymous_inline_fragment_include_false() {
run_query("{ a, ... @include(if: false) { b } }", |result| { 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); assert_eq!(result.get_field_value("b"), None);
}) })
.await; .await;
@ -195,8 +196,8 @@ async fn anonymous_inline_fragment_include_false() {
#[tokio::test] #[tokio::test]
async fn anonymous_inline_fragment_skip_false() { async fn anonymous_inline_fragment_skip_false() {
run_query("{ a, ... @skip(if: false) { b } }", |result| { 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("a"), Some(&graphql_value!("a")));
assert_eq!(result.get_field_value("b"), Some(&Value::scalar("b"))); assert_eq!(result.get_field_value("b"), Some(&graphql_value!("b")));
}) })
.await; .await;
} }
@ -204,7 +205,7 @@ async fn anonymous_inline_fragment_skip_false() {
#[tokio::test] #[tokio::test]
async fn anonymous_inline_fragment_skip_true() { async fn anonymous_inline_fragment_skip_true() {
run_query("{ a, ... @skip(if: true) { b } }", |result| { 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); assert_eq!(result.get_field_value("b"), None);
}) })
.await; .await;
@ -213,7 +214,7 @@ async fn anonymous_inline_fragment_skip_true() {
#[tokio::test] #[tokio::test]
async fn scalar_include_true_skip_true() { async fn scalar_include_true_skip_true() {
run_query("{ a, b @include(if: true) @skip(if: true) }", |result| { 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); assert_eq!(result.get_field_value("b"), None);
}) })
.await; .await;
@ -222,8 +223,8 @@ async fn scalar_include_true_skip_true() {
#[tokio::test] #[tokio::test]
async fn scalar_include_true_skip_false() { async fn scalar_include_true_skip_false() {
run_query("{ a, b @include(if: true) @skip(if: false) }", |result| { 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("a"), Some(&graphql_value!("a")));
assert_eq!(result.get_field_value("b"), Some(&Value::scalar("b"))); assert_eq!(result.get_field_value("b"), Some(&graphql_value!("b")));
}) })
.await; .await;
} }
@ -231,7 +232,7 @@ async fn scalar_include_true_skip_false() {
#[tokio::test] #[tokio::test]
async fn scalar_include_false_skip_true() { async fn scalar_include_false_skip_true() {
run_query("{ a, b @include(if: false) @skip(if: true) }", |result| { 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); assert_eq!(result.get_field_value("b"), None);
}) })
.await; .await;
@ -240,7 +241,7 @@ async fn scalar_include_false_skip_true() {
#[tokio::test] #[tokio::test]
async fn scalar_include_false_skip_false() { async fn scalar_include_false_skip_false() {
run_query("{ a, b @include(if: false) @skip(if: false) }", |result| { 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); assert_eq!(result.get_field_value("b"), None);
}) })
.await; .await;

View file

@ -5,7 +5,7 @@ use crate::{
schema::model::RootNode, schema::model::RootNode,
types::scalars::{EmptyMutation, EmptySubscription}, types::scalars::{EmptyMutation, EmptySubscription},
validation::RuleError, validation::RuleError,
value::{DefaultScalarValue, Object, Value}, value::{DefaultScalarValue, Object},
GraphQLEnum, GraphQLEnum,
GraphQLError::ValidationError, GraphQLError::ValidationError,
}; };
@ -64,7 +64,7 @@ async fn accepts_enum_literal() {
run_query("{ toString(color: RED) }", |result| { run_query("{ toString(color: RED) }", |result| {
assert_eq!( assert_eq!(
result.get_field_value("toString"), result.get_field_value("toString"),
Some(&Value::scalar("Color::Red")) Some(&graphql_value!("Color::Red")),
); );
}) })
.await; .await;
@ -75,7 +75,7 @@ async fn serializes_as_output() {
run_query("{ aColor }", |result| { run_query("{ aColor }", |result| {
assert_eq!( assert_eq!(
result.get_field_value("aColor"), result.get_field_value("aColor"),
Some(&Value::scalar("RED")) Some(&graphql_value!("RED")),
); );
}) })
.await; .await;
@ -115,7 +115,7 @@ async fn accepts_strings_in_variables() {
|result| { |result| {
assert_eq!( assert_eq!(
result.get_field_value("toString"), result.get_field_value("toString"),
Some(&Value::scalar("Color::Red")) Some(&graphql_value!("Color::Red")),
); );
}, },
) )

View file

@ -385,7 +385,6 @@ mod dynamic_context_switching {
parser::SourcePosition, parser::SourcePosition,
schema::model::RootNode, schema::model::RootNode,
types::scalars::{EmptyMutation, EmptySubscription}, types::scalars::{EmptyMutation, EmptySubscription},
value::Value,
Executor, ScalarValue, Executor, ScalarValue,
}; };
@ -485,21 +484,10 @@ mod dynamic_context_switching {
assert_eq!( assert_eq!(
result, result,
Value::object( graphql_value!({
vec![ "first": {"value": "First value"},
( "missing": None,
"first", }),
Value::object(
vec![("value", Value::scalar("First value"))]
.into_iter()
.collect(),
),
),
("missing", Value::null()),
]
.into_iter()
.collect()
)
); );
} }
@ -545,21 +533,7 @@ mod dynamic_context_switching {
println!("Result: {:#?}", result); println!("Result: {:#?}", result);
assert_eq!( assert_eq!(result, graphql_value!({"first": {"value": "First value"}}));
result,
Value::object(
vec![(
"first",
Value::object(
vec![("value", Value::scalar("First value"))]
.into_iter()
.collect(),
),
)]
.into_iter()
.collect()
)
);
} }
#[tokio::test] #[tokio::test]
@ -603,13 +577,13 @@ mod dynamic_context_switching {
vec![ExecutionError::new( vec![ExecutionError::new(
SourcePosition::new(14, 1, 12), SourcePosition::new(14, 1, 12),
&["missing"], &["missing"],
FieldError::new("Could not find key 2", Value::null()), FieldError::new("Could not find key 2", graphql_value!(None)),
)] )]
); );
println!("Result: {:#?}", result); println!("Result: {:#?}", result);
assert_eq!(result, Value::null()); assert_eq!(result, graphql_value!(None));
} }
#[tokio::test] #[tokio::test]
@ -657,7 +631,7 @@ mod dynamic_context_switching {
[ExecutionError::new( [ExecutionError::new(
SourcePosition::new(123, 4, 12), SourcePosition::new(123, 4, 12),
&["tooLarge"], &["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!( assert_eq!(
result, result,
Value::object( graphql_value!({
vec![ "first": {"value": "First value"},
( "missing": None,
"first", "tooLarge": None,
Value::object( }),
vec![("value", Value::scalar("First value"))]
.into_iter()
.collect(),
),
),
("missing", Value::null()),
("tooLarge", Value::null()),
]
.into_iter()
.collect()
)
); );
} }
@ -722,21 +685,7 @@ mod dynamic_context_switching {
println!("Result: {:#?}", result); println!("Result: {:#?}", result);
assert_eq!( assert_eq!(result, graphql_value!({"first": {"value": "First value"}}));
result,
Value::object(
vec![(
"first",
Value::object(
vec![("value", Value::scalar("First value"))]
.into_iter()
.collect(),
),
)]
.into_iter()
.collect()
)
);
} }
} }
@ -832,7 +781,7 @@ mod propagates_errors_to_nullable_fields {
vec![ExecutionError::new( vec![ExecutionError::new(
SourcePosition::new(10, 0, 10), SourcePosition::new(10, 0, 10),
&["inner", "nullableErrorField"], &["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( vec![ExecutionError::new(
SourcePosition::new(10, 0, 10), SourcePosition::new(10, 0, 10),
&["inner", "nonNullableErrorField"], &["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( vec![ExecutionError::new(
SourcePosition::new(26, 0, 26), SourcePosition::new(26, 0, 26),
&["inner", "nullableField", "nonNullableErrorField"], &["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( vec![ExecutionError::new(
SourcePosition::new(29, 0, 29), SourcePosition::new(29, 0, 29),
&["inner", "nonNullableField", "nonNullableErrorField"], &["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( vec![ExecutionError::new(
SourcePosition::new(29, 0, 29), SourcePosition::new(29, 0, 29),
&["inner", "nonNullableField", "nullableErrorField"], &["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( vec![ExecutionError::new(
SourcePosition::new(11, 0, 11), SourcePosition::new(11, 0, 11),
&["inners", "nonNullableErrorField"], &["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( ExecutionError::new(
SourcePosition::new(19, 0, 19), SourcePosition::new(19, 0, 19),
&["nullableInners", "nonNullableErrorField"], &["nullableInners", "nonNullableErrorField"],
FieldError::new("Error for nonNullableErrorField", Value::null()), FieldError::new("Error for nonNullableErrorField", graphql_value!(None)),
), ),
ExecutionError::new( ExecutionError::new(
SourcePosition::new(19, 0, 19), SourcePosition::new(19, 0, 19),
&["nullableInners", "nonNullableErrorField"], &["nullableInners", "nonNullableErrorField"],
FieldError::new("Error for nonNullableErrorField", Value::null()), FieldError::new("Error for nonNullableErrorField", graphql_value!(None)),
), ),
ExecutionError::new( ExecutionError::new(
SourcePosition::new(19, 0, 19), SourcePosition::new(19, 0, 19),
&["nullableInners", "nonNullableErrorField"], &["nullableInners", "nonNullableErrorField"],
FieldError::new("Error for nonNullableErrorField", Value::null()), FieldError::new("Error for nonNullableErrorField", graphql_value!(None)),
), ),
ExecutionError::new( ExecutionError::new(
SourcePosition::new(19, 0, 19), SourcePosition::new(19, 0, 19),
&["nullableInners", "nonNullableErrorField"], &["nullableInners", "nonNullableErrorField"],
FieldError::new("Error for nonNullableErrorField", Value::null()), FieldError::new("Error for nonNullableErrorField", graphql_value!(None)),
), ),
ExecutionError::new( ExecutionError::new(
SourcePosition::new(19, 0, 19), SourcePosition::new(19, 0, 19),
&["nullableInners", "nonNullableErrorField"], &["nullableInners", "nonNullableErrorField"],
FieldError::new("Error for nonNullableErrorField", Value::null()), FieldError::new("Error for nonNullableErrorField", graphql_value!(None)),
), ),
] ]
); );

View file

@ -3,7 +3,6 @@ mod interface {
graphql_interface, graphql_object, graphql_interface, graphql_object,
schema::model::RootNode, schema::model::RootNode,
types::scalars::{EmptyMutation, EmptySubscription}, types::scalars::{EmptyMutation, EmptySubscription},
value::Value,
}; };
#[graphql_interface(for = [Cat, Dog])] #[graphql_interface(for = [Cat, Dog])]
@ -126,31 +125,15 @@ mod interface {
assert_eq!( assert_eq!(
result, result,
Value::object( graphql_value!({
vec![( "pets": [{
"pets", "name": "Odie",
Value::list(vec![ "woofs": true,
Value::object( }, {
vec![ "name": "Garfield",
("name", Value::scalar("Odie")), "meows": false,
("woofs", Value::scalar(true)), }],
] }),
.into_iter()
.collect(),
),
Value::object(
vec![
("name", Value::scalar("Garfield")),
("meows", Value::scalar(false)),
]
.into_iter()
.collect(),
),
]),
)]
.into_iter()
.collect()
)
); );
} }
} }
@ -160,7 +143,6 @@ mod union {
graphql_object, graphql_union, graphql_object, graphql_union,
schema::model::RootNode, schema::model::RootNode,
types::scalars::{EmptyMutation, EmptySubscription}, types::scalars::{EmptyMutation, EmptySubscription},
value::Value,
}; };
#[graphql_union] #[graphql_union]
@ -271,33 +253,17 @@ mod union {
assert_eq!( assert_eq!(
result, result,
Value::object( graphql_value!({
vec![( "pets": [{
"pets", "__typename": "Dog",
Value::list(vec![ "name": "Odie",
Value::object( "woofs": true,
vec![ }, {
("__typename", Value::scalar("Dog")), "__typename": "Cat",
("name", Value::scalar("Odie")), "name": "Garfield",
("woofs", Value::scalar(true)), "meows": false,
] }],
.into_iter() }),
.collect(),
),
Value::object(
vec![
("__typename", Value::scalar("Cat")),
("name", Value::scalar("Garfield")),
("meows", Value::scalar(false)),
]
.into_iter()
.collect(),
),
]),
)]
.into_iter()
.collect()
)
); );
} }
} }

View file

@ -1,5 +1,6 @@
use crate::{ use crate::{
executor::Variables, executor::Variables,
graphql_value,
schema::model::RootNode, schema::model::RootNode,
types::scalars::{EmptyMutation, EmptySubscription}, types::scalars::{EmptyMutation, EmptySubscription},
value::{DefaultScalarValue, Object, Value}, value::{DefaultScalarValue, Object, Value},
@ -142,36 +143,28 @@ async fn default_name_introspection() {
run_type_info_query(doc, |(type_info, values)| { run_type_info_query(doc, |(type_info, values)| {
assert_eq!( assert_eq!(
type_info.get_field_value("name"), type_info.get_field_value("name"),
Some(&Value::scalar("DefaultName")) Some(&graphql_value!("DefaultName")),
); );
assert_eq!( assert_eq!(
type_info.get_field_value("description"), type_info.get_field_value("description"),
Some(&Value::null()) Some(&graphql_value!(None)),
); );
assert_eq!(values.len(), 2); assert_eq!(values.len(), 2);
assert!(values.contains(&Value::object( assert!(values.contains(&graphql_value!({
vec![ "name": "FOO",
("name", Value::scalar("FOO")), "description": None,
("description", Value::null()), "isDeprecated": false,
("isDeprecated", Value::scalar(false)), "deprecationReason": None,
("deprecationReason", Value::null()), })));
]
.into_iter()
.collect(),
)));
assert!(values.contains(&Value::object( assert!(values.contains(&graphql_value!({
vec![ "name": "BAR",
("name", Value::scalar("BAR")), "description": None,
("description", Value::null()), "isDeprecated": false,
("isDeprecated", Value::scalar(false)), "deprecationReason": None,
("deprecationReason", Value::null()), })));
]
.into_iter()
.collect(),
)));
}) })
.await; .await;
} }
@ -196,36 +189,28 @@ async fn named_introspection() {
run_type_info_query(doc, |(type_info, values)| { run_type_info_query(doc, |(type_info, values)| {
assert_eq!( assert_eq!(
type_info.get_field_value("name"), type_info.get_field_value("name"),
Some(&Value::scalar("ANamedEnum")) Some(&graphql_value!("ANamedEnum")),
); );
assert_eq!( assert_eq!(
type_info.get_field_value("description"), type_info.get_field_value("description"),
Some(&Value::null()) Some(&graphql_value!(None)),
); );
assert_eq!(values.len(), 2); assert_eq!(values.len(), 2);
assert!(values.contains(&Value::object( assert!(values.contains(&graphql_value!({
vec![ "name": "FOO",
("name", Value::scalar("FOO")), "description": None,
("description", Value::null()), "isDeprecated": false,
("isDeprecated", Value::scalar(false)), "deprecationReason": None,
("deprecationReason", Value::null()), })));
]
.into_iter()
.collect(),
)));
assert!(values.contains(&Value::object( assert!(values.contains(&graphql_value!({
vec![ "name": "BAR",
("name", Value::scalar("BAR")), "description": None,
("description", Value::null()), "isDeprecated": false,
("isDeprecated", Value::scalar(false)), "deprecationReason": None,
("deprecationReason", Value::null()), })));
]
.into_iter()
.collect(),
)));
}) })
.await; .await;
} }
@ -250,36 +235,28 @@ async fn no_trailing_comma_introspection() {
run_type_info_query(doc, |(type_info, values)| { run_type_info_query(doc, |(type_info, values)| {
assert_eq!( assert_eq!(
type_info.get_field_value("name"), type_info.get_field_value("name"),
Some(&Value::scalar("NoTrailingComma")) Some(&graphql_value!("NoTrailingComma")),
); );
assert_eq!( assert_eq!(
type_info.get_field_value("description"), type_info.get_field_value("description"),
Some(&Value::null()) Some(&graphql_value!(None)),
); );
assert_eq!(values.len(), 2); assert_eq!(values.len(), 2);
assert!(values.contains(&Value::object( assert!(values.contains(&graphql_value!({
vec![ "name": "FOO",
("name", Value::scalar("FOO")), "description": None,
("description", Value::null()), "isDeprecated": false,
("isDeprecated", Value::scalar(false)), "deprecationReason": None,
("deprecationReason", Value::null()), })));
]
.into_iter()
.collect(),
)));
assert!(values.contains(&Value::object( assert!(values.contains(&graphql_value!({
vec![ "name": "BAR",
("name", Value::scalar("BAR")), "description": None,
("description", Value::null()), "isDeprecated": false,
("isDeprecated", Value::scalar(false)), "deprecationReason": None,
("deprecationReason", Value::null()), })));
]
.into_iter()
.collect(),
)));
}) })
.await; .await;
} }
@ -304,36 +281,28 @@ async fn enum_description_introspection() {
run_type_info_query(doc, |(type_info, values)| { run_type_info_query(doc, |(type_info, values)| {
assert_eq!( assert_eq!(
type_info.get_field_value("name"), type_info.get_field_value("name"),
Some(&Value::scalar("EnumDescription")) Some(&graphql_value!("EnumDescription")),
); );
assert_eq!( assert_eq!(
type_info.get_field_value("description"), 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_eq!(values.len(), 2);
assert!(values.contains(&Value::object( assert!(values.contains(&graphql_value!({
vec![ "name": "FOO",
("name", Value::scalar("FOO")), "description": None,
("description", Value::null()), "isDeprecated": false,
("isDeprecated", Value::scalar(false)), "deprecationReason": None,
("deprecationReason", Value::null()), })));
]
.into_iter()
.collect(),
)));
assert!(values.contains(&Value::object( assert!(values.contains(&graphql_value!({
vec![ "name": "BAR",
("name", Value::scalar("BAR")), "description": None,
("description", Value::null()), "isDeprecated": false,
("isDeprecated", Value::scalar(false)), "deprecationReason": None,
("deprecationReason", Value::null()), })));
]
.into_iter()
.collect(),
)));
}) })
.await; .await;
} }
@ -358,36 +327,28 @@ async fn enum_value_description_introspection() {
run_type_info_query(doc, |(type_info, values)| { run_type_info_query(doc, |(type_info, values)| {
assert_eq!( assert_eq!(
type_info.get_field_value("name"), type_info.get_field_value("name"),
Some(&Value::scalar("EnumValueDescription")) Some(&graphql_value!("EnumValueDescription")),
); );
assert_eq!( assert_eq!(
type_info.get_field_value("description"), type_info.get_field_value("description"),
Some(&Value::null()) Some(&graphql_value!(None)),
); );
assert_eq!(values.len(), 2); assert_eq!(values.len(), 2);
assert!(values.contains(&Value::object( assert!(values.contains(&graphql_value!({
vec![ "name": "FOO",
("name", Value::scalar("FOO")), "description": "The FOO value",
("description", Value::scalar("The FOO value")), "isDeprecated": false,
("isDeprecated", Value::scalar(false)), "deprecationReason": None,
("deprecationReason", Value::null()), })));
]
.into_iter()
.collect(),
)));
assert!(values.contains(&Value::object( assert!(values.contains(&graphql_value!({
vec![ "name": "BAR",
("name", Value::scalar("BAR")), "description": "The BAR value",
("description", Value::scalar("The BAR value")), "isDeprecated": false,
("isDeprecated", Value::scalar(false)), "deprecationReason": None,
("deprecationReason", Value::null()), })));
]
.into_iter()
.collect(),
)));
}) })
.await; .await;
} }
@ -412,42 +373,28 @@ async fn enum_deprecation_introspection() {
run_type_info_query(doc, |(type_info, values)| { run_type_info_query(doc, |(type_info, values)| {
assert_eq!( assert_eq!(
type_info.get_field_value("name"), type_info.get_field_value("name"),
Some(&Value::scalar("EnumDeprecation")) Some(&graphql_value!("EnumDeprecation")),
); );
assert_eq!( assert_eq!(
type_info.get_field_value("description"), type_info.get_field_value("description"),
Some(&Value::null()) Some(&graphql_value!(None)),
); );
assert_eq!(values.len(), 2); assert_eq!(values.len(), 2);
assert!(values.contains(&Value::object( assert!(values.contains(&graphql_value!({
vec![ "name": "FOO",
("name", Value::scalar("FOO")), "description": None,
("description", Value::null()), "isDeprecated": true,
("isDeprecated", Value::scalar(true)), "deprecationReason": "Please don't use FOO any more",
( })));
"deprecationReason",
Value::scalar("Please don't use FOO any more"),
),
]
.into_iter()
.collect(),
)));
assert!(values.contains(&Value::object( assert!(values.contains(&graphql_value!({
vec![ "name": "BAR",
("name", Value::scalar("BAR")), "description": "The BAR value",
("description", Value::scalar("The BAR value")), "isDeprecated": true,
("isDeprecated", Value::scalar(true)), "deprecationReason": "Please don't use BAR any more",
( })));
"deprecationReason",
Value::scalar("Please don't use BAR any more"),
),
]
.into_iter()
.collect(),
)));
}) })
.await; .await;
} }
@ -472,11 +419,11 @@ async fn enum_deprecation_no_values_introspection() {
run_type_info_query(doc, |(type_info, values)| { run_type_info_query(doc, |(type_info, values)| {
assert_eq!( assert_eq!(
type_info.get_field_value("name"), type_info.get_field_value("name"),
Some(&Value::scalar("EnumDeprecation")) Some(&graphql_value!("EnumDeprecation")),
); );
assert_eq!( assert_eq!(
type_info.get_field_value("description"), type_info.get_field_value("description"),
Some(&Value::null()) Some(&graphql_value!(None)),
); );
assert_eq!(values.len(), 0); assert_eq!(values.len(), 0);

View file

@ -7,7 +7,7 @@ use self::input_object::{NamedPublic, NamedPublicWithDescription};
use crate::{ use crate::{
executor::Variables, executor::Variables,
graphql_interface, graphql_object, graphql_scalar, graphql_interface, graphql_object, graphql_scalar, graphql_value,
schema::model::RootNode, schema::model::RootNode,
types::scalars::{EmptyMutation, EmptySubscription}, types::scalars::{EmptyMutation, EmptySubscription},
value::{ParseScalarResult, ParseScalarValue, ScalarValue, Value}, value::{ParseScalarResult, ParseScalarValue, ScalarValue, Value},
@ -93,15 +93,11 @@ async fn test_execution() {
assert_eq!( assert_eq!(
result, result,
Value::object( graphql_value!({
vec![ "sampleEnum": "ONE",
("sampleEnum", Value::scalar("ONE")), "first": 123,
("first", Value::scalar(123)), "second": 30,
("second", Value::scalar(30)), }),
]
.into_iter()
.collect()
)
); );
} }
@ -150,29 +146,32 @@ async fn enum_introspection() {
assert_eq!( assert_eq!(
type_info.get_field_value("name"), type_info.get_field_value("name"),
Some(&Value::scalar("SampleEnum")) Some(&graphql_value!("SampleEnum")),
); );
assert_eq!( assert_eq!(
type_info.get_field_value("kind"), type_info.get_field_value("kind"),
Some(&Value::scalar("ENUM")) Some(&graphql_value!("ENUM")),
); );
assert_eq!( assert_eq!(
type_info.get_field_value("description"), type_info.get_field_value("description"),
Some(&Value::null()) Some(&graphql_value!(None)),
); );
assert_eq!( assert_eq!(
type_info.get_field_value("interfaces"), type_info.get_field_value("interfaces"),
Some(&Value::null()) Some(&graphql_value!(None)),
); );
assert_eq!( assert_eq!(
type_info.get_field_value("possibleTypes"), type_info.get_field_value("possibleTypes"),
Some(&Value::null()) Some(&graphql_value!(None)),
); );
assert_eq!( assert_eq!(
type_info.get_field_value("inputFields"), 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 let values = type_info
.get_field_value("enumValues") .get_field_value("enumValues")
@ -182,27 +181,19 @@ async fn enum_introspection() {
assert_eq!(values.len(), 2); assert_eq!(values.len(), 2);
assert!(values.contains(&Value::object( assert!(values.contains(&graphql_value!({
vec![ "name": "ONE",
("name", Value::scalar("ONE")), "description": None,
("description", Value::null()), "isDeprecated": false,
("isDeprecated", Value::scalar(false)), "deprecationReason": None,
("deprecationReason", Value::null()), })));
]
.into_iter()
.collect(),
)));
assert!(values.contains(&Value::object( assert!(values.contains(&graphql_value!({
vec![ "name": "TWO",
("name", Value::scalar("TWO")), "description": None,
("description", Value::null()), "isDeprecated": false,
("isDeprecated", Value::scalar(false)), "deprecationReason": None,
("deprecationReason", Value::null()), })));
]
.into_iter()
.collect(),
)));
} }
#[tokio::test] #[tokio::test]
@ -264,29 +255,32 @@ async fn interface_introspection() {
assert_eq!( assert_eq!(
type_info.get_field_value("name"), type_info.get_field_value("name"),
Some(&Value::scalar("SampleInterface")) Some(&graphql_value!("SampleInterface")),
); );
assert_eq!( assert_eq!(
type_info.get_field_value("kind"), type_info.get_field_value("kind"),
Some(&Value::scalar("INTERFACE")) Some(&graphql_value!("INTERFACE")),
); );
assert_eq!( assert_eq!(
type_info.get_field_value("description"), type_info.get_field_value("description"),
Some(&Value::scalar("A sample interface")) Some(&graphql_value!("A sample interface")),
); );
assert_eq!( assert_eq!(
type_info.get_field_value("interfaces"), type_info.get_field_value("interfaces"),
Some(&Value::null()) Some(&graphql_value!(None)),
); );
assert_eq!( assert_eq!(
type_info.get_field_value("enumValues"), type_info.get_field_value("enumValues"),
Some(&Value::null()) Some(&graphql_value!(None)),
); );
assert_eq!( assert_eq!(
type_info.get_field_value("inputFields"), 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 let possible_types = type_info
.get_field_value("possibleTypes") .get_field_value("possibleTypes")
@ -296,9 +290,7 @@ async fn interface_introspection() {
assert_eq!(possible_types.len(), 1); assert_eq!(possible_types.len(), 1);
assert!(possible_types.contains(&Value::object( assert!(possible_types.contains(&graphql_value!({"name": "Root"})));
vec![("name", Value::scalar("Root"))].into_iter().collect()
)));
let fields = type_info let fields = type_info
.get_field_value("fields") .get_field_value("fields")
@ -308,42 +300,21 @@ async fn interface_introspection() {
assert_eq!(fields.len(), 1); assert_eq!(fields.len(), 1);
assert!(fields.contains(&Value::object( assert!(fields.contains(&graphql_value!({
vec![ "name": "sampleEnum",
("name", Value::scalar("sampleEnum")), "description": "A sample field in the interface",
( "args": [],
"description", "type": {
Value::scalar("A sample field in the interface"), "name": None,
), "kind": "NON_NULL",
("args", Value::list(vec![])), "ofType": {
( "name": "SampleEnum",
"type", "kind": "ENUM",
Value::object( },
vec![ },
("name", Value::null()), "isDeprecated": false,
("kind", Value::scalar("NON_NULL")), "deprecationReason": None,
( })));
"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(),
)));
} }
#[tokio::test] #[tokio::test]
@ -416,36 +387,35 @@ async fn object_introspection() {
assert_eq!( assert_eq!(
type_info.get_field_value("name"), type_info.get_field_value("name"),
Some(&Value::scalar("Root")) Some(&graphql_value!("Root")),
); );
assert_eq!( assert_eq!(
type_info.get_field_value("kind"), type_info.get_field_value("kind"),
Some(&Value::scalar("OBJECT")) Some(&graphql_value!("OBJECT")),
); );
assert_eq!( assert_eq!(
type_info.get_field_value("description"), 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!( assert_eq!(
type_info.get_field_value("interfaces"), type_info.get_field_value("interfaces"),
Some(&Value::list(vec![Value::object( Some(&graphql_value!([{"name": "SampleInterface"}])),
vec![("name", Value::scalar("SampleInterface"))]
.into_iter()
.collect(),
)]))
); );
assert_eq!( assert_eq!(
type_info.get_field_value("enumValues"), type_info.get_field_value("enumValues"),
Some(&Value::null()) Some(&graphql_value!(None)),
); );
assert_eq!( assert_eq!(
type_info.get_field_value("inputFields"), 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!( assert_eq!(
type_info.get_field_value("possibleTypes"), type_info.get_field_value("possibleTypes"),
Some(&Value::null()) Some(&graphql_value!(None)),
); );
let fields = type_info let fields = type_info
@ -458,133 +428,59 @@ async fn object_introspection() {
println!("Fields: {:#?}", fields); println!("Fields: {:#?}", fields);
assert!(fields.contains(&Value::object( assert!(fields.contains(&graphql_value!({
vec![ "name": "sampleEnum",
("name", Value::scalar("sampleEnum")), "description": None,
("description", Value::null()), "args": [],
("args", Value::list(vec![])), "type": {
( "name": None,
"type", "kind": "NON_NULL",
Value::object( "ofType": {
vec![ "name": "SampleEnum",
("name", Value::null()), "kind": "ENUM",
("kind", Value::scalar("NON_NULL")), },
( },
"ofType", "isDeprecated": false,
Value::object( "deprecationReason": None,
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(&Value::object( assert!(fields.contains(&graphql_value!({
vec![ "name": "sampleScalar",
("name", Value::scalar("sampleScalar")), "description": "A sample scalar field on the object",
( "args": [{
"description", "name": "first",
Value::scalar("A sample scalar field on the object"), "description": "The first number",
), "type": {
( "name": None,
"args", "kind": "NON_NULL",
Value::list(vec![ "ofType": {
Value::object( "name": "Int",
vec![ "kind": "SCALAR",
("name", Value::scalar("first")), "ofType": None,
("description", Value::scalar("The first number")), },
( },
"type", "defaultValue": None,
Value::object( }, {
vec![ "name": "second",
("name", Value::null()), "description": "The second number",
("kind", Value::scalar("NON_NULL")), "type": {
( "name": "Int",
"ofType", "kind": "SCALAR",
Value::object( "ofType": None,
vec![ },
("name", Value::scalar("Int")), "defaultValue": "123",
("kind", Value::scalar("SCALAR")), }],
("ofType", Value::null()), "type": {
] "name": None,
.into_iter() "kind": "NON_NULL",
.collect(), "ofType": {
), "name": "SampleScalar",
), "kind": "SCALAR",
] },
.into_iter() },
.collect(), "isDeprecated": false,
), "deprecationReason": None,
), })));
("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(),
)));
} }
#[tokio::test] #[tokio::test]
@ -626,20 +522,16 @@ async fn scalar_introspection() {
assert_eq!( assert_eq!(
type_info, type_info,
&Value::object( &graphql_value!({
vec![ "name": "SampleScalar",
("name", Value::scalar("SampleScalar")), "kind": "SCALAR",
("kind", Value::scalar("SCALAR")), "description": None,
("description", Value::null()), "fields": None,
("fields", Value::null()), "interfaces": None,
("interfaces", Value::null()), "possibleTypes": None,
("possibleTypes", Value::null()), "enumValues": None,
("enumValues", Value::null()), "inputFields": None,
("inputFields", Value::null()), "ofType": None,
("ofType", Value::null()), }),
]
.into_iter()
.collect()
)
); );
} }

View file

@ -1,12 +1,12 @@
use crate::{ use crate::{
ast::InputValue, ast::InputValue,
executor::Variables, executor::Variables,
graphql_object, graphql_scalar, graphql_object, graphql_scalar, graphql_value,
parser::SourcePosition, parser::SourcePosition,
schema::model::RootNode, schema::model::RootNode,
types::scalars::{EmptyMutation, EmptySubscription}, types::scalars::{EmptyMutation, EmptySubscription},
validation::RuleError, validation::RuleError,
value::{DefaultScalarValue, Object, ParseScalarResult, ParseScalarValue, ScalarValue, Value}, value::{DefaultScalarValue, Object, ParseScalarResult, ParseScalarValue, ScalarValue},
GraphQLError::ValidationError, GraphQLError::ValidationError,
GraphQLInputObject, GraphQLInputObject,
}; };
@ -17,7 +17,7 @@ struct TestComplexScalar;
#[graphql_scalar] #[graphql_scalar]
impl<S: ScalarValue> GraphQLScalar for TestComplexScalar { impl<S: ScalarValue> GraphQLScalar for TestComplexScalar {
fn resolve(&self) -> Value { fn resolve(&self) -> Value {
Value::scalar(String::from("SerializedValue")) graphql_value!("SerializedValue")
} }
fn from_input_value(v: &InputValue) -> Option<TestComplexScalar> { fn from_input_value(v: &InputValue) -> Option<TestComplexScalar> {
@ -157,7 +157,7 @@ async fn inline_complex_input() {
|result: &Object<DefaultScalarValue>| { |result: &Object<DefaultScalarValue>| {
assert_eq!( assert_eq!(
result.get_field_value("fieldWithObjectInput"), 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 })"# 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<DefaultScalarValue>| { |result: &Object<DefaultScalarValue>| {
assert_eq!( assert_eq!(
result.get_field_value("fieldWithObjectInput"), 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 })"# 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<DefaultScalarValue>| { |result: &Object<DefaultScalarValue>| {
assert_eq!( assert_eq!(
result.get_field_value("fieldWithObjectInput"), result.get_field_value("fieldWithObjectInput"),
Some(&Value::scalar( Some(&graphql_value!(
r#"Some(TestInputObject { a: None, b: None, c: "baz", d: Some(TestComplexScalar) })"# r#"Some(TestInputObject { a: None, b: None, c: "baz", d: Some(TestComplexScalar) })"#
)) ))
); );
@ -216,7 +216,7 @@ async fn variable_complex_input() {
|result: &Object<DefaultScalarValue>| { |result: &Object<DefaultScalarValue>| {
assert_eq!( assert_eq!(
result.get_field_value("fieldWithObjectInput"), 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 })"# 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<DefaultScalarValue>| { |result: &Object<DefaultScalarValue>| {
assert_eq!( assert_eq!(
result.get_field_value("fieldWithObjectInput"), 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 })"# 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<DefaultScalarValue>| { |result: &Object<DefaultScalarValue>| {
assert_eq!( assert_eq!(
result.get_field_value("fieldWithObjectInput"), result.get_field_value("fieldWithObjectInput"),
Some(&Value::scalar( Some(&graphql_value!(
r#"Some(TestInputObject { a: None, b: None, c: "baz", d: Some(TestComplexScalar) })"# 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<DefaultScalarValue>| { |result: &Object<DefaultScalarValue>| {
assert_eq!( assert_eq!(
result.get_field_value("fieldWithNullableStringInput"), 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<DefaultScalarValue>| { |result: &Object<DefaultScalarValue>| {
assert_eq!( assert_eq!(
result.get_field_value("fieldWithNullableStringInput"), 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<DefaultScalarValue>| { |result: &Object<DefaultScalarValue>| {
assert_eq!( assert_eq!(
result.get_field_value("fieldWithNullableStringInput"), 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<DefaultScalarValue>| { |result: &Object<DefaultScalarValue>| {
assert_eq!( assert_eq!(
result.get_field_value("fieldWithNullableStringInput"), 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<DefaultScalarValue>| { |result: &Object<DefaultScalarValue>| {
assert_eq!( assert_eq!(
result.get_field_value("fieldWithNullableStringInput"), 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<DefaultScalarValue>| { |result: &Object<DefaultScalarValue>| {
assert_eq!( assert_eq!(
result.get_field_value("fieldWithNullableStringInput"), 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| { |result| {
assert_eq!( assert_eq!(
result.get_field_value("fieldWithNonNullableStringInput"), 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<DefaultScalarValue>| { |result: &Object<DefaultScalarValue>| {
assert_eq!( assert_eq!(
result.get_field_value("fieldWithNonNullableStringInput"), 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<DefaultScalarValue>| { |result: &Object<DefaultScalarValue>| {
assert_eq!( assert_eq!(
result.get_field_value("list"), 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| { |result| {
assert_eq!( assert_eq!(
result.get_field_value("list"), 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| { |result| {
assert_eq!( assert_eq!(
result.get_field_value("list"), 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| { |result| {
assert_eq!( assert_eq!(
result.get_field_value("nnList"), 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| { |result| {
assert_eq!( assert_eq!(
result.get_field_value("nnList"), 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| { |result| {
assert_eq!( assert_eq!(
result.get_field_value("listNn"), 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| { |result| {
assert_eq!( assert_eq!(
result.get_field_value("listNn"), 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| { |result| {
assert_eq!( assert_eq!(
result.get_field_value("nnListNn"), 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| { run_query(r#"{ fieldWithDefaultArgumentValue }"#, |result| {
assert_eq!( assert_eq!(
result.get_field_value("fieldWithDefaultArgumentValue"), result.get_field_value("fieldWithDefaultArgumentValue"),
Some(&Value::scalar(r#""Hello World""#)) Some(&graphql_value!(r#""Hello World""#)),
); );
}) })
.await; .await;
@ -929,7 +929,7 @@ async fn default_argument_when_nullable_variable_not_provided() {
|result| { |result| {
assert_eq!( assert_eq!(
result.get_field_value("fieldWithDefaultArgumentValue"), 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| { |result| {
assert_eq!( assert_eq!(
result.get_field_value("fieldWithDefaultArgumentValue"), 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| { run_query(r#"{ exampleInput(arg: {a: "abc", b: 123}) }"#, |result| {
assert_eq!( assert_eq!(
result.get_field_value("exampleInput"), result.get_field_value("exampleInput"),
Some(&Value::scalar(r#"a: Some("abc"), b: 123"#)) Some(&graphql_value!(r#"a: Some("abc"), b: 123"#)),
); );
}) })
.await; .await;
@ -966,7 +966,7 @@ async fn nullable_input_object_arguments_successful_without_variables() {
run_query(r#"{ exampleInput(arg: {a: null, b: 1}) }"#, |result| { run_query(r#"{ exampleInput(arg: {a: null, b: 1}) }"#, |result| {
assert_eq!( assert_eq!(
result.get_field_value("exampleInput"), result.get_field_value("exampleInput"),
Some(&Value::scalar(r#"a: None, b: 1"#)) Some(&graphql_value!(r#"a: None, b: 1"#)),
); );
}) })
.await; .await;
@ -982,7 +982,7 @@ async fn nullable_input_object_arguments_successful_with_variables() {
|result| { |result| {
assert_eq!( assert_eq!(
result.get_field_value("exampleInput"), 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| { |result| {
assert_eq!( assert_eq!(
result.get_field_value("exampleInput"), 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| { |result| {
assert_eq!( assert_eq!(
result.get_field_value("exampleInput"), 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| { run_query(r#"{ inputWithDefaults(arg: {a: 1}) }"#, |result| {
assert_eq!( assert_eq!(
result.get_field_value("inputWithDefaults"), result.get_field_value("inputWithDefaults"),
Some(&Value::scalar(r#"a: 1"#)) Some(&graphql_value!(r#"a: 1"#)),
); );
}) })
.await; .await;
@ -1131,7 +1131,7 @@ async fn input_object_with_default_values() {
|result| { |result| {
assert_eq!( assert_eq!(
result.get_field_value("inputWithDefaults"), 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| { |result| {
assert_eq!( assert_eq!(
result.get_field_value("inputWithDefaults"), 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| { |result| {
assert_eq!( assert_eq!(
result.get_field_value("inputWithDefaults"), result.get_field_value("inputWithDefaults"),
Some(&Value::scalar(r#"a: 2"#)) Some(&graphql_value!(r#"a: 2"#)),
); );
}, },
) )
@ -1177,7 +1177,7 @@ mod integers {
|result| { |result| {
assert_eq!( assert_eq!(
result.get_field_value("integerInput"), result.get_field_value("integerInput"),
Some(&Value::scalar(r#"value: 1"#)) Some(&graphql_value!(r#"value: 1"#)),
); );
}, },
) )
@ -1191,7 +1191,7 @@ mod integers {
|result| { |result| {
assert_eq!( assert_eq!(
result.get_field_value("integerInput"), result.get_field_value("integerInput"),
Some(&Value::scalar(r#"value: -1"#)) Some(&graphql_value!(r#"value: -1"#)),
); );
}, },
) )
@ -1264,7 +1264,7 @@ mod floats {
|result| { |result| {
assert_eq!( assert_eq!(
result.get_field_value("floatInput"), result.get_field_value("floatInput"),
Some(&Value::scalar(r#"value: 10"#)) Some(&graphql_value!(r#"value: 10"#)),
); );
}, },
) )
@ -1281,7 +1281,7 @@ mod floats {
|result| { |result| {
assert_eq!( assert_eq!(
result.get_field_value("floatInput"), result.get_field_value("floatInput"),
Some(&Value::scalar(r#"value: -1"#)) Some(&graphql_value!(r#"value: -1"#)),
); );
}, },
) )

View file

@ -177,7 +177,7 @@ mod test {
} }
fn datetime_utc_test(raw: &'static str) { fn datetime_utc_test(raw: &'static str) {
let input: crate::InputValue<DefaultScalarValue> = InputValue::scalar(raw.to_string()); let input = <InputValue<DefaultScalarValue>>::scalar(raw.to_string());
let parsed: DateTime<Utc> = crate::FromInputValue::from_input_value(&input).unwrap(); let parsed: DateTime<Utc> = crate::FromInputValue::from_input_value(&input).unwrap();
let expected = DateTime::parse_from_rfc3339(raw) let expected = DateTime::parse_from_rfc3339(raw)
@ -237,7 +237,7 @@ mod test {
#[test] #[test]
fn naivedatetime_from_input_value() { fn naivedatetime_from_input_value() {
let raw = 1_000_000_000_f64; let raw = 1_000_000_000_f64;
let input: InputValue<DefaultScalarValue> = InputValue::scalar(raw); let input = <InputValue<DefaultScalarValue>>::scalar(raw);
let parsed: NaiveDateTime = crate::FromInputValue::from_input_value(&input).unwrap(); let parsed: NaiveDateTime = crate::FromInputValue::from_input_value(&input).unwrap();
let expected = NaiveDateTime::from_timestamp_opt(raw as i64, 0).unwrap(); let expected = NaiveDateTime::from_timestamp_opt(raw as i64, 0).unwrap();

View file

@ -27,13 +27,14 @@ where
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use crate::InputValue;
use url::Url; use url::Url;
use crate::{DefaultScalarValue, InputValue};
#[test] #[test]
fn url_from_input_value() { fn url_from_input_value() {
let raw = "https://example.net/"; let raw = "https://example.net/";
let input: InputValue = InputValue::scalar(raw.to_string()); let input = <InputValue<DefaultScalarValue>>::scalar(raw.to_string());
let parsed: Url = crate::FromInputValue::from_input_value(&input).unwrap(); let parsed: Url = crate::FromInputValue::from_input_value(&input).unwrap();
let url = Url::parse(raw).unwrap(); let url = Url::parse(raw).unwrap();

View file

@ -40,7 +40,7 @@ mod test {
#[test] #[test]
fn uuid_from_input_value() { fn uuid_from_input_value() {
let raw = "123e4567-e89b-12d3-a456-426655440000"; let raw = "123e4567-e89b-12d3-a456-426655440000";
let input: InputValue<DefaultScalarValue> = InputValue::scalar(raw.to_string()); let input = <InputValue<DefaultScalarValue>>::scalar(raw.to_string());
let parsed: Uuid = crate::FromInputValue::from_input_value(&input).unwrap(); let parsed: Uuid = crate::FromInputValue::from_input_value(&input).unwrap();
let id = Uuid::parse_str(raw).unwrap(); let id = Uuid::parse_str(raw).unwrap();

View file

@ -5,17 +5,15 @@ use crate::{
schema::model::RootNode, schema::model::RootNode,
tests::fixtures::starwars::schema::{Database, Query}, tests::fixtures::starwars::schema::{Database, Query},
types::scalars::{EmptyMutation, EmptySubscription}, types::scalars::{EmptyMutation, EmptySubscription},
value::Value,
}; };
#[tokio::test] #[tokio::test]
async fn test_hero_name() { async fn test_hero_name() {
let doc = r#" let doc = r#"{
{ hero {
hero { name
name }
} }"#;
}"#;
let database = Database::new(); let database = Database::new();
let schema = RootNode::new( let schema = RootNode::new(
Query, Query,
@ -25,17 +23,7 @@ async fn test_hero_name() {
assert_eq!( assert_eq!(
crate::execute(doc, None, &schema, &Variables::new(), &database).await, crate::execute(doc, None, &schema, &Variables::new(), &database).await,
Ok(( Ok((graphql_value!({"hero": {"name": "R2-D2"}}), vec![])),
Value::object(
vec![(
"hero",
Value::object(vec![("name", Value::scalar("R2-D2"))].into_iter().collect()),
)]
.into_iter()
.collect()
),
vec![]
))
); );
} }
@ -48,77 +36,46 @@ async fn test_hero_field_order() {
EmptySubscription::<Database>::new(), EmptySubscription::<Database>::new(),
); );
let doc = r#" let doc = r#"{
{ hero {
hero { id
id name
name }
} }"#;
}"#;
assert_eq!( assert_eq!(
crate::execute(doc, None, &schema, &Variables::new(), &database).await, crate::execute(doc, None, &schema, &Variables::new(), &database).await,
Ok(( Ok((
Value::object( graphql_value!({"hero": {"id": "2001", "name": "R2-D2"}}),
vec![( vec![],
"hero", )),
Value::object(
vec![
("id", Value::scalar("2001")),
("name", Value::scalar("R2-D2")),
]
.into_iter()
.collect(),
),
)]
.into_iter()
.collect()
),
vec![]
))
); );
let doc_reversed = r#" let doc_reversed = r#"{
{ hero {
hero { name
name id
id }
} }"#;
}"#;
assert_eq!( assert_eq!(
crate::execute(doc_reversed, None, &schema, &Variables::new(), &database).await, crate::execute(doc_reversed, None, &schema, &Variables::new(), &database).await,
Ok(( Ok((
Value::object( graphql_value!({"hero": {"name": "R2-D2", "id": "2001"}}),
vec![( vec![],
"hero", )),
Value::object(
vec![
("name", Value::scalar("R2-D2")),
("id", Value::scalar("2001")),
]
.into_iter()
.collect(),
),
)]
.into_iter()
.collect()
),
vec![]
))
); );
} }
#[tokio::test] #[tokio::test]
async fn test_hero_name_and_friends() { async fn test_hero_name_and_friends() {
let doc = r#" let doc = r#"{
{ hero {
hero { id
id name
friends {
name name
friends {
name
}
} }
}"#; }
}"#;
let database = Database::new(); let database = Database::new();
let schema = RootNode::new( let schema = RootNode::new(
Query, Query,
@ -129,62 +86,35 @@ async fn test_hero_name_and_friends() {
assert_eq!( assert_eq!(
crate::execute(doc, None, &schema, &Variables::new(), &database).await, crate::execute(doc, None, &schema, &Variables::new(), &database).await,
Ok(( Ok((
Value::object( graphql_value!({"hero": {
vec![( "id": "2001",
"hero", "name": "R2-D2",
Value::object( "friends": [
vec![ {"name": "Luke Skywalker"},
("id", Value::scalar("2001")), {"name": "Han Solo"},
("name", Value::scalar("R2-D2")), {"name": "Leia Organa"},
( ],
"friends", }}),
Value::list(vec![ 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![]
))
); );
} }
#[tokio::test] #[tokio::test]
async fn test_hero_name_and_friends_and_friends_of_friends() { async fn test_hero_name_and_friends_and_friends_of_friends() {
let doc = r#" let doc = r#"{
{ hero {
hero { id
id name
friends {
name name
appearsIn
friends { friends {
name name
appearsIn
friends {
name
}
} }
} }
}"#; }
}"#;
let database = Database::new(); let database = Database::new();
let schema = RootNode::new( let schema = RootNode::new(
Query, Query,
@ -195,155 +125,39 @@ async fn test_hero_name_and_friends_and_friends_of_friends() {
assert_eq!( assert_eq!(
crate::execute(doc, None, &schema, &Variables::new(), &database).await, crate::execute(doc, None, &schema, &Variables::new(), &database).await,
Ok(( Ok((
Value::object( graphql_value!({"hero": {
vec![( "id": "2001",
"hero", "name": "R2-D2",
Value::object( "friends": [{
vec![ "name": "Luke Skywalker",
("id", Value::scalar("2001")), "appearsIn": ["NEW_HOPE", "EMPIRE", "JEDI"],
("name", Value::scalar("R2-D2")), "friends": [
( {"name": "Han Solo"},
"friends", {"name": "Leia Organa"},
Value::list(vec![ {"name": "C-3PO"},
Value::object( {"name": "R2-D2"},
vec![ ],
("name", Value::scalar("Luke Skywalker")), }, {
( "name": "Han Solo",
"appearsIn", "appearsIn": ["NEW_HOPE", "EMPIRE", "JEDI"],
Value::list(vec![ "friends": [
Value::scalar("NEW_HOPE"), {"name": "Luke Skywalker"},
Value::scalar("EMPIRE"), {"name": "Leia Organa"},
Value::scalar("JEDI"), {"name": "R2-D2"},
]), ],
), }, {
( "name": "Leia Organa",
"friends", "appearsIn": ["NEW_HOPE", "EMPIRE", "JEDI"],
Value::list(vec![ "friends": [
Value::object( {"name": "Luke Skywalker"},
vec![("name", Value::scalar("Han Solo"))] {"name": "Han Solo"},
.into_iter() {"name": "C-3PO"},
.collect(), {"name": "R2-D2"},
), ],
Value::object( }],
vec![( }}),
"name", vec![],
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![]
))
); );
} }
@ -360,20 +174,9 @@ async fn test_query_name() {
assert_eq!( assert_eq!(
crate::execute(doc, None, &schema, &Variables::new(), &database).await, crate::execute(doc, None, &schema, &Variables::new(), &database).await,
Ok(( Ok((
Value::object( graphql_value!({"human": {"name": "Luke Skywalker"}}),
vec![( vec![],
"human", )),
Value::object(
vec![("name", Value::scalar("Luke Skywalker"))]
.into_iter()
.collect(),
),
)]
.into_iter()
.collect()
),
vec![]
))
); );
} }
@ -389,31 +192,16 @@ async fn test_query_alias_single() {
assert_eq!( assert_eq!(
crate::execute(doc, None, &schema, &Variables::new(), &database).await, crate::execute(doc, None, &schema, &Variables::new(), &database).await,
Ok(( Ok((graphql_value!({"luke": {"name": "Luke Skywalker"}}), vec![])),
Value::object(
vec![(
"luke",
Value::object(
vec![("name", Value::scalar("Luke Skywalker"))]
.into_iter()
.collect(),
),
)]
.into_iter()
.collect()
),
vec![]
))
); );
} }
#[tokio::test] #[tokio::test]
async fn test_query_alias_multiple() { async fn test_query_alias_multiple() {
let doc = r#" let doc = r#"{
{ luke: human(id: "1000") { name }
luke: human(id: "1000") { name } leia: human(id: "1003") { name }
leia: human(id: "1003") { name } }"#;
}"#;
let database = Database::new(); let database = Database::new();
let schema = RootNode::new( let schema = RootNode::new(
Query, Query,
@ -424,30 +212,12 @@ async fn test_query_alias_multiple() {
assert_eq!( assert_eq!(
crate::execute(doc, None, &schema, &Variables::new(), &database).await, crate::execute(doc, None, &schema, &Variables::new(), &database).await,
Ok(( Ok((
Value::object( graphql_value!({
vec![ "luke": {"name": "Luke Skywalker"},
( "leia": {"name": "Leia Organa"},
"luke", }),
Value::object( vec![],
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![]
))
); );
} }
@ -473,36 +243,12 @@ async fn test_query_alias_multiple_with_fragment() {
assert_eq!( assert_eq!(
crate::execute(doc, None, &schema, &Variables::new(), &database).await, crate::execute(doc, None, &schema, &Variables::new(), &database).await,
Ok(( Ok((
Value::object( graphql_value!({
vec![ "luke": {"name": "Luke Skywalker", "homePlanet": "Tatooine"},
( "leia": {"name": "Leia Organa", "homePlanet": "Alderaan"},
"luke", }),
Value::object( vec![],
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![]
))
); );
} }
@ -523,20 +269,9 @@ async fn test_query_name_variable() {
assert_eq!( assert_eq!(
crate::execute(doc, None, &schema, &vars, &database).await, crate::execute(doc, None, &schema, &vars, &database).await,
Ok(( Ok((
Value::object( graphql_value!({"human": {"name": "Luke Skywalker"}}),
vec![( vec![],
"human", )),
Value::object(
vec![("name", Value::scalar("Luke Skywalker"))]
.into_iter()
.collect(),
),
)]
.into_iter()
.collect()
),
vec![]
))
); );
} }
@ -556,10 +291,7 @@ async fn test_query_name_invalid_variable() {
assert_eq!( assert_eq!(
crate::execute(doc, None, &schema, &vars, &database).await, crate::execute(doc, None, &schema, &vars, &database).await,
Ok(( Ok((graphql_value!({ "human": None }), vec![])),
Value::object(vec![("human", Value::null())].into_iter().collect()),
vec![]
))
); );
} }
@ -576,57 +308,31 @@ async fn test_query_friends_names() {
assert_eq!( assert_eq!(
crate::execute(doc, None, &schema, &Variables::new(), &database).await, crate::execute(doc, None, &schema, &Variables::new(), &database).await,
Ok(( Ok((
Value::object( graphql_value!({"human": {
vec![( "friends": [
"human", {"name": "Han Solo"},
Value::object( {"name": "Leia Organa"},
vec![( {"name": "C-3PO"},
"friends", {"name": "R2-D2"},
Value::list(vec![ ],
Value::object( }}),
vec![("name", Value::scalar("Han Solo"))] vec![],
.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![]
))
); );
} }
#[tokio::test] #[tokio::test]
async fn test_query_inline_fragments_droid() { async fn test_query_inline_fragments_droid() {
let doc = r#" let doc = r#"query InlineFragments {
query InlineFragments { hero {
hero { name
name __typename
__typename
...on Droid { ...on Droid {
primaryFunction primaryFunction
}
} }
} }
"#; }"#;
let database = Database::new(); let database = Database::new();
let schema = RootNode::new( let schema = RootNode::new(
Query, Query,
@ -637,37 +343,24 @@ async fn test_query_inline_fragments_droid() {
assert_eq!( assert_eq!(
crate::execute(doc, None, &schema, &Variables::new(), &database).await, crate::execute(doc, None, &schema, &Variables::new(), &database).await,
Ok(( Ok((
Value::object( graphql_value!({"hero": {
vec![( "__typename": "Droid",
"hero", "name": "R2-D2",
Value::object( "primaryFunction": "Astromech",
vec![ }}),
("__typename", Value::scalar("Droid")), vec![],
("name", Value::scalar("R2-D2")), )),
("primaryFunction", Value::scalar("Astromech")),
]
.into_iter()
.collect(),
),
)]
.into_iter()
.collect()
),
vec![]
))
); );
} }
#[tokio::test] #[tokio::test]
async fn test_query_inline_fragments_human() { async fn test_query_inline_fragments_human() {
let doc = r#" let doc = r#"query InlineFragments {
query InlineFragments { hero(episode: EMPIRE) {
hero(episode: EMPIRE) { __typename
__typename name
name
}
} }
"#; }"#;
let database = Database::new(); let database = Database::new();
let schema = RootNode::new( let schema = RootNode::new(
Query, Query,
@ -678,34 +371,22 @@ async fn test_query_inline_fragments_human() {
assert_eq!( assert_eq!(
crate::execute(doc, None, &schema, &Variables::new(), &database).await, crate::execute(doc, None, &schema, &Variables::new(), &database).await,
Ok(( Ok((
Value::object( graphql_value!({"hero": {
vec![( "__typename": "Human",
"hero", "name": "Luke Skywalker",
Value::object( }}),
vec![ vec![],
("__typename", Value::scalar("Human")), )),
("name", Value::scalar("Luke Skywalker")),
]
.into_iter()
.collect(),
),
)]
.into_iter()
.collect()
),
vec![]
))
); );
} }
#[tokio::test] #[tokio::test]
async fn test_object_typename() { async fn test_object_typename() {
let doc = r#" let doc = r#"{
{ human(id: "1000") {
human(id: "1000") { __typename
__typename }
} }"#;
}"#;
let database = Database::new(); let database = Database::new();
let schema = RootNode::new( let schema = RootNode::new(
Query, Query,
@ -715,21 +396,7 @@ async fn test_object_typename() {
assert_eq!( assert_eq!(
crate::execute(doc, None, &schema, &Variables::new(), &database).await, crate::execute(doc, None, &schema, &Variables::new(), &database).await,
Ok(( Ok((graphql_value!({"human": {"__typename": "Human"}}), vec![])),
Value::object(
vec![(
"human",
Value::object(
vec![("__typename", Value::scalar("Human"))]
.into_iter()
.collect(),
),
)]
.into_iter()
.collect()
),
vec![]
))
); );
} }

File diff suppressed because it is too large Load diff

View file

@ -3,8 +3,9 @@ use std::{iter, iter::FromIterator as _, pin::Pin};
use futures::{stream, StreamExt as _}; use futures::{stream, StreamExt as _};
use crate::{ use crate::{
graphql_object, graphql_subscription, http::GraphQLRequest, Context, DefaultScalarValue, graphql_object, graphql_subscription, graphql_value, http::GraphQLRequest, Context,
EmptyMutation, ExecutionError, FieldError, GraphQLObject, Object, RootNode, Value, DefaultScalarValue, EmptyMutation, ExecutionError, FieldError, GraphQLObject, Object, RootNode,
Value,
}; };
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
@ -57,7 +58,7 @@ impl MySubscription {
async fn error_human() -> Result<HumanStream, FieldError> { async fn error_human() -> Result<HumanStream, FieldError> {
Err(FieldError::new( Err(FieldError::new(
"handler error", "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 || { std::iter::from_fn(move || {
iterator_count += 1; iterator_count += 1;
match iterator_count { match iterator_count {
1 => Some(( 1 => Some(("id", graphql_value!("stream id"))),
"id", 2 => Some(("name", graphql_value!("stream name"))),
Value::Scalar(DefaultScalarValue::String("stream id".to_string())),
)),
2 => Some((
"name",
Value::Scalar(DefaultScalarValue::String("stream name".to_string())),
)),
_ => None, _ => None,
} }
}), }),
@ -199,10 +194,7 @@ fn returns_error() {
let expected_error = ExecutionError::new( let expected_error = ExecutionError::new(
crate::parser::SourcePosition::new(23, 1, 8), crate::parser::SourcePosition::new(23, 1, 8),
&vec!["errorHuman"], &vec!["errorHuman"],
FieldError::new( FieldError::new("handler error", graphql_value!("more details")),
"handler error",
Value::Scalar(DefaultScalarValue::String("more details".to_string())),
),
); );
assert_eq!(returned_errors, vec![expected_error]); assert_eq!(returned_errors, vec![expected_error]);
@ -224,10 +216,7 @@ fn can_access_context() {
move || { move || {
iterator_count += 1; iterator_count += 1;
match iterator_count { match iterator_count {
1 => Some(( 1 => Some(("id", graphql_value!("2"))),
"id",
Value::Scalar(DefaultScalarValue::String("2".to_string())),
)),
_ => None, _ => None,
} }
}, },
@ -255,10 +244,7 @@ fn resolves_typed_inline_fragments() {
move || { move || {
iterator_count += 1; iterator_count += 1;
match iterator_count { match iterator_count {
1 => Some(( 1 => Some(("id", graphql_value!("stream id"))),
"id",
Value::Scalar(DefaultScalarValue::String("stream id".to_string())),
)),
_ => None, _ => None,
} }
}, },
@ -286,10 +272,7 @@ fn resolves_nontyped_inline_fragments() {
move || { move || {
iterator_count += 1; iterator_count += 1;
match iterator_count { match iterator_count {
1 => Some(( 1 => Some(("id", graphql_value!("stream id"))),
"id",
Value::Scalar(DefaultScalarValue::String("stream id".to_string())),
)),
_ => None, _ => None,
} }
}, },
@ -316,14 +299,8 @@ fn can_access_arguments() {
move || { move || {
iterator_count += 1; iterator_count += 1;
match iterator_count { match iterator_count {
1 => Some(( 1 => Some(("id", graphql_value!("123"))),
"id", 2 => Some(("name", graphql_value!("args name"))),
Value::Scalar(DefaultScalarValue::String("123".to_string())),
)),
2 => Some((
"name",
Value::Scalar(DefaultScalarValue::String("args name".to_string())),
)),
_ => None, _ => None,
} }
}, },
@ -350,14 +327,8 @@ fn type_alias() {
move || { move || {
iterator_count += 1; iterator_count += 1;
match iterator_count { match iterator_count {
1 => Some(( 1 => Some(("id", graphql_value!("stream id"))),
"id", 2 => Some(("name", graphql_value!("stream name"))),
Value::Scalar(DefaultScalarValue::String("stream id".to_string())),
)),
2 => Some((
"name",
Value::Scalar(DefaultScalarValue::String("stream name".to_string())),
)),
_ => None, _ => None,
} }
}, },

View file

@ -2,12 +2,13 @@ use indexmap::IndexMap;
use crate::{ use crate::{
executor::{ExecutionResult, Executor, Registry, Variables}, executor::{ExecutionResult, Executor, Registry, Variables},
graphql_value,
schema::{meta::MetaType, model::RootNode}, schema::{meta::MetaType, model::RootNode},
types::{ types::{
base::{Arguments, GraphQLType, GraphQLValue}, base::{Arguments, GraphQLType, GraphQLValue},
scalars::{EmptyMutation, EmptySubscription}, scalars::{EmptyMutation, EmptySubscription},
}, },
value::{ScalarValue, Value}, value::ScalarValue,
}; };
pub struct NodeTypeInfo { pub struct NodeTypeInfo {
@ -95,16 +96,12 @@ fn test_node() {
assert_eq!( assert_eq!(
crate::execute_sync(doc, None, &schema, &Variables::new(), &()), crate::execute_sync(doc, None, &schema, &Variables::new(), &()),
Ok(( Ok((
Value::object( graphql_value!({
vec![ "foo": "1",
("foo", Value::scalar("1")), "bar": "2",
("bar", Value::scalar("2")), "baz": "3",
("baz", Value::scalar("3")), }),
] vec![],
.into_iter() )),
.collect()
),
vec![]
))
); );
} }

View file

@ -78,7 +78,7 @@ impl<S> IntoIterator for Object<S> {
impl<S> From<Object<S>> for Value<S> { impl<S> From<Object<S>> for Value<S> {
fn from(o: Object<S>) -> Self { fn from(o: Object<S>) -> Self {
Value::Object(o) Self::Object(o)
} }
} }

View file

@ -633,9 +633,9 @@ mod test {
use juniper::{ use juniper::{
futures::sink::SinkExt, futures::sink::SinkExt,
graphql_object, graphql_subscription, graphql_object, graphql_subscription, graphql_value,
parser::{ParseError, Spanning, Token}, parser::{ParseError, Spanning, Token},
DefaultScalarValue, EmptyMutation, FieldError, FieldResult, InputValue, RootNode, Value, DefaultScalarValue, EmptyMutation, FieldError, FieldResult, InputValue, RootNode,
}; };
use super::*; use super::*;
@ -681,7 +681,7 @@ mod test {
async fn error(_context: &Context) -> BoxStream<'static, FieldResult<i32>> { async fn error(_context: &Context) -> BoxStream<'static, FieldResult<i32>> {
stream::once(future::ready(Err(FieldError::new( stream::once(future::ready(Err(FieldError::new(
"field error", "field error",
Value::null(), graphql_value!(None),
)))) ))))
.chain( .chain(
tokio::time::sleep(Duration::from_secs(10000)) tokio::time::sleep(Duration::from_secs(10000))
@ -729,12 +729,7 @@ mod test {
ServerMessage::Data { ServerMessage::Data {
id: "foo".to_string(), id: "foo".to_string(),
payload: DataPayload { payload: DataPayload {
data: Value::Object( data: graphql_value!({"context": 1}),
[("context", Value::Scalar(DefaultScalarValue::Int(1)))]
.iter()
.cloned()
.collect()
),
errors: vec![], errors: vec![],
}, },
}, },
@ -779,7 +774,7 @@ mod test {
ServerMessage::Data { ServerMessage::Data {
id: "foo".to_string(), id: "foo".to_string(),
payload: DataPayload { payload: DataPayload {
data: Value::Object([("context", Value::scalar(1))].iter().cloned().collect()), data: graphql_value!({"context": 1}),
errors: vec![], errors: vec![],
}, },
}, },
@ -801,7 +796,7 @@ mod test {
ServerMessage::Data { ServerMessage::Data {
id: "bar".to_string(), id: "bar".to_string(),
payload: DataPayload { payload: DataPayload {
data: Value::Object([("context", Value::scalar(1))].iter().cloned().collect()), data: graphql_value!({"context": 1}),
errors: vec![], errors: vec![],
}, },
}, },
@ -1009,12 +1004,7 @@ mod test {
ServerMessage::Data { ServerMessage::Data {
id: "foo".to_string(), id: "foo".to_string(),
payload: DataPayload { payload: DataPayload {
data: Value::Object( data: graphql_value!({"context": 1}),
[("context", Value::Scalar(DefaultScalarValue::Int(1)))]
.iter()
.cloned()
.collect()
),
errors: vec![], errors: vec![],
}, },
}, },
@ -1054,10 +1044,7 @@ mod test {
payload: DataPayload { data, errors }, payload: DataPayload { data, errors },
} => { } => {
assert_eq!(id, "foo"); assert_eq!(id, "foo");
assert_eq!( assert_eq!(data, graphql_value!({ "error": None }),);
data,
Value::Object([("error", Value::null())].iter().cloned().collect())
);
assert_eq!(errors.len(), 1); assert_eq!(errors.len(), 1);
} }
msg @ _ => panic!("expected data, got: {:?}", msg), msg @ _ => panic!("expected data, got: {:?}", msg),

View file

@ -134,8 +134,9 @@ pub enum ServerMessage<S: ScalarValue> {
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use juniper::{graphql_value, DefaultScalarValue};
use super::*; use super::*;
use juniper::DefaultScalarValue;
#[test] #[test]
fn test_serialization() { fn test_serialization() {
@ -160,7 +161,7 @@ mod test {
serde_json::to_string(&ServerMessage::Data { serde_json::to_string(&ServerMessage::Data {
id: "foo".to_string(), id: "foo".to_string(),
payload: DataPayload { payload: DataPayload {
data: Value::null(), data: graphql_value!(None),
errors: vec![], errors: vec![],
}, },
}) })

View file

@ -254,17 +254,17 @@ where
#[cfg(test)] #[cfg(test)]
mod whole_responses_stream { mod whole_responses_stream {
use futures::{stream, StreamExt as _}; use futures::{stream, StreamExt as _};
use juniper::{DefaultScalarValue, ExecutionError, FieldError}; use juniper::{graphql_value, DefaultScalarValue, ExecutionError, FieldError};
use super::*; use super::*;
#[tokio::test] #[tokio::test]
async fn with_error() { async fn with_error() {
let expected = vec![ExecutionOutput { let expected: Vec<ExecutionOutput<DefaultScalarValue>> = vec![ExecutionOutput {
data: Value::<DefaultScalarValue>::Null, data: graphql_value!(None),
errors: vec![ExecutionError::at_origin(FieldError::new( errors: vec![ExecutionError::at_origin(FieldError::new(
"field error", "field error",
Value::Null, graphql_value!(None),
))], ))],
}]; }];
let expected = serde_json::to_string(&expected).unwrap(); let expected = serde_json::to_string(&expected).unwrap();
@ -273,7 +273,7 @@ mod whole_responses_stream {
Value::Null, Value::Null,
vec![ExecutionError::at_origin(FieldError::new( vec![ExecutionError::at_origin(FieldError::new(
"field error", "field error",
Value::Null, graphql_value!(None),
))], ))],
) )
.collect::<Vec<_>>() .collect::<Vec<_>>()
@ -285,9 +285,8 @@ mod whole_responses_stream {
#[tokio::test] #[tokio::test]
async fn value_null() { async fn value_null() {
let expected = vec![ExecutionOutput::from_data( let expected: Vec<ExecutionOutput<DefaultScalarValue>> =
Value::<DefaultScalarValue>::Null, vec![ExecutionOutput::from_data(graphql_value!(None))];
)];
let expected = serde_json::to_string(&expected).unwrap(); let expected = serde_json::to_string(&expected).unwrap();
let result = whole_responses_stream::<DefaultScalarValue>(Value::Null, vec![]) let result = whole_responses_stream::<DefaultScalarValue>(Value::Null, vec![])
@ -302,12 +301,12 @@ mod whole_responses_stream {
#[tokio::test] #[tokio::test]
async fn value_scalar() { async fn value_scalar() {
let expected = vec![ let expected: Vec<ExecutionOutput<DefaultScalarValue>> = vec![
ExecutionOutput::from_data(Value::Scalar(DefaultScalarValue::Int(1i32))), ExecutionOutput::from_data(graphql_value!(1)),
ExecutionOutput::from_data(Value::Scalar(DefaultScalarValue::Int(2i32))), ExecutionOutput::from_data(graphql_value!(2)),
ExecutionOutput::from_data(Value::Scalar(DefaultScalarValue::Int(3i32))), ExecutionOutput::from_data(graphql_value!(3)),
ExecutionOutput::from_data(Value::Scalar(DefaultScalarValue::Int(4i32))), ExecutionOutput::from_data(graphql_value!(4)),
ExecutionOutput::from_data(Value::Scalar(DefaultScalarValue::Int(5i32))), ExecutionOutput::from_data(graphql_value!(5)),
]; ];
let expected = serde_json::to_string(&expected).unwrap(); let expected = serde_json::to_string(&expected).unwrap();
@ -317,7 +316,7 @@ mod whole_responses_stream {
return Poll::Ready(None); return Poll::Ready(None);
} }
counter += 1; counter += 1;
Poll::Ready(Some(Ok(Value::Scalar(DefaultScalarValue::Int(counter))))) Poll::Ready(Some(Ok(graphql_value!(counter))))
}); });
let result = let result =
@ -331,24 +330,24 @@ mod whole_responses_stream {
#[tokio::test] #[tokio::test]
async fn value_list() { async fn value_list() {
let expected = vec![ let expected: Vec<ExecutionOutput<DefaultScalarValue>> = vec![
ExecutionOutput::from_data(Value::Scalar(DefaultScalarValue::Int(1i32))), ExecutionOutput::from_data(graphql_value!(1)),
ExecutionOutput::from_data(Value::Scalar(DefaultScalarValue::Int(2i32))), ExecutionOutput::from_data(graphql_value!(2)),
ExecutionOutput::from_data(Value::null()), ExecutionOutput::from_data(graphql_value!(None)),
ExecutionOutput::from_data(Value::Scalar(DefaultScalarValue::Int(4i32))), ExecutionOutput::from_data(graphql_value!(4)),
]; ];
let expected = serde_json::to_string(&expected).unwrap(); let expected = serde_json::to_string(&expected).unwrap();
let streams: Vec<Value<ValuesStream>> = vec![ let streams: Vec<Value<ValuesStream>> = vec![
Value::Scalar(Box::pin(stream::once(async { 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 { Value::Scalar(Box::pin(stream::once(async {
PollResult::Ok(Value::Scalar(DefaultScalarValue::Int(2i32))) PollResult::Ok(graphql_value!(2))
}))), }))),
Value::Null, Value::Null,
Value::Scalar(Box::pin(stream::once(async { 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] #[tokio::test]
async fn value_object() { async fn value_object() {
let expected = vec![ let expected: Vec<ExecutionOutput<DefaultScalarValue>> = vec![
ExecutionOutput::from_data(Value::Object(Object::from_iter( ExecutionOutput::from_data(graphql_value!({"one": 1, "two": 1})),
vec![ ExecutionOutput::from_data(graphql_value!({"one": 2, "two": 2})),
("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 = serde_json::to_string(&expected).unwrap(); let expected = serde_json::to_string(&expected).unwrap();
@ -386,7 +373,7 @@ mod whole_responses_stream {
return Poll::Ready(None); return Poll::Ready(None);
} }
counter += 1; counter += 1;
Poll::Ready(Some(Ok(Value::Scalar(DefaultScalarValue::Int(counter))))) Poll::Ready(Some(Ok(graphql_value!(counter))))
}); });
let mut counter = 0; let mut counter = 0;
@ -395,7 +382,7 @@ mod whole_responses_stream {
return Poll::Ready(None); return Poll::Ready(None);
} }
counter += 1; counter += 1;
Poll::Ready(Some(Ok(Value::Scalar(DefaultScalarValue::Int(counter))))) Poll::Ready(Some(Ok(graphql_value!(counter))))
}); });
let vals: Vec<(&str, Value<ValuesStream>)> = vec![ let vals: Vec<(&str, Value<ValuesStream>)> = vec![