Use graphql_value!() macro in tests asap
This commit is contained in:
parent
a3fda7363d
commit
74afe4c04a
27 changed files with 1253 additions and 1945 deletions
|
@ -9,9 +9,9 @@ use actix_web::{
|
|||
};
|
||||
|
||||
use juniper::{
|
||||
graphql_object, graphql_subscription,
|
||||
graphql_object, graphql_subscription, graphql_value,
|
||||
tests::fixtures::starwars::schema::{Character as _, Database, Query},
|
||||
DefaultScalarValue, EmptyMutation, FieldError, RootNode, Value,
|
||||
EmptyMutation, FieldError, RootNode,
|
||||
};
|
||||
use juniper_actix::{graphql_handler, playground_handler, subscriptions::subscriptions_handler};
|
||||
use juniper_graphql_ws::ConnectionConfig;
|
||||
|
@ -77,9 +77,7 @@ impl Subscription {
|
|||
if counter == 2 {
|
||||
yield Err(FieldError::new(
|
||||
"some field error from handler",
|
||||
Value::Scalar(DefaultScalarValue::String(
|
||||
"some additional string".to_string(),
|
||||
)),
|
||||
graphql_value!("some additional string"),
|
||||
))
|
||||
} else {
|
||||
let random_id = rng.gen_range(1000..1005).to_string();
|
||||
|
|
|
@ -4,8 +4,8 @@ use std::{env, pin::Pin, sync::Arc, time::Duration};
|
|||
|
||||
use futures::{FutureExt as _, Stream};
|
||||
use juniper::{
|
||||
graphql_object, graphql_subscription, DefaultScalarValue, EmptyMutation, FieldError,
|
||||
GraphQLEnum, RootNode, Value,
|
||||
graphql_object, graphql_subscription, graphql_value, EmptyMutation, FieldError, GraphQLEnum,
|
||||
RootNode,
|
||||
};
|
||||
use juniper_graphql_ws::ConnectionConfig;
|
||||
use juniper_warp::{playground_filter, subscriptions::serve_graphql_ws};
|
||||
|
@ -117,9 +117,7 @@ impl Subscription {
|
|||
if counter == 2 {
|
||||
yield Err(FieldError::new(
|
||||
"some field error from handler",
|
||||
Value::Scalar(DefaultScalarValue::String(
|
||||
"some additional string".to_string(),
|
||||
)),
|
||||
graphql_value!("some additional string"),
|
||||
))
|
||||
} else {
|
||||
yield Ok(User {
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
use crate::custom_scalar::MyScalarValue;
|
||||
use juniper::{
|
||||
execute, EmptyMutation, EmptySubscription, FromInputValue, InputValue, RootNode, ToInputValue,
|
||||
Value, Variables,
|
||||
execute, graphql_value, EmptyMutation, EmptySubscription, FromInputValue, InputValue, RootNode,
|
||||
ToInputValue, Value, Variables,
|
||||
};
|
||||
|
||||
use crate::custom_scalar::MyScalarValue;
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Hash, juniper::GraphQLScalarValue)]
|
||||
#[graphql(transparent, scalar = MyScalarValue)]
|
||||
pub struct LargeId(i64);
|
||||
|
@ -56,28 +57,14 @@ async fn test_scalar_value_large_query() {
|
|||
EmptySubscription::<()>::new(),
|
||||
);
|
||||
|
||||
let doc = r#"
|
||||
query {
|
||||
user { id }
|
||||
}"#;
|
||||
let doc = r#"{
|
||||
user { id }
|
||||
}"#;
|
||||
|
||||
let val = Value::<MyScalarValue>::scalar(0_i64);
|
||||
assert_eq!(
|
||||
execute(doc, None, &schema, &Variables::<MyScalarValue>::new(), &()).await,
|
||||
Ok((
|
||||
Value::object(
|
||||
vec![(
|
||||
"user",
|
||||
Value::object(
|
||||
vec![("id", Value::<MyScalarValue>::scalar(0_i64)),]
|
||||
.into_iter()
|
||||
.collect(),
|
||||
),
|
||||
)]
|
||||
.into_iter()
|
||||
.collect()
|
||||
),
|
||||
vec![]
|
||||
))
|
||||
Ok((graphql_value!({"user": {"id": val}}), vec![])),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -89,51 +76,23 @@ async fn test_scalar_value_large_mutation() {
|
|||
EmptySubscription::<()>::new(),
|
||||
);
|
||||
|
||||
let doc = r#"
|
||||
mutation {
|
||||
changeUser(id: 1) { id }
|
||||
}"#;
|
||||
let doc = r#"mutation {
|
||||
changeUser(id: 1) { id }
|
||||
}"#;
|
||||
|
||||
let val = Value::<MyScalarValue>::scalar(1_i64);
|
||||
assert_eq!(
|
||||
execute(doc, None, &schema, &Variables::<MyScalarValue>::new(), &()).await,
|
||||
Ok((
|
||||
Value::object(
|
||||
vec![(
|
||||
"changeUser",
|
||||
Value::object(
|
||||
vec![("id", Value::<MyScalarValue>::scalar(1_i64)),]
|
||||
.into_iter()
|
||||
.collect(),
|
||||
),
|
||||
)]
|
||||
.into_iter()
|
||||
.collect()
|
||||
),
|
||||
vec![]
|
||||
))
|
||||
Ok((graphql_value!({"changeUser": {"id": val}}), vec![])),
|
||||
);
|
||||
|
||||
let doc = r#"
|
||||
mutation {
|
||||
changeUser(id: 4294967297) { id }
|
||||
}"#;
|
||||
let doc = r#"mutation {
|
||||
changeUser(id: 4294967297) { id }
|
||||
}"#;
|
||||
|
||||
let val = Value::<MyScalarValue>::scalar(4294967297_i64);
|
||||
assert_eq!(
|
||||
execute(doc, None, &schema, &Variables::<MyScalarValue>::new(), &()).await,
|
||||
Ok((
|
||||
Value::object(
|
||||
vec![(
|
||||
"changeUser",
|
||||
Value::object(
|
||||
vec![("id", Value::<MyScalarValue>::scalar(4294967297_i64)),]
|
||||
.into_iter()
|
||||
.collect(),
|
||||
),
|
||||
)]
|
||||
.into_iter()
|
||||
.collect()
|
||||
),
|
||||
vec![]
|
||||
))
|
||||
Ok((graphql_value!({"changeUser": {"id": val}}), vec![])),
|
||||
);
|
||||
}
|
||||
|
|
|
@ -222,11 +222,11 @@ async fn default_name_introspection() {
|
|||
run_type_info_query(doc, |type_info| {
|
||||
assert_eq!(
|
||||
type_info.get_field_value("name"),
|
||||
Some(&Value::scalar("DefaultName"))
|
||||
Some(&graphql_value!("DefaultName")),
|
||||
);
|
||||
assert_eq!(
|
||||
type_info.get_field_value("description"),
|
||||
Some(&Value::null())
|
||||
Some(&graphql_value!(None)),
|
||||
);
|
||||
})
|
||||
.await;
|
||||
|
@ -246,11 +246,11 @@ async fn other_order_introspection() {
|
|||
run_type_info_query(doc, |type_info| {
|
||||
assert_eq!(
|
||||
type_info.get_field_value("name"),
|
||||
Some(&Value::scalar("OtherOrder"))
|
||||
Some(&graphql_value!("OtherOrder")),
|
||||
);
|
||||
assert_eq!(
|
||||
type_info.get_field_value("description"),
|
||||
Some(&Value::null())
|
||||
Some(&graphql_value!(None)),
|
||||
);
|
||||
})
|
||||
.await;
|
||||
|
@ -270,11 +270,11 @@ async fn named_introspection() {
|
|||
run_type_info_query(doc, |type_info| {
|
||||
assert_eq!(
|
||||
type_info.get_field_value("name"),
|
||||
Some(&Value::scalar("ANamedScalar"))
|
||||
Some(&graphql_value!("ANamedScalar")),
|
||||
);
|
||||
assert_eq!(
|
||||
type_info.get_field_value("description"),
|
||||
Some(&Value::null())
|
||||
Some(&graphql_value!(None)),
|
||||
);
|
||||
})
|
||||
.await;
|
||||
|
@ -294,11 +294,13 @@ async fn scalar_description_introspection() {
|
|||
run_type_info_query(doc, |type_info| {
|
||||
assert_eq!(
|
||||
type_info.get_field_value("name"),
|
||||
Some(&Value::scalar("ScalarDescription"))
|
||||
Some(&graphql_value!("ScalarDescription")),
|
||||
);
|
||||
assert_eq!(
|
||||
type_info.get_field_value("description"),
|
||||
Some(&Value::scalar("A sample scalar, represented as an integer"))
|
||||
Some(&graphql_value!(
|
||||
"A sample scalar, represented as an integer"
|
||||
)),
|
||||
);
|
||||
})
|
||||
.await;
|
||||
|
@ -318,11 +320,11 @@ async fn generated_scalar_introspection() {
|
|||
run_type_info_query(doc, |type_info| {
|
||||
assert_eq!(
|
||||
type_info.get_field_value("name"),
|
||||
Some(&Value::scalar("Generated"))
|
||||
Some(&graphql_value!("Generated")),
|
||||
);
|
||||
assert_eq!(
|
||||
type_info.get_field_value("description"),
|
||||
Some(&Value::null())
|
||||
Some(&graphql_value!(None)),
|
||||
);
|
||||
})
|
||||
.await;
|
||||
|
|
|
@ -2,14 +2,15 @@
|
|||
|
||||
use std::pin::Pin;
|
||||
|
||||
use futures::{future, stream, FutureExt as _, StreamExt as _};
|
||||
use futures::{future, stream, FutureExt as _};
|
||||
use juniper::{
|
||||
execute, graphql_object, graphql_subscription, graphql_value, resolve_into_stream,
|
||||
DefaultScalarValue, EmptyMutation, ExecutionError, Executor, FieldError, FieldResult,
|
||||
GraphQLError, GraphQLInputObject, GraphQLType, IntoFieldError, RootNode, ScalarValue, Value,
|
||||
ValuesStream, Variables,
|
||||
DefaultScalarValue, EmptyMutation, Executor, FieldError, FieldResult, GraphQLInputObject,
|
||||
GraphQLType, IntoFieldError, RootNode, ScalarValue, Variables,
|
||||
};
|
||||
|
||||
use crate::util::extract_next;
|
||||
|
||||
struct Query;
|
||||
|
||||
#[graphql_object]
|
||||
|
@ -44,29 +45,6 @@ where
|
|||
|
||||
type Stream<'a, I> = Pin<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 {
|
||||
use super::*;
|
||||
|
||||
|
|
|
@ -218,7 +218,7 @@ async fn querying_long() {
|
|||
run_query("{ longField }", |result| {
|
||||
assert_eq!(
|
||||
result.get_field_value("longField"),
|
||||
Some(&Value::scalar(i64::from(i32::max_value()) + 1))
|
||||
Some(&Value::scalar(i64::from(i32::MAX) + 1))
|
||||
);
|
||||
})
|
||||
.await;
|
||||
|
@ -227,14 +227,11 @@ async fn querying_long() {
|
|||
#[tokio::test]
|
||||
async fn querying_long_arg() {
|
||||
run_query(
|
||||
&format!(
|
||||
"{{ longWithArg(longArg: {}) }}",
|
||||
i64::from(i32::max_value()) + 3
|
||||
),
|
||||
&format!("{{ longWithArg(longArg: {}) }}", i64::from(i32::MAX) + 3),
|
||||
|result| {
|
||||
assert_eq!(
|
||||
result.get_field_value("longWithArg"),
|
||||
Some(&Value::scalar(i64::from(i32::max_value()) + 3))
|
||||
Some(&Value::scalar(i64::from(i32::MAX) + 3))
|
||||
);
|
||||
},
|
||||
)
|
||||
|
@ -247,14 +244,14 @@ async fn querying_long_variable() {
|
|||
"query q($test: Long!){ longWithArg(longArg: $test) }",
|
||||
vec![(
|
||||
"test".to_owned(),
|
||||
InputValue::Scalar(MyScalarValue::Long(i64::from(i32::max_value()) + 42)),
|
||||
InputValue::Scalar(MyScalarValue::Long(i64::from(i32::MAX) + 42)),
|
||||
)]
|
||||
.into_iter()
|
||||
.collect(),
|
||||
|result| {
|
||||
assert_eq!(
|
||||
result.get_field_value("longWithArg"),
|
||||
Some(&Value::scalar(i64::from(i32::max_value()) + 42))
|
||||
Some(&Value::scalar(i64::from(i32::MAX) + 42))
|
||||
);
|
||||
},
|
||||
)
|
||||
|
@ -263,7 +260,7 @@ async fn querying_long_variable() {
|
|||
|
||||
#[test]
|
||||
fn deserialize_variable() {
|
||||
let json = format!("{{\"field\": {}}}", i64::from(i32::max_value()) + 42);
|
||||
let json = format!("{{\"field\": {}}}", i64::from(i32::MAX) + 42);
|
||||
|
||||
let input_value: InputValue<MyScalarValue> = serde_json::from_str(&json).unwrap();
|
||||
assert_eq!(
|
||||
|
@ -271,7 +268,7 @@ fn deserialize_variable() {
|
|||
InputValue::Object(vec![(
|
||||
Spanning::unlocated("field".into()),
|
||||
Spanning::unlocated(InputValue::Scalar(MyScalarValue::Long(
|
||||
i64::from(i32::max_value()) + 42
|
||||
i64::from(i32::MAX) + 42
|
||||
)))
|
||||
)])
|
||||
);
|
||||
|
|
|
@ -1,8 +1,13 @@
|
|||
//! Checks that `__typename` field queries okay on root types.
|
||||
//! See [#372](https://github.com/graphql-rust/juniper/issues/372) for details.
|
||||
|
||||
use futures::{stream, StreamExt as _};
|
||||
use juniper::{graphql_object, graphql_subscription, graphql_value, RootNode, Value, Variables};
|
||||
use futures::{stream, FutureExt as _};
|
||||
use juniper::{
|
||||
execute, graphql_object, graphql_subscription, graphql_value, resolve_into_stream, RootNode,
|
||||
Variables,
|
||||
};
|
||||
|
||||
use crate::util::extract_next;
|
||||
|
||||
pub struct Query;
|
||||
|
||||
|
@ -36,12 +41,11 @@ async fn implicit_query_typename() {
|
|||
let query = r#"{ __typename }"#;
|
||||
|
||||
let schema = RootNode::new(Query, Mutation, Subscription);
|
||||
let (res, errors) = juniper::execute(query, None, &schema, &Variables::new(), &())
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(errors.len(), 0);
|
||||
assert_eq!(res, graphql_value!({"__typename": "Query"}));
|
||||
assert_eq!(
|
||||
execute(query, None, &schema, &Variables::new(), &()).await,
|
||||
Ok((graphql_value!({"__typename": "Query"}), vec![])),
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
|
@ -49,12 +53,11 @@ async fn query_typename() {
|
|||
let query = r#"query { __typename }"#;
|
||||
|
||||
let schema = RootNode::new(Query, Mutation, Subscription);
|
||||
let (res, errors) = juniper::execute(query, None, &schema, &Variables::new(), &())
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(errors.len(), 0);
|
||||
assert_eq!(res, graphql_value!({"__typename": "Query"}));
|
||||
assert_eq!(
|
||||
execute(query, None, &schema, &Variables::new(), &()).await,
|
||||
Ok((graphql_value!({"__typename": "Query"}), vec![])),
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
|
@ -62,12 +65,11 @@ async fn explicit_query_typename() {
|
|||
let query = r#"query Query { __typename }"#;
|
||||
|
||||
let schema = RootNode::new(Query, Mutation, Subscription);
|
||||
let (res, errors) = juniper::execute(query, None, &schema, &Variables::new(), &())
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(errors.len(), 0);
|
||||
assert_eq!(res, graphql_value!({"__typename": "Query"}));
|
||||
assert_eq!(
|
||||
execute(query, None, &schema, &Variables::new(), &()).await,
|
||||
Ok((graphql_value!({"__typename": "Query"}), vec![])),
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
|
@ -75,12 +77,11 @@ async fn mutation_typename() {
|
|||
let query = r#"mutation { __typename }"#;
|
||||
|
||||
let schema = RootNode::new(Query, Mutation, Subscription);
|
||||
let (res, errors) = juniper::execute(query, None, &schema, &Variables::new(), &())
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(errors.len(), 0);
|
||||
assert_eq!(res, graphql_value!({"__typename": "Mutation"}));
|
||||
assert_eq!(
|
||||
execute(query, None, &schema, &Variables::new(), &()).await,
|
||||
Ok((graphql_value!({"__typename": "Mutation"}), vec![])),
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
|
@ -88,12 +89,11 @@ async fn explicit_mutation_typename() {
|
|||
let query = r#"mutation Mutation { __typename }"#;
|
||||
|
||||
let schema = RootNode::new(Query, Mutation, Subscription);
|
||||
let (res, errors) = juniper::execute(query, None, &schema, &Variables::new(), &())
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(errors.len(), 0);
|
||||
assert_eq!(res, graphql_value!({"__typename": "Mutation"}));
|
||||
assert_eq!(
|
||||
execute(query, None, &schema, &Variables::new(), &()).await,
|
||||
Ok((graphql_value!({"__typename": "Mutation"}), vec![])),
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
|
@ -101,24 +101,13 @@ async fn subscription_typename() {
|
|||
let query = r#"subscription { __typename }"#;
|
||||
|
||||
let schema = RootNode::new(Query, Mutation, Subscription);
|
||||
let (res, errors) = juniper::resolve_into_stream(query, None, &schema, &Variables::new(), &())
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(errors.len(), 0);
|
||||
assert!(matches!(res, Value::Object(_)));
|
||||
if let Value::Object(mut obj) = res {
|
||||
assert!(obj.contains_field("__typename"));
|
||||
|
||||
let val = obj.get_mut_field_value("__typename").unwrap();
|
||||
assert!(matches!(val, Value::Scalar(_)));
|
||||
if let Value::Scalar(ref mut stream) = val {
|
||||
assert_eq!(
|
||||
stream.next().await,
|
||||
Some(Ok(graphql_value!("Subscription"))),
|
||||
);
|
||||
}
|
||||
}
|
||||
assert_eq!(
|
||||
resolve_into_stream(query, None, &schema, &Variables::new(), &())
|
||||
.then(|s| extract_next(s))
|
||||
.await,
|
||||
Ok((graphql_value!({"__typename": "Subscription"}), vec![])),
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
|
@ -126,22 +115,11 @@ async fn explicit_subscription_typename() {
|
|||
let query = r#"subscription Subscription { __typename }"#;
|
||||
|
||||
let schema = RootNode::new(Query, Mutation, Subscription);
|
||||
let (res, errors) = juniper::resolve_into_stream(query, None, &schema, &Variables::new(), &())
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(errors.len(), 0);
|
||||
assert!(matches!(res, Value::Object(_)));
|
||||
if let Value::Object(mut obj) = res {
|
||||
assert!(obj.contains_field("__typename"));
|
||||
|
||||
let val = obj.get_mut_field_value("__typename").unwrap();
|
||||
assert!(matches!(val, Value::Scalar(_)));
|
||||
if let Value::Scalar(ref mut stream) = val {
|
||||
assert_eq!(
|
||||
stream.next().await,
|
||||
Some(Ok(graphql_value!("Subscription"))),
|
||||
);
|
||||
}
|
||||
}
|
||||
assert_eq!(
|
||||
resolve_into_stream(query, None, &schema, &Variables::new(), &())
|
||||
.then(|s| extract_next(s))
|
||||
.await,
|
||||
Ok((graphql_value!({"__typename": "Subscription"}), vec![])),
|
||||
);
|
||||
}
|
||||
|
|
|
@ -32,3 +32,36 @@ mod issue_925;
|
|||
mod issue_945;
|
||||
#[cfg(test)]
|
||||
mod pre_parse;
|
||||
|
||||
#[cfg(test)]
|
||||
/// Common utilities used across tests.
|
||||
pub(crate) mod util {
|
||||
use futures::StreamExt as _;
|
||||
use juniper::{graphql_value, ExecutionError, GraphQLError, ScalarValue, Value, ValuesStream};
|
||||
|
||||
/// Extracts a single next value from the result returned by
|
||||
/// [`juniper::resolve_into_stream()`] and transforms it into a regular
|
||||
/// [`Value`].
|
||||
pub(crate) async fn extract_next<'a, S: ScalarValue>(
|
||||
input: Result<(Value<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")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
use crate::{graphql_object, EmptyMutation, EmptySubscription, GraphQLEnum, RootNode, Value};
|
||||
use crate::{
|
||||
graphql_object, graphql_value, EmptyMutation, EmptySubscription, GraphQLEnum, RootNode, Value,
|
||||
};
|
||||
|
||||
#[derive(GraphQLEnum)]
|
||||
enum UserKind {
|
||||
|
@ -74,10 +76,10 @@ impl Query {
|
|||
async fn async_simple() {
|
||||
let schema = RootNode::new(Query, EmptyMutation::new(), EmptySubscription::new());
|
||||
let doc = r#"
|
||||
query {
|
||||
query {
|
||||
fieldSync
|
||||
fieldAsyncPlain
|
||||
delayed
|
||||
fieldAsyncPlain
|
||||
delayed
|
||||
user(id: "user1") {
|
||||
name
|
||||
}
|
||||
|
@ -96,7 +98,7 @@ async fn async_simple() {
|
|||
|
||||
assert_eq!(
|
||||
value,
|
||||
crate::graphql_value!({
|
||||
graphql_value!({
|
||||
"delayed": true,
|
||||
"fieldAsyncPlain": "field_async_plain",
|
||||
"fieldSync": "field_sync",
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
use crate::{
|
||||
executor::Variables,
|
||||
graphql_value,
|
||||
schema::model::RootNode,
|
||||
types::scalars::{EmptyMutation, EmptySubscription},
|
||||
value::{DefaultScalarValue, Object, Value},
|
||||
value::{DefaultScalarValue, Object},
|
||||
};
|
||||
|
||||
struct TestType;
|
||||
|
@ -51,8 +52,8 @@ where
|
|||
#[tokio::test]
|
||||
async fn scalar_include_true() {
|
||||
run_query("{ a, b @include(if: true) }", |result| {
|
||||
assert_eq!(result.get_field_value("a"), Some(&Value::scalar("a")));
|
||||
assert_eq!(result.get_field_value("b"), Some(&Value::scalar("b")));
|
||||
assert_eq!(result.get_field_value("a"), Some(&graphql_value!("a")));
|
||||
assert_eq!(result.get_field_value("b"), Some(&graphql_value!("b")));
|
||||
})
|
||||
.await;
|
||||
}
|
||||
|
@ -60,7 +61,7 @@ async fn scalar_include_true() {
|
|||
#[tokio::test]
|
||||
async fn scalar_include_false() {
|
||||
run_query("{ a, b @include(if: false) }", |result| {
|
||||
assert_eq!(result.get_field_value("a"), Some(&Value::scalar("a")));
|
||||
assert_eq!(result.get_field_value("a"), Some(&graphql_value!("a")));
|
||||
assert_eq!(result.get_field_value("b"), None);
|
||||
})
|
||||
.await;
|
||||
|
@ -69,8 +70,8 @@ async fn scalar_include_false() {
|
|||
#[tokio::test]
|
||||
async fn scalar_skip_false() {
|
||||
run_query("{ a, b @skip(if: false) }", |result| {
|
||||
assert_eq!(result.get_field_value("a"), Some(&Value::scalar("a")));
|
||||
assert_eq!(result.get_field_value("b"), Some(&Value::scalar("b")));
|
||||
assert_eq!(result.get_field_value("a"), Some(&graphql_value!("a")));
|
||||
assert_eq!(result.get_field_value("b"), Some(&graphql_value!("b")));
|
||||
})
|
||||
.await;
|
||||
}
|
||||
|
@ -78,7 +79,7 @@ async fn scalar_skip_false() {
|
|||
#[tokio::test]
|
||||
async fn scalar_skip_true() {
|
||||
run_query("{ a, b @skip(if: true) }", |result| {
|
||||
assert_eq!(result.get_field_value("a"), Some(&Value::scalar("a")));
|
||||
assert_eq!(result.get_field_value("a"), Some(&graphql_value!("a")));
|
||||
assert_eq!(result.get_field_value("b"), None);
|
||||
})
|
||||
.await;
|
||||
|
@ -89,8 +90,8 @@ async fn fragment_spread_include_true() {
|
|||
run_query(
|
||||
"{ a, ...Frag @include(if: true) } fragment Frag on TestType { b }",
|
||||
|result| {
|
||||
assert_eq!(result.get_field_value("a"), Some(&Value::scalar("a")));
|
||||
assert_eq!(result.get_field_value("b"), Some(&Value::scalar("b")));
|
||||
assert_eq!(result.get_field_value("a"), Some(&graphql_value!("a")));
|
||||
assert_eq!(result.get_field_value("b"), Some(&graphql_value!("b")));
|
||||
},
|
||||
)
|
||||
.await;
|
||||
|
@ -101,7 +102,7 @@ async fn fragment_spread_include_false() {
|
|||
run_query(
|
||||
"{ a, ...Frag @include(if: false) } fragment Frag on TestType { b }",
|
||||
|result| {
|
||||
assert_eq!(result.get_field_value("a"), Some(&Value::scalar("a")));
|
||||
assert_eq!(result.get_field_value("a"), Some(&graphql_value!("a")));
|
||||
assert_eq!(result.get_field_value("b"), None);
|
||||
},
|
||||
)
|
||||
|
@ -113,8 +114,8 @@ async fn fragment_spread_skip_false() {
|
|||
run_query(
|
||||
"{ a, ...Frag @skip(if: false) } fragment Frag on TestType { b }",
|
||||
|result| {
|
||||
assert_eq!(result.get_field_value("a"), Some(&Value::scalar("a")));
|
||||
assert_eq!(result.get_field_value("b"), Some(&Value::scalar("b")));
|
||||
assert_eq!(result.get_field_value("a"), Some(&graphql_value!("a")));
|
||||
assert_eq!(result.get_field_value("b"), Some(&graphql_value!("b")));
|
||||
},
|
||||
)
|
||||
.await;
|
||||
|
@ -125,7 +126,7 @@ async fn fragment_spread_skip_true() {
|
|||
run_query(
|
||||
"{ a, ...Frag @skip(if: true) } fragment Frag on TestType { b }",
|
||||
|result| {
|
||||
assert_eq!(result.get_field_value("a"), Some(&Value::scalar("a")));
|
||||
assert_eq!(result.get_field_value("a"), Some(&graphql_value!("a")));
|
||||
assert_eq!(result.get_field_value("b"), None);
|
||||
},
|
||||
)
|
||||
|
@ -137,8 +138,8 @@ async fn inline_fragment_include_true() {
|
|||
run_query(
|
||||
"{ a, ... on TestType @include(if: true) { b } }",
|
||||
|result| {
|
||||
assert_eq!(result.get_field_value("a"), Some(&Value::scalar("a")));
|
||||
assert_eq!(result.get_field_value("b"), Some(&Value::scalar("b")));
|
||||
assert_eq!(result.get_field_value("a"), Some(&graphql_value!("a")));
|
||||
assert_eq!(result.get_field_value("b"), Some(&graphql_value!("b")));
|
||||
},
|
||||
)
|
||||
.await;
|
||||
|
@ -149,7 +150,7 @@ async fn inline_fragment_include_false() {
|
|||
run_query(
|
||||
"{ a, ... on TestType @include(if: false) { b } }",
|
||||
|result| {
|
||||
assert_eq!(result.get_field_value("a"), Some(&Value::scalar("a")));
|
||||
assert_eq!(result.get_field_value("a"), Some(&graphql_value!("a")));
|
||||
assert_eq!(result.get_field_value("b"), None);
|
||||
},
|
||||
)
|
||||
|
@ -159,8 +160,8 @@ async fn inline_fragment_include_false() {
|
|||
#[tokio::test]
|
||||
async fn inline_fragment_skip_false() {
|
||||
run_query("{ a, ... on TestType @skip(if: false) { b } }", |result| {
|
||||
assert_eq!(result.get_field_value("a"), Some(&Value::scalar("a")));
|
||||
assert_eq!(result.get_field_value("b"), Some(&Value::scalar("b")));
|
||||
assert_eq!(result.get_field_value("a"), Some(&graphql_value!("a")));
|
||||
assert_eq!(result.get_field_value("b"), Some(&graphql_value!("b")));
|
||||
})
|
||||
.await;
|
||||
}
|
||||
|
@ -168,7 +169,7 @@ async fn inline_fragment_skip_false() {
|
|||
#[tokio::test]
|
||||
async fn inline_fragment_skip_true() {
|
||||
run_query("{ a, ... on TestType @skip(if: true) { b } }", |result| {
|
||||
assert_eq!(result.get_field_value("a"), Some(&Value::scalar("a")));
|
||||
assert_eq!(result.get_field_value("a"), Some(&graphql_value!("a")));
|
||||
assert_eq!(result.get_field_value("b"), None);
|
||||
})
|
||||
.await;
|
||||
|
@ -177,8 +178,8 @@ async fn inline_fragment_skip_true() {
|
|||
#[tokio::test]
|
||||
async fn anonymous_inline_fragment_include_true() {
|
||||
run_query("{ a, ... @include(if: true) { b } }", |result| {
|
||||
assert_eq!(result.get_field_value("a"), Some(&Value::scalar("a")));
|
||||
assert_eq!(result.get_field_value("b"), Some(&Value::scalar("b")));
|
||||
assert_eq!(result.get_field_value("a"), Some(&graphql_value!("a")));
|
||||
assert_eq!(result.get_field_value("b"), Some(&graphql_value!("b")));
|
||||
})
|
||||
.await;
|
||||
}
|
||||
|
@ -186,7 +187,7 @@ async fn anonymous_inline_fragment_include_true() {
|
|||
#[tokio::test]
|
||||
async fn anonymous_inline_fragment_include_false() {
|
||||
run_query("{ a, ... @include(if: false) { b } }", |result| {
|
||||
assert_eq!(result.get_field_value("a"), Some(&Value::scalar("a")));
|
||||
assert_eq!(result.get_field_value("a"), Some(&graphql_value!("a")));
|
||||
assert_eq!(result.get_field_value("b"), None);
|
||||
})
|
||||
.await;
|
||||
|
@ -195,8 +196,8 @@ async fn anonymous_inline_fragment_include_false() {
|
|||
#[tokio::test]
|
||||
async fn anonymous_inline_fragment_skip_false() {
|
||||
run_query("{ a, ... @skip(if: false) { b } }", |result| {
|
||||
assert_eq!(result.get_field_value("a"), Some(&Value::scalar("a")));
|
||||
assert_eq!(result.get_field_value("b"), Some(&Value::scalar("b")));
|
||||
assert_eq!(result.get_field_value("a"), Some(&graphql_value!("a")));
|
||||
assert_eq!(result.get_field_value("b"), Some(&graphql_value!("b")));
|
||||
})
|
||||
.await;
|
||||
}
|
||||
|
@ -204,7 +205,7 @@ async fn anonymous_inline_fragment_skip_false() {
|
|||
#[tokio::test]
|
||||
async fn anonymous_inline_fragment_skip_true() {
|
||||
run_query("{ a, ... @skip(if: true) { b } }", |result| {
|
||||
assert_eq!(result.get_field_value("a"), Some(&Value::scalar("a")));
|
||||
assert_eq!(result.get_field_value("a"), Some(&graphql_value!("a")));
|
||||
assert_eq!(result.get_field_value("b"), None);
|
||||
})
|
||||
.await;
|
||||
|
@ -213,7 +214,7 @@ async fn anonymous_inline_fragment_skip_true() {
|
|||
#[tokio::test]
|
||||
async fn scalar_include_true_skip_true() {
|
||||
run_query("{ a, b @include(if: true) @skip(if: true) }", |result| {
|
||||
assert_eq!(result.get_field_value("a"), Some(&Value::scalar("a")));
|
||||
assert_eq!(result.get_field_value("a"), Some(&graphql_value!("a")));
|
||||
assert_eq!(result.get_field_value("b"), None);
|
||||
})
|
||||
.await;
|
||||
|
@ -222,8 +223,8 @@ async fn scalar_include_true_skip_true() {
|
|||
#[tokio::test]
|
||||
async fn scalar_include_true_skip_false() {
|
||||
run_query("{ a, b @include(if: true) @skip(if: false) }", |result| {
|
||||
assert_eq!(result.get_field_value("a"), Some(&Value::scalar("a")));
|
||||
assert_eq!(result.get_field_value("b"), Some(&Value::scalar("b")));
|
||||
assert_eq!(result.get_field_value("a"), Some(&graphql_value!("a")));
|
||||
assert_eq!(result.get_field_value("b"), Some(&graphql_value!("b")));
|
||||
})
|
||||
.await;
|
||||
}
|
||||
|
@ -231,7 +232,7 @@ async fn scalar_include_true_skip_false() {
|
|||
#[tokio::test]
|
||||
async fn scalar_include_false_skip_true() {
|
||||
run_query("{ a, b @include(if: false) @skip(if: true) }", |result| {
|
||||
assert_eq!(result.get_field_value("a"), Some(&Value::scalar("a")));
|
||||
assert_eq!(result.get_field_value("a"), Some(&graphql_value!("a")));
|
||||
assert_eq!(result.get_field_value("b"), None);
|
||||
})
|
||||
.await;
|
||||
|
@ -240,7 +241,7 @@ async fn scalar_include_false_skip_true() {
|
|||
#[tokio::test]
|
||||
async fn scalar_include_false_skip_false() {
|
||||
run_query("{ a, b @include(if: false) @skip(if: false) }", |result| {
|
||||
assert_eq!(result.get_field_value("a"), Some(&Value::scalar("a")));
|
||||
assert_eq!(result.get_field_value("a"), Some(&graphql_value!("a")));
|
||||
assert_eq!(result.get_field_value("b"), None);
|
||||
})
|
||||
.await;
|
||||
|
|
|
@ -5,7 +5,7 @@ use crate::{
|
|||
schema::model::RootNode,
|
||||
types::scalars::{EmptyMutation, EmptySubscription},
|
||||
validation::RuleError,
|
||||
value::{DefaultScalarValue, Object, Value},
|
||||
value::{DefaultScalarValue, Object},
|
||||
GraphQLEnum,
|
||||
GraphQLError::ValidationError,
|
||||
};
|
||||
|
@ -64,7 +64,7 @@ async fn accepts_enum_literal() {
|
|||
run_query("{ toString(color: RED) }", |result| {
|
||||
assert_eq!(
|
||||
result.get_field_value("toString"),
|
||||
Some(&Value::scalar("Color::Red"))
|
||||
Some(&graphql_value!("Color::Red")),
|
||||
);
|
||||
})
|
||||
.await;
|
||||
|
@ -75,7 +75,7 @@ async fn serializes_as_output() {
|
|||
run_query("{ aColor }", |result| {
|
||||
assert_eq!(
|
||||
result.get_field_value("aColor"),
|
||||
Some(&Value::scalar("RED"))
|
||||
Some(&graphql_value!("RED")),
|
||||
);
|
||||
})
|
||||
.await;
|
||||
|
@ -115,7 +115,7 @@ async fn accepts_strings_in_variables() {
|
|||
|result| {
|
||||
assert_eq!(
|
||||
result.get_field_value("toString"),
|
||||
Some(&Value::scalar("Color::Red"))
|
||||
Some(&graphql_value!("Color::Red")),
|
||||
);
|
||||
},
|
||||
)
|
||||
|
|
|
@ -385,7 +385,6 @@ mod dynamic_context_switching {
|
|||
parser::SourcePosition,
|
||||
schema::model::RootNode,
|
||||
types::scalars::{EmptyMutation, EmptySubscription},
|
||||
value::Value,
|
||||
Executor, ScalarValue,
|
||||
};
|
||||
|
||||
|
@ -485,21 +484,10 @@ mod dynamic_context_switching {
|
|||
|
||||
assert_eq!(
|
||||
result,
|
||||
Value::object(
|
||||
vec![
|
||||
(
|
||||
"first",
|
||||
Value::object(
|
||||
vec![("value", Value::scalar("First value"))]
|
||||
.into_iter()
|
||||
.collect(),
|
||||
),
|
||||
),
|
||||
("missing", Value::null()),
|
||||
]
|
||||
.into_iter()
|
||||
.collect()
|
||||
)
|
||||
graphql_value!({
|
||||
"first": {"value": "First value"},
|
||||
"missing": None,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -545,21 +533,7 @@ mod dynamic_context_switching {
|
|||
|
||||
println!("Result: {:#?}", result);
|
||||
|
||||
assert_eq!(
|
||||
result,
|
||||
Value::object(
|
||||
vec![(
|
||||
"first",
|
||||
Value::object(
|
||||
vec![("value", Value::scalar("First value"))]
|
||||
.into_iter()
|
||||
.collect(),
|
||||
),
|
||||
)]
|
||||
.into_iter()
|
||||
.collect()
|
||||
)
|
||||
);
|
||||
assert_eq!(result, graphql_value!({"first": {"value": "First value"}}));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
|
@ -603,13 +577,13 @@ mod dynamic_context_switching {
|
|||
vec![ExecutionError::new(
|
||||
SourcePosition::new(14, 1, 12),
|
||||
&["missing"],
|
||||
FieldError::new("Could not find key 2", Value::null()),
|
||||
FieldError::new("Could not find key 2", graphql_value!(None)),
|
||||
)]
|
||||
);
|
||||
|
||||
println!("Result: {:#?}", result);
|
||||
|
||||
assert_eq!(result, Value::null());
|
||||
assert_eq!(result, graphql_value!(None));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
|
@ -657,7 +631,7 @@ mod dynamic_context_switching {
|
|||
[ExecutionError::new(
|
||||
SourcePosition::new(123, 4, 12),
|
||||
&["tooLarge"],
|
||||
FieldError::new("Key too large: 200", Value::null()),
|
||||
FieldError::new("Key too large: 200", graphql_value!(None)),
|
||||
)]
|
||||
);
|
||||
|
||||
|
@ -665,22 +639,11 @@ mod dynamic_context_switching {
|
|||
|
||||
assert_eq!(
|
||||
result,
|
||||
Value::object(
|
||||
vec![
|
||||
(
|
||||
"first",
|
||||
Value::object(
|
||||
vec![("value", Value::scalar("First value"))]
|
||||
.into_iter()
|
||||
.collect(),
|
||||
),
|
||||
),
|
||||
("missing", Value::null()),
|
||||
("tooLarge", Value::null()),
|
||||
]
|
||||
.into_iter()
|
||||
.collect()
|
||||
)
|
||||
graphql_value!({
|
||||
"first": {"value": "First value"},
|
||||
"missing": None,
|
||||
"tooLarge": None,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -722,21 +685,7 @@ mod dynamic_context_switching {
|
|||
|
||||
println!("Result: {:#?}", result);
|
||||
|
||||
assert_eq!(
|
||||
result,
|
||||
Value::object(
|
||||
vec![(
|
||||
"first",
|
||||
Value::object(
|
||||
vec![("value", Value::scalar("First value"))]
|
||||
.into_iter()
|
||||
.collect(),
|
||||
),
|
||||
)]
|
||||
.into_iter()
|
||||
.collect()
|
||||
)
|
||||
);
|
||||
assert_eq!(result, graphql_value!({"first": {"value": "First value"}}));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -832,7 +781,7 @@ mod propagates_errors_to_nullable_fields {
|
|||
vec![ExecutionError::new(
|
||||
SourcePosition::new(10, 0, 10),
|
||||
&["inner", "nullableErrorField"],
|
||||
FieldError::new("Error for nullableErrorField", Value::null()),
|
||||
FieldError::new("Error for nullableErrorField", graphql_value!(None)),
|
||||
)]
|
||||
);
|
||||
}
|
||||
|
@ -861,7 +810,7 @@ mod propagates_errors_to_nullable_fields {
|
|||
vec![ExecutionError::new(
|
||||
SourcePosition::new(10, 0, 10),
|
||||
&["inner", "nonNullableErrorField"],
|
||||
FieldError::new("Error for nonNullableErrorField", Value::null()),
|
||||
FieldError::new("Error for nonNullableErrorField", graphql_value!(None)),
|
||||
)]
|
||||
);
|
||||
}
|
||||
|
@ -922,7 +871,7 @@ mod propagates_errors_to_nullable_fields {
|
|||
vec![ExecutionError::new(
|
||||
SourcePosition::new(26, 0, 26),
|
||||
&["inner", "nullableField", "nonNullableErrorField"],
|
||||
FieldError::new("Error for nonNullableErrorField", Value::null()),
|
||||
FieldError::new("Error for nonNullableErrorField", graphql_value!(None)),
|
||||
)]
|
||||
);
|
||||
}
|
||||
|
@ -951,7 +900,7 @@ mod propagates_errors_to_nullable_fields {
|
|||
vec![ExecutionError::new(
|
||||
SourcePosition::new(29, 0, 29),
|
||||
&["inner", "nonNullableField", "nonNullableErrorField"],
|
||||
FieldError::new("Error for nonNullableErrorField", Value::null()),
|
||||
FieldError::new("Error for nonNullableErrorField", graphql_value!(None)),
|
||||
)]
|
||||
);
|
||||
}
|
||||
|
@ -983,7 +932,7 @@ mod propagates_errors_to_nullable_fields {
|
|||
vec![ExecutionError::new(
|
||||
SourcePosition::new(29, 0, 29),
|
||||
&["inner", "nonNullableField", "nullableErrorField"],
|
||||
FieldError::new("Error for nullableErrorField", Value::null()),
|
||||
FieldError::new("Error for nullableErrorField", graphql_value!(None)),
|
||||
)]
|
||||
);
|
||||
}
|
||||
|
@ -1012,7 +961,7 @@ mod propagates_errors_to_nullable_fields {
|
|||
vec![ExecutionError::new(
|
||||
SourcePosition::new(11, 0, 11),
|
||||
&["inners", "nonNullableErrorField"],
|
||||
FieldError::new("Error for nonNullableErrorField", Value::null()),
|
||||
FieldError::new("Error for nonNullableErrorField", graphql_value!(None)),
|
||||
)]
|
||||
);
|
||||
}
|
||||
|
@ -1045,27 +994,27 @@ mod propagates_errors_to_nullable_fields {
|
|||
ExecutionError::new(
|
||||
SourcePosition::new(19, 0, 19),
|
||||
&["nullableInners", "nonNullableErrorField"],
|
||||
FieldError::new("Error for nonNullableErrorField", Value::null()),
|
||||
FieldError::new("Error for nonNullableErrorField", graphql_value!(None)),
|
||||
),
|
||||
ExecutionError::new(
|
||||
SourcePosition::new(19, 0, 19),
|
||||
&["nullableInners", "nonNullableErrorField"],
|
||||
FieldError::new("Error for nonNullableErrorField", Value::null()),
|
||||
FieldError::new("Error for nonNullableErrorField", graphql_value!(None)),
|
||||
),
|
||||
ExecutionError::new(
|
||||
SourcePosition::new(19, 0, 19),
|
||||
&["nullableInners", "nonNullableErrorField"],
|
||||
FieldError::new("Error for nonNullableErrorField", Value::null()),
|
||||
FieldError::new("Error for nonNullableErrorField", graphql_value!(None)),
|
||||
),
|
||||
ExecutionError::new(
|
||||
SourcePosition::new(19, 0, 19),
|
||||
&["nullableInners", "nonNullableErrorField"],
|
||||
FieldError::new("Error for nonNullableErrorField", Value::null()),
|
||||
FieldError::new("Error for nonNullableErrorField", graphql_value!(None)),
|
||||
),
|
||||
ExecutionError::new(
|
||||
SourcePosition::new(19, 0, 19),
|
||||
&["nullableInners", "nonNullableErrorField"],
|
||||
FieldError::new("Error for nonNullableErrorField", Value::null()),
|
||||
FieldError::new("Error for nonNullableErrorField", graphql_value!(None)),
|
||||
),
|
||||
]
|
||||
);
|
||||
|
|
|
@ -3,7 +3,6 @@ mod interface {
|
|||
graphql_interface, graphql_object,
|
||||
schema::model::RootNode,
|
||||
types::scalars::{EmptyMutation, EmptySubscription},
|
||||
value::Value,
|
||||
};
|
||||
|
||||
#[graphql_interface(for = [Cat, Dog])]
|
||||
|
@ -126,31 +125,15 @@ mod interface {
|
|||
|
||||
assert_eq!(
|
||||
result,
|
||||
Value::object(
|
||||
vec![(
|
||||
"pets",
|
||||
Value::list(vec![
|
||||
Value::object(
|
||||
vec![
|
||||
("name", Value::scalar("Odie")),
|
||||
("woofs", Value::scalar(true)),
|
||||
]
|
||||
.into_iter()
|
||||
.collect(),
|
||||
),
|
||||
Value::object(
|
||||
vec![
|
||||
("name", Value::scalar("Garfield")),
|
||||
("meows", Value::scalar(false)),
|
||||
]
|
||||
.into_iter()
|
||||
.collect(),
|
||||
),
|
||||
]),
|
||||
)]
|
||||
.into_iter()
|
||||
.collect()
|
||||
)
|
||||
graphql_value!({
|
||||
"pets": [{
|
||||
"name": "Odie",
|
||||
"woofs": true,
|
||||
}, {
|
||||
"name": "Garfield",
|
||||
"meows": false,
|
||||
}],
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -160,7 +143,6 @@ mod union {
|
|||
graphql_object, graphql_union,
|
||||
schema::model::RootNode,
|
||||
types::scalars::{EmptyMutation, EmptySubscription},
|
||||
value::Value,
|
||||
};
|
||||
|
||||
#[graphql_union]
|
||||
|
@ -271,33 +253,17 @@ mod union {
|
|||
|
||||
assert_eq!(
|
||||
result,
|
||||
Value::object(
|
||||
vec![(
|
||||
"pets",
|
||||
Value::list(vec![
|
||||
Value::object(
|
||||
vec![
|
||||
("__typename", Value::scalar("Dog")),
|
||||
("name", Value::scalar("Odie")),
|
||||
("woofs", Value::scalar(true)),
|
||||
]
|
||||
.into_iter()
|
||||
.collect(),
|
||||
),
|
||||
Value::object(
|
||||
vec![
|
||||
("__typename", Value::scalar("Cat")),
|
||||
("name", Value::scalar("Garfield")),
|
||||
("meows", Value::scalar(false)),
|
||||
]
|
||||
.into_iter()
|
||||
.collect(),
|
||||
),
|
||||
]),
|
||||
)]
|
||||
.into_iter()
|
||||
.collect()
|
||||
)
|
||||
graphql_value!({
|
||||
"pets": [{
|
||||
"__typename": "Dog",
|
||||
"name": "Odie",
|
||||
"woofs": true,
|
||||
}, {
|
||||
"__typename": "Cat",
|
||||
"name": "Garfield",
|
||||
"meows": false,
|
||||
}],
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
use crate::{
|
||||
executor::Variables,
|
||||
graphql_value,
|
||||
schema::model::RootNode,
|
||||
types::scalars::{EmptyMutation, EmptySubscription},
|
||||
value::{DefaultScalarValue, Object, Value},
|
||||
|
@ -142,36 +143,28 @@ async fn default_name_introspection() {
|
|||
run_type_info_query(doc, |(type_info, values)| {
|
||||
assert_eq!(
|
||||
type_info.get_field_value("name"),
|
||||
Some(&Value::scalar("DefaultName"))
|
||||
Some(&graphql_value!("DefaultName")),
|
||||
);
|
||||
assert_eq!(
|
||||
type_info.get_field_value("description"),
|
||||
Some(&Value::null())
|
||||
Some(&graphql_value!(None)),
|
||||
);
|
||||
|
||||
assert_eq!(values.len(), 2);
|
||||
|
||||
assert!(values.contains(&Value::object(
|
||||
vec![
|
||||
("name", Value::scalar("FOO")),
|
||||
("description", Value::null()),
|
||||
("isDeprecated", Value::scalar(false)),
|
||||
("deprecationReason", Value::null()),
|
||||
]
|
||||
.into_iter()
|
||||
.collect(),
|
||||
)));
|
||||
assert!(values.contains(&graphql_value!({
|
||||
"name": "FOO",
|
||||
"description": None,
|
||||
"isDeprecated": false,
|
||||
"deprecationReason": None,
|
||||
})));
|
||||
|
||||
assert!(values.contains(&Value::object(
|
||||
vec![
|
||||
("name", Value::scalar("BAR")),
|
||||
("description", Value::null()),
|
||||
("isDeprecated", Value::scalar(false)),
|
||||
("deprecationReason", Value::null()),
|
||||
]
|
||||
.into_iter()
|
||||
.collect(),
|
||||
)));
|
||||
assert!(values.contains(&graphql_value!({
|
||||
"name": "BAR",
|
||||
"description": None,
|
||||
"isDeprecated": false,
|
||||
"deprecationReason": None,
|
||||
})));
|
||||
})
|
||||
.await;
|
||||
}
|
||||
|
@ -196,36 +189,28 @@ async fn named_introspection() {
|
|||
run_type_info_query(doc, |(type_info, values)| {
|
||||
assert_eq!(
|
||||
type_info.get_field_value("name"),
|
||||
Some(&Value::scalar("ANamedEnum"))
|
||||
Some(&graphql_value!("ANamedEnum")),
|
||||
);
|
||||
assert_eq!(
|
||||
type_info.get_field_value("description"),
|
||||
Some(&Value::null())
|
||||
Some(&graphql_value!(None)),
|
||||
);
|
||||
|
||||
assert_eq!(values.len(), 2);
|
||||
|
||||
assert!(values.contains(&Value::object(
|
||||
vec![
|
||||
("name", Value::scalar("FOO")),
|
||||
("description", Value::null()),
|
||||
("isDeprecated", Value::scalar(false)),
|
||||
("deprecationReason", Value::null()),
|
||||
]
|
||||
.into_iter()
|
||||
.collect(),
|
||||
)));
|
||||
assert!(values.contains(&graphql_value!({
|
||||
"name": "FOO",
|
||||
"description": None,
|
||||
"isDeprecated": false,
|
||||
"deprecationReason": None,
|
||||
})));
|
||||
|
||||
assert!(values.contains(&Value::object(
|
||||
vec![
|
||||
("name", Value::scalar("BAR")),
|
||||
("description", Value::null()),
|
||||
("isDeprecated", Value::scalar(false)),
|
||||
("deprecationReason", Value::null()),
|
||||
]
|
||||
.into_iter()
|
||||
.collect(),
|
||||
)));
|
||||
assert!(values.contains(&graphql_value!({
|
||||
"name": "BAR",
|
||||
"description": None,
|
||||
"isDeprecated": false,
|
||||
"deprecationReason": None,
|
||||
})));
|
||||
})
|
||||
.await;
|
||||
}
|
||||
|
@ -250,36 +235,28 @@ async fn no_trailing_comma_introspection() {
|
|||
run_type_info_query(doc, |(type_info, values)| {
|
||||
assert_eq!(
|
||||
type_info.get_field_value("name"),
|
||||
Some(&Value::scalar("NoTrailingComma"))
|
||||
Some(&graphql_value!("NoTrailingComma")),
|
||||
);
|
||||
assert_eq!(
|
||||
type_info.get_field_value("description"),
|
||||
Some(&Value::null())
|
||||
Some(&graphql_value!(None)),
|
||||
);
|
||||
|
||||
assert_eq!(values.len(), 2);
|
||||
|
||||
assert!(values.contains(&Value::object(
|
||||
vec![
|
||||
("name", Value::scalar("FOO")),
|
||||
("description", Value::null()),
|
||||
("isDeprecated", Value::scalar(false)),
|
||||
("deprecationReason", Value::null()),
|
||||
]
|
||||
.into_iter()
|
||||
.collect(),
|
||||
)));
|
||||
assert!(values.contains(&graphql_value!({
|
||||
"name": "FOO",
|
||||
"description": None,
|
||||
"isDeprecated": false,
|
||||
"deprecationReason": None,
|
||||
})));
|
||||
|
||||
assert!(values.contains(&Value::object(
|
||||
vec![
|
||||
("name", Value::scalar("BAR")),
|
||||
("description", Value::null()),
|
||||
("isDeprecated", Value::scalar(false)),
|
||||
("deprecationReason", Value::null()),
|
||||
]
|
||||
.into_iter()
|
||||
.collect(),
|
||||
)));
|
||||
assert!(values.contains(&graphql_value!({
|
||||
"name": "BAR",
|
||||
"description": None,
|
||||
"isDeprecated": false,
|
||||
"deprecationReason": None,
|
||||
})));
|
||||
})
|
||||
.await;
|
||||
}
|
||||
|
@ -304,36 +281,28 @@ async fn enum_description_introspection() {
|
|||
run_type_info_query(doc, |(type_info, values)| {
|
||||
assert_eq!(
|
||||
type_info.get_field_value("name"),
|
||||
Some(&Value::scalar("EnumDescription"))
|
||||
Some(&graphql_value!("EnumDescription")),
|
||||
);
|
||||
assert_eq!(
|
||||
type_info.get_field_value("description"),
|
||||
Some(&Value::scalar("A description of the enum itself"))
|
||||
Some(&graphql_value!("A description of the enum itself")),
|
||||
);
|
||||
|
||||
assert_eq!(values.len(), 2);
|
||||
|
||||
assert!(values.contains(&Value::object(
|
||||
vec![
|
||||
("name", Value::scalar("FOO")),
|
||||
("description", Value::null()),
|
||||
("isDeprecated", Value::scalar(false)),
|
||||
("deprecationReason", Value::null()),
|
||||
]
|
||||
.into_iter()
|
||||
.collect(),
|
||||
)));
|
||||
assert!(values.contains(&graphql_value!({
|
||||
"name": "FOO",
|
||||
"description": None,
|
||||
"isDeprecated": false,
|
||||
"deprecationReason": None,
|
||||
})));
|
||||
|
||||
assert!(values.contains(&Value::object(
|
||||
vec![
|
||||
("name", Value::scalar("BAR")),
|
||||
("description", Value::null()),
|
||||
("isDeprecated", Value::scalar(false)),
|
||||
("deprecationReason", Value::null()),
|
||||
]
|
||||
.into_iter()
|
||||
.collect(),
|
||||
)));
|
||||
assert!(values.contains(&graphql_value!({
|
||||
"name": "BAR",
|
||||
"description": None,
|
||||
"isDeprecated": false,
|
||||
"deprecationReason": None,
|
||||
})));
|
||||
})
|
||||
.await;
|
||||
}
|
||||
|
@ -358,36 +327,28 @@ async fn enum_value_description_introspection() {
|
|||
run_type_info_query(doc, |(type_info, values)| {
|
||||
assert_eq!(
|
||||
type_info.get_field_value("name"),
|
||||
Some(&Value::scalar("EnumValueDescription"))
|
||||
Some(&graphql_value!("EnumValueDescription")),
|
||||
);
|
||||
assert_eq!(
|
||||
type_info.get_field_value("description"),
|
||||
Some(&Value::null())
|
||||
Some(&graphql_value!(None)),
|
||||
);
|
||||
|
||||
assert_eq!(values.len(), 2);
|
||||
|
||||
assert!(values.contains(&Value::object(
|
||||
vec![
|
||||
("name", Value::scalar("FOO")),
|
||||
("description", Value::scalar("The FOO value")),
|
||||
("isDeprecated", Value::scalar(false)),
|
||||
("deprecationReason", Value::null()),
|
||||
]
|
||||
.into_iter()
|
||||
.collect(),
|
||||
)));
|
||||
assert!(values.contains(&graphql_value!({
|
||||
"name": "FOO",
|
||||
"description": "The FOO value",
|
||||
"isDeprecated": false,
|
||||
"deprecationReason": None,
|
||||
})));
|
||||
|
||||
assert!(values.contains(&Value::object(
|
||||
vec![
|
||||
("name", Value::scalar("BAR")),
|
||||
("description", Value::scalar("The BAR value")),
|
||||
("isDeprecated", Value::scalar(false)),
|
||||
("deprecationReason", Value::null()),
|
||||
]
|
||||
.into_iter()
|
||||
.collect(),
|
||||
)));
|
||||
assert!(values.contains(&graphql_value!({
|
||||
"name": "BAR",
|
||||
"description": "The BAR value",
|
||||
"isDeprecated": false,
|
||||
"deprecationReason": None,
|
||||
})));
|
||||
})
|
||||
.await;
|
||||
}
|
||||
|
@ -412,42 +373,28 @@ async fn enum_deprecation_introspection() {
|
|||
run_type_info_query(doc, |(type_info, values)| {
|
||||
assert_eq!(
|
||||
type_info.get_field_value("name"),
|
||||
Some(&Value::scalar("EnumDeprecation"))
|
||||
Some(&graphql_value!("EnumDeprecation")),
|
||||
);
|
||||
assert_eq!(
|
||||
type_info.get_field_value("description"),
|
||||
Some(&Value::null())
|
||||
Some(&graphql_value!(None)),
|
||||
);
|
||||
|
||||
assert_eq!(values.len(), 2);
|
||||
|
||||
assert!(values.contains(&Value::object(
|
||||
vec![
|
||||
("name", Value::scalar("FOO")),
|
||||
("description", Value::null()),
|
||||
("isDeprecated", Value::scalar(true)),
|
||||
(
|
||||
"deprecationReason",
|
||||
Value::scalar("Please don't use FOO any more"),
|
||||
),
|
||||
]
|
||||
.into_iter()
|
||||
.collect(),
|
||||
)));
|
||||
assert!(values.contains(&graphql_value!({
|
||||
"name": "FOO",
|
||||
"description": None,
|
||||
"isDeprecated": true,
|
||||
"deprecationReason": "Please don't use FOO any more",
|
||||
})));
|
||||
|
||||
assert!(values.contains(&Value::object(
|
||||
vec![
|
||||
("name", Value::scalar("BAR")),
|
||||
("description", Value::scalar("The BAR value")),
|
||||
("isDeprecated", Value::scalar(true)),
|
||||
(
|
||||
"deprecationReason",
|
||||
Value::scalar("Please don't use BAR any more"),
|
||||
),
|
||||
]
|
||||
.into_iter()
|
||||
.collect(),
|
||||
)));
|
||||
assert!(values.contains(&graphql_value!({
|
||||
"name": "BAR",
|
||||
"description": "The BAR value",
|
||||
"isDeprecated": true,
|
||||
"deprecationReason": "Please don't use BAR any more",
|
||||
})));
|
||||
})
|
||||
.await;
|
||||
}
|
||||
|
@ -472,11 +419,11 @@ async fn enum_deprecation_no_values_introspection() {
|
|||
run_type_info_query(doc, |(type_info, values)| {
|
||||
assert_eq!(
|
||||
type_info.get_field_value("name"),
|
||||
Some(&Value::scalar("EnumDeprecation"))
|
||||
Some(&graphql_value!("EnumDeprecation")),
|
||||
);
|
||||
assert_eq!(
|
||||
type_info.get_field_value("description"),
|
||||
Some(&Value::null())
|
||||
Some(&graphql_value!(None)),
|
||||
);
|
||||
|
||||
assert_eq!(values.len(), 0);
|
||||
|
|
|
@ -7,7 +7,7 @@ use self::input_object::{NamedPublic, NamedPublicWithDescription};
|
|||
|
||||
use crate::{
|
||||
executor::Variables,
|
||||
graphql_interface, graphql_object, graphql_scalar,
|
||||
graphql_interface, graphql_object, graphql_scalar, graphql_value,
|
||||
schema::model::RootNode,
|
||||
types::scalars::{EmptyMutation, EmptySubscription},
|
||||
value::{ParseScalarResult, ParseScalarValue, ScalarValue, Value},
|
||||
|
@ -93,15 +93,11 @@ async fn test_execution() {
|
|||
|
||||
assert_eq!(
|
||||
result,
|
||||
Value::object(
|
||||
vec![
|
||||
("sampleEnum", Value::scalar("ONE")),
|
||||
("first", Value::scalar(123)),
|
||||
("second", Value::scalar(30)),
|
||||
]
|
||||
.into_iter()
|
||||
.collect()
|
||||
)
|
||||
graphql_value!({
|
||||
"sampleEnum": "ONE",
|
||||
"first": 123,
|
||||
"second": 30,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -150,29 +146,32 @@ async fn enum_introspection() {
|
|||
|
||||
assert_eq!(
|
||||
type_info.get_field_value("name"),
|
||||
Some(&Value::scalar("SampleEnum"))
|
||||
Some(&graphql_value!("SampleEnum")),
|
||||
);
|
||||
assert_eq!(
|
||||
type_info.get_field_value("kind"),
|
||||
Some(&Value::scalar("ENUM"))
|
||||
Some(&graphql_value!("ENUM")),
|
||||
);
|
||||
assert_eq!(
|
||||
type_info.get_field_value("description"),
|
||||
Some(&Value::null())
|
||||
Some(&graphql_value!(None)),
|
||||
);
|
||||
assert_eq!(
|
||||
type_info.get_field_value("interfaces"),
|
||||
Some(&Value::null())
|
||||
Some(&graphql_value!(None)),
|
||||
);
|
||||
assert_eq!(
|
||||
type_info.get_field_value("possibleTypes"),
|
||||
Some(&Value::null())
|
||||
Some(&graphql_value!(None)),
|
||||
);
|
||||
assert_eq!(
|
||||
type_info.get_field_value("inputFields"),
|
||||
Some(&Value::null())
|
||||
Some(&graphql_value!(None)),
|
||||
);
|
||||
assert_eq!(
|
||||
type_info.get_field_value("ofType"),
|
||||
Some(&graphql_value!(None))
|
||||
);
|
||||
assert_eq!(type_info.get_field_value("ofType"), Some(&Value::null()));
|
||||
|
||||
let values = type_info
|
||||
.get_field_value("enumValues")
|
||||
|
@ -182,27 +181,19 @@ async fn enum_introspection() {
|
|||
|
||||
assert_eq!(values.len(), 2);
|
||||
|
||||
assert!(values.contains(&Value::object(
|
||||
vec![
|
||||
("name", Value::scalar("ONE")),
|
||||
("description", Value::null()),
|
||||
("isDeprecated", Value::scalar(false)),
|
||||
("deprecationReason", Value::null()),
|
||||
]
|
||||
.into_iter()
|
||||
.collect(),
|
||||
)));
|
||||
assert!(values.contains(&graphql_value!({
|
||||
"name": "ONE",
|
||||
"description": None,
|
||||
"isDeprecated": false,
|
||||
"deprecationReason": None,
|
||||
})));
|
||||
|
||||
assert!(values.contains(&Value::object(
|
||||
vec![
|
||||
("name", Value::scalar("TWO")),
|
||||
("description", Value::null()),
|
||||
("isDeprecated", Value::scalar(false)),
|
||||
("deprecationReason", Value::null()),
|
||||
]
|
||||
.into_iter()
|
||||
.collect(),
|
||||
)));
|
||||
assert!(values.contains(&graphql_value!({
|
||||
"name": "TWO",
|
||||
"description": None,
|
||||
"isDeprecated": false,
|
||||
"deprecationReason": None,
|
||||
})));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
|
@ -264,29 +255,32 @@ async fn interface_introspection() {
|
|||
|
||||
assert_eq!(
|
||||
type_info.get_field_value("name"),
|
||||
Some(&Value::scalar("SampleInterface"))
|
||||
Some(&graphql_value!("SampleInterface")),
|
||||
);
|
||||
assert_eq!(
|
||||
type_info.get_field_value("kind"),
|
||||
Some(&Value::scalar("INTERFACE"))
|
||||
Some(&graphql_value!("INTERFACE")),
|
||||
);
|
||||
assert_eq!(
|
||||
type_info.get_field_value("description"),
|
||||
Some(&Value::scalar("A sample interface"))
|
||||
Some(&graphql_value!("A sample interface")),
|
||||
);
|
||||
assert_eq!(
|
||||
type_info.get_field_value("interfaces"),
|
||||
Some(&Value::null())
|
||||
Some(&graphql_value!(None)),
|
||||
);
|
||||
assert_eq!(
|
||||
type_info.get_field_value("enumValues"),
|
||||
Some(&Value::null())
|
||||
Some(&graphql_value!(None)),
|
||||
);
|
||||
assert_eq!(
|
||||
type_info.get_field_value("inputFields"),
|
||||
Some(&Value::null())
|
||||
Some(&graphql_value!(None)),
|
||||
);
|
||||
assert_eq!(
|
||||
type_info.get_field_value("ofType"),
|
||||
Some(&graphql_value!(None))
|
||||
);
|
||||
assert_eq!(type_info.get_field_value("ofType"), Some(&Value::null()));
|
||||
|
||||
let possible_types = type_info
|
||||
.get_field_value("possibleTypes")
|
||||
|
@ -296,9 +290,7 @@ async fn interface_introspection() {
|
|||
|
||||
assert_eq!(possible_types.len(), 1);
|
||||
|
||||
assert!(possible_types.contains(&Value::object(
|
||||
vec![("name", Value::scalar("Root"))].into_iter().collect()
|
||||
)));
|
||||
assert!(possible_types.contains(&graphql_value!({"name": "Root"})));
|
||||
|
||||
let fields = type_info
|
||||
.get_field_value("fields")
|
||||
|
@ -308,42 +300,21 @@ async fn interface_introspection() {
|
|||
|
||||
assert_eq!(fields.len(), 1);
|
||||
|
||||
assert!(fields.contains(&Value::object(
|
||||
vec![
|
||||
("name", Value::scalar("sampleEnum")),
|
||||
(
|
||||
"description",
|
||||
Value::scalar("A sample field in the interface"),
|
||||
),
|
||||
("args", Value::list(vec![])),
|
||||
(
|
||||
"type",
|
||||
Value::object(
|
||||
vec![
|
||||
("name", Value::null()),
|
||||
("kind", Value::scalar("NON_NULL")),
|
||||
(
|
||||
"ofType",
|
||||
Value::object(
|
||||
vec![
|
||||
("name", Value::scalar("SampleEnum")),
|
||||
("kind", Value::scalar("ENUM")),
|
||||
]
|
||||
.into_iter()
|
||||
.collect(),
|
||||
),
|
||||
),
|
||||
]
|
||||
.into_iter()
|
||||
.collect(),
|
||||
),
|
||||
),
|
||||
("isDeprecated", Value::scalar(false)),
|
||||
("deprecationReason", Value::null()),
|
||||
]
|
||||
.into_iter()
|
||||
.collect(),
|
||||
)));
|
||||
assert!(fields.contains(&graphql_value!({
|
||||
"name": "sampleEnum",
|
||||
"description": "A sample field in the interface",
|
||||
"args": [],
|
||||
"type": {
|
||||
"name": None,
|
||||
"kind": "NON_NULL",
|
||||
"ofType": {
|
||||
"name": "SampleEnum",
|
||||
"kind": "ENUM",
|
||||
},
|
||||
},
|
||||
"isDeprecated": false,
|
||||
"deprecationReason": None,
|
||||
})));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
|
@ -416,36 +387,35 @@ async fn object_introspection() {
|
|||
|
||||
assert_eq!(
|
||||
type_info.get_field_value("name"),
|
||||
Some(&Value::scalar("Root"))
|
||||
Some(&graphql_value!("Root")),
|
||||
);
|
||||
assert_eq!(
|
||||
type_info.get_field_value("kind"),
|
||||
Some(&Value::scalar("OBJECT"))
|
||||
Some(&graphql_value!("OBJECT")),
|
||||
);
|
||||
assert_eq!(
|
||||
type_info.get_field_value("description"),
|
||||
Some(&Value::scalar("The root query object in the schema"))
|
||||
Some(&graphql_value!("The root query object in the schema")),
|
||||
);
|
||||
assert_eq!(
|
||||
type_info.get_field_value("interfaces"),
|
||||
Some(&Value::list(vec![Value::object(
|
||||
vec![("name", Value::scalar("SampleInterface"))]
|
||||
.into_iter()
|
||||
.collect(),
|
||||
)]))
|
||||
Some(&graphql_value!([{"name": "SampleInterface"}])),
|
||||
);
|
||||
assert_eq!(
|
||||
type_info.get_field_value("enumValues"),
|
||||
Some(&Value::null())
|
||||
Some(&graphql_value!(None)),
|
||||
);
|
||||
assert_eq!(
|
||||
type_info.get_field_value("inputFields"),
|
||||
Some(&Value::null())
|
||||
Some(&graphql_value!(None)),
|
||||
);
|
||||
assert_eq!(
|
||||
type_info.get_field_value("ofType"),
|
||||
Some(&graphql_value!(None))
|
||||
);
|
||||
assert_eq!(type_info.get_field_value("ofType"), Some(&Value::null()));
|
||||
assert_eq!(
|
||||
type_info.get_field_value("possibleTypes"),
|
||||
Some(&Value::null())
|
||||
Some(&graphql_value!(None)),
|
||||
);
|
||||
|
||||
let fields = type_info
|
||||
|
@ -458,133 +428,59 @@ async fn object_introspection() {
|
|||
|
||||
println!("Fields: {:#?}", fields);
|
||||
|
||||
assert!(fields.contains(&Value::object(
|
||||
vec![
|
||||
("name", Value::scalar("sampleEnum")),
|
||||
("description", Value::null()),
|
||||
("args", Value::list(vec![])),
|
||||
(
|
||||
"type",
|
||||
Value::object(
|
||||
vec![
|
||||
("name", Value::null()),
|
||||
("kind", Value::scalar("NON_NULL")),
|
||||
(
|
||||
"ofType",
|
||||
Value::object(
|
||||
vec![
|
||||
("name", Value::scalar("SampleEnum")),
|
||||
("kind", Value::scalar("ENUM")),
|
||||
]
|
||||
.into_iter()
|
||||
.collect(),
|
||||
),
|
||||
),
|
||||
]
|
||||
.into_iter()
|
||||
.collect(),
|
||||
),
|
||||
),
|
||||
("isDeprecated", Value::scalar(false)),
|
||||
("deprecationReason", Value::null()),
|
||||
]
|
||||
.into_iter()
|
||||
.collect(),
|
||||
)));
|
||||
assert!(fields.contains(&graphql_value!({
|
||||
"name": "sampleEnum",
|
||||
"description": None,
|
||||
"args": [],
|
||||
"type": {
|
||||
"name": None,
|
||||
"kind": "NON_NULL",
|
||||
"ofType": {
|
||||
"name": "SampleEnum",
|
||||
"kind": "ENUM",
|
||||
},
|
||||
},
|
||||
"isDeprecated": false,
|
||||
"deprecationReason": None,
|
||||
})));
|
||||
|
||||
assert!(fields.contains(&Value::object(
|
||||
vec![
|
||||
("name", Value::scalar("sampleScalar")),
|
||||
(
|
||||
"description",
|
||||
Value::scalar("A sample scalar field on the object"),
|
||||
),
|
||||
(
|
||||
"args",
|
||||
Value::list(vec![
|
||||
Value::object(
|
||||
vec![
|
||||
("name", Value::scalar("first")),
|
||||
("description", Value::scalar("The first number")),
|
||||
(
|
||||
"type",
|
||||
Value::object(
|
||||
vec![
|
||||
("name", Value::null()),
|
||||
("kind", Value::scalar("NON_NULL")),
|
||||
(
|
||||
"ofType",
|
||||
Value::object(
|
||||
vec![
|
||||
("name", Value::scalar("Int")),
|
||||
("kind", Value::scalar("SCALAR")),
|
||||
("ofType", Value::null()),
|
||||
]
|
||||
.into_iter()
|
||||
.collect(),
|
||||
),
|
||||
),
|
||||
]
|
||||
.into_iter()
|
||||
.collect(),
|
||||
),
|
||||
),
|
||||
("defaultValue", Value::null()),
|
||||
]
|
||||
.into_iter()
|
||||
.collect(),
|
||||
),
|
||||
Value::object(
|
||||
vec![
|
||||
("name", Value::scalar("second")),
|
||||
("description", Value::scalar("The second number")),
|
||||
(
|
||||
"type",
|
||||
Value::object(
|
||||
vec![
|
||||
("name", Value::scalar("Int")),
|
||||
("kind", Value::scalar("SCALAR")),
|
||||
("ofType", Value::null()),
|
||||
]
|
||||
.into_iter()
|
||||
.collect(),
|
||||
),
|
||||
),
|
||||
("defaultValue", Value::scalar("123")),
|
||||
]
|
||||
.into_iter()
|
||||
.collect(),
|
||||
),
|
||||
]),
|
||||
),
|
||||
(
|
||||
"type",
|
||||
Value::object(
|
||||
vec![
|
||||
("name", Value::null()),
|
||||
("kind", Value::scalar("NON_NULL")),
|
||||
(
|
||||
"ofType",
|
||||
Value::object(
|
||||
vec![
|
||||
("name", Value::scalar("SampleScalar")),
|
||||
("kind", Value::scalar("SCALAR")),
|
||||
]
|
||||
.into_iter()
|
||||
.collect(),
|
||||
),
|
||||
),
|
||||
]
|
||||
.into_iter()
|
||||
.collect(),
|
||||
),
|
||||
),
|
||||
("isDeprecated", Value::scalar(false)),
|
||||
("deprecationReason", Value::null()),
|
||||
]
|
||||
.into_iter()
|
||||
.collect(),
|
||||
)));
|
||||
assert!(fields.contains(&graphql_value!({
|
||||
"name": "sampleScalar",
|
||||
"description": "A sample scalar field on the object",
|
||||
"args": [{
|
||||
"name": "first",
|
||||
"description": "The first number",
|
||||
"type": {
|
||||
"name": None,
|
||||
"kind": "NON_NULL",
|
||||
"ofType": {
|
||||
"name": "Int",
|
||||
"kind": "SCALAR",
|
||||
"ofType": None,
|
||||
},
|
||||
},
|
||||
"defaultValue": None,
|
||||
}, {
|
||||
"name": "second",
|
||||
"description": "The second number",
|
||||
"type": {
|
||||
"name": "Int",
|
||||
"kind": "SCALAR",
|
||||
"ofType": None,
|
||||
},
|
||||
"defaultValue": "123",
|
||||
}],
|
||||
"type": {
|
||||
"name": None,
|
||||
"kind": "NON_NULL",
|
||||
"ofType": {
|
||||
"name": "SampleScalar",
|
||||
"kind": "SCALAR",
|
||||
},
|
||||
},
|
||||
"isDeprecated": false,
|
||||
"deprecationReason": None,
|
||||
})));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
|
@ -626,20 +522,16 @@ async fn scalar_introspection() {
|
|||
|
||||
assert_eq!(
|
||||
type_info,
|
||||
&Value::object(
|
||||
vec![
|
||||
("name", Value::scalar("SampleScalar")),
|
||||
("kind", Value::scalar("SCALAR")),
|
||||
("description", Value::null()),
|
||||
("fields", Value::null()),
|
||||
("interfaces", Value::null()),
|
||||
("possibleTypes", Value::null()),
|
||||
("enumValues", Value::null()),
|
||||
("inputFields", Value::null()),
|
||||
("ofType", Value::null()),
|
||||
]
|
||||
.into_iter()
|
||||
.collect()
|
||||
)
|
||||
&graphql_value!({
|
||||
"name": "SampleScalar",
|
||||
"kind": "SCALAR",
|
||||
"description": None,
|
||||
"fields": None,
|
||||
"interfaces": None,
|
||||
"possibleTypes": None,
|
||||
"enumValues": None,
|
||||
"inputFields": None,
|
||||
"ofType": None,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
use crate::{
|
||||
ast::InputValue,
|
||||
executor::Variables,
|
||||
graphql_object, graphql_scalar,
|
||||
graphql_object, graphql_scalar, graphql_value,
|
||||
parser::SourcePosition,
|
||||
schema::model::RootNode,
|
||||
types::scalars::{EmptyMutation, EmptySubscription},
|
||||
validation::RuleError,
|
||||
value::{DefaultScalarValue, Object, ParseScalarResult, ParseScalarValue, ScalarValue, Value},
|
||||
value::{DefaultScalarValue, Object, ParseScalarResult, ParseScalarValue, ScalarValue},
|
||||
GraphQLError::ValidationError,
|
||||
GraphQLInputObject,
|
||||
};
|
||||
|
@ -17,7 +17,7 @@ struct TestComplexScalar;
|
|||
#[graphql_scalar]
|
||||
impl<S: ScalarValue> GraphQLScalar for TestComplexScalar {
|
||||
fn resolve(&self) -> Value {
|
||||
Value::scalar(String::from("SerializedValue"))
|
||||
graphql_value!("SerializedValue")
|
||||
}
|
||||
|
||||
fn from_input_value(v: &InputValue) -> Option<TestComplexScalar> {
|
||||
|
@ -157,7 +157,7 @@ async fn inline_complex_input() {
|
|||
|result: &Object<DefaultScalarValue>| {
|
||||
assert_eq!(
|
||||
result.get_field_value("fieldWithObjectInput"),
|
||||
Some(&Value::scalar(
|
||||
Some(&graphql_value!(
|
||||
r#"Some(TestInputObject { a: Some("foo"), b: Some([Some("bar")]), c: "baz", d: None })"#
|
||||
))
|
||||
);
|
||||
|
@ -172,7 +172,7 @@ async fn inline_parse_single_value_to_list() {
|
|||
|result: &Object<DefaultScalarValue>| {
|
||||
assert_eq!(
|
||||
result.get_field_value("fieldWithObjectInput"),
|
||||
Some(&Value::scalar(
|
||||
Some(&graphql_value!(
|
||||
r#"Some(TestInputObject { a: Some("foo"), b: Some([Some("bar")]), c: "baz", d: None })"#
|
||||
))
|
||||
);
|
||||
|
@ -187,7 +187,7 @@ async fn inline_runs_from_input_value_on_scalar() {
|
|||
|result: &Object<DefaultScalarValue>| {
|
||||
assert_eq!(
|
||||
result.get_field_value("fieldWithObjectInput"),
|
||||
Some(&Value::scalar(
|
||||
Some(&graphql_value!(
|
||||
r#"Some(TestInputObject { a: None, b: None, c: "baz", d: Some(TestComplexScalar) })"#
|
||||
))
|
||||
);
|
||||
|
@ -216,7 +216,7 @@ async fn variable_complex_input() {
|
|||
|result: &Object<DefaultScalarValue>| {
|
||||
assert_eq!(
|
||||
result.get_field_value("fieldWithObjectInput"),
|
||||
Some(&Value::scalar(
|
||||
Some(&graphql_value!(
|
||||
r#"Some(TestInputObject { a: Some("foo"), b: Some([Some("bar")]), c: "baz", d: None })"#
|
||||
))
|
||||
);
|
||||
|
@ -245,7 +245,7 @@ async fn variable_parse_single_value_to_list() {
|
|||
|result: &Object<DefaultScalarValue>| {
|
||||
assert_eq!(
|
||||
result.get_field_value("fieldWithObjectInput"),
|
||||
Some(&Value::scalar(
|
||||
Some(&graphql_value!(
|
||||
r#"Some(TestInputObject { a: Some("foo"), b: Some([Some("bar")]), c: "baz", d: None })"#
|
||||
))
|
||||
);
|
||||
|
@ -273,7 +273,7 @@ async fn variable_runs_from_input_value_on_scalar() {
|
|||
|result: &Object<DefaultScalarValue>| {
|
||||
assert_eq!(
|
||||
result.get_field_value("fieldWithObjectInput"),
|
||||
Some(&Value::scalar(
|
||||
Some(&graphql_value!(
|
||||
r#"Some(TestInputObject { a: None, b: None, c: "baz", d: Some(TestComplexScalar) })"#
|
||||
))
|
||||
);
|
||||
|
@ -468,7 +468,7 @@ async fn allow_nullable_inputs_to_be_omitted() {
|
|||
|result: &Object<DefaultScalarValue>| {
|
||||
assert_eq!(
|
||||
result.get_field_value("fieldWithNullableStringInput"),
|
||||
Some(&Value::scalar(r#"None"#))
|
||||
Some(&graphql_value!(r#"None"#))
|
||||
);
|
||||
},
|
||||
)
|
||||
|
@ -482,7 +482,7 @@ async fn allow_nullable_inputs_to_be_omitted_in_variable() {
|
|||
|result: &Object<DefaultScalarValue>| {
|
||||
assert_eq!(
|
||||
result.get_field_value("fieldWithNullableStringInput"),
|
||||
Some(&Value::scalar(r#"None"#))
|
||||
Some(&graphql_value!(r#"None"#))
|
||||
);
|
||||
},
|
||||
)
|
||||
|
@ -496,7 +496,7 @@ async fn allow_nullable_inputs_to_be_explicitly_null() {
|
|||
|result: &Object<DefaultScalarValue>| {
|
||||
assert_eq!(
|
||||
result.get_field_value("fieldWithNullableStringInput"),
|
||||
Some(&Value::scalar(r#"None"#))
|
||||
Some(&graphql_value!(r#"None"#))
|
||||
);
|
||||
},
|
||||
)
|
||||
|
@ -513,7 +513,7 @@ async fn allow_nullable_inputs_to_be_set_to_null_in_variable() {
|
|||
|result: &Object<DefaultScalarValue>| {
|
||||
assert_eq!(
|
||||
result.get_field_value("fieldWithNullableStringInput"),
|
||||
Some(&Value::scalar(r#"None"#))
|
||||
Some(&graphql_value!(r#"None"#))
|
||||
);
|
||||
},
|
||||
)
|
||||
|
@ -530,7 +530,7 @@ async fn allow_nullable_inputs_to_be_set_to_value_in_variable() {
|
|||
|result: &Object<DefaultScalarValue>| {
|
||||
assert_eq!(
|
||||
result.get_field_value("fieldWithNullableStringInput"),
|
||||
Some(&Value::scalar(r#"Some("a")"#))
|
||||
Some(&graphql_value!(r#"Some("a")"#))
|
||||
);
|
||||
},
|
||||
)
|
||||
|
@ -544,7 +544,7 @@ async fn allow_nullable_inputs_to_be_set_to_value_directly() {
|
|||
|result: &Object<DefaultScalarValue>| {
|
||||
assert_eq!(
|
||||
result.get_field_value("fieldWithNullableStringInput"),
|
||||
Some(&Value::scalar(r#"Some("a")"#))
|
||||
Some(&graphql_value!(r#"Some("a")"#))
|
||||
);
|
||||
},
|
||||
)
|
||||
|
@ -611,7 +611,7 @@ async fn allow_non_nullable_inputs_to_be_set_to_value_in_variable() {
|
|||
|result| {
|
||||
assert_eq!(
|
||||
result.get_field_value("fieldWithNonNullableStringInput"),
|
||||
Some(&Value::scalar(r#""a""#))
|
||||
Some(&graphql_value!(r#""a""#))
|
||||
);
|
||||
},
|
||||
)
|
||||
|
@ -625,7 +625,7 @@ async fn allow_non_nullable_inputs_to_be_set_to_value_directly() {
|
|||
|result: &Object<DefaultScalarValue>| {
|
||||
assert_eq!(
|
||||
result.get_field_value("fieldWithNonNullableStringInput"),
|
||||
Some(&Value::scalar(r#""a""#))
|
||||
Some(&graphql_value!(r#""a""#))
|
||||
);
|
||||
},
|
||||
)
|
||||
|
@ -642,7 +642,7 @@ async fn allow_lists_to_be_null() {
|
|||
|result: &Object<DefaultScalarValue>| {
|
||||
assert_eq!(
|
||||
result.get_field_value("list"),
|
||||
Some(&Value::scalar(r#"None"#))
|
||||
Some(&graphql_value!(r#"None"#))
|
||||
);
|
||||
},
|
||||
)
|
||||
|
@ -662,7 +662,7 @@ async fn allow_lists_to_contain_values() {
|
|||
|result| {
|
||||
assert_eq!(
|
||||
result.get_field_value("list"),
|
||||
Some(&Value::scalar(r#"Some([Some("A")])"#))
|
||||
Some(&graphql_value!(r#"Some([Some("A")])"#))
|
||||
);
|
||||
},
|
||||
)
|
||||
|
@ -686,7 +686,7 @@ async fn allow_lists_to_contain_null() {
|
|||
|result| {
|
||||
assert_eq!(
|
||||
result.get_field_value("list"),
|
||||
Some(&Value::scalar(r#"Some([Some("A"), None, Some("B")])"#))
|
||||
Some(&graphql_value!(r#"Some([Some("A"), None, Some("B")])"#))
|
||||
);
|
||||
},
|
||||
)
|
||||
|
@ -732,7 +732,7 @@ async fn allow_non_null_lists_to_contain_values() {
|
|||
|result| {
|
||||
assert_eq!(
|
||||
result.get_field_value("nnList"),
|
||||
Some(&Value::scalar(r#"[Some("A")]"#))
|
||||
Some(&graphql_value!(r#"[Some("A")]"#))
|
||||
);
|
||||
},
|
||||
)
|
||||
|
@ -755,7 +755,7 @@ async fn allow_non_null_lists_to_contain_null() {
|
|||
|result| {
|
||||
assert_eq!(
|
||||
result.get_field_value("nnList"),
|
||||
Some(&Value::scalar(r#"[Some("A"), None, Some("B")]"#))
|
||||
Some(&graphql_value!(r#"[Some("A"), None, Some("B")]"#))
|
||||
);
|
||||
},
|
||||
)
|
||||
|
@ -772,7 +772,7 @@ async fn allow_lists_of_non_null_to_be_null() {
|
|||
|result| {
|
||||
assert_eq!(
|
||||
result.get_field_value("listNn"),
|
||||
Some(&Value::scalar(r#"None"#))
|
||||
Some(&graphql_value!(r#"None"#)),
|
||||
);
|
||||
},
|
||||
)
|
||||
|
@ -792,7 +792,7 @@ async fn allow_lists_of_non_null_to_contain_values() {
|
|||
|result| {
|
||||
assert_eq!(
|
||||
result.get_field_value("listNn"),
|
||||
Some(&Value::scalar(r#"Some(["A"])"#))
|
||||
Some(&graphql_value!(r#"Some(["A"])"#)),
|
||||
);
|
||||
},
|
||||
)
|
||||
|
@ -904,7 +904,7 @@ async fn allow_non_null_lists_of_non_null_to_contain_values() {
|
|||
|result| {
|
||||
assert_eq!(
|
||||
result.get_field_value("nnListNn"),
|
||||
Some(&Value::scalar(r#"["A"]"#))
|
||||
Some(&graphql_value!(r#"["A"]"#)),
|
||||
);
|
||||
},
|
||||
)
|
||||
|
@ -916,7 +916,7 @@ async fn default_argument_when_not_provided() {
|
|||
run_query(r#"{ fieldWithDefaultArgumentValue }"#, |result| {
|
||||
assert_eq!(
|
||||
result.get_field_value("fieldWithDefaultArgumentValue"),
|
||||
Some(&Value::scalar(r#""Hello World""#))
|
||||
Some(&graphql_value!(r#""Hello World""#)),
|
||||
);
|
||||
})
|
||||
.await;
|
||||
|
@ -929,7 +929,7 @@ async fn default_argument_when_nullable_variable_not_provided() {
|
|||
|result| {
|
||||
assert_eq!(
|
||||
result.get_field_value("fieldWithDefaultArgumentValue"),
|
||||
Some(&Value::scalar(r#""Hello World""#))
|
||||
Some(&graphql_value!(r#""Hello World""#)),
|
||||
);
|
||||
},
|
||||
)
|
||||
|
@ -946,7 +946,7 @@ async fn default_argument_when_nullable_variable_set_to_null() {
|
|||
|result| {
|
||||
assert_eq!(
|
||||
result.get_field_value("fieldWithDefaultArgumentValue"),
|
||||
Some(&Value::scalar(r#""Hello World""#))
|
||||
Some(&graphql_value!(r#""Hello World""#)),
|
||||
);
|
||||
},
|
||||
)
|
||||
|
@ -958,7 +958,7 @@ async fn nullable_input_object_arguments_successful_without_variables() {
|
|||
run_query(r#"{ exampleInput(arg: {a: "abc", b: 123}) }"#, |result| {
|
||||
assert_eq!(
|
||||
result.get_field_value("exampleInput"),
|
||||
Some(&Value::scalar(r#"a: Some("abc"), b: 123"#))
|
||||
Some(&graphql_value!(r#"a: Some("abc"), b: 123"#)),
|
||||
);
|
||||
})
|
||||
.await;
|
||||
|
@ -966,7 +966,7 @@ async fn nullable_input_object_arguments_successful_without_variables() {
|
|||
run_query(r#"{ exampleInput(arg: {a: null, b: 1}) }"#, |result| {
|
||||
assert_eq!(
|
||||
result.get_field_value("exampleInput"),
|
||||
Some(&Value::scalar(r#"a: None, b: 1"#))
|
||||
Some(&graphql_value!(r#"a: None, b: 1"#)),
|
||||
);
|
||||
})
|
||||
.await;
|
||||
|
@ -982,7 +982,7 @@ async fn nullable_input_object_arguments_successful_with_variables() {
|
|||
|result| {
|
||||
assert_eq!(
|
||||
result.get_field_value("exampleInput"),
|
||||
Some(&Value::scalar(r#"a: None, b: 123"#))
|
||||
Some(&graphql_value!(r#"a: None, b: 123"#)),
|
||||
);
|
||||
},
|
||||
)
|
||||
|
@ -996,7 +996,7 @@ async fn nullable_input_object_arguments_successful_with_variables() {
|
|||
|result| {
|
||||
assert_eq!(
|
||||
result.get_field_value("exampleInput"),
|
||||
Some(&Value::scalar(r#"a: None, b: 1"#))
|
||||
Some(&graphql_value!(r#"a: None, b: 1"#)),
|
||||
);
|
||||
},
|
||||
)
|
||||
|
@ -1008,7 +1008,7 @@ async fn nullable_input_object_arguments_successful_with_variables() {
|
|||
|result| {
|
||||
assert_eq!(
|
||||
result.get_field_value("exampleInput"),
|
||||
Some(&Value::scalar(r#"a: None, b: 1"#))
|
||||
Some(&graphql_value!(r#"a: None, b: 1"#)),
|
||||
);
|
||||
},
|
||||
)
|
||||
|
@ -1118,7 +1118,7 @@ async fn input_object_with_default_values() {
|
|||
run_query(r#"{ inputWithDefaults(arg: {a: 1}) }"#, |result| {
|
||||
assert_eq!(
|
||||
result.get_field_value("inputWithDefaults"),
|
||||
Some(&Value::scalar(r#"a: 1"#))
|
||||
Some(&graphql_value!(r#"a: 1"#)),
|
||||
);
|
||||
})
|
||||
.await;
|
||||
|
@ -1131,7 +1131,7 @@ async fn input_object_with_default_values() {
|
|||
|result| {
|
||||
assert_eq!(
|
||||
result.get_field_value("inputWithDefaults"),
|
||||
Some(&Value::scalar(r#"a: 1"#))
|
||||
Some(&graphql_value!(r#"a: 1"#)),
|
||||
);
|
||||
},
|
||||
)
|
||||
|
@ -1143,7 +1143,7 @@ async fn input_object_with_default_values() {
|
|||
|result| {
|
||||
assert_eq!(
|
||||
result.get_field_value("inputWithDefaults"),
|
||||
Some(&Value::scalar(r#"a: 1"#))
|
||||
Some(&graphql_value!(r#"a: 1"#)),
|
||||
);
|
||||
},
|
||||
)
|
||||
|
@ -1157,7 +1157,7 @@ async fn input_object_with_default_values() {
|
|||
|result| {
|
||||
assert_eq!(
|
||||
result.get_field_value("inputWithDefaults"),
|
||||
Some(&Value::scalar(r#"a: 2"#))
|
||||
Some(&graphql_value!(r#"a: 2"#)),
|
||||
);
|
||||
},
|
||||
)
|
||||
|
@ -1177,7 +1177,7 @@ mod integers {
|
|||
|result| {
|
||||
assert_eq!(
|
||||
result.get_field_value("integerInput"),
|
||||
Some(&Value::scalar(r#"value: 1"#))
|
||||
Some(&graphql_value!(r#"value: 1"#)),
|
||||
);
|
||||
},
|
||||
)
|
||||
|
@ -1191,7 +1191,7 @@ mod integers {
|
|||
|result| {
|
||||
assert_eq!(
|
||||
result.get_field_value("integerInput"),
|
||||
Some(&Value::scalar(r#"value: -1"#))
|
||||
Some(&graphql_value!(r#"value: -1"#)),
|
||||
);
|
||||
},
|
||||
)
|
||||
|
@ -1264,7 +1264,7 @@ mod floats {
|
|||
|result| {
|
||||
assert_eq!(
|
||||
result.get_field_value("floatInput"),
|
||||
Some(&Value::scalar(r#"value: 10"#))
|
||||
Some(&graphql_value!(r#"value: 10"#)),
|
||||
);
|
||||
},
|
||||
)
|
||||
|
@ -1281,7 +1281,7 @@ mod floats {
|
|||
|result| {
|
||||
assert_eq!(
|
||||
result.get_field_value("floatInput"),
|
||||
Some(&Value::scalar(r#"value: -1"#))
|
||||
Some(&graphql_value!(r#"value: -1"#)),
|
||||
);
|
||||
},
|
||||
)
|
||||
|
|
|
@ -177,7 +177,7 @@ mod test {
|
|||
}
|
||||
|
||||
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 expected = DateTime::parse_from_rfc3339(raw)
|
||||
|
@ -237,7 +237,7 @@ mod test {
|
|||
#[test]
|
||||
fn naivedatetime_from_input_value() {
|
||||
let raw = 1_000_000_000_f64;
|
||||
let input: InputValue<DefaultScalarValue> = InputValue::scalar(raw);
|
||||
let input = <InputValue<DefaultScalarValue>>::scalar(raw);
|
||||
|
||||
let parsed: NaiveDateTime = crate::FromInputValue::from_input_value(&input).unwrap();
|
||||
let expected = NaiveDateTime::from_timestamp_opt(raw as i64, 0).unwrap();
|
||||
|
|
|
@ -27,13 +27,14 @@ where
|
|||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::InputValue;
|
||||
use url::Url;
|
||||
|
||||
use crate::{DefaultScalarValue, InputValue};
|
||||
|
||||
#[test]
|
||||
fn url_from_input_value() {
|
||||
let raw = "https://example.net/";
|
||||
let input: InputValue = InputValue::scalar(raw.to_string());
|
||||
let input = <InputValue<DefaultScalarValue>>::scalar(raw.to_string());
|
||||
|
||||
let parsed: Url = crate::FromInputValue::from_input_value(&input).unwrap();
|
||||
let url = Url::parse(raw).unwrap();
|
||||
|
|
|
@ -40,7 +40,7 @@ mod test {
|
|||
#[test]
|
||||
fn uuid_from_input_value() {
|
||||
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 id = Uuid::parse_str(raw).unwrap();
|
||||
|
|
|
@ -5,17 +5,15 @@ use crate::{
|
|||
schema::model::RootNode,
|
||||
tests::fixtures::starwars::schema::{Database, Query},
|
||||
types::scalars::{EmptyMutation, EmptySubscription},
|
||||
value::Value,
|
||||
};
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_hero_name() {
|
||||
let doc = r#"
|
||||
{
|
||||
hero {
|
||||
name
|
||||
}
|
||||
}"#;
|
||||
let doc = r#"{
|
||||
hero {
|
||||
name
|
||||
}
|
||||
}"#;
|
||||
let database = Database::new();
|
||||
let schema = RootNode::new(
|
||||
Query,
|
||||
|
@ -25,17 +23,7 @@ async fn test_hero_name() {
|
|||
|
||||
assert_eq!(
|
||||
crate::execute(doc, None, &schema, &Variables::new(), &database).await,
|
||||
Ok((
|
||||
Value::object(
|
||||
vec![(
|
||||
"hero",
|
||||
Value::object(vec![("name", Value::scalar("R2-D2"))].into_iter().collect()),
|
||||
)]
|
||||
.into_iter()
|
||||
.collect()
|
||||
),
|
||||
vec![]
|
||||
))
|
||||
Ok((graphql_value!({"hero": {"name": "R2-D2"}}), vec![])),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -48,77 +36,46 @@ async fn test_hero_field_order() {
|
|||
EmptySubscription::<Database>::new(),
|
||||
);
|
||||
|
||||
let doc = r#"
|
||||
{
|
||||
hero {
|
||||
id
|
||||
name
|
||||
}
|
||||
}"#;
|
||||
let doc = r#"{
|
||||
hero {
|
||||
id
|
||||
name
|
||||
}
|
||||
}"#;
|
||||
assert_eq!(
|
||||
crate::execute(doc, None, &schema, &Variables::new(), &database).await,
|
||||
Ok((
|
||||
Value::object(
|
||||
vec![(
|
||||
"hero",
|
||||
Value::object(
|
||||
vec![
|
||||
("id", Value::scalar("2001")),
|
||||
("name", Value::scalar("R2-D2")),
|
||||
]
|
||||
.into_iter()
|
||||
.collect(),
|
||||
),
|
||||
)]
|
||||
.into_iter()
|
||||
.collect()
|
||||
),
|
||||
vec![]
|
||||
))
|
||||
graphql_value!({"hero": {"id": "2001", "name": "R2-D2"}}),
|
||||
vec![],
|
||||
)),
|
||||
);
|
||||
|
||||
let doc_reversed = r#"
|
||||
{
|
||||
hero {
|
||||
name
|
||||
id
|
||||
}
|
||||
}"#;
|
||||
let doc_reversed = r#"{
|
||||
hero {
|
||||
name
|
||||
id
|
||||
}
|
||||
}"#;
|
||||
assert_eq!(
|
||||
crate::execute(doc_reversed, None, &schema, &Variables::new(), &database).await,
|
||||
Ok((
|
||||
Value::object(
|
||||
vec![(
|
||||
"hero",
|
||||
Value::object(
|
||||
vec![
|
||||
("name", Value::scalar("R2-D2")),
|
||||
("id", Value::scalar("2001")),
|
||||
]
|
||||
.into_iter()
|
||||
.collect(),
|
||||
),
|
||||
)]
|
||||
.into_iter()
|
||||
.collect()
|
||||
),
|
||||
vec![]
|
||||
))
|
||||
graphql_value!({"hero": {"name": "R2-D2", "id": "2001"}}),
|
||||
vec![],
|
||||
)),
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_hero_name_and_friends() {
|
||||
let doc = r#"
|
||||
{
|
||||
hero {
|
||||
id
|
||||
let doc = r#"{
|
||||
hero {
|
||||
id
|
||||
name
|
||||
friends {
|
||||
name
|
||||
friends {
|
||||
name
|
||||
}
|
||||
}
|
||||
}"#;
|
||||
}
|
||||
}"#;
|
||||
let database = Database::new();
|
||||
let schema = RootNode::new(
|
||||
Query,
|
||||
|
@ -129,62 +86,35 @@ async fn test_hero_name_and_friends() {
|
|||
assert_eq!(
|
||||
crate::execute(doc, None, &schema, &Variables::new(), &database).await,
|
||||
Ok((
|
||||
Value::object(
|
||||
vec![(
|
||||
"hero",
|
||||
Value::object(
|
||||
vec![
|
||||
("id", Value::scalar("2001")),
|
||||
("name", Value::scalar("R2-D2")),
|
||||
(
|
||||
"friends",
|
||||
Value::list(vec![
|
||||
Value::object(
|
||||
vec![("name", Value::scalar("Luke Skywalker"))]
|
||||
.into_iter()
|
||||
.collect(),
|
||||
),
|
||||
Value::object(
|
||||
vec![("name", Value::scalar("Han Solo"))]
|
||||
.into_iter()
|
||||
.collect(),
|
||||
),
|
||||
Value::object(
|
||||
vec![("name", Value::scalar("Leia Organa"))]
|
||||
.into_iter()
|
||||
.collect(),
|
||||
),
|
||||
]),
|
||||
),
|
||||
]
|
||||
.into_iter()
|
||||
.collect(),
|
||||
),
|
||||
)]
|
||||
.into_iter()
|
||||
.collect()
|
||||
),
|
||||
vec![]
|
||||
))
|
||||
graphql_value!({"hero": {
|
||||
"id": "2001",
|
||||
"name": "R2-D2",
|
||||
"friends": [
|
||||
{"name": "Luke Skywalker"},
|
||||
{"name": "Han Solo"},
|
||||
{"name": "Leia Organa"},
|
||||
],
|
||||
}}),
|
||||
vec![],
|
||||
)),
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_hero_name_and_friends_and_friends_of_friends() {
|
||||
let doc = r#"
|
||||
{
|
||||
hero {
|
||||
id
|
||||
let doc = r#"{
|
||||
hero {
|
||||
id
|
||||
name
|
||||
friends {
|
||||
name
|
||||
appearsIn
|
||||
friends {
|
||||
name
|
||||
appearsIn
|
||||
friends {
|
||||
name
|
||||
}
|
||||
name
|
||||
}
|
||||
}
|
||||
}"#;
|
||||
}
|
||||
}"#;
|
||||
let database = Database::new();
|
||||
let schema = RootNode::new(
|
||||
Query,
|
||||
|
@ -195,155 +125,39 @@ async fn test_hero_name_and_friends_and_friends_of_friends() {
|
|||
assert_eq!(
|
||||
crate::execute(doc, None, &schema, &Variables::new(), &database).await,
|
||||
Ok((
|
||||
Value::object(
|
||||
vec![(
|
||||
"hero",
|
||||
Value::object(
|
||||
vec![
|
||||
("id", Value::scalar("2001")),
|
||||
("name", Value::scalar("R2-D2")),
|
||||
(
|
||||
"friends",
|
||||
Value::list(vec![
|
||||
Value::object(
|
||||
vec![
|
||||
("name", Value::scalar("Luke Skywalker")),
|
||||
(
|
||||
"appearsIn",
|
||||
Value::list(vec![
|
||||
Value::scalar("NEW_HOPE"),
|
||||
Value::scalar("EMPIRE"),
|
||||
Value::scalar("JEDI"),
|
||||
]),
|
||||
),
|
||||
(
|
||||
"friends",
|
||||
Value::list(vec![
|
||||
Value::object(
|
||||
vec![("name", Value::scalar("Han Solo"))]
|
||||
.into_iter()
|
||||
.collect(),
|
||||
),
|
||||
Value::object(
|
||||
vec![(
|
||||
"name",
|
||||
Value::scalar("Leia Organa"),
|
||||
)]
|
||||
.into_iter()
|
||||
.collect(),
|
||||
),
|
||||
Value::object(
|
||||
vec![("name", Value::scalar("C-3PO"))]
|
||||
.into_iter()
|
||||
.collect(),
|
||||
),
|
||||
Value::object(
|
||||
vec![("name", Value::scalar("R2-D2"))]
|
||||
.into_iter()
|
||||
.collect(),
|
||||
),
|
||||
]),
|
||||
),
|
||||
]
|
||||
.into_iter()
|
||||
.collect(),
|
||||
),
|
||||
Value::object(
|
||||
vec![
|
||||
("name", Value::scalar("Han Solo")),
|
||||
(
|
||||
"appearsIn",
|
||||
Value::list(vec![
|
||||
Value::scalar("NEW_HOPE"),
|
||||
Value::scalar("EMPIRE"),
|
||||
Value::scalar("JEDI"),
|
||||
]),
|
||||
),
|
||||
(
|
||||
"friends",
|
||||
Value::list(vec![
|
||||
Value::object(
|
||||
vec![(
|
||||
"name",
|
||||
Value::scalar("Luke Skywalker"),
|
||||
)]
|
||||
.into_iter()
|
||||
.collect(),
|
||||
),
|
||||
Value::object(
|
||||
vec![(
|
||||
"name",
|
||||
Value::scalar("Leia Organa"),
|
||||
)]
|
||||
.into_iter()
|
||||
.collect(),
|
||||
),
|
||||
Value::object(
|
||||
vec![("name", Value::scalar("R2-D2"))]
|
||||
.into_iter()
|
||||
.collect(),
|
||||
),
|
||||
]),
|
||||
),
|
||||
]
|
||||
.into_iter()
|
||||
.collect(),
|
||||
),
|
||||
Value::object(
|
||||
vec![
|
||||
("name", Value::scalar("Leia Organa")),
|
||||
(
|
||||
"appearsIn",
|
||||
Value::list(vec![
|
||||
Value::scalar("NEW_HOPE"),
|
||||
Value::scalar("EMPIRE"),
|
||||
Value::scalar("JEDI"),
|
||||
]),
|
||||
),
|
||||
(
|
||||
"friends",
|
||||
Value::list(vec![
|
||||
Value::object(
|
||||
vec![(
|
||||
"name",
|
||||
Value::scalar("Luke Skywalker"),
|
||||
)]
|
||||
.into_iter()
|
||||
.collect(),
|
||||
),
|
||||
Value::object(
|
||||
vec![("name", Value::scalar("Han Solo"))]
|
||||
.into_iter()
|
||||
.collect(),
|
||||
),
|
||||
Value::object(
|
||||
vec![("name", Value::scalar("C-3PO"))]
|
||||
.into_iter()
|
||||
.collect(),
|
||||
),
|
||||
Value::object(
|
||||
vec![("name", Value::scalar("R2-D2"))]
|
||||
.into_iter()
|
||||
.collect(),
|
||||
),
|
||||
]),
|
||||
),
|
||||
]
|
||||
.into_iter()
|
||||
.collect(),
|
||||
),
|
||||
]),
|
||||
),
|
||||
]
|
||||
.into_iter()
|
||||
.collect(),
|
||||
),
|
||||
)]
|
||||
.into_iter()
|
||||
.collect()
|
||||
),
|
||||
vec![]
|
||||
))
|
||||
graphql_value!({"hero": {
|
||||
"id": "2001",
|
||||
"name": "R2-D2",
|
||||
"friends": [{
|
||||
"name": "Luke Skywalker",
|
||||
"appearsIn": ["NEW_HOPE", "EMPIRE", "JEDI"],
|
||||
"friends": [
|
||||
{"name": "Han Solo"},
|
||||
{"name": "Leia Organa"},
|
||||
{"name": "C-3PO"},
|
||||
{"name": "R2-D2"},
|
||||
],
|
||||
}, {
|
||||
"name": "Han Solo",
|
||||
"appearsIn": ["NEW_HOPE", "EMPIRE", "JEDI"],
|
||||
"friends": [
|
||||
{"name": "Luke Skywalker"},
|
||||
{"name": "Leia Organa"},
|
||||
{"name": "R2-D2"},
|
||||
],
|
||||
}, {
|
||||
"name": "Leia Organa",
|
||||
"appearsIn": ["NEW_HOPE", "EMPIRE", "JEDI"],
|
||||
"friends": [
|
||||
{"name": "Luke Skywalker"},
|
||||
{"name": "Han Solo"},
|
||||
{"name": "C-3PO"},
|
||||
{"name": "R2-D2"},
|
||||
],
|
||||
}],
|
||||
}}),
|
||||
vec![],
|
||||
)),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -360,20 +174,9 @@ async fn test_query_name() {
|
|||
assert_eq!(
|
||||
crate::execute(doc, None, &schema, &Variables::new(), &database).await,
|
||||
Ok((
|
||||
Value::object(
|
||||
vec![(
|
||||
"human",
|
||||
Value::object(
|
||||
vec![("name", Value::scalar("Luke Skywalker"))]
|
||||
.into_iter()
|
||||
.collect(),
|
||||
),
|
||||
)]
|
||||
.into_iter()
|
||||
.collect()
|
||||
),
|
||||
vec![]
|
||||
))
|
||||
graphql_value!({"human": {"name": "Luke Skywalker"}}),
|
||||
vec![],
|
||||
)),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -389,31 +192,16 @@ async fn test_query_alias_single() {
|
|||
|
||||
assert_eq!(
|
||||
crate::execute(doc, None, &schema, &Variables::new(), &database).await,
|
||||
Ok((
|
||||
Value::object(
|
||||
vec![(
|
||||
"luke",
|
||||
Value::object(
|
||||
vec![("name", Value::scalar("Luke Skywalker"))]
|
||||
.into_iter()
|
||||
.collect(),
|
||||
),
|
||||
)]
|
||||
.into_iter()
|
||||
.collect()
|
||||
),
|
||||
vec![]
|
||||
))
|
||||
Ok((graphql_value!({"luke": {"name": "Luke Skywalker"}}), vec![])),
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_query_alias_multiple() {
|
||||
let doc = r#"
|
||||
{
|
||||
luke: human(id: "1000") { name }
|
||||
leia: human(id: "1003") { name }
|
||||
}"#;
|
||||
let doc = r#"{
|
||||
luke: human(id: "1000") { name }
|
||||
leia: human(id: "1003") { name }
|
||||
}"#;
|
||||
let database = Database::new();
|
||||
let schema = RootNode::new(
|
||||
Query,
|
||||
|
@ -424,30 +212,12 @@ async fn test_query_alias_multiple() {
|
|||
assert_eq!(
|
||||
crate::execute(doc, None, &schema, &Variables::new(), &database).await,
|
||||
Ok((
|
||||
Value::object(
|
||||
vec![
|
||||
(
|
||||
"luke",
|
||||
Value::object(
|
||||
vec![("name", Value::scalar("Luke Skywalker"))]
|
||||
.into_iter()
|
||||
.collect(),
|
||||
),
|
||||
),
|
||||
(
|
||||
"leia",
|
||||
Value::object(
|
||||
vec![("name", Value::scalar("Leia Organa"))]
|
||||
.into_iter()
|
||||
.collect(),
|
||||
),
|
||||
),
|
||||
]
|
||||
.into_iter()
|
||||
.collect()
|
||||
),
|
||||
vec![]
|
||||
))
|
||||
graphql_value!({
|
||||
"luke": {"name": "Luke Skywalker"},
|
||||
"leia": {"name": "Leia Organa"},
|
||||
}),
|
||||
vec![],
|
||||
)),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -473,36 +243,12 @@ async fn test_query_alias_multiple_with_fragment() {
|
|||
assert_eq!(
|
||||
crate::execute(doc, None, &schema, &Variables::new(), &database).await,
|
||||
Ok((
|
||||
Value::object(
|
||||
vec![
|
||||
(
|
||||
"luke",
|
||||
Value::object(
|
||||
vec![
|
||||
("name", Value::scalar("Luke Skywalker")),
|
||||
("homePlanet", Value::scalar("Tatooine")),
|
||||
]
|
||||
.into_iter()
|
||||
.collect(),
|
||||
),
|
||||
),
|
||||
(
|
||||
"leia",
|
||||
Value::object(
|
||||
vec![
|
||||
("name", Value::scalar("Leia Organa")),
|
||||
("homePlanet", Value::scalar("Alderaan")),
|
||||
]
|
||||
.into_iter()
|
||||
.collect(),
|
||||
),
|
||||
),
|
||||
]
|
||||
.into_iter()
|
||||
.collect()
|
||||
),
|
||||
vec![]
|
||||
))
|
||||
graphql_value!({
|
||||
"luke": {"name": "Luke Skywalker", "homePlanet": "Tatooine"},
|
||||
"leia": {"name": "Leia Organa", "homePlanet": "Alderaan"},
|
||||
}),
|
||||
vec![],
|
||||
)),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -523,20 +269,9 @@ async fn test_query_name_variable() {
|
|||
assert_eq!(
|
||||
crate::execute(doc, None, &schema, &vars, &database).await,
|
||||
Ok((
|
||||
Value::object(
|
||||
vec![(
|
||||
"human",
|
||||
Value::object(
|
||||
vec![("name", Value::scalar("Luke Skywalker"))]
|
||||
.into_iter()
|
||||
.collect(),
|
||||
),
|
||||
)]
|
||||
.into_iter()
|
||||
.collect()
|
||||
),
|
||||
vec![]
|
||||
))
|
||||
graphql_value!({"human": {"name": "Luke Skywalker"}}),
|
||||
vec![],
|
||||
)),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -556,10 +291,7 @@ async fn test_query_name_invalid_variable() {
|
|||
|
||||
assert_eq!(
|
||||
crate::execute(doc, None, &schema, &vars, &database).await,
|
||||
Ok((
|
||||
Value::object(vec![("human", Value::null())].into_iter().collect()),
|
||||
vec![]
|
||||
))
|
||||
Ok((graphql_value!({ "human": None }), vec![])),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -576,57 +308,31 @@ async fn test_query_friends_names() {
|
|||
assert_eq!(
|
||||
crate::execute(doc, None, &schema, &Variables::new(), &database).await,
|
||||
Ok((
|
||||
Value::object(
|
||||
vec![(
|
||||
"human",
|
||||
Value::object(
|
||||
vec![(
|
||||
"friends",
|
||||
Value::list(vec![
|
||||
Value::object(
|
||||
vec![("name", Value::scalar("Han Solo"))]
|
||||
.into_iter()
|
||||
.collect(),
|
||||
),
|
||||
Value::object(
|
||||
vec![("name", Value::scalar("Leia Organa"))]
|
||||
.into_iter()
|
||||
.collect(),
|
||||
),
|
||||
Value::object(
|
||||
vec![("name", Value::scalar("C-3PO"))].into_iter().collect(),
|
||||
),
|
||||
Value::object(
|
||||
vec![("name", Value::scalar("R2-D2"))].into_iter().collect(),
|
||||
),
|
||||
]),
|
||||
)]
|
||||
.into_iter()
|
||||
.collect(),
|
||||
),
|
||||
)]
|
||||
.into_iter()
|
||||
.collect()
|
||||
),
|
||||
vec![]
|
||||
))
|
||||
graphql_value!({"human": {
|
||||
"friends": [
|
||||
{"name": "Han Solo"},
|
||||
{"name": "Leia Organa"},
|
||||
{"name": "C-3PO"},
|
||||
{"name": "R2-D2"},
|
||||
],
|
||||
}}),
|
||||
vec![],
|
||||
)),
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_query_inline_fragments_droid() {
|
||||
let doc = r#"
|
||||
query InlineFragments {
|
||||
hero {
|
||||
name
|
||||
__typename
|
||||
let doc = r#"query InlineFragments {
|
||||
hero {
|
||||
name
|
||||
__typename
|
||||
|
||||
...on Droid {
|
||||
primaryFunction
|
||||
}
|
||||
...on Droid {
|
||||
primaryFunction
|
||||
}
|
||||
}
|
||||
"#;
|
||||
}"#;
|
||||
let database = Database::new();
|
||||
let schema = RootNode::new(
|
||||
Query,
|
||||
|
@ -637,37 +343,24 @@ async fn test_query_inline_fragments_droid() {
|
|||
assert_eq!(
|
||||
crate::execute(doc, None, &schema, &Variables::new(), &database).await,
|
||||
Ok((
|
||||
Value::object(
|
||||
vec![(
|
||||
"hero",
|
||||
Value::object(
|
||||
vec![
|
||||
("__typename", Value::scalar("Droid")),
|
||||
("name", Value::scalar("R2-D2")),
|
||||
("primaryFunction", Value::scalar("Astromech")),
|
||||
]
|
||||
.into_iter()
|
||||
.collect(),
|
||||
),
|
||||
)]
|
||||
.into_iter()
|
||||
.collect()
|
||||
),
|
||||
vec![]
|
||||
))
|
||||
graphql_value!({"hero": {
|
||||
"__typename": "Droid",
|
||||
"name": "R2-D2",
|
||||
"primaryFunction": "Astromech",
|
||||
}}),
|
||||
vec![],
|
||||
)),
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_query_inline_fragments_human() {
|
||||
let doc = r#"
|
||||
query InlineFragments {
|
||||
hero(episode: EMPIRE) {
|
||||
__typename
|
||||
name
|
||||
}
|
||||
let doc = r#"query InlineFragments {
|
||||
hero(episode: EMPIRE) {
|
||||
__typename
|
||||
name
|
||||
}
|
||||
"#;
|
||||
}"#;
|
||||
let database = Database::new();
|
||||
let schema = RootNode::new(
|
||||
Query,
|
||||
|
@ -678,34 +371,22 @@ async fn test_query_inline_fragments_human() {
|
|||
assert_eq!(
|
||||
crate::execute(doc, None, &schema, &Variables::new(), &database).await,
|
||||
Ok((
|
||||
Value::object(
|
||||
vec![(
|
||||
"hero",
|
||||
Value::object(
|
||||
vec![
|
||||
("__typename", Value::scalar("Human")),
|
||||
("name", Value::scalar("Luke Skywalker")),
|
||||
]
|
||||
.into_iter()
|
||||
.collect(),
|
||||
),
|
||||
)]
|
||||
.into_iter()
|
||||
.collect()
|
||||
),
|
||||
vec![]
|
||||
))
|
||||
graphql_value!({"hero": {
|
||||
"__typename": "Human",
|
||||
"name": "Luke Skywalker",
|
||||
}}),
|
||||
vec![],
|
||||
)),
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_object_typename() {
|
||||
let doc = r#"
|
||||
{
|
||||
human(id: "1000") {
|
||||
__typename
|
||||
}
|
||||
}"#;
|
||||
let doc = r#"{
|
||||
human(id: "1000") {
|
||||
__typename
|
||||
}
|
||||
}"#;
|
||||
let database = Database::new();
|
||||
let schema = RootNode::new(
|
||||
Query,
|
||||
|
@ -715,21 +396,7 @@ async fn test_object_typename() {
|
|||
|
||||
assert_eq!(
|
||||
crate::execute(doc, None, &schema, &Variables::new(), &database).await,
|
||||
Ok((
|
||||
Value::object(
|
||||
vec![(
|
||||
"human",
|
||||
Value::object(
|
||||
vec![("__typename", Value::scalar("Human"))]
|
||||
.into_iter()
|
||||
.collect(),
|
||||
),
|
||||
)]
|
||||
.into_iter()
|
||||
.collect()
|
||||
),
|
||||
vec![]
|
||||
))
|
||||
Ok((graphql_value!({"human": {"__typename": "Human"}}), vec![])),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -3,8 +3,9 @@ use std::{iter, iter::FromIterator as _, pin::Pin};
|
|||
use futures::{stream, StreamExt as _};
|
||||
|
||||
use crate::{
|
||||
graphql_object, graphql_subscription, http::GraphQLRequest, Context, DefaultScalarValue,
|
||||
EmptyMutation, ExecutionError, FieldError, GraphQLObject, Object, RootNode, Value,
|
||||
graphql_object, graphql_subscription, graphql_value, http::GraphQLRequest, Context,
|
||||
DefaultScalarValue, EmptyMutation, ExecutionError, FieldError, GraphQLObject, Object, RootNode,
|
||||
Value,
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
|
@ -57,7 +58,7 @@ impl MySubscription {
|
|||
async fn error_human() -> Result<HumanStream, FieldError> {
|
||||
Err(FieldError::new(
|
||||
"handler error",
|
||||
Value::Scalar(DefaultScalarValue::String("more details".to_string())),
|
||||
graphql_value!("more details"),
|
||||
))
|
||||
}
|
||||
|
||||
|
@ -163,14 +164,8 @@ fn returns_requested_object() {
|
|||
std::iter::from_fn(move || {
|
||||
iterator_count += 1;
|
||||
match iterator_count {
|
||||
1 => Some((
|
||||
"id",
|
||||
Value::Scalar(DefaultScalarValue::String("stream id".to_string())),
|
||||
)),
|
||||
2 => Some((
|
||||
"name",
|
||||
Value::Scalar(DefaultScalarValue::String("stream name".to_string())),
|
||||
)),
|
||||
1 => Some(("id", graphql_value!("stream id"))),
|
||||
2 => Some(("name", graphql_value!("stream name"))),
|
||||
_ => None,
|
||||
}
|
||||
}),
|
||||
|
@ -199,10 +194,7 @@ fn returns_error() {
|
|||
let expected_error = ExecutionError::new(
|
||||
crate::parser::SourcePosition::new(23, 1, 8),
|
||||
&vec!["errorHuman"],
|
||||
FieldError::new(
|
||||
"handler error",
|
||||
Value::Scalar(DefaultScalarValue::String("more details".to_string())),
|
||||
),
|
||||
FieldError::new("handler error", graphql_value!("more details")),
|
||||
);
|
||||
|
||||
assert_eq!(returned_errors, vec![expected_error]);
|
||||
|
@ -224,10 +216,7 @@ fn can_access_context() {
|
|||
move || {
|
||||
iterator_count += 1;
|
||||
match iterator_count {
|
||||
1 => Some((
|
||||
"id",
|
||||
Value::Scalar(DefaultScalarValue::String("2".to_string())),
|
||||
)),
|
||||
1 => Some(("id", graphql_value!("2"))),
|
||||
_ => None,
|
||||
}
|
||||
},
|
||||
|
@ -255,10 +244,7 @@ fn resolves_typed_inline_fragments() {
|
|||
move || {
|
||||
iterator_count += 1;
|
||||
match iterator_count {
|
||||
1 => Some((
|
||||
"id",
|
||||
Value::Scalar(DefaultScalarValue::String("stream id".to_string())),
|
||||
)),
|
||||
1 => Some(("id", graphql_value!("stream id"))),
|
||||
_ => None,
|
||||
}
|
||||
},
|
||||
|
@ -286,10 +272,7 @@ fn resolves_nontyped_inline_fragments() {
|
|||
move || {
|
||||
iterator_count += 1;
|
||||
match iterator_count {
|
||||
1 => Some((
|
||||
"id",
|
||||
Value::Scalar(DefaultScalarValue::String("stream id".to_string())),
|
||||
)),
|
||||
1 => Some(("id", graphql_value!("stream id"))),
|
||||
_ => None,
|
||||
}
|
||||
},
|
||||
|
@ -316,14 +299,8 @@ fn can_access_arguments() {
|
|||
move || {
|
||||
iterator_count += 1;
|
||||
match iterator_count {
|
||||
1 => Some((
|
||||
"id",
|
||||
Value::Scalar(DefaultScalarValue::String("123".to_string())),
|
||||
)),
|
||||
2 => Some((
|
||||
"name",
|
||||
Value::Scalar(DefaultScalarValue::String("args name".to_string())),
|
||||
)),
|
||||
1 => Some(("id", graphql_value!("123"))),
|
||||
2 => Some(("name", graphql_value!("args name"))),
|
||||
_ => None,
|
||||
}
|
||||
},
|
||||
|
@ -350,14 +327,8 @@ fn type_alias() {
|
|||
move || {
|
||||
iterator_count += 1;
|
||||
match iterator_count {
|
||||
1 => Some((
|
||||
"id",
|
||||
Value::Scalar(DefaultScalarValue::String("stream id".to_string())),
|
||||
)),
|
||||
2 => Some((
|
||||
"name",
|
||||
Value::Scalar(DefaultScalarValue::String("stream name".to_string())),
|
||||
)),
|
||||
1 => Some(("id", graphql_value!("stream id"))),
|
||||
2 => Some(("name", graphql_value!("stream name"))),
|
||||
_ => None,
|
||||
}
|
||||
},
|
||||
|
|
|
@ -2,12 +2,13 @@ use indexmap::IndexMap;
|
|||
|
||||
use crate::{
|
||||
executor::{ExecutionResult, Executor, Registry, Variables},
|
||||
graphql_value,
|
||||
schema::{meta::MetaType, model::RootNode},
|
||||
types::{
|
||||
base::{Arguments, GraphQLType, GraphQLValue},
|
||||
scalars::{EmptyMutation, EmptySubscription},
|
||||
},
|
||||
value::{ScalarValue, Value},
|
||||
value::ScalarValue,
|
||||
};
|
||||
|
||||
pub struct NodeTypeInfo {
|
||||
|
@ -95,16 +96,12 @@ fn test_node() {
|
|||
assert_eq!(
|
||||
crate::execute_sync(doc, None, &schema, &Variables::new(), &()),
|
||||
Ok((
|
||||
Value::object(
|
||||
vec![
|
||||
("foo", Value::scalar("1")),
|
||||
("bar", Value::scalar("2")),
|
||||
("baz", Value::scalar("3")),
|
||||
]
|
||||
.into_iter()
|
||||
.collect()
|
||||
),
|
||||
vec![]
|
||||
))
|
||||
graphql_value!({
|
||||
"foo": "1",
|
||||
"bar": "2",
|
||||
"baz": "3",
|
||||
}),
|
||||
vec![],
|
||||
)),
|
||||
);
|
||||
}
|
||||
|
|
|
@ -78,7 +78,7 @@ impl<S> IntoIterator for Object<S> {
|
|||
|
||||
impl<S> From<Object<S>> for Value<S> {
|
||||
fn from(o: Object<S>) -> Self {
|
||||
Value::Object(o)
|
||||
Self::Object(o)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -633,9 +633,9 @@ mod test {
|
|||
|
||||
use juniper::{
|
||||
futures::sink::SinkExt,
|
||||
graphql_object, graphql_subscription,
|
||||
graphql_object, graphql_subscription, graphql_value,
|
||||
parser::{ParseError, Spanning, Token},
|
||||
DefaultScalarValue, EmptyMutation, FieldError, FieldResult, InputValue, RootNode, Value,
|
||||
DefaultScalarValue, EmptyMutation, FieldError, FieldResult, InputValue, RootNode,
|
||||
};
|
||||
|
||||
use super::*;
|
||||
|
@ -681,7 +681,7 @@ mod test {
|
|||
async fn error(_context: &Context) -> BoxStream<'static, FieldResult<i32>> {
|
||||
stream::once(future::ready(Err(FieldError::new(
|
||||
"field error",
|
||||
Value::null(),
|
||||
graphql_value!(None),
|
||||
))))
|
||||
.chain(
|
||||
tokio::time::sleep(Duration::from_secs(10000))
|
||||
|
@ -729,12 +729,7 @@ mod test {
|
|||
ServerMessage::Data {
|
||||
id: "foo".to_string(),
|
||||
payload: DataPayload {
|
||||
data: Value::Object(
|
||||
[("context", Value::Scalar(DefaultScalarValue::Int(1)))]
|
||||
.iter()
|
||||
.cloned()
|
||||
.collect()
|
||||
),
|
||||
data: graphql_value!({"context": 1}),
|
||||
errors: vec![],
|
||||
},
|
||||
},
|
||||
|
@ -779,7 +774,7 @@ mod test {
|
|||
ServerMessage::Data {
|
||||
id: "foo".to_string(),
|
||||
payload: DataPayload {
|
||||
data: Value::Object([("context", Value::scalar(1))].iter().cloned().collect()),
|
||||
data: graphql_value!({"context": 1}),
|
||||
errors: vec![],
|
||||
},
|
||||
},
|
||||
|
@ -801,7 +796,7 @@ mod test {
|
|||
ServerMessage::Data {
|
||||
id: "bar".to_string(),
|
||||
payload: DataPayload {
|
||||
data: Value::Object([("context", Value::scalar(1))].iter().cloned().collect()),
|
||||
data: graphql_value!({"context": 1}),
|
||||
errors: vec![],
|
||||
},
|
||||
},
|
||||
|
@ -1009,12 +1004,7 @@ mod test {
|
|||
ServerMessage::Data {
|
||||
id: "foo".to_string(),
|
||||
payload: DataPayload {
|
||||
data: Value::Object(
|
||||
[("context", Value::Scalar(DefaultScalarValue::Int(1)))]
|
||||
.iter()
|
||||
.cloned()
|
||||
.collect()
|
||||
),
|
||||
data: graphql_value!({"context": 1}),
|
||||
errors: vec![],
|
||||
},
|
||||
},
|
||||
|
@ -1054,10 +1044,7 @@ mod test {
|
|||
payload: DataPayload { data, errors },
|
||||
} => {
|
||||
assert_eq!(id, "foo");
|
||||
assert_eq!(
|
||||
data,
|
||||
Value::Object([("error", Value::null())].iter().cloned().collect())
|
||||
);
|
||||
assert_eq!(data, graphql_value!({ "error": None }),);
|
||||
assert_eq!(errors.len(), 1);
|
||||
}
|
||||
msg @ _ => panic!("expected data, got: {:?}", msg),
|
||||
|
|
|
@ -134,8 +134,9 @@ pub enum ServerMessage<S: ScalarValue> {
|
|||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use juniper::{graphql_value, DefaultScalarValue};
|
||||
|
||||
use super::*;
|
||||
use juniper::DefaultScalarValue;
|
||||
|
||||
#[test]
|
||||
fn test_serialization() {
|
||||
|
@ -160,7 +161,7 @@ mod test {
|
|||
serde_json::to_string(&ServerMessage::Data {
|
||||
id: "foo".to_string(),
|
||||
payload: DataPayload {
|
||||
data: Value::null(),
|
||||
data: graphql_value!(None),
|
||||
errors: vec![],
|
||||
},
|
||||
})
|
||||
|
|
|
@ -254,17 +254,17 @@ where
|
|||
#[cfg(test)]
|
||||
mod whole_responses_stream {
|
||||
use futures::{stream, StreamExt as _};
|
||||
use juniper::{DefaultScalarValue, ExecutionError, FieldError};
|
||||
use juniper::{graphql_value, DefaultScalarValue, ExecutionError, FieldError};
|
||||
|
||||
use super::*;
|
||||
|
||||
#[tokio::test]
|
||||
async fn with_error() {
|
||||
let expected = vec![ExecutionOutput {
|
||||
data: Value::<DefaultScalarValue>::Null,
|
||||
let expected: Vec<ExecutionOutput<DefaultScalarValue>> = vec![ExecutionOutput {
|
||||
data: graphql_value!(None),
|
||||
errors: vec![ExecutionError::at_origin(FieldError::new(
|
||||
"field error",
|
||||
Value::Null,
|
||||
graphql_value!(None),
|
||||
))],
|
||||
}];
|
||||
let expected = serde_json::to_string(&expected).unwrap();
|
||||
|
@ -273,7 +273,7 @@ mod whole_responses_stream {
|
|||
Value::Null,
|
||||
vec![ExecutionError::at_origin(FieldError::new(
|
||||
"field error",
|
||||
Value::Null,
|
||||
graphql_value!(None),
|
||||
))],
|
||||
)
|
||||
.collect::<Vec<_>>()
|
||||
|
@ -285,9 +285,8 @@ mod whole_responses_stream {
|
|||
|
||||
#[tokio::test]
|
||||
async fn value_null() {
|
||||
let expected = vec![ExecutionOutput::from_data(
|
||||
Value::<DefaultScalarValue>::Null,
|
||||
)];
|
||||
let expected: Vec<ExecutionOutput<DefaultScalarValue>> =
|
||||
vec![ExecutionOutput::from_data(graphql_value!(None))];
|
||||
let expected = serde_json::to_string(&expected).unwrap();
|
||||
|
||||
let result = whole_responses_stream::<DefaultScalarValue>(Value::Null, vec![])
|
||||
|
@ -302,12 +301,12 @@ mod whole_responses_stream {
|
|||
|
||||
#[tokio::test]
|
||||
async fn value_scalar() {
|
||||
let expected = vec![
|
||||
ExecutionOutput::from_data(Value::Scalar(DefaultScalarValue::Int(1i32))),
|
||||
ExecutionOutput::from_data(Value::Scalar(DefaultScalarValue::Int(2i32))),
|
||||
ExecutionOutput::from_data(Value::Scalar(DefaultScalarValue::Int(3i32))),
|
||||
ExecutionOutput::from_data(Value::Scalar(DefaultScalarValue::Int(4i32))),
|
||||
ExecutionOutput::from_data(Value::Scalar(DefaultScalarValue::Int(5i32))),
|
||||
let expected: Vec<ExecutionOutput<DefaultScalarValue>> = vec![
|
||||
ExecutionOutput::from_data(graphql_value!(1)),
|
||||
ExecutionOutput::from_data(graphql_value!(2)),
|
||||
ExecutionOutput::from_data(graphql_value!(3)),
|
||||
ExecutionOutput::from_data(graphql_value!(4)),
|
||||
ExecutionOutput::from_data(graphql_value!(5)),
|
||||
];
|
||||
let expected = serde_json::to_string(&expected).unwrap();
|
||||
|
||||
|
@ -317,7 +316,7 @@ mod whole_responses_stream {
|
|||
return Poll::Ready(None);
|
||||
}
|
||||
counter += 1;
|
||||
Poll::Ready(Some(Ok(Value::Scalar(DefaultScalarValue::Int(counter)))))
|
||||
Poll::Ready(Some(Ok(graphql_value!(counter))))
|
||||
});
|
||||
|
||||
let result =
|
||||
|
@ -331,24 +330,24 @@ mod whole_responses_stream {
|
|||
|
||||
#[tokio::test]
|
||||
async fn value_list() {
|
||||
let expected = vec![
|
||||
ExecutionOutput::from_data(Value::Scalar(DefaultScalarValue::Int(1i32))),
|
||||
ExecutionOutput::from_data(Value::Scalar(DefaultScalarValue::Int(2i32))),
|
||||
ExecutionOutput::from_data(Value::null()),
|
||||
ExecutionOutput::from_data(Value::Scalar(DefaultScalarValue::Int(4i32))),
|
||||
let expected: Vec<ExecutionOutput<DefaultScalarValue>> = vec![
|
||||
ExecutionOutput::from_data(graphql_value!(1)),
|
||||
ExecutionOutput::from_data(graphql_value!(2)),
|
||||
ExecutionOutput::from_data(graphql_value!(None)),
|
||||
ExecutionOutput::from_data(graphql_value!(4)),
|
||||
];
|
||||
let expected = serde_json::to_string(&expected).unwrap();
|
||||
|
||||
let streams: Vec<Value<ValuesStream>> = vec![
|
||||
Value::Scalar(Box::pin(stream::once(async {
|
||||
PollResult::Ok(Value::Scalar(DefaultScalarValue::Int(1i32)))
|
||||
PollResult::Ok(graphql_value!(1))
|
||||
}))),
|
||||
Value::Scalar(Box::pin(stream::once(async {
|
||||
PollResult::Ok(Value::Scalar(DefaultScalarValue::Int(2i32)))
|
||||
PollResult::Ok(graphql_value!(2))
|
||||
}))),
|
||||
Value::Null,
|
||||
Value::Scalar(Box::pin(stream::once(async {
|
||||
PollResult::Ok(Value::Scalar(DefaultScalarValue::Int(4i32)))
|
||||
PollResult::Ok(graphql_value!(4))
|
||||
}))),
|
||||
];
|
||||
|
||||
|
@ -362,21 +361,9 @@ mod whole_responses_stream {
|
|||
|
||||
#[tokio::test]
|
||||
async fn value_object() {
|
||||
let expected = vec![
|
||||
ExecutionOutput::from_data(Value::Object(Object::from_iter(
|
||||
vec![
|
||||
("one", Value::Scalar(DefaultScalarValue::Int(1i32))),
|
||||
("two", Value::Scalar(DefaultScalarValue::Int(1i32))),
|
||||
]
|
||||
.into_iter(),
|
||||
))),
|
||||
ExecutionOutput::from_data(Value::Object(Object::from_iter(
|
||||
vec![
|
||||
("one", Value::Scalar(DefaultScalarValue::Int(2i32))),
|
||||
("two", Value::Scalar(DefaultScalarValue::Int(2i32))),
|
||||
]
|
||||
.into_iter(),
|
||||
))),
|
||||
let expected: Vec<ExecutionOutput<DefaultScalarValue>> = vec![
|
||||
ExecutionOutput::from_data(graphql_value!({"one": 1, "two": 1})),
|
||||
ExecutionOutput::from_data(graphql_value!({"one": 2, "two": 2})),
|
||||
];
|
||||
let expected = serde_json::to_string(&expected).unwrap();
|
||||
|
||||
|
@ -386,7 +373,7 @@ mod whole_responses_stream {
|
|||
return Poll::Ready(None);
|
||||
}
|
||||
counter += 1;
|
||||
Poll::Ready(Some(Ok(Value::Scalar(DefaultScalarValue::Int(counter)))))
|
||||
Poll::Ready(Some(Ok(graphql_value!(counter))))
|
||||
});
|
||||
|
||||
let mut counter = 0;
|
||||
|
@ -395,7 +382,7 @@ mod whole_responses_stream {
|
|||
return Poll::Ready(None);
|
||||
}
|
||||
counter += 1;
|
||||
Poll::Ready(Some(Ok(Value::Scalar(DefaultScalarValue::Int(counter)))))
|
||||
Poll::Ready(Some(Ok(graphql_value!(counter))))
|
||||
});
|
||||
|
||||
let vals: Vec<(&str, Value<ValuesStream>)> = vec![
|
||||
|
|
Loading…
Reference in a new issue