- add `From` impls to `InputValue` mirroring `Value` impls to provide better support for `Option` handling - support expressions in `graphql_value!` macro - use `null` in addition to `None` to create `Value::Null` in `graphql_value!` macro to mirror `serde_json::json!` - use macros for `InputValue` and `Variables` construction in tests Co-authored-by: Ilya Solovyiov <ilya.solovyiov@gmail.com>
This commit is contained in:
parent
bc66a2d898
commit
acde85a814
58 changed files with 3337 additions and 1999 deletions
|
@ -1,6 +1,6 @@
|
||||||
use juniper::{
|
use juniper::{
|
||||||
graphql_object, graphql_value, EmptyMutation, EmptySubscription, GraphQLInputObject, RootNode,
|
graphql_object, graphql_value, graphql_vars, EmptyMutation, EmptySubscription,
|
||||||
Variables,
|
GraphQLInputObject, RootNode,
|
||||||
};
|
};
|
||||||
|
|
||||||
mod as_output_field {
|
mod as_output_field {
|
||||||
|
@ -24,7 +24,7 @@ mod as_output_field {
|
||||||
"#;
|
"#;
|
||||||
|
|
||||||
let schema = RootNode::new(Query, EmptyMutation::new(), EmptySubscription::new());
|
let schema = RootNode::new(Query, EmptyMutation::new(), EmptySubscription::new());
|
||||||
let (res, errors) = juniper::execute(query, None, &schema, &Variables::new(), &())
|
let (res, errors) = juniper::execute(query, None, &schema, &graphql_vars! {}, &())
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -68,7 +68,7 @@ mod as_input_field {
|
||||||
"#;
|
"#;
|
||||||
|
|
||||||
let schema = RootNode::new(Query, EmptyMutation::new(), EmptySubscription::new());
|
let schema = RootNode::new(Query, EmptyMutation::new(), EmptySubscription::new());
|
||||||
let (res, errors) = juniper::execute(query, None, &schema, &Variables::new(), &())
|
let (res, errors) = juniper::execute(query, None, &schema, &graphql_vars! {}, &())
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -85,7 +85,7 @@ mod as_input_field {
|
||||||
"#;
|
"#;
|
||||||
|
|
||||||
let schema = RootNode::new(Query, EmptyMutation::new(), EmptySubscription::new());
|
let schema = RootNode::new(Query, EmptyMutation::new(), EmptySubscription::new());
|
||||||
let res = juniper::execute(query, None, &schema, &Variables::new(), &()).await;
|
let res = juniper::execute(query, None, &schema, &graphql_vars! {}, &()).await;
|
||||||
|
|
||||||
assert!(res.is_err());
|
assert!(res.is_err());
|
||||||
assert!(res
|
assert!(res
|
||||||
|
@ -103,7 +103,7 @@ mod as_input_field {
|
||||||
"#;
|
"#;
|
||||||
|
|
||||||
let schema = RootNode::new(Query, EmptyMutation::new(), EmptySubscription::new());
|
let schema = RootNode::new(Query, EmptyMutation::new(), EmptySubscription::new());
|
||||||
let res = juniper::execute(query, None, &schema, &Variables::new(), &()).await;
|
let res = juniper::execute(query, None, &schema, &graphql_vars! {}, &()).await;
|
||||||
|
|
||||||
assert!(res.is_err());
|
assert!(res.is_err());
|
||||||
assert!(res
|
assert!(res
|
||||||
|
@ -121,7 +121,7 @@ mod as_input_field {
|
||||||
"#;
|
"#;
|
||||||
|
|
||||||
let schema = RootNode::new(Query, EmptyMutation::new(), EmptySubscription::new());
|
let schema = RootNode::new(Query, EmptyMutation::new(), EmptySubscription::new());
|
||||||
let (res, errors) = juniper::execute(query, None, &schema, &Variables::new(), &())
|
let (res, errors) = juniper::execute(query, None, &schema, &graphql_vars! {}, &())
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -159,7 +159,7 @@ mod as_input_argument {
|
||||||
"#;
|
"#;
|
||||||
|
|
||||||
let schema = RootNode::new(Query, EmptyMutation::new(), EmptySubscription::new());
|
let schema = RootNode::new(Query, EmptyMutation::new(), EmptySubscription::new());
|
||||||
let (res, errors) = juniper::execute(query, None, &schema, &Variables::new(), &())
|
let (res, errors) = juniper::execute(query, None, &schema, &graphql_vars! {}, &())
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -176,7 +176,7 @@ mod as_input_argument {
|
||||||
"#;
|
"#;
|
||||||
|
|
||||||
let schema = RootNode::new(Query, EmptyMutation::new(), EmptySubscription::new());
|
let schema = RootNode::new(Query, EmptyMutation::new(), EmptySubscription::new());
|
||||||
let res = juniper::execute(query, None, &schema, &Variables::new(), &()).await;
|
let res = juniper::execute(query, None, &schema, &graphql_vars! {}, &()).await;
|
||||||
|
|
||||||
assert!(res.is_err());
|
assert!(res.is_err());
|
||||||
assert!(res
|
assert!(res
|
||||||
|
@ -194,7 +194,7 @@ mod as_input_argument {
|
||||||
"#;
|
"#;
|
||||||
|
|
||||||
let schema = RootNode::new(Query, EmptyMutation::new(), EmptySubscription::new());
|
let schema = RootNode::new(Query, EmptyMutation::new(), EmptySubscription::new());
|
||||||
let res = juniper::execute(query, None, &schema, &Variables::new(), &()).await;
|
let res = juniper::execute(query, None, &schema, &graphql_vars! {}, &()).await;
|
||||||
|
|
||||||
assert!(res.is_err());
|
assert!(res.is_err());
|
||||||
assert!(res
|
assert!(res
|
||||||
|
@ -212,7 +212,7 @@ mod as_input_argument {
|
||||||
"#;
|
"#;
|
||||||
|
|
||||||
let schema = RootNode::new(Query, EmptyMutation::new(), EmptySubscription::new());
|
let schema = RootNode::new(Query, EmptyMutation::new(), EmptySubscription::new());
|
||||||
let (res, errors) = juniper::execute(query, None, &schema, &Variables::new(), &())
|
let (res, errors) = juniper::execute(query, None, &schema, &graphql_vars! {}, &())
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -229,7 +229,7 @@ mod as_input_argument {
|
||||||
"#;
|
"#;
|
||||||
|
|
||||||
let schema = RootNode::new(Query, EmptyMutation::new(), EmptySubscription::new());
|
let schema = RootNode::new(Query, EmptyMutation::new(), EmptySubscription::new());
|
||||||
let (res, errors) = juniper::execute(query, None, &schema, &Variables::new(), &())
|
let (res, errors) = juniper::execute(query, None, &schema, &graphql_vars! {}, &())
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -246,7 +246,7 @@ mod as_input_argument {
|
||||||
"#;
|
"#;
|
||||||
|
|
||||||
let schema = RootNode::new(Query, EmptyMutation::new(), EmptySubscription::new());
|
let schema = RootNode::new(Query, EmptyMutation::new(), EmptySubscription::new());
|
||||||
let (res, errors) = juniper::execute(query, None, &schema, &Variables::new(), &())
|
let (res, errors) = juniper::execute(query, None, &schema, &graphql_vars! {}, &())
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use fnv::FnvHashMap;
|
use fnv::FnvHashMap;
|
||||||
use juniper::{
|
use juniper::{
|
||||||
DefaultScalarValue, FromInputValue, GraphQLEnum, GraphQLType, InputValue, Registry,
|
graphql_input_value, DefaultScalarValue, FromInputValue, GraphQLEnum, GraphQLType, Registry,
|
||||||
ToInputValue,
|
ToInputValue,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -74,26 +74,26 @@ fn test_derived_enum() {
|
||||||
// Test no rename variant.
|
// Test no rename variant.
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
<_ as ToInputValue>::to_input_value(&NoRenameEnum::AnotherVariant),
|
<_ as ToInputValue>::to_input_value(&NoRenameEnum::AnotherVariant),
|
||||||
InputValue::scalar("AnotherVariant")
|
graphql_input_value!("AnotherVariant"),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Test Regular variant.
|
// Test Regular variant.
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
<_ as ToInputValue>::to_input_value(&SomeEnum::Regular),
|
<_ as ToInputValue>::to_input_value(&SomeEnum::Regular),
|
||||||
InputValue::scalar("REGULAR")
|
graphql_input_value!("REGULAR"),
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
FromInputValue::<DefaultScalarValue>::from_input_value(&InputValue::scalar("REGULAR")),
|
FromInputValue::<DefaultScalarValue>::from_input_value(&graphql_input_value!(REGULAR)),
|
||||||
Some(SomeEnum::Regular)
|
Some(SomeEnum::Regular),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Test FULL variant.
|
// Test FULL variant.
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
<_ as ToInputValue>::to_input_value(&SomeEnum::Full),
|
<_ as ToInputValue>::to_input_value(&SomeEnum::Full),
|
||||||
InputValue::scalar("FULL")
|
graphql_input_value!("FULL"),
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
FromInputValue::<DefaultScalarValue>::from_input_value(&InputValue::scalar("FULL")),
|
FromInputValue::<DefaultScalarValue>::from_input_value(&graphql_input_value!(FULL)),
|
||||||
Some(SomeEnum::Full)
|
Some(SomeEnum::Full)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use fnv::FnvHashMap;
|
use fnv::FnvHashMap;
|
||||||
use juniper::{
|
use juniper::{
|
||||||
marker, DefaultScalarValue, FromInputValue, GraphQLInputObject, GraphQLType, GraphQLValue,
|
graphql_input_value, marker, DefaultScalarValue, FromInputValue, GraphQLInputObject,
|
||||||
InputValue, Registry, ToInputValue,
|
GraphQLType, GraphQLValue, InputValue, Registry, ToInputValue,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(GraphQLInputObject, Debug, PartialEq)]
|
#[derive(GraphQLInputObject, Debug, PartialEq)]
|
||||||
|
@ -65,7 +65,7 @@ impl<'a> FromInputValue for &'a Fake {
|
||||||
|
|
||||||
impl<'a> ToInputValue for &'a Fake {
|
impl<'a> ToInputValue for &'a Fake {
|
||||||
fn to_input_value(&self) -> InputValue {
|
fn to_input_value(&self) -> InputValue {
|
||||||
InputValue::scalar("this is fake")
|
graphql_input_value!("this is fake")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -119,19 +119,17 @@ fn test_derived_input_object() {
|
||||||
|
|
||||||
// Test default value injection.
|
// Test default value injection.
|
||||||
|
|
||||||
let input_no_defaults: InputValue = ::serde_json::from_value(serde_json::json!({
|
let input_no_defaults = graphql_input_value!({
|
||||||
"regularField": "a",
|
"regularField": "a",
|
||||||
}))
|
});
|
||||||
.unwrap();
|
let output_no_defaults = Input::from_input_value(&input_no_defaults).unwrap();
|
||||||
|
|
||||||
let output_no_defaults: Input = FromInputValue::from_input_value(&input_no_defaults).unwrap();
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
output_no_defaults,
|
output_no_defaults,
|
||||||
Input {
|
Input {
|
||||||
regular_field: "a".into(),
|
regular_field: "a".into(),
|
||||||
c: 33,
|
c: 33,
|
||||||
other: None,
|
other: None,
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
// Test with all values supplied.
|
// Test with all values supplied.
|
||||||
|
@ -150,7 +148,7 @@ fn test_derived_input_object() {
|
||||||
regular_field: "a".into(),
|
regular_field: "a".into(),
|
||||||
c: 55,
|
c: 55,
|
||||||
other: Some(true),
|
other: Some(true),
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
// Test disable renaming
|
// Test disable renaming
|
||||||
|
@ -165,7 +163,7 @@ fn test_derived_input_object() {
|
||||||
output,
|
output,
|
||||||
NoRenameInput {
|
NoRenameInput {
|
||||||
regular_field: "hello".into(),
|
regular_field: "hello".into(),
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use juniper::{
|
use juniper::{
|
||||||
execute, graphql_object, graphql_value, EmptyMutation, EmptySubscription, GraphQLInputObject,
|
execute, graphql_object, graphql_value, graphql_vars, EmptyMutation, EmptySubscription,
|
||||||
RootNode, Value, Variables,
|
GraphQLInputObject, RootNode, Value,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub struct Query;
|
pub struct Query;
|
||||||
|
@ -93,7 +93,7 @@ async fn run_type_info_query(doc: &str) -> Value {
|
||||||
EmptySubscription::<()>::new(),
|
EmptySubscription::<()>::new(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let (result, errs) = execute(doc, None, &schema, &Variables::new(), &())
|
let (result, errs) = execute(doc, None, &schema, &graphql_vars! {}, &())
|
||||||
.await
|
.await
|
||||||
.expect("Execution failed");
|
.expect("Execution failed");
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use juniper::{
|
use juniper::{
|
||||||
execute, graphql_object, graphql_scalar, graphql_value, DefaultScalarValue, EmptyMutation,
|
execute, graphql_object, graphql_scalar, graphql_value, graphql_vars, DefaultScalarValue,
|
||||||
EmptySubscription, Object, ParseScalarResult, ParseScalarValue, RootNode, Value, Variables,
|
EmptyMutation, EmptySubscription, Object, ParseScalarResult, ParseScalarValue, RootNode, Value,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::custom_scalar::MyScalarValue;
|
use crate::custom_scalar::MyScalarValue;
|
||||||
|
@ -169,7 +169,7 @@ where
|
||||||
EmptySubscription::<()>::new(),
|
EmptySubscription::<()>::new(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let (result, errs) = execute(doc, None, &schema, &Variables::new(), &())
|
let (result, errs) = execute(doc, None, &schema, &graphql_vars! {}, &())
|
||||||
.await
|
.await
|
||||||
.expect("Execution failed");
|
.expect("Execution failed");
|
||||||
|
|
||||||
|
@ -226,7 +226,7 @@ async fn default_name_introspection() {
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
type_info.get_field_value("description"),
|
type_info.get_field_value("description"),
|
||||||
Some(&graphql_value!(None)),
|
Some(&graphql_value!(null)),
|
||||||
);
|
);
|
||||||
})
|
})
|
||||||
.await;
|
.await;
|
||||||
|
@ -250,7 +250,7 @@ async fn other_order_introspection() {
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
type_info.get_field_value("description"),
|
type_info.get_field_value("description"),
|
||||||
Some(&graphql_value!(None)),
|
Some(&graphql_value!(null)),
|
||||||
);
|
);
|
||||||
})
|
})
|
||||||
.await;
|
.await;
|
||||||
|
@ -274,7 +274,7 @@ async fn named_introspection() {
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
type_info.get_field_value("description"),
|
type_info.get_field_value("description"),
|
||||||
Some(&graphql_value!(None)),
|
Some(&graphql_value!(null)),
|
||||||
);
|
);
|
||||||
})
|
})
|
||||||
.await;
|
.await;
|
||||||
|
@ -299,7 +299,7 @@ async fn scalar_description_introspection() {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
type_info.get_field_value("description"),
|
type_info.get_field_value("description"),
|
||||||
Some(&graphql_value!(
|
Some(&graphql_value!(
|
||||||
"A sample scalar, represented as an integer"
|
"A sample scalar, represented as an integer",
|
||||||
)),
|
)),
|
||||||
);
|
);
|
||||||
})
|
})
|
||||||
|
@ -324,7 +324,7 @@ async fn generated_scalar_introspection() {
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
type_info.get_field_value("description"),
|
type_info.get_field_value("description"),
|
||||||
Some(&graphql_value!(None)),
|
Some(&graphql_value!(null)),
|
||||||
);
|
);
|
||||||
})
|
})
|
||||||
.await;
|
.await;
|
||||||
|
@ -341,7 +341,7 @@ async fn resolves_with_custom_scalar_value() {
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((graphql_value!({"withCustomScalarValue": 0}), vec![])),
|
Ok((graphql_value!({"withCustomScalarValue": 0}), vec![])),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,9 +1,9 @@
|
||||||
//! Tests for `#[graphql_object]` macro.
|
//! Tests for `#[graphql_object]` macro.
|
||||||
|
|
||||||
use juniper::{
|
use juniper::{
|
||||||
execute, graphql_object, graphql_value, DefaultScalarValue, EmptyMutation, EmptySubscription,
|
execute, graphql_object, graphql_value, graphql_vars, DefaultScalarValue, EmptyMutation,
|
||||||
Executor, FieldError, FieldResult, GraphQLInputObject, GraphQLObject, GraphQLType,
|
EmptySubscription, Executor, FieldError, FieldResult, GraphQLInputObject, GraphQLObject,
|
||||||
IntoFieldError, RootNode, ScalarValue, Variables,
|
GraphQLType, IntoFieldError, RootNode, ScalarValue,
|
||||||
};
|
};
|
||||||
|
|
||||||
fn schema<'q, C, Q>(query_root: Q) -> RootNode<'q, Q, EmptyMutation<C>, EmptySubscription<C>>
|
fn schema<'q, C, Q>(query_root: Q) -> RootNode<'q, Q, EmptyMutation<C>, EmptySubscription<C>>
|
||||||
|
@ -63,7 +63,7 @@ mod trivial {
|
||||||
let schema = schema(QueryRoot);
|
let schema = schema(QueryRoot);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((graphql_value!({"human": {"id": "human-32"}}), vec![])),
|
Ok((graphql_value!({"human": {"id": "human-32"}}), vec![])),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -79,7 +79,7 @@ mod trivial {
|
||||||
let schema = schema(QueryRoot);
|
let schema = schema(QueryRoot);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((graphql_value!({"__type": {"kind": "OBJECT"}}), vec![])),
|
Ok((graphql_value!({"__type": {"kind": "OBJECT"}}), vec![])),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -95,7 +95,7 @@ mod trivial {
|
||||||
let schema = schema(QueryRoot);
|
let schema = schema(QueryRoot);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((graphql_value!({"__type": {"name": "Human"}}), vec![])),
|
Ok((graphql_value!({"__type": {"name": "Human"}}), vec![])),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -111,8 +111,8 @@ mod trivial {
|
||||||
let schema = schema(QueryRoot);
|
let schema = schema(QueryRoot);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((graphql_value!({"__type": {"description": None}}), vec![])),
|
Ok((graphql_value!({"__type": {"description": null}}), vec![])),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -151,7 +151,7 @@ mod trivial_async {
|
||||||
let schema = schema(QueryRoot);
|
let schema = schema(QueryRoot);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((graphql_value!({"human": {"id": "human-32"}}), vec![])),
|
Ok((graphql_value!({"human": {"id": "human-32"}}), vec![])),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -167,7 +167,7 @@ mod trivial_async {
|
||||||
let schema = schema(QueryRoot);
|
let schema = schema(QueryRoot);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((graphql_value!({"__type": {"kind": "OBJECT"}}), vec![])),
|
Ok((graphql_value!({"__type": {"kind": "OBJECT"}}), vec![])),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -183,7 +183,7 @@ mod trivial_async {
|
||||||
let schema = schema(QueryRoot);
|
let schema = schema(QueryRoot);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((graphql_value!({"__type": {"name": "Human"}}), vec![])),
|
Ok((graphql_value!({"__type": {"name": "Human"}}), vec![])),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -199,8 +199,8 @@ mod trivial_async {
|
||||||
let schema = schema(QueryRoot);
|
let schema = schema(QueryRoot);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((graphql_value!({"__type": {"description": None}}), vec![])),
|
Ok((graphql_value!({"__type": {"description": null}}), vec![])),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -242,7 +242,7 @@ mod raw_method {
|
||||||
let schema = schema(QueryRoot);
|
let schema = schema(QueryRoot);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"human": {"myId": "human-32", "async": "async-32"}}),
|
graphql_value!({"human": {"myId": "human-32", "async": "async-32"}}),
|
||||||
vec![],
|
vec![],
|
||||||
|
@ -265,7 +265,7 @@ mod raw_method {
|
||||||
let schema = schema(QueryRoot);
|
let schema = schema(QueryRoot);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"__type": {
|
graphql_value!({"__type": {
|
||||||
"name": "Human",
|
"name": "Human",
|
||||||
|
@ -316,7 +316,7 @@ mod ignored_method {
|
||||||
let schema = schema(QueryRoot);
|
let schema = schema(QueryRoot);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((graphql_value!({"human": {"id": "human-32"}}), vec![])),
|
Ok((graphql_value!({"human": {"id": "human-32"}}), vec![])),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -334,7 +334,7 @@ mod ignored_method {
|
||||||
let schema = schema(QueryRoot);
|
let schema = schema(QueryRoot);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"__type": {"fields": [{"name": "id"}]}}),
|
graphql_value!({"__type": {"fields": [{"name": "id"}]}}),
|
||||||
vec![],
|
vec![],
|
||||||
|
@ -393,7 +393,7 @@ mod fallible_method {
|
||||||
let schema = schema(QueryRoot);
|
let schema = schema(QueryRoot);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"human": {"id": "human-32", "homePlanet": "earth"}}),
|
graphql_value!({"human": {"id": "human-32", "homePlanet": "earth"}}),
|
||||||
vec![],
|
vec![],
|
||||||
|
@ -422,7 +422,7 @@ mod fallible_method {
|
||||||
let schema = schema(QueryRoot);
|
let schema = schema(QueryRoot);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"__type": {
|
graphql_value!({"__type": {
|
||||||
"name": "Human",
|
"name": "Human",
|
||||||
|
@ -494,7 +494,7 @@ mod generic {
|
||||||
let schema = schema(QueryRoot);
|
let schema = schema(QueryRoot);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((graphql_value!({"human": {"id": 32}}), vec![])),
|
Ok((graphql_value!({"human": {"id": 32}}), vec![])),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -510,7 +510,7 @@ mod generic {
|
||||||
let schema = schema(QueryRoot);
|
let schema = schema(QueryRoot);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((graphql_value!({"humanString": {"id": "human-32"}}), vec![])),
|
Ok((graphql_value!({"humanString": {"id": "human-32"}}), vec![])),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -526,7 +526,7 @@ mod generic {
|
||||||
let schema = schema(QueryRoot);
|
let schema = schema(QueryRoot);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((graphql_value!({"__type": {"name": "Human"}}), vec![])),
|
Ok((graphql_value!({"__type": {"name": "Human"}}), vec![])),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -585,7 +585,7 @@ mod generic_async {
|
||||||
let schema = schema(QueryRoot);
|
let schema = schema(QueryRoot);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((graphql_value!({"human": {"id": 32}}), vec![])),
|
Ok((graphql_value!({"human": {"id": 32}}), vec![])),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -601,7 +601,7 @@ mod generic_async {
|
||||||
let schema = schema(QueryRoot);
|
let schema = schema(QueryRoot);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((graphql_value!({"humanString": {"id": "human-32"}}), vec![])),
|
Ok((graphql_value!({"humanString": {"id": "human-32"}}), vec![])),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -617,7 +617,7 @@ mod generic_async {
|
||||||
let schema = schema(QueryRoot);
|
let schema = schema(QueryRoot);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((graphql_value!({"__type": {"name": "Human"}}), vec![])),
|
Ok((graphql_value!({"__type": {"name": "Human"}}), vec![])),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -685,7 +685,7 @@ mod generic_lifetime_async {
|
||||||
let schema = schema(QueryRoot("mars".into()));
|
let schema = schema(QueryRoot("mars".into()));
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"human": {"id": 32, "planet": "earth"}}),
|
graphql_value!({"human": {"id": 32, "planet": "earth"}}),
|
||||||
vec![],
|
vec![],
|
||||||
|
@ -705,7 +705,7 @@ mod generic_lifetime_async {
|
||||||
let schema = schema(QueryRoot("mars".into()));
|
let schema = schema(QueryRoot("mars".into()));
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"humanString": {"id": "mars", "planet": "mars"}}),
|
graphql_value!({"humanString": {"id": "mars", "planet": "mars"}}),
|
||||||
vec![],
|
vec![],
|
||||||
|
@ -724,7 +724,7 @@ mod generic_lifetime_async {
|
||||||
let schema = schema(QueryRoot("mars".into()));
|
let schema = schema(QueryRoot("mars".into()));
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((graphql_value!({"__type": {"name": "Human"}}), vec![])),
|
Ok((graphql_value!({"__type": {"name": "Human"}}), vec![])),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -837,7 +837,7 @@ mod nested_generic_lifetime_async {
|
||||||
let schema = schema(QueryRoot("mars".into()));
|
let schema = schema(QueryRoot("mars".into()));
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"human": {
|
graphql_value!({"human": {
|
||||||
"id": 32,
|
"id": 32,
|
||||||
|
@ -868,7 +868,7 @@ mod nested_generic_lifetime_async {
|
||||||
let schema = schema(QueryRoot("mars".into()));
|
let schema = schema(QueryRoot("mars".into()));
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"humanString": {
|
graphql_value!({"humanString": {
|
||||||
"id": "mars",
|
"id": "mars",
|
||||||
|
@ -899,7 +899,7 @@ mod nested_generic_lifetime_async {
|
||||||
|
|
||||||
let expected_name: &str = *object;
|
let expected_name: &str = *object;
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(&doc, None, &schema, &Variables::new(), &()).await,
|
execute(&doc, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((graphql_value!({"__type": {"name": expected_name}}), vec![])),
|
Ok((graphql_value!({"__type": {"name": expected_name}}), vec![])),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -943,7 +943,7 @@ mod argument {
|
||||||
let schema = schema(QueryRoot);
|
let schema = schema(QueryRoot);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"human": {"id": "human-32", "homePlanet": "earth,None"}}),
|
graphql_value!({"human": {"id": "human-32", "homePlanet": "earth,None"}}),
|
||||||
vec![],
|
vec![],
|
||||||
|
@ -967,7 +967,7 @@ mod argument {
|
||||||
let schema = schema(QueryRoot);
|
let schema = schema(QueryRoot);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"__type": {"fields": [
|
graphql_value!({"__type": {"fields": [
|
||||||
{"name": "id", "args": [{"name": "arg"}]},
|
{"name": "id", "args": [{"name": "arg"}]},
|
||||||
|
@ -993,11 +993,11 @@ mod argument {
|
||||||
let schema = schema(QueryRoot);
|
let schema = schema(QueryRoot);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"__type": {"fields": [
|
graphql_value!({"__type": {"fields": [
|
||||||
{"args": [{"description": None}]},
|
{"args": [{"description": null}]},
|
||||||
{"args": [{"description": None}, {"description": None}]},
|
{"args": [{"description": null}, {"description": null}]},
|
||||||
]}}),
|
]}}),
|
||||||
vec![],
|
vec![],
|
||||||
)),
|
)),
|
||||||
|
@ -1019,11 +1019,11 @@ mod argument {
|
||||||
let schema = schema(QueryRoot);
|
let schema = schema(QueryRoot);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"__type": {"fields": [
|
graphql_value!({"__type": {"fields": [
|
||||||
{"args": [{"defaultValue": None}]},
|
{"args": [{"defaultValue": null}]},
|
||||||
{"args": [{"defaultValue": None}, {"defaultValue": None}]},
|
{"args": [{"defaultValue": null}, {"defaultValue": null}]},
|
||||||
]}}),
|
]}}),
|
||||||
vec![],
|
vec![],
|
||||||
)),
|
)),
|
||||||
|
@ -1082,7 +1082,7 @@ mod default_argument {
|
||||||
let expected: &str = *expected;
|
let expected: &str = *expected;
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(*input, None, &schema, &Variables::new(), &()).await,
|
execute(*input, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((graphql_value!({"human": {"id": expected}}), vec![])),
|
Ok((graphql_value!({"human": {"id": expected}}), vec![])),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1099,7 +1099,7 @@ mod default_argument {
|
||||||
let expected: i32 = *expected;
|
let expected: i32 = *expected;
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(*input, None, &schema, &Variables::new(), &()).await,
|
execute(*input, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((graphql_value!({"human": {"info": expected}}), vec![])),
|
Ok((graphql_value!({"human": {"info": expected}}), vec![])),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1127,27 +1127,27 @@ mod default_argument {
|
||||||
let schema = schema(QueryRoot);
|
let schema = schema(QueryRoot);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"__type": {"fields": [{
|
graphql_value!({"__type": {"fields": [{
|
||||||
"args": [{
|
"args": [{
|
||||||
"name": "arg1",
|
"name": "arg1",
|
||||||
"defaultValue": "0",
|
"defaultValue": "0",
|
||||||
"type": {"name": "Int", "ofType": None},
|
"type": {"name": "Int", "ofType": null},
|
||||||
}, {
|
}, {
|
||||||
"name": "arg2",
|
"name": "arg2",
|
||||||
"defaultValue": r#""second""#,
|
"defaultValue": r#""second""#,
|
||||||
"type": {"name": "String", "ofType": None},
|
"type": {"name": "String", "ofType": null},
|
||||||
}, {
|
}, {
|
||||||
"name": "arg3",
|
"name": "arg3",
|
||||||
"defaultValue": "true",
|
"defaultValue": "true",
|
||||||
"type": {"name": "Boolean", "ofType": None},
|
"type": {"name": "Boolean", "ofType": null},
|
||||||
}],
|
}],
|
||||||
}, {
|
}, {
|
||||||
"args": [{
|
"args": [{
|
||||||
"name": "coord",
|
"name": "coord",
|
||||||
"defaultValue": "{x: 1}",
|
"defaultValue": "{x: 1}",
|
||||||
"type": {"name": "Point", "ofType": None},
|
"type": {"name": "Point", "ofType": null},
|
||||||
}],
|
}],
|
||||||
}]}}),
|
}]}}),
|
||||||
vec![],
|
vec![],
|
||||||
|
@ -1193,7 +1193,7 @@ mod description_from_doc_comment {
|
||||||
let schema = schema(QueryRoot);
|
let schema = schema(QueryRoot);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"__type": {
|
graphql_value!({"__type": {
|
||||||
"description": "Rust docs.",
|
"description": "Rust docs.",
|
||||||
|
@ -1247,7 +1247,7 @@ mod deprecation_from_attr {
|
||||||
let schema = schema(QueryRoot);
|
let schema = schema(QueryRoot);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((graphql_value!({"human": {"id": "human-32"}}), vec![])),
|
Ok((graphql_value!({"human": {"id": "human-32"}}), vec![])),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1264,7 +1264,7 @@ mod deprecation_from_attr {
|
||||||
let schema = schema(QueryRoot);
|
let schema = schema(QueryRoot);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((graphql_value!({"human": {"a": "a", "b": "b"}}), vec![])),
|
Ok((graphql_value!({"human": {"a": "a", "b": "b"}}), vec![])),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1283,7 +1283,7 @@ mod deprecation_from_attr {
|
||||||
let schema = schema(QueryRoot);
|
let schema = schema(QueryRoot);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"__type": {"fields": [
|
graphql_value!({"__type": {"fields": [
|
||||||
{"name": "id", "isDeprecated": false},
|
{"name": "id", "isDeprecated": false},
|
||||||
|
@ -1309,11 +1309,11 @@ mod deprecation_from_attr {
|
||||||
let schema = schema(QueryRoot);
|
let schema = schema(QueryRoot);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"__type": {"fields": [
|
graphql_value!({"__type": {"fields": [
|
||||||
{"name": "id", "deprecationReason": None},
|
{"name": "id", "deprecationReason": null},
|
||||||
{"name": "a", "deprecationReason": None},
|
{"name": "a", "deprecationReason": null},
|
||||||
{"name": "b", "deprecationReason": "Use `id`."},
|
{"name": "b", "deprecationReason": "Use `id`."},
|
||||||
]}}),
|
]}}),
|
||||||
vec![],
|
vec![],
|
||||||
|
@ -1372,7 +1372,7 @@ mod explicit_name_description_and_deprecation {
|
||||||
let schema = schema(QueryRoot);
|
let schema = schema(QueryRoot);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"human": {"myId": "human-32", "a": "a", "b": "b"}}),
|
graphql_value!({"human": {"myId": "human-32", "a": "a", "b": "b"}}),
|
||||||
vec![],
|
vec![],
|
||||||
|
@ -1397,7 +1397,7 @@ mod explicit_name_description_and_deprecation {
|
||||||
let schema = schema(QueryRoot);
|
let schema = schema(QueryRoot);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"__type": {
|
graphql_value!({"__type": {
|
||||||
"name": "MyHuman",
|
"name": "MyHuman",
|
||||||
|
@ -1430,7 +1430,7 @@ mod explicit_name_description_and_deprecation {
|
||||||
let schema = schema(QueryRoot);
|
let schema = schema(QueryRoot);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"__type": {
|
graphql_value!({"__type": {
|
||||||
"description": "My human.",
|
"description": "My human.",
|
||||||
|
@ -1440,11 +1440,11 @@ mod explicit_name_description_and_deprecation {
|
||||||
"args": [{"description": "My argument."}],
|
"args": [{"description": "My argument."}],
|
||||||
}, {
|
}, {
|
||||||
"name": "a",
|
"name": "a",
|
||||||
"description": None,
|
"description": null,
|
||||||
"args": [],
|
"args": [],
|
||||||
}, {
|
}, {
|
||||||
"name": "b",
|
"name": "b",
|
||||||
"description": None,
|
"description": null,
|
||||||
"args": [],
|
"args": [],
|
||||||
}],
|
}],
|
||||||
}}),
|
}}),
|
||||||
|
@ -1468,7 +1468,7 @@ mod explicit_name_description_and_deprecation {
|
||||||
let schema = schema(QueryRoot);
|
let schema = schema(QueryRoot);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"__type": {
|
graphql_value!({"__type": {
|
||||||
"fields": [{
|
"fields": [{
|
||||||
|
@ -1478,11 +1478,11 @@ mod explicit_name_description_and_deprecation {
|
||||||
}, {
|
}, {
|
||||||
"name": "a",
|
"name": "a",
|
||||||
"isDeprecated": true,
|
"isDeprecated": true,
|
||||||
"deprecationReason": None,
|
"deprecationReason": null,
|
||||||
}, {
|
}, {
|
||||||
"name": "b",
|
"name": "b",
|
||||||
"isDeprecated": false,
|
"isDeprecated": false,
|
||||||
"deprecationReason": None,
|
"deprecationReason": null,
|
||||||
}],
|
}],
|
||||||
}}),
|
}}),
|
||||||
vec![],
|
vec![],
|
||||||
|
@ -1533,7 +1533,7 @@ mod renamed_all_fields_and_args {
|
||||||
let schema = schema(QueryRoot);
|
let schema = schema(QueryRoot);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"human": {
|
graphql_value!({"human": {
|
||||||
"id": "human-32",
|
"id": "human-32",
|
||||||
|
@ -1561,7 +1561,7 @@ mod renamed_all_fields_and_args {
|
||||||
let schema = schema(QueryRoot);
|
let schema = schema(QueryRoot);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"__type": {"fields": [
|
graphql_value!({"__type": {"fields": [
|
||||||
{"name": "id", "args": []},
|
{"name": "id", "args": []},
|
||||||
|
@ -1611,7 +1611,7 @@ mod explicit_scalar {
|
||||||
let schema = schema(QueryRoot);
|
let schema = schema(QueryRoot);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"human": {"id": "human-32", "homePlanet": "earth"}}),
|
graphql_value!({"human": {"id": "human-32", "homePlanet": "earth"}}),
|
||||||
vec![],
|
vec![],
|
||||||
|
@ -1659,7 +1659,7 @@ mod custom_scalar {
|
||||||
let schema = schema_with_scalar::<MyScalarValue, _, _>(QueryRoot);
|
let schema = schema_with_scalar::<MyScalarValue, _, _>(QueryRoot);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"human": {"id": "human-32", "homePlanet": "earth"}}),
|
graphql_value!({"human": {"id": "human-32", "homePlanet": "earth"}}),
|
||||||
vec![],
|
vec![],
|
||||||
|
@ -1709,7 +1709,7 @@ mod explicit_generic_scalar {
|
||||||
let schema = schema(QueryRoot);
|
let schema = schema(QueryRoot);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"human": {
|
graphql_value!({"human": {
|
||||||
"id": "human-32",
|
"id": "human-32",
|
||||||
|
@ -1760,7 +1760,7 @@ mod bounded_generic_scalar {
|
||||||
let schema = schema(QueryRoot);
|
let schema = schema(QueryRoot);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"human": {
|
graphql_value!({"human": {
|
||||||
"id": "human-32",
|
"id": "human-32",
|
||||||
|
@ -1819,7 +1819,7 @@ mod explicit_custom_context {
|
||||||
let ctx = CustomContext("ctx!".into());
|
let ctx = CustomContext("ctx!".into());
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &ctx).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &ctx).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"human": {
|
graphql_value!({"human": {
|
||||||
"id": "ctx!",
|
"id": "ctx!",
|
||||||
|
@ -1879,7 +1879,7 @@ mod inferred_custom_context_from_field {
|
||||||
let ctx = CustomContext("ctx!".into());
|
let ctx = CustomContext("ctx!".into());
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &ctx).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &ctx).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"human": {
|
graphql_value!({"human": {
|
||||||
"id": "ctx!",
|
"id": "ctx!",
|
||||||
|
@ -1943,7 +1943,7 @@ mod executor {
|
||||||
let schema = schema(QueryRoot);
|
let schema = schema(QueryRoot);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"human": {
|
graphql_value!({"human": {
|
||||||
"id": "id",
|
"id": "id",
|
||||||
|
@ -1971,7 +1971,7 @@ mod executor {
|
||||||
let schema = schema(QueryRoot);
|
let schema = schema(QueryRoot);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"__type": {"fields": [
|
graphql_value!({"__type": {"fields": [
|
||||||
{"name": "id", "args": []},
|
{"name": "id", "args": []},
|
||||||
|
@ -2052,7 +2052,7 @@ mod switched_context {
|
||||||
let ctx = CustomContext;
|
let ctx = CustomContext;
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &ctx).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &ctx).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"human": {
|
graphql_value!({"human": {
|
||||||
"switchAlways": {"id": 0},
|
"switchAlways": {"id": 0},
|
||||||
|
@ -2086,13 +2086,13 @@ mod switched_context {
|
||||||
let ctx = CustomContext;
|
let ctx = CustomContext;
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &ctx).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &ctx).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"__type": {"fields": [{
|
graphql_value!({"__type": {"fields": [{
|
||||||
"name": "switchAlways",
|
"name": "switchAlways",
|
||||||
"type": {
|
"type": {
|
||||||
"kind": "NON_NULL",
|
"kind": "NON_NULL",
|
||||||
"name": None,
|
"name": null,
|
||||||
"ofType": {"name": "Droid"},
|
"ofType": {"name": "Droid"},
|
||||||
},
|
},
|
||||||
}, {
|
}, {
|
||||||
|
@ -2100,13 +2100,13 @@ mod switched_context {
|
||||||
"type": {
|
"type": {
|
||||||
"kind": "OBJECT",
|
"kind": "OBJECT",
|
||||||
"name": "Droid",
|
"name": "Droid",
|
||||||
"ofType": None,
|
"ofType": null,
|
||||||
},
|
},
|
||||||
}, {
|
}, {
|
||||||
"name": "switchRes",
|
"name": "switchRes",
|
||||||
"type": {
|
"type": {
|
||||||
"kind": "NON_NULL",
|
"kind": "NON_NULL",
|
||||||
"name": None,
|
"name": null,
|
||||||
"ofType": {"name": "Droid"},
|
"ofType": {"name": "Droid"},
|
||||||
},
|
},
|
||||||
}, {
|
}, {
|
||||||
|
@ -2114,7 +2114,7 @@ mod switched_context {
|
||||||
"type": {
|
"type": {
|
||||||
"kind": "OBJECT",
|
"kind": "OBJECT",
|
||||||
"name": "Droid",
|
"name": "Droid",
|
||||||
"ofType": None,
|
"ofType": null,
|
||||||
},
|
},
|
||||||
}]}}),
|
}]}}),
|
||||||
vec![],
|
vec![],
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
//! Tests for `#[derive(GraphQLObject)]` macro.
|
//! Tests for `#[derive(GraphQLObject)]` macro.
|
||||||
|
|
||||||
use juniper::{
|
use juniper::{
|
||||||
execute, graphql_object, graphql_value, DefaultScalarValue, EmptyMutation, EmptySubscription,
|
execute, graphql_object, graphql_value, graphql_vars, DefaultScalarValue, EmptyMutation,
|
||||||
GraphQLObject, GraphQLType, RootNode, ScalarValue, Variables,
|
EmptySubscription, GraphQLObject, GraphQLType, RootNode, ScalarValue,
|
||||||
};
|
};
|
||||||
|
|
||||||
fn schema<'q, C, Q>(query_root: Q) -> RootNode<'q, Q, EmptyMutation<C>, EmptySubscription<C>>
|
fn schema<'q, C, Q>(query_root: Q) -> RootNode<'q, Q, EmptyMutation<C>, EmptySubscription<C>>
|
||||||
|
@ -58,7 +58,7 @@ mod trivial {
|
||||||
let schema = schema(QueryRoot);
|
let schema = schema(QueryRoot);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((graphql_value!({"human": {"id": "human-32"}}), vec![])),
|
Ok((graphql_value!({"human": {"id": "human-32"}}), vec![])),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -74,7 +74,7 @@ mod trivial {
|
||||||
let schema = schema(QueryRoot);
|
let schema = schema(QueryRoot);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((graphql_value!({"__type": {"kind": "OBJECT"}}), vec![])),
|
Ok((graphql_value!({"__type": {"kind": "OBJECT"}}), vec![])),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -90,7 +90,7 @@ mod trivial {
|
||||||
let schema = schema(QueryRoot);
|
let schema = schema(QueryRoot);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((graphql_value!({"__type": {"name": "Human"}}), vec![])),
|
Ok((graphql_value!({"__type": {"name": "Human"}}), vec![])),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -106,8 +106,8 @@ mod trivial {
|
||||||
let schema = schema(QueryRoot);
|
let schema = schema(QueryRoot);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((graphql_value!({"__type": {"description": None}}), vec![])),
|
Ok((graphql_value!({"__type": {"description": null}}), vec![])),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -142,7 +142,7 @@ mod raw_field {
|
||||||
let schema = schema(QueryRoot);
|
let schema = schema(QueryRoot);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((graphql_value!({"human": {"async": "human-32"}}), vec![])),
|
Ok((graphql_value!({"human": {"async": "human-32"}}), vec![])),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -162,7 +162,7 @@ mod raw_field {
|
||||||
let schema = schema(QueryRoot);
|
let schema = schema(QueryRoot);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"__type": {
|
graphql_value!({"__type": {
|
||||||
"name": "Human",
|
"name": "Human",
|
||||||
|
@ -209,7 +209,7 @@ mod ignored_field {
|
||||||
let schema = schema(QueryRoot);
|
let schema = schema(QueryRoot);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((graphql_value!({"human": {"id": "human-32"}}), vec![])),
|
Ok((graphql_value!({"human": {"id": "human-32"}}), vec![])),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -227,7 +227,7 @@ mod ignored_field {
|
||||||
let schema = schema(QueryRoot);
|
let schema = schema(QueryRoot);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"__type": {"fields": [{"name": "id"}]}}),
|
graphql_value!({"__type": {"fields": [{"name": "id"}]}}),
|
||||||
vec![],
|
vec![],
|
||||||
|
@ -269,7 +269,7 @@ mod generic {
|
||||||
let schema = schema(QueryRoot);
|
let schema = schema(QueryRoot);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((graphql_value!({"human": {"id": "human-32"}}), vec![])),
|
Ok((graphql_value!({"human": {"id": "human-32"}}), vec![])),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -285,7 +285,7 @@ mod generic {
|
||||||
let schema = schema(QueryRoot);
|
let schema = schema(QueryRoot);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((graphql_value!({"__type": {"name": "Human"}}), vec![])),
|
Ok((graphql_value!({"__type": {"name": "Human"}}), vec![])),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -324,7 +324,7 @@ mod generic_lifetime {
|
||||||
let schema = schema(QueryRoot("mars".into()));
|
let schema = schema(QueryRoot("mars".into()));
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((graphql_value!({"human": {"id": "mars"}}), vec![])),
|
Ok((graphql_value!({"human": {"id": "mars"}}), vec![])),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -340,7 +340,7 @@ mod generic_lifetime {
|
||||||
let schema = schema(QueryRoot("mars".into()));
|
let schema = schema(QueryRoot("mars".into()));
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((graphql_value!({"__type": {"name": "Human"}}), vec![])),
|
Ok((graphql_value!({"__type": {"name": "Human"}}), vec![])),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -391,7 +391,7 @@ mod nested_generic_lifetime_async {
|
||||||
let schema = schema(QueryRoot("mars".into()));
|
let schema = schema(QueryRoot("mars".into()));
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"human": {
|
graphql_value!({"human": {
|
||||||
"id": 32,
|
"id": 32,
|
||||||
|
@ -420,7 +420,7 @@ mod nested_generic_lifetime_async {
|
||||||
|
|
||||||
let expected_name: &str = *object;
|
let expected_name: &str = *object;
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(&doc, None, &schema, &Variables::new(), &()).await,
|
execute(&doc, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((graphql_value!({"__type": {"name": expected_name}}), vec![])),
|
Ok((graphql_value!({"__type": {"name": expected_name}}), vec![])),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -464,7 +464,7 @@ mod description_from_doc_comment {
|
||||||
let schema = schema(QueryRoot);
|
let schema = schema(QueryRoot);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"__type": {
|
graphql_value!({"__type": {
|
||||||
"description": "Rust docs. Here.",
|
"description": "Rust docs. Here.",
|
||||||
|
@ -513,7 +513,7 @@ mod deprecation_from_attr {
|
||||||
let schema = schema(QueryRoot);
|
let schema = schema(QueryRoot);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((graphql_value!({"human": {"id": "human-32"}}), vec![])),
|
Ok((graphql_value!({"human": {"id": "human-32"}}), vec![])),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -530,7 +530,7 @@ mod deprecation_from_attr {
|
||||||
let schema = schema(QueryRoot);
|
let schema = schema(QueryRoot);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((graphql_value!({"human": {"a": "a", "b": "b"}}), vec![])),
|
Ok((graphql_value!({"human": {"a": "a", "b": "b"}}), vec![])),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -549,7 +549,7 @@ mod deprecation_from_attr {
|
||||||
let schema = schema(QueryRoot);
|
let schema = schema(QueryRoot);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"__type": {"fields": [
|
graphql_value!({"__type": {"fields": [
|
||||||
{"name": "id", "isDeprecated": false},
|
{"name": "id", "isDeprecated": false},
|
||||||
|
@ -575,11 +575,11 @@ mod deprecation_from_attr {
|
||||||
let schema = schema(QueryRoot);
|
let schema = schema(QueryRoot);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"__type": {"fields": [
|
graphql_value!({"__type": {"fields": [
|
||||||
{"name": "id", "deprecationReason": None},
|
{"name": "id", "deprecationReason": null},
|
||||||
{"name": "a", "deprecationReason": None},
|
{"name": "a", "deprecationReason": null},
|
||||||
{"name": "b", "deprecationReason": "Use `id`."},
|
{"name": "b", "deprecationReason": "Use `id`."},
|
||||||
]}}),
|
]}}),
|
||||||
vec![],
|
vec![],
|
||||||
|
@ -632,7 +632,7 @@ mod explicit_name_description_and_deprecation {
|
||||||
let schema = schema(QueryRoot);
|
let schema = schema(QueryRoot);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"human": {"myId": "human-32", "a": "a", "b": "b"}}),
|
graphql_value!({"human": {"myId": "human-32", "a": "a", "b": "b"}}),
|
||||||
vec![],
|
vec![],
|
||||||
|
@ -654,7 +654,7 @@ mod explicit_name_description_and_deprecation {
|
||||||
let schema = schema(QueryRoot);
|
let schema = schema(QueryRoot);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"__type": {
|
graphql_value!({"__type": {
|
||||||
"name": "MyHuman",
|
"name": "MyHuman",
|
||||||
|
@ -684,7 +684,7 @@ mod explicit_name_description_and_deprecation {
|
||||||
let schema = schema(QueryRoot);
|
let schema = schema(QueryRoot);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"__type": {
|
graphql_value!({"__type": {
|
||||||
"description": "My human.",
|
"description": "My human.",
|
||||||
|
@ -693,10 +693,10 @@ mod explicit_name_description_and_deprecation {
|
||||||
"description": "My human ID.",
|
"description": "My human ID.",
|
||||||
}, {
|
}, {
|
||||||
"name": "a",
|
"name": "a",
|
||||||
"description": None,
|
"description": null,
|
||||||
}, {
|
}, {
|
||||||
"name": "b",
|
"name": "b",
|
||||||
"description": None,
|
"description": null,
|
||||||
}],
|
}],
|
||||||
}}),
|
}}),
|
||||||
vec![],
|
vec![],
|
||||||
|
@ -719,7 +719,7 @@ mod explicit_name_description_and_deprecation {
|
||||||
let schema = schema(QueryRoot);
|
let schema = schema(QueryRoot);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"__type": {
|
graphql_value!({"__type": {
|
||||||
"fields": [{
|
"fields": [{
|
||||||
|
@ -729,11 +729,11 @@ mod explicit_name_description_and_deprecation {
|
||||||
}, {
|
}, {
|
||||||
"name": "a",
|
"name": "a",
|
||||||
"isDeprecated": true,
|
"isDeprecated": true,
|
||||||
"deprecationReason": None,
|
"deprecationReason": null,
|
||||||
}, {
|
}, {
|
||||||
"name": "b",
|
"name": "b",
|
||||||
"isDeprecated": false,
|
"isDeprecated": false,
|
||||||
"deprecationReason": None,
|
"deprecationReason": null,
|
||||||
}],
|
}],
|
||||||
}}),
|
}}),
|
||||||
vec![],
|
vec![],
|
||||||
|
@ -779,7 +779,7 @@ mod renamed_all_fields {
|
||||||
let schema = schema(QueryRoot);
|
let schema = schema(QueryRoot);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"human": {
|
graphql_value!({"human": {
|
||||||
"id": "human-32",
|
"id": "human-32",
|
||||||
|
@ -804,7 +804,7 @@ mod renamed_all_fields {
|
||||||
let schema = schema(QueryRoot);
|
let schema = schema(QueryRoot);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"__type": {"fields": [
|
graphql_value!({"__type": {"fields": [
|
||||||
{"name": "id"},
|
{"name": "id"},
|
||||||
|
@ -846,7 +846,7 @@ mod explicit_scalar {
|
||||||
let schema = schema(QueryRoot);
|
let schema = schema(QueryRoot);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((graphql_value!({"human": {"id": "human-32"}}), vec![])),
|
Ok((graphql_value!({"human": {"id": "human-32"}}), vec![])),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -883,7 +883,7 @@ mod custom_scalar {
|
||||||
let schema = schema_with_scalar::<MyScalarValue, _, _>(QueryRoot);
|
let schema = schema_with_scalar::<MyScalarValue, _, _>(QueryRoot);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((graphql_value!({"human": {"id": "human-32"}}), vec![])),
|
Ok((graphql_value!({"human": {"id": "human-32"}}), vec![])),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -925,7 +925,7 @@ mod explicit_generic_scalar {
|
||||||
let schema = schema(QueryRoot);
|
let schema = schema(QueryRoot);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((graphql_value!({"human": {"id": "human-32"}}), vec![])),
|
Ok((graphql_value!({"human": {"id": "human-32"}}), vec![])),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -960,7 +960,7 @@ mod bounded_generic_scalar {
|
||||||
let schema = schema(QueryRoot);
|
let schema = schema(QueryRoot);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((graphql_value!({"human": {"id": "human-32"}}), vec![])),
|
Ok((graphql_value!({"human": {"id": "human-32"}}), vec![])),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1000,7 +1000,7 @@ mod explicit_custom_context {
|
||||||
let ctx = CustomContext("ctx!".into());
|
let ctx = CustomContext("ctx!".into());
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &ctx).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &ctx).await,
|
||||||
Ok((graphql_value!({"human": {"id": "ctx!"}}), vec![])),
|
Ok((graphql_value!({"human": {"id": "ctx!"}}), vec![])),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use fnv::FnvHashMap;
|
use fnv::FnvHashMap;
|
||||||
use juniper::{
|
use juniper::{
|
||||||
graphql_object, DefaultScalarValue, FromInputValue, GraphQLObject, GraphQLScalarValue,
|
graphql_input_value, graphql_object, DefaultScalarValue, FromInputValue, GraphQLObject,
|
||||||
GraphQLType, InputValue, Registry, ToInputValue,
|
GraphQLScalarValue, GraphQLType, InputValue, Registry, ToInputValue,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(GraphQLScalarValue, Debug, Eq, PartialEq)]
|
#[derive(GraphQLScalarValue, Debug, Eq, PartialEq)]
|
||||||
|
@ -50,7 +50,7 @@ fn test_scalar_value_simple() {
|
||||||
|
|
||||||
let id = UserId("111".into());
|
let id = UserId("111".into());
|
||||||
let output = ToInputValue::<DefaultScalarValue>::to_input_value(&id);
|
let output = ToInputValue::<DefaultScalarValue>::to_input_value(&id);
|
||||||
assert_eq!(output, InputValue::scalar("111"),);
|
assert_eq!(output, graphql_input_value!("111"));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -71,7 +71,7 @@ fn test_scalar_value_custom() {
|
||||||
|
|
||||||
let id = CustomUserId("111".into());
|
let id = CustomUserId("111".into());
|
||||||
let output = ToInputValue::<DefaultScalarValue>::to_input_value(&id);
|
let output = ToInputValue::<DefaultScalarValue>::to_input_value(&id);
|
||||||
assert_eq!(output, InputValue::scalar("111"),);
|
assert_eq!(output, graphql_input_value!("111"));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
@ -4,9 +4,9 @@ use std::pin::Pin;
|
||||||
|
|
||||||
use futures::{future, stream, FutureExt as _};
|
use futures::{future, stream, FutureExt as _};
|
||||||
use juniper::{
|
use juniper::{
|
||||||
execute, graphql_object, graphql_subscription, graphql_value, resolve_into_stream,
|
execute, graphql_object, graphql_subscription, graphql_value, graphql_vars,
|
||||||
DefaultScalarValue, EmptyMutation, Executor, FieldError, FieldResult, GraphQLInputObject,
|
resolve_into_stream, DefaultScalarValue, EmptyMutation, Executor, FieldError, FieldResult,
|
||||||
GraphQLType, IntoFieldError, RootNode, ScalarValue, Variables,
|
GraphQLInputObject, GraphQLType, IntoFieldError, RootNode, ScalarValue,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::util::extract_next;
|
use crate::util::extract_next;
|
||||||
|
@ -71,7 +71,7 @@ mod trivial {
|
||||||
let schema = schema(Query, Human);
|
let schema = schema(Query, Human);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
resolve_into_stream(DOC, None, &schema, &Variables::new(), &())
|
resolve_into_stream(DOC, None, &schema, &graphql_vars! {}, &())
|
||||||
.then(|s| extract_next(s))
|
.then(|s| extract_next(s))
|
||||||
.await,
|
.await,
|
||||||
Ok((graphql_value!({"id": "human-32"}), vec![])),
|
Ok((graphql_value!({"id": "human-32"}), vec![])),
|
||||||
|
@ -87,7 +87,7 @@ mod trivial {
|
||||||
let schema = schema(Query, Human);
|
let schema = schema(Query, Human);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
resolve_into_stream(DOC, None, &schema, &Variables::new(), &())
|
resolve_into_stream(DOC, None, &schema, &graphql_vars! {}, &())
|
||||||
.then(|s| extract_next(s))
|
.then(|s| extract_next(s))
|
||||||
.await,
|
.await,
|
||||||
Ok((graphql_value!({"homePlanet": "earth"}), vec![])),
|
Ok((graphql_value!({"homePlanet": "earth"}), vec![])),
|
||||||
|
@ -105,7 +105,7 @@ mod trivial {
|
||||||
let schema = schema(Query, Human);
|
let schema = schema(Query, Human);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((graphql_value!({"__type": {"kind": "OBJECT"}}), vec![])),
|
Ok((graphql_value!({"__type": {"kind": "OBJECT"}}), vec![])),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -121,7 +121,7 @@ mod trivial {
|
||||||
let schema = schema(Query, Human);
|
let schema = schema(Query, Human);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((graphql_value!({"__type": {"name": "Human"}}), vec![])),
|
Ok((graphql_value!({"__type": {"name": "Human"}}), vec![])),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -137,8 +137,8 @@ mod trivial {
|
||||||
let schema = schema(Query, Human);
|
let schema = schema(Query, Human);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((graphql_value!({"__type": {"description": None}}), vec![])),
|
Ok((graphql_value!({"__type": {"description": null}}), vec![])),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -168,7 +168,7 @@ mod raw_method {
|
||||||
let schema = schema(Query, Human);
|
let schema = schema(Query, Human);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
resolve_into_stream(DOC, None, &schema, &Variables::new(), &())
|
resolve_into_stream(DOC, None, &schema, &graphql_vars! {}, &())
|
||||||
.then(|s| extract_next(s))
|
.then(|s| extract_next(s))
|
||||||
.await,
|
.await,
|
||||||
Ok((graphql_value!({"myId": "human-32"}), vec![])),
|
Ok((graphql_value!({"myId": "human-32"}), vec![])),
|
||||||
|
@ -184,7 +184,7 @@ mod raw_method {
|
||||||
let schema = schema(Query, Human);
|
let schema = schema(Query, Human);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
resolve_into_stream(DOC, None, &schema, &Variables::new(), &())
|
resolve_into_stream(DOC, None, &schema, &graphql_vars! {}, &())
|
||||||
.then(|s| extract_next(s))
|
.then(|s| extract_next(s))
|
||||||
.await,
|
.await,
|
||||||
Ok((graphql_value!({"async": "async-32"}), vec![])),
|
Ok((graphql_value!({"async": "async-32"}), vec![])),
|
||||||
|
@ -206,7 +206,7 @@ mod raw_method {
|
||||||
let schema = schema(Query, Human);
|
let schema = schema(Query, Human);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"__type": {
|
graphql_value!({"__type": {
|
||||||
"name": "Human",
|
"name": "Human",
|
||||||
|
@ -246,7 +246,7 @@ mod ignored_method {
|
||||||
let schema = schema(Query, Human);
|
let schema = schema(Query, Human);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
resolve_into_stream(DOC, None, &schema, &Variables::new(), &())
|
resolve_into_stream(DOC, None, &schema, &graphql_vars! {}, &())
|
||||||
.then(|s| extract_next(s))
|
.then(|s| extract_next(s))
|
||||||
.await,
|
.await,
|
||||||
Ok((graphql_value!({"id": "human-32"}), vec![])),
|
Ok((graphql_value!({"id": "human-32"}), vec![])),
|
||||||
|
@ -266,7 +266,7 @@ mod ignored_method {
|
||||||
let schema = schema(Query, Human);
|
let schema = schema(Query, Human);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"__type": {"fields": [{"name": "id"}]}}),
|
graphql_value!({"__type": {"fields": [{"name": "id"}]}}),
|
||||||
vec![],
|
vec![],
|
||||||
|
@ -308,7 +308,7 @@ mod fallible_method {
|
||||||
let schema = schema(Query, Human);
|
let schema = schema(Query, Human);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
resolve_into_stream(DOC, None, &schema, &Variables::new(), &())
|
resolve_into_stream(DOC, None, &schema, &graphql_vars! {}, &())
|
||||||
.then(|s| extract_next(s))
|
.then(|s| extract_next(s))
|
||||||
.await,
|
.await,
|
||||||
Ok((graphql_value!({"id": "human-32"}), vec![])),
|
Ok((graphql_value!({"id": "human-32"}), vec![])),
|
||||||
|
@ -324,7 +324,7 @@ mod fallible_method {
|
||||||
let schema = schema(Query, Human);
|
let schema = schema(Query, Human);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
resolve_into_stream(DOC, None, &schema, &Variables::new(), &())
|
resolve_into_stream(DOC, None, &schema, &graphql_vars! {}, &())
|
||||||
.then(|s| extract_next(s))
|
.then(|s| extract_next(s))
|
||||||
.await,
|
.await,
|
||||||
Ok((graphql_value!({"homePlanet": "earth"}), vec![])),
|
Ok((graphql_value!({"homePlanet": "earth"}), vec![])),
|
||||||
|
@ -352,7 +352,7 @@ mod fallible_method {
|
||||||
let schema = schema(Query, Human);
|
let schema = schema(Query, Human);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"__type": {
|
graphql_value!({"__type": {
|
||||||
"name": "Human",
|
"name": "Human",
|
||||||
|
@ -403,7 +403,7 @@ mod argument {
|
||||||
let schema = schema(Query, Human);
|
let schema = schema(Query, Human);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
resolve_into_stream(DOC, None, &schema, &Variables::new(), &())
|
resolve_into_stream(DOC, None, &schema, &graphql_vars! {}, &())
|
||||||
.then(|s| extract_next(s))
|
.then(|s| extract_next(s))
|
||||||
.await,
|
.await,
|
||||||
Ok((graphql_value!({"id": "human-32"}), vec![])),
|
Ok((graphql_value!({"id": "human-32"}), vec![])),
|
||||||
|
@ -419,7 +419,7 @@ mod argument {
|
||||||
let schema = schema(Query, Human);
|
let schema = schema(Query, Human);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
resolve_into_stream(DOC, None, &schema, &Variables::new(), &())
|
resolve_into_stream(DOC, None, &schema, &graphql_vars! {}, &())
|
||||||
.then(|s| extract_next(s))
|
.then(|s| extract_next(s))
|
||||||
.await,
|
.await,
|
||||||
Ok((graphql_value!({"homePlanet": "earth,None"}), vec![])),
|
Ok((graphql_value!({"homePlanet": "earth,None"}), vec![])),
|
||||||
|
@ -442,7 +442,7 @@ mod argument {
|
||||||
let schema = schema(Query, Human);
|
let schema = schema(Query, Human);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"__type": {"fields": [
|
graphql_value!({"__type": {"fields": [
|
||||||
{"name": "id", "args": [{"name": "arg"}]},
|
{"name": "id", "args": [{"name": "arg"}]},
|
||||||
|
@ -468,11 +468,11 @@ mod argument {
|
||||||
let schema = schema(Query, Human);
|
let schema = schema(Query, Human);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"__type": {"fields": [
|
graphql_value!({"__type": {"fields": [
|
||||||
{"args": [{"description": None}]},
|
{"args": [{"description": null}]},
|
||||||
{"args": [{"description": None}, {"description": None}]},
|
{"args": [{"description": null}, {"description": null}]},
|
||||||
]}}),
|
]}}),
|
||||||
vec![],
|
vec![],
|
||||||
)),
|
)),
|
||||||
|
@ -494,11 +494,11 @@ mod argument {
|
||||||
let schema = schema(Query, Human);
|
let schema = schema(Query, Human);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"__type": {"fields": [
|
graphql_value!({"__type": {"fields": [
|
||||||
{"args": [{"defaultValue": None}]},
|
{"args": [{"defaultValue": null}]},
|
||||||
{"args": [{"defaultValue": None}, {"defaultValue": None}]},
|
{"args": [{"defaultValue": null}, {"defaultValue": null}]},
|
||||||
]}}),
|
]}}),
|
||||||
vec![],
|
vec![],
|
||||||
)),
|
)),
|
||||||
|
@ -552,7 +552,7 @@ mod default_argument {
|
||||||
let expected: &str = *expected;
|
let expected: &str = *expected;
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
resolve_into_stream(*input, None, &schema, &Variables::new(), &())
|
resolve_into_stream(*input, None, &schema, &graphql_vars! {}, &())
|
||||||
.then(|s| extract_next(s))
|
.then(|s| extract_next(s))
|
||||||
.await,
|
.await,
|
||||||
Ok((graphql_value!({ "id": expected }), vec![])),
|
Ok((graphql_value!({ "id": expected }), vec![])),
|
||||||
|
@ -571,7 +571,7 @@ mod default_argument {
|
||||||
let expected: i32 = *expected;
|
let expected: i32 = *expected;
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
resolve_into_stream(*input, None, &schema, &Variables::new(), &())
|
resolve_into_stream(*input, None, &schema, &graphql_vars! {}, &())
|
||||||
.then(|s| extract_next(s))
|
.then(|s| extract_next(s))
|
||||||
.await,
|
.await,
|
||||||
Ok((graphql_value!({ "info": expected }), vec![])),
|
Ok((graphql_value!({ "info": expected }), vec![])),
|
||||||
|
@ -601,27 +601,27 @@ mod default_argument {
|
||||||
let schema = schema(Query, Human);
|
let schema = schema(Query, Human);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"__type": {"fields": [{
|
graphql_value!({"__type": {"fields": [{
|
||||||
"args": [{
|
"args": [{
|
||||||
"name": "arg1",
|
"name": "arg1",
|
||||||
"defaultValue": "0",
|
"defaultValue": "0",
|
||||||
"type": {"name": "Int", "ofType": None},
|
"type": {"name": "Int", "ofType": null},
|
||||||
}, {
|
}, {
|
||||||
"name": "arg2",
|
"name": "arg2",
|
||||||
"defaultValue": r#""second""#,
|
"defaultValue": r#""second""#,
|
||||||
"type": {"name": "String", "ofType": None},
|
"type": {"name": "String", "ofType": null},
|
||||||
}, {
|
}, {
|
||||||
"name": "arg3",
|
"name": "arg3",
|
||||||
"defaultValue": "true",
|
"defaultValue": "true",
|
||||||
"type": {"name": "Boolean", "ofType": None},
|
"type": {"name": "Boolean", "ofType": null},
|
||||||
}],
|
}],
|
||||||
}, {
|
}, {
|
||||||
"args": [{
|
"args": [{
|
||||||
"name": "coord",
|
"name": "coord",
|
||||||
"defaultValue": "{x: 1}",
|
"defaultValue": "{x: 1}",
|
||||||
"type": {"name": "Point", "ofType": None},
|
"type": {"name": "Point", "ofType": null},
|
||||||
}],
|
}],
|
||||||
}]}}),
|
}]}}),
|
||||||
vec![],
|
vec![],
|
||||||
|
@ -667,7 +667,7 @@ mod generic {
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
resolve_into_stream(DOC, None, &schema, &Variables::new(), &())
|
resolve_into_stream(DOC, None, &schema, &graphql_vars! {}, &())
|
||||||
.then(|s| extract_next(s))
|
.then(|s| extract_next(s))
|
||||||
.await,
|
.await,
|
||||||
Ok((graphql_value!({"id": 34}), vec![])),
|
Ok((graphql_value!({"id": 34}), vec![])),
|
||||||
|
@ -689,7 +689,7 @@ mod generic {
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
resolve_into_stream(DOC, None, &schema, &Variables::new(), &())
|
resolve_into_stream(DOC, None, &schema, &graphql_vars! {}, &())
|
||||||
.then(|s| extract_next(s))
|
.then(|s| extract_next(s))
|
||||||
.await,
|
.await,
|
||||||
Ok((graphql_value!({"id": "human-32"}), vec![])),
|
Ok((graphql_value!({"id": "human-32"}), vec![])),
|
||||||
|
@ -713,7 +713,7 @@ mod generic {
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((graphql_value!({"__type": {"name": "Human"}}), vec![])),
|
Ok((graphql_value!({"__type": {"name": "Human"}}), vec![])),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -767,7 +767,7 @@ mod generic_lifetime {
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
resolve_into_stream(DOC, None, &schema, &Variables::new(), &())
|
resolve_into_stream(DOC, None, &schema, &graphql_vars! {}, &())
|
||||||
.then(|s| extract_next(s))
|
.then(|s| extract_next(s))
|
||||||
.await,
|
.await,
|
||||||
Ok((graphql_value!({"id": 34}), vec![])),
|
Ok((graphql_value!({"id": 34}), vec![])),
|
||||||
|
@ -789,7 +789,7 @@ mod generic_lifetime {
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
resolve_into_stream(DOC, None, &schema, &Variables::new(), &())
|
resolve_into_stream(DOC, None, &schema, &graphql_vars! {}, &())
|
||||||
.then(|s| extract_next(s))
|
.then(|s| extract_next(s))
|
||||||
.await,
|
.await,
|
||||||
Ok((graphql_value!({"planet": "earth"}), vec![])),
|
Ok((graphql_value!({"planet": "earth"}), vec![])),
|
||||||
|
@ -811,7 +811,7 @@ mod generic_lifetime {
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
resolve_into_stream(DOC, None, &schema, &Variables::new(), &())
|
resolve_into_stream(DOC, None, &schema, &graphql_vars! {}, &())
|
||||||
.then(|s| extract_next(s))
|
.then(|s| extract_next(s))
|
||||||
.await,
|
.await,
|
||||||
Ok((graphql_value!({"id": "human-32"}), vec![])),
|
Ok((graphql_value!({"id": "human-32"}), vec![])),
|
||||||
|
@ -833,7 +833,7 @@ mod generic_lifetime {
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
resolve_into_stream(DOC, None, &schema, &Variables::new(), &())
|
resolve_into_stream(DOC, None, &schema, &graphql_vars! {}, &())
|
||||||
.then(|s| extract_next(s))
|
.then(|s| extract_next(s))
|
||||||
.await,
|
.await,
|
||||||
Ok((graphql_value!({"planet": "mars"}), vec![])),
|
Ok((graphql_value!({"planet": "mars"}), vec![])),
|
||||||
|
@ -857,7 +857,7 @@ mod generic_lifetime {
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((graphql_value!({"__type": {"name": "Human"}}), vec![])),
|
Ok((graphql_value!({"__type": {"name": "Human"}}), vec![])),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -892,7 +892,7 @@ mod description_from_doc_comment {
|
||||||
let schema = schema(Query, Human);
|
let schema = schema(Query, Human);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"__type": {
|
graphql_value!({"__type": {
|
||||||
"description": "Rust docs.",
|
"description": "Rust docs.",
|
||||||
|
@ -935,7 +935,7 @@ mod deprecation_from_attr {
|
||||||
let schema = schema(Query, Human);
|
let schema = schema(Query, Human);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
resolve_into_stream(DOC, None, &schema, &Variables::new(), &())
|
resolve_into_stream(DOC, None, &schema, &graphql_vars! {}, &())
|
||||||
.then(|s| extract_next(s))
|
.then(|s| extract_next(s))
|
||||||
.await,
|
.await,
|
||||||
Ok((graphql_value!({"id": "human-32"}), vec![])),
|
Ok((graphql_value!({"id": "human-32"}), vec![])),
|
||||||
|
@ -951,7 +951,7 @@ mod deprecation_from_attr {
|
||||||
let schema = schema(Query, Human);
|
let schema = schema(Query, Human);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
resolve_into_stream(DOC, None, &schema, &Variables::new(), &())
|
resolve_into_stream(DOC, None, &schema, &graphql_vars! {}, &())
|
||||||
.then(|s| extract_next(s))
|
.then(|s| extract_next(s))
|
||||||
.await,
|
.await,
|
||||||
Ok((graphql_value!({"a": "a"}), vec![])),
|
Ok((graphql_value!({"a": "a"}), vec![])),
|
||||||
|
@ -967,7 +967,7 @@ mod deprecation_from_attr {
|
||||||
let schema = schema(Query, Human);
|
let schema = schema(Query, Human);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
resolve_into_stream(DOC, None, &schema, &Variables::new(), &())
|
resolve_into_stream(DOC, None, &schema, &graphql_vars! {}, &())
|
||||||
.then(|s| extract_next(s))
|
.then(|s| extract_next(s))
|
||||||
.await,
|
.await,
|
||||||
Ok((graphql_value!({"b": "b"}), vec![])),
|
Ok((graphql_value!({"b": "b"}), vec![])),
|
||||||
|
@ -988,7 +988,7 @@ mod deprecation_from_attr {
|
||||||
let schema = schema(Query, Human);
|
let schema = schema(Query, Human);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"__type": {"fields": [
|
graphql_value!({"__type": {"fields": [
|
||||||
{"name": "id", "isDeprecated": false},
|
{"name": "id", "isDeprecated": false},
|
||||||
|
@ -1014,11 +1014,11 @@ mod deprecation_from_attr {
|
||||||
let schema = schema(Query, Human);
|
let schema = schema(Query, Human);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"__type": {"fields": [
|
graphql_value!({"__type": {"fields": [
|
||||||
{"name": "id", "deprecationReason": None},
|
{"name": "id", "deprecationReason": null},
|
||||||
{"name": "a", "deprecationReason": None},
|
{"name": "a", "deprecationReason": null},
|
||||||
{"name": "b", "deprecationReason": "Use `id`."},
|
{"name": "b", "deprecationReason": "Use `id`."},
|
||||||
]}}),
|
]}}),
|
||||||
vec![],
|
vec![],
|
||||||
|
@ -1064,7 +1064,7 @@ mod explicit_name_description_and_deprecation {
|
||||||
let schema = schema(Query, Human);
|
let schema = schema(Query, Human);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
resolve_into_stream(DOC, None, &schema, &Variables::new(), &())
|
resolve_into_stream(DOC, None, &schema, &graphql_vars! {}, &())
|
||||||
.then(|s| extract_next(s))
|
.then(|s| extract_next(s))
|
||||||
.await,
|
.await,
|
||||||
Ok((graphql_value!({"myId": "human-32"}), vec![])),
|
Ok((graphql_value!({"myId": "human-32"}), vec![])),
|
||||||
|
@ -1080,7 +1080,7 @@ mod explicit_name_description_and_deprecation {
|
||||||
let schema = schema(Query, Human);
|
let schema = schema(Query, Human);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
resolve_into_stream(DOC, None, &schema, &Variables::new(), &())
|
resolve_into_stream(DOC, None, &schema, &graphql_vars! {}, &())
|
||||||
.then(|s| extract_next(s))
|
.then(|s| extract_next(s))
|
||||||
.await,
|
.await,
|
||||||
Ok((graphql_value!({"a": "a"}), vec![])),
|
Ok((graphql_value!({"a": "a"}), vec![])),
|
||||||
|
@ -1096,7 +1096,7 @@ mod explicit_name_description_and_deprecation {
|
||||||
let schema = schema(Query, Human);
|
let schema = schema(Query, Human);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
resolve_into_stream(DOC, None, &schema, &Variables::new(), &())
|
resolve_into_stream(DOC, None, &schema, &graphql_vars! {}, &())
|
||||||
.then(|s| extract_next(s))
|
.then(|s| extract_next(s))
|
||||||
.await,
|
.await,
|
||||||
Ok((graphql_value!({"b": "b"}), vec![])),
|
Ok((graphql_value!({"b": "b"}), vec![])),
|
||||||
|
@ -1120,7 +1120,7 @@ mod explicit_name_description_and_deprecation {
|
||||||
let schema = schema(Query, Human);
|
let schema = schema(Query, Human);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"__type": {
|
graphql_value!({"__type": {
|
||||||
"name": "MyHuman",
|
"name": "MyHuman",
|
||||||
|
@ -1153,7 +1153,7 @@ mod explicit_name_description_and_deprecation {
|
||||||
let schema = schema(Query, Human);
|
let schema = schema(Query, Human);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"__type": {
|
graphql_value!({"__type": {
|
||||||
"description": "My human.",
|
"description": "My human.",
|
||||||
|
@ -1163,11 +1163,11 @@ mod explicit_name_description_and_deprecation {
|
||||||
"args": [{"description": "My argument."}],
|
"args": [{"description": "My argument."}],
|
||||||
}, {
|
}, {
|
||||||
"name": "a",
|
"name": "a",
|
||||||
"description": None,
|
"description": null,
|
||||||
"args": [],
|
"args": [],
|
||||||
}, {
|
}, {
|
||||||
"name": "b",
|
"name": "b",
|
||||||
"description": None,
|
"description": null,
|
||||||
"args": [],
|
"args": [],
|
||||||
}],
|
}],
|
||||||
}}),
|
}}),
|
||||||
|
@ -1191,7 +1191,7 @@ mod explicit_name_description_and_deprecation {
|
||||||
let schema = schema(Query, Human);
|
let schema = schema(Query, Human);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"__type": {
|
graphql_value!({"__type": {
|
||||||
"fields": [{
|
"fields": [{
|
||||||
|
@ -1201,11 +1201,11 @@ mod explicit_name_description_and_deprecation {
|
||||||
}, {
|
}, {
|
||||||
"name": "a",
|
"name": "a",
|
||||||
"isDeprecated": true,
|
"isDeprecated": true,
|
||||||
"deprecationReason": None,
|
"deprecationReason": null,
|
||||||
}, {
|
}, {
|
||||||
"name": "b",
|
"name": "b",
|
||||||
"isDeprecated": false,
|
"isDeprecated": false,
|
||||||
"deprecationReason": None,
|
"deprecationReason": null,
|
||||||
}],
|
}],
|
||||||
}}),
|
}}),
|
||||||
vec![],
|
vec![],
|
||||||
|
@ -1243,7 +1243,7 @@ mod renamed_all_fields_and_args {
|
||||||
let schema = schema(Query, Human);
|
let schema = schema(Query, Human);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
resolve_into_stream(DOC, None, &schema, &Variables::new(), &())
|
resolve_into_stream(DOC, None, &schema, &graphql_vars! {}, &())
|
||||||
.then(|s| extract_next(s))
|
.then(|s| extract_next(s))
|
||||||
.await,
|
.await,
|
||||||
Ok((graphql_value!({"id": "human-32"}), vec![])),
|
Ok((graphql_value!({"id": "human-32"}), vec![])),
|
||||||
|
@ -1259,7 +1259,7 @@ mod renamed_all_fields_and_args {
|
||||||
let schema = schema(Query, Human);
|
let schema = schema(Query, Human);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
resolve_into_stream(DOC, None, &schema, &Variables::new(), &())
|
resolve_into_stream(DOC, None, &schema, &graphql_vars! {}, &())
|
||||||
.then(|s| extract_next(s))
|
.then(|s| extract_next(s))
|
||||||
.await,
|
.await,
|
||||||
Ok((graphql_value!({"home_planet": "earth"}), vec![])),
|
Ok((graphql_value!({"home_planet": "earth"}), vec![])),
|
||||||
|
@ -1275,7 +1275,7 @@ mod renamed_all_fields_and_args {
|
||||||
let schema = schema(Query, Human);
|
let schema = schema(Query, Human);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
resolve_into_stream(DOC, None, &schema, &Variables::new(), &())
|
resolve_into_stream(DOC, None, &schema, &graphql_vars! {}, &())
|
||||||
.then(|s| extract_next(s))
|
.then(|s| extract_next(s))
|
||||||
.await,
|
.await,
|
||||||
Ok((graphql_value!({"async_info": 3}), vec![])),
|
Ok((graphql_value!({"async_info": 3}), vec![])),
|
||||||
|
@ -1298,7 +1298,7 @@ mod renamed_all_fields_and_args {
|
||||||
let schema = schema(Query, Human);
|
let schema = schema(Query, Human);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"__type": {"fields": [
|
graphql_value!({"__type": {"fields": [
|
||||||
{"name": "id", "args": []},
|
{"name": "id", "args": []},
|
||||||
|
@ -1336,7 +1336,7 @@ mod explicit_scalar {
|
||||||
let schema = schema(Query, Human);
|
let schema = schema(Query, Human);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
resolve_into_stream(DOC, None, &schema, &Variables::new(), &())
|
resolve_into_stream(DOC, None, &schema, &graphql_vars! {}, &())
|
||||||
.then(|s| extract_next(s))
|
.then(|s| extract_next(s))
|
||||||
.await,
|
.await,
|
||||||
Ok((graphql_value!({"id": "human-32"}), vec![])),
|
Ok((graphql_value!({"id": "human-32"}), vec![])),
|
||||||
|
@ -1352,7 +1352,7 @@ mod explicit_scalar {
|
||||||
let schema = schema(Query, Human);
|
let schema = schema(Query, Human);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
resolve_into_stream(DOC, None, &schema, &Variables::new(), &())
|
resolve_into_stream(DOC, None, &schema, &graphql_vars! {}, &())
|
||||||
.then(|s| extract_next(s))
|
.then(|s| extract_next(s))
|
||||||
.await,
|
.await,
|
||||||
Ok((graphql_value!({"homePlanet": "earth"}), vec![])),
|
Ok((graphql_value!({"homePlanet": "earth"}), vec![])),
|
||||||
|
@ -1387,7 +1387,7 @@ mod custom_scalar {
|
||||||
let schema = schema_with_scalar::<MyScalarValue, _, _, _>(Query, Human);
|
let schema = schema_with_scalar::<MyScalarValue, _, _, _>(Query, Human);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
resolve_into_stream(DOC, None, &schema, &Variables::new(), &())
|
resolve_into_stream(DOC, None, &schema, &graphql_vars! {}, &())
|
||||||
.then(|s| extract_next(s))
|
.then(|s| extract_next(s))
|
||||||
.await,
|
.await,
|
||||||
Ok((graphql_value!({"id": "human-32"}), vec![])),
|
Ok((graphql_value!({"id": "human-32"}), vec![])),
|
||||||
|
@ -1403,7 +1403,7 @@ mod custom_scalar {
|
||||||
let schema = schema_with_scalar::<MyScalarValue, _, _, _>(Query, Human);
|
let schema = schema_with_scalar::<MyScalarValue, _, _, _>(Query, Human);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
resolve_into_stream(DOC, None, &schema, &Variables::new(), &())
|
resolve_into_stream(DOC, None, &schema, &graphql_vars! {}, &())
|
||||||
.then(|s| extract_next(s))
|
.then(|s| extract_next(s))
|
||||||
.await,
|
.await,
|
||||||
Ok((graphql_value!({"homePlanet": "earth"}), vec![])),
|
Ok((graphql_value!({"homePlanet": "earth"}), vec![])),
|
||||||
|
@ -1438,7 +1438,7 @@ mod explicit_generic_scalar {
|
||||||
let schema = schema(Query, Human::<DefaultScalarValue>(PhantomData));
|
let schema = schema(Query, Human::<DefaultScalarValue>(PhantomData));
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
resolve_into_stream(DOC, None, &schema, &Variables::new(), &())
|
resolve_into_stream(DOC, None, &schema, &graphql_vars! {}, &())
|
||||||
.then(|s| extract_next(s))
|
.then(|s| extract_next(s))
|
||||||
.await,
|
.await,
|
||||||
Ok((graphql_value!({"id": "human-32"}), vec![])),
|
Ok((graphql_value!({"id": "human-32"}), vec![])),
|
||||||
|
@ -1454,7 +1454,7 @@ mod explicit_generic_scalar {
|
||||||
let schema = schema(Query, Human::<DefaultScalarValue>(PhantomData));
|
let schema = schema(Query, Human::<DefaultScalarValue>(PhantomData));
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
resolve_into_stream(DOC, None, &schema, &Variables::new(), &())
|
resolve_into_stream(DOC, None, &schema, &graphql_vars! {}, &())
|
||||||
.then(|s| extract_next(s))
|
.then(|s| extract_next(s))
|
||||||
.await,
|
.await,
|
||||||
Ok((graphql_value!({"homePlanet": "earth"}), vec![])),
|
Ok((graphql_value!({"homePlanet": "earth"}), vec![])),
|
||||||
|
@ -1489,7 +1489,7 @@ mod bounded_generic_scalar {
|
||||||
let schema = schema(Query, Human);
|
let schema = schema(Query, Human);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
resolve_into_stream(DOC, None, &schema, &Variables::new(), &())
|
resolve_into_stream(DOC, None, &schema, &graphql_vars! {}, &())
|
||||||
.then(|s| extract_next(s))
|
.then(|s| extract_next(s))
|
||||||
.await,
|
.await,
|
||||||
Ok((graphql_value!({"id": "human-32"}), vec![])),
|
Ok((graphql_value!({"id": "human-32"}), vec![])),
|
||||||
|
@ -1505,7 +1505,7 @@ mod bounded_generic_scalar {
|
||||||
let schema = schema(Query, Human);
|
let schema = schema(Query, Human);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
resolve_into_stream(DOC, None, &schema, &Variables::new(), &())
|
resolve_into_stream(DOC, None, &schema, &graphql_vars! {}, &())
|
||||||
.then(|s| extract_next(s))
|
.then(|s| extract_next(s))
|
||||||
.await,
|
.await,
|
||||||
Ok((graphql_value!({"homePlanet": "earth"}), vec![])),
|
Ok((graphql_value!({"homePlanet": "earth"}), vec![])),
|
||||||
|
@ -1558,7 +1558,7 @@ mod explicit_custom_context {
|
||||||
let ctx = CustomContext("ctx!".into());
|
let ctx = CustomContext("ctx!".into());
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
resolve_into_stream(DOC, None, &schema, &Variables::new(), &ctx)
|
resolve_into_stream(DOC, None, &schema, &graphql_vars! {}, &ctx)
|
||||||
.then(|s| extract_next(s))
|
.then(|s| extract_next(s))
|
||||||
.await,
|
.await,
|
||||||
Ok((graphql_value!({"id": "ctx!"}), vec![])),
|
Ok((graphql_value!({"id": "ctx!"}), vec![])),
|
||||||
|
@ -1575,7 +1575,7 @@ mod explicit_custom_context {
|
||||||
let ctx = CustomContext("ctx!".into());
|
let ctx = CustomContext("ctx!".into());
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
resolve_into_stream(DOC, None, &schema, &Variables::new(), &ctx)
|
resolve_into_stream(DOC, None, &schema, &graphql_vars! {}, &ctx)
|
||||||
.then(|s| extract_next(s))
|
.then(|s| extract_next(s))
|
||||||
.await,
|
.await,
|
||||||
Ok((graphql_value!({"info": "human being"}), vec![])),
|
Ok((graphql_value!({"info": "human being"}), vec![])),
|
||||||
|
@ -1592,7 +1592,7 @@ mod explicit_custom_context {
|
||||||
let ctx = CustomContext("ctx!".into());
|
let ctx = CustomContext("ctx!".into());
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
resolve_into_stream(DOC, None, &schema, &Variables::new(), &ctx)
|
resolve_into_stream(DOC, None, &schema, &graphql_vars! {}, &ctx)
|
||||||
.then(|s| extract_next(s))
|
.then(|s| extract_next(s))
|
||||||
.await,
|
.await,
|
||||||
Ok((graphql_value!({"more": "ctx!"}), vec![])),
|
Ok((graphql_value!({"more": "ctx!"}), vec![])),
|
||||||
|
@ -1645,7 +1645,7 @@ mod inferred_custom_context_from_field {
|
||||||
let ctx = CustomContext("ctx!".into());
|
let ctx = CustomContext("ctx!".into());
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
resolve_into_stream(DOC, None, &schema, &Variables::new(), &ctx)
|
resolve_into_stream(DOC, None, &schema, &graphql_vars! {}, &ctx)
|
||||||
.then(|s| extract_next(s))
|
.then(|s| extract_next(s))
|
||||||
.await,
|
.await,
|
||||||
Ok((graphql_value!({"id": "ctx!"}), vec![])),
|
Ok((graphql_value!({"id": "ctx!"}), vec![])),
|
||||||
|
@ -1662,7 +1662,7 @@ mod inferred_custom_context_from_field {
|
||||||
let ctx = CustomContext("ctx!".into());
|
let ctx = CustomContext("ctx!".into());
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
resolve_into_stream(DOC, None, &schema, &Variables::new(), &ctx)
|
resolve_into_stream(DOC, None, &schema, &graphql_vars! {}, &ctx)
|
||||||
.then(|s| extract_next(s))
|
.then(|s| extract_next(s))
|
||||||
.await,
|
.await,
|
||||||
Ok((graphql_value!({"info": "human being"}), vec![])),
|
Ok((graphql_value!({"info": "human being"}), vec![])),
|
||||||
|
@ -1679,7 +1679,7 @@ mod inferred_custom_context_from_field {
|
||||||
let ctx = CustomContext("ctx!".into());
|
let ctx = CustomContext("ctx!".into());
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
resolve_into_stream(DOC, None, &schema, &Variables::new(), &ctx)
|
resolve_into_stream(DOC, None, &schema, &graphql_vars! {}, &ctx)
|
||||||
.then(|s| extract_next(s))
|
.then(|s| extract_next(s))
|
||||||
.await,
|
.await,
|
||||||
Ok((graphql_value!({"more": "ctx!"}), vec![])),
|
Ok((graphql_value!({"more": "ctx!"}), vec![])),
|
||||||
|
@ -1731,7 +1731,7 @@ mod executor {
|
||||||
let schema = schema(Query, Human);
|
let schema = schema(Query, Human);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
resolve_into_stream(DOC, None, &schema, &Variables::new(), &())
|
resolve_into_stream(DOC, None, &schema, &graphql_vars! {}, &())
|
||||||
.then(|s| extract_next(s))
|
.then(|s| extract_next(s))
|
||||||
.await,
|
.await,
|
||||||
Ok((graphql_value!({"id": "id"}), vec![])),
|
Ok((graphql_value!({"id": "id"}), vec![])),
|
||||||
|
@ -1747,7 +1747,7 @@ mod executor {
|
||||||
let schema = schema(Query, Human);
|
let schema = schema(Query, Human);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
resolve_into_stream(DOC, None, &schema, &Variables::new(), &())
|
resolve_into_stream(DOC, None, &schema, &graphql_vars! {}, &())
|
||||||
.then(|s| extract_next(s))
|
.then(|s| extract_next(s))
|
||||||
.await,
|
.await,
|
||||||
Ok((graphql_value!({"info": "input!"}), vec![])),
|
Ok((graphql_value!({"info": "input!"}), vec![])),
|
||||||
|
@ -1763,7 +1763,7 @@ mod executor {
|
||||||
let schema = schema(Query, Human);
|
let schema = schema(Query, Human);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
resolve_into_stream(DOC, None, &schema, &Variables::new(), &())
|
resolve_into_stream(DOC, None, &schema, &graphql_vars! {}, &())
|
||||||
.then(|s| extract_next(s))
|
.then(|s| extract_next(s))
|
||||||
.await,
|
.await,
|
||||||
Ok((graphql_value!({"info2": "no info"}), vec![])),
|
Ok((graphql_value!({"info2": "no info"}), vec![])),
|
||||||
|
@ -1786,7 +1786,7 @@ mod executor {
|
||||||
let schema = schema(Query, Human);
|
let schema = schema(Query, Human);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"__type": {"fields": [
|
graphql_value!({"__type": {"fields": [
|
||||||
{"name": "id", "args": []},
|
{"name": "id", "args": []},
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
//! Tests for `#[graphql_union]` macro.
|
//! Tests for `#[graphql_union]` macro.
|
||||||
|
|
||||||
use juniper::{
|
use juniper::{
|
||||||
execute, graphql_object, graphql_union, graphql_value, DefaultScalarValue, EmptyMutation,
|
execute, graphql_object, graphql_union, graphql_value, graphql_vars, DefaultScalarValue,
|
||||||
EmptySubscription, GraphQLObject, GraphQLType, RootNode, ScalarValue, Variables,
|
EmptyMutation, EmptySubscription, GraphQLObject, GraphQLType, RootNode, ScalarValue,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(GraphQLObject)]
|
#[derive(GraphQLObject)]
|
||||||
|
@ -143,7 +143,7 @@ mod trivial {
|
||||||
let schema = schema(QueryRoot::Human);
|
let schema = schema(QueryRoot::Human);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"character": {"humanId": "human-32", "homePlanet": "earth"}}),
|
graphql_value!({"character": {"humanId": "human-32", "homePlanet": "earth"}}),
|
||||||
vec![],
|
vec![],
|
||||||
|
@ -156,7 +156,7 @@ mod trivial {
|
||||||
let schema = schema(QueryRoot::Droid);
|
let schema = schema(QueryRoot::Droid);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"character": {"droidId": "droid-99", "primaryFunction": "run"}}),
|
graphql_value!({"character": {"droidId": "droid-99", "primaryFunction": "run"}}),
|
||||||
vec![],
|
vec![],
|
||||||
|
@ -175,7 +175,7 @@ mod trivial {
|
||||||
let schema = schema(QueryRoot::Human);
|
let schema = schema(QueryRoot::Human);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((graphql_value!({"__type": {"kind": "UNION"}}), vec![])),
|
Ok((graphql_value!({"__type": {"kind": "UNION"}}), vec![])),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -191,7 +191,7 @@ mod trivial {
|
||||||
let schema = schema(QueryRoot::Human);
|
let schema = schema(QueryRoot::Human);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((graphql_value!({"__type": {"name": "Character"}}), vec![])),
|
Ok((graphql_value!({"__type": {"name": "Character"}}), vec![])),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -207,8 +207,8 @@ mod trivial {
|
||||||
let schema = schema(QueryRoot::Human);
|
let schema = schema(QueryRoot::Human);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((graphql_value!({"__type": {"description": None}}), vec![])),
|
Ok((graphql_value!({"__type": {"description": null}}), vec![])),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -280,7 +280,7 @@ mod generic {
|
||||||
let schema = schema(QueryRoot::Human);
|
let schema = schema(QueryRoot::Human);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"character": {"humanId": "human-32", "homePlanet": "earth"}}),
|
graphql_value!({"character": {"humanId": "human-32", "homePlanet": "earth"}}),
|
||||||
vec![],
|
vec![],
|
||||||
|
@ -293,7 +293,7 @@ mod generic {
|
||||||
let schema = schema(QueryRoot::Droid);
|
let schema = schema(QueryRoot::Droid);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"character": {"droidId": "droid-99", "primaryFunction": "run"}}),
|
graphql_value!({"character": {"droidId": "droid-99", "primaryFunction": "run"}}),
|
||||||
vec![],
|
vec![],
|
||||||
|
@ -312,7 +312,7 @@ mod generic {
|
||||||
let schema = schema(QueryRoot::Human);
|
let schema = schema(QueryRoot::Human);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((graphql_value!({"__type": {"name": "Character"}}), vec![])),
|
Ok((graphql_value!({"__type": {"name": "Character"}}), vec![])),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -363,7 +363,7 @@ mod description_from_doc_comment {
|
||||||
let schema = schema(QueryRoot);
|
let schema = schema(QueryRoot);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"character": {"humanId": "human-32", "homePlanet": "earth"}}),
|
graphql_value!({"character": {"humanId": "human-32", "homePlanet": "earth"}}),
|
||||||
vec![],
|
vec![],
|
||||||
|
@ -382,7 +382,7 @@ mod description_from_doc_comment {
|
||||||
let schema = schema(QueryRoot);
|
let schema = schema(QueryRoot);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"__type": {"description": "Rust docs."}}),
|
graphql_value!({"__type": {"description": "Rust docs."}}),
|
||||||
vec![],
|
vec![],
|
||||||
|
@ -436,7 +436,7 @@ mod explicit_name_and_description {
|
||||||
let schema = schema(QueryRoot);
|
let schema = schema(QueryRoot);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"character": {"humanId": "human-32", "homePlanet": "earth"}}),
|
graphql_value!({"character": {"humanId": "human-32", "homePlanet": "earth"}}),
|
||||||
vec![],
|
vec![],
|
||||||
|
@ -455,7 +455,7 @@ mod explicit_name_and_description {
|
||||||
let schema = schema(QueryRoot);
|
let schema = schema(QueryRoot);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((graphql_value!({"__type": {"name": "MyChar"}}), vec![])),
|
Ok((graphql_value!({"__type": {"name": "MyChar"}}), vec![])),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -471,7 +471,7 @@ mod explicit_name_and_description {
|
||||||
let schema = schema(QueryRoot);
|
let schema = schema(QueryRoot);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"__type": {"description": "My character."}}),
|
graphql_value!({"__type": {"description": "My character."}}),
|
||||||
vec![],
|
vec![],
|
||||||
|
@ -547,7 +547,7 @@ mod explicit_scalar {
|
||||||
let schema = schema(QueryRoot::Human);
|
let schema = schema(QueryRoot::Human);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"character": {"humanId": "human-32", "homePlanet": "earth"}}),
|
graphql_value!({"character": {"humanId": "human-32", "homePlanet": "earth"}}),
|
||||||
vec![],
|
vec![],
|
||||||
|
@ -560,7 +560,7 @@ mod explicit_scalar {
|
||||||
let schema = schema(QueryRoot::Droid);
|
let schema = schema(QueryRoot::Droid);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"character": {"droidId": "droid-99", "primaryFunction": "run"}}),
|
graphql_value!({"character": {"droidId": "droid-99", "primaryFunction": "run"}}),
|
||||||
vec![],
|
vec![],
|
||||||
|
@ -638,7 +638,7 @@ mod custom_scalar {
|
||||||
let schema = schema_with_scalar::<MyScalarValue, _, _>(QueryRoot::Human);
|
let schema = schema_with_scalar::<MyScalarValue, _, _>(QueryRoot::Human);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"character": {"humanId": "human-32", "homePlanet": "earth"}}),
|
graphql_value!({"character": {"humanId": "human-32", "homePlanet": "earth"}}),
|
||||||
vec![],
|
vec![],
|
||||||
|
@ -651,7 +651,7 @@ mod custom_scalar {
|
||||||
let schema = schema_with_scalar::<MyScalarValue, _, _>(QueryRoot::Droid);
|
let schema = schema_with_scalar::<MyScalarValue, _, _>(QueryRoot::Droid);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"character": {"droidId": "droid-99", "primaryFunction": "run"}}),
|
graphql_value!({"character": {"droidId": "droid-99", "primaryFunction": "run"}}),
|
||||||
vec![],
|
vec![],
|
||||||
|
@ -727,7 +727,7 @@ mod explicit_generic_scalar {
|
||||||
let schema = schema(QueryRoot::Human);
|
let schema = schema(QueryRoot::Human);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"character": {"humanId": "human-32", "homePlanet": "earth"}}),
|
graphql_value!({"character": {"humanId": "human-32", "homePlanet": "earth"}}),
|
||||||
vec![],
|
vec![],
|
||||||
|
@ -740,7 +740,7 @@ mod explicit_generic_scalar {
|
||||||
let schema = schema(QueryRoot::Droid);
|
let schema = schema(QueryRoot::Droid);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"character": {"droidId": "droid-99", "primaryFunction": "run"}}),
|
graphql_value!({"character": {"droidId": "droid-99", "primaryFunction": "run"}}),
|
||||||
vec![],
|
vec![],
|
||||||
|
@ -816,7 +816,7 @@ mod bounded_generic_scalar {
|
||||||
let schema = schema(QueryRoot::Human);
|
let schema = schema(QueryRoot::Human);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"character": {"humanId": "human-32", "homePlanet": "earth"}}),
|
graphql_value!({"character": {"humanId": "human-32", "homePlanet": "earth"}}),
|
||||||
vec![],
|
vec![],
|
||||||
|
@ -829,7 +829,7 @@ mod bounded_generic_scalar {
|
||||||
let schema = schema(QueryRoot::Droid);
|
let schema = schema(QueryRoot::Droid);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"character": {"droidId": "droid-99", "primaryFunction": "run"}}),
|
graphql_value!({"character": {"droidId": "droid-99", "primaryFunction": "run"}}),
|
||||||
vec![],
|
vec![],
|
||||||
|
@ -903,7 +903,7 @@ mod explicit_custom_context {
|
||||||
let schema = schema(QueryRoot);
|
let schema = schema(QueryRoot);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &CustomContext::Human).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &CustomContext::Human).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"character": {"humanId": "human-32", "homePlanet": "earth"}}),
|
graphql_value!({"character": {"humanId": "human-32", "homePlanet": "earth"}}),
|
||||||
vec![],
|
vec![],
|
||||||
|
@ -916,7 +916,7 @@ mod explicit_custom_context {
|
||||||
let schema = schema(QueryRoot);
|
let schema = schema(QueryRoot);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &CustomContext::Droid).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &CustomContext::Droid).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"character": {"droidId": "droid-99", "primaryFunction": "run"}}),
|
graphql_value!({"character": {"droidId": "droid-99", "primaryFunction": "run"}}),
|
||||||
vec![],
|
vec![],
|
||||||
|
@ -990,7 +990,7 @@ mod inferred_custom_context {
|
||||||
let schema = schema(QueryRoot);
|
let schema = schema(QueryRoot);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &CustomContext::Human).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &CustomContext::Human).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"character": {"humanId": "human-32", "homePlanet": "earth"}}),
|
graphql_value!({"character": {"humanId": "human-32", "homePlanet": "earth"}}),
|
||||||
vec![],
|
vec![],
|
||||||
|
@ -1003,7 +1003,7 @@ mod inferred_custom_context {
|
||||||
let schema = schema(QueryRoot);
|
let schema = schema(QueryRoot);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &CustomContext::Droid).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &CustomContext::Droid).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"character": {"droidId": "droid-99", "primaryFunction": "run"}}),
|
graphql_value!({"character": {"droidId": "droid-99", "primaryFunction": "run"}}),
|
||||||
vec![],
|
vec![],
|
||||||
|
@ -1062,7 +1062,7 @@ mod ignored_method {
|
||||||
let schema = schema(QueryRoot);
|
let schema = schema(QueryRoot);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"character": {"humanId": "human-32", "homePlanet": "earth"}}),
|
graphql_value!({"character": {"humanId": "human-32", "homePlanet": "earth"}}),
|
||||||
vec![],
|
vec![],
|
||||||
|
@ -1083,7 +1083,7 @@ mod ignored_method {
|
||||||
let schema = schema(QueryRoot);
|
let schema = schema(QueryRoot);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"__type": {"possibleTypes": [{"name": "Human"}]}}),
|
graphql_value!({"__type": {"possibleTypes": [{"name": "Human"}]}}),
|
||||||
vec![],
|
vec![],
|
||||||
|
@ -1165,7 +1165,7 @@ mod external_resolver {
|
||||||
let db = Database { droid: None };
|
let db = Database { droid: None };
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &db).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &db).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"character": {"humanId": "human-32", "homePlanet": "earth"}}),
|
graphql_value!({"character": {"humanId": "human-32", "homePlanet": "earth"}}),
|
||||||
vec![],
|
vec![],
|
||||||
|
@ -1184,7 +1184,7 @@ mod external_resolver {
|
||||||
};
|
};
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &db).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &db).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"character": {"droidId": "droid-99", "primaryFunction": "run"}}),
|
graphql_value!({"character": {"droidId": "droid-99", "primaryFunction": "run"}}),
|
||||||
vec![],
|
vec![],
|
||||||
|
@ -1288,7 +1288,7 @@ mod full_featured {
|
||||||
let schema = schema(QueryRoot);
|
let schema = schema(QueryRoot);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &CustomContext::Human).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &CustomContext::Human).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"character": {"humanId": "human-32", "homePlanet": "earth"}}),
|
graphql_value!({"character": {"humanId": "human-32", "homePlanet": "earth"}}),
|
||||||
vec![],
|
vec![],
|
||||||
|
@ -1301,7 +1301,7 @@ mod full_featured {
|
||||||
let schema = schema(QueryRoot);
|
let schema = schema(QueryRoot);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &CustomContext::Droid).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &CustomContext::Droid).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"character": {"droidId": "droid-99", "primaryFunction": "run"}}),
|
graphql_value!({"character": {"droidId": "droid-99", "primaryFunction": "run"}}),
|
||||||
vec![],
|
vec![],
|
||||||
|
@ -1314,7 +1314,7 @@ mod full_featured {
|
||||||
let schema = schema(QueryRoot);
|
let schema = schema(QueryRoot);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &CustomContext::Ewok).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &CustomContext::Ewok).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"character": {"ewokId": "ewok-1", "funny": true}}),
|
graphql_value!({"character": {"ewokId": "ewok-1", "funny": true}}),
|
||||||
vec![],
|
vec![],
|
||||||
|
@ -1333,7 +1333,7 @@ mod full_featured {
|
||||||
let schema = schema(QueryRoot);
|
let schema = schema(QueryRoot);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &CustomContext::Ewok).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &CustomContext::Ewok).await,
|
||||||
Ok((graphql_value!({"__type": {"name": "MyChar"}}), vec![])),
|
Ok((graphql_value!({"__type": {"name": "MyChar"}}), vec![])),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1349,7 +1349,7 @@ mod full_featured {
|
||||||
let schema = schema(QueryRoot);
|
let schema = schema(QueryRoot);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &CustomContext::Ewok).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &CustomContext::Ewok).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"__type": {"description": "My character."}}),
|
graphql_value!({"__type": {"description": "My character."}}),
|
||||||
vec![],
|
vec![],
|
||||||
|
|
|
@ -3,8 +3,8 @@
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
|
|
||||||
use juniper::{
|
use juniper::{
|
||||||
execute, graphql_object, graphql_value, DefaultScalarValue, EmptyMutation, EmptySubscription,
|
execute, graphql_object, graphql_value, graphql_vars, DefaultScalarValue, EmptyMutation,
|
||||||
GraphQLObject, GraphQLType, GraphQLUnion, RootNode, ScalarValue, Variables,
|
EmptySubscription, GraphQLObject, GraphQLType, GraphQLUnion, RootNode, ScalarValue,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(GraphQLObject)]
|
#[derive(GraphQLObject)]
|
||||||
|
@ -126,7 +126,7 @@ mod trivial_enum {
|
||||||
let schema = schema(QueryRoot::Human);
|
let schema = schema(QueryRoot::Human);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"character": {"humanId": "human-32", "homePlanet": "earth"}}),
|
graphql_value!({"character": {"humanId": "human-32", "homePlanet": "earth"}}),
|
||||||
vec![],
|
vec![],
|
||||||
|
@ -139,7 +139,7 @@ mod trivial_enum {
|
||||||
let schema = schema(QueryRoot::Droid);
|
let schema = schema(QueryRoot::Droid);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"character": {"droidId": "droid-99", "primaryFunction": "run"}}),
|
graphql_value!({"character": {"droidId": "droid-99", "primaryFunction": "run"}}),
|
||||||
vec![],
|
vec![],
|
||||||
|
@ -158,7 +158,7 @@ mod trivial_enum {
|
||||||
let schema = schema(QueryRoot::Human);
|
let schema = schema(QueryRoot::Human);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((graphql_value!({"__type": {"kind": "UNION"}}), vec![])),
|
Ok((graphql_value!({"__type": {"kind": "UNION"}}), vec![])),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -174,7 +174,7 @@ mod trivial_enum {
|
||||||
let schema = schema(QueryRoot::Human);
|
let schema = schema(QueryRoot::Human);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((graphql_value!({"__type": {"name": "Character"}}), vec![])),
|
Ok((graphql_value!({"__type": {"name": "Character"}}), vec![])),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -190,8 +190,8 @@ mod trivial_enum {
|
||||||
let schema = schema(QueryRoot::Human);
|
let schema = schema(QueryRoot::Human);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((graphql_value!({"__type": {"description": None}}), vec![])),
|
Ok((graphql_value!({"__type": {"description": null}}), vec![])),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -246,7 +246,7 @@ mod generic_enum {
|
||||||
let schema = schema(QueryRoot::Human);
|
let schema = schema(QueryRoot::Human);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"character": {"humanId": "human-32", "homePlanet": "earth"}}),
|
graphql_value!({"character": {"humanId": "human-32", "homePlanet": "earth"}}),
|
||||||
vec![],
|
vec![],
|
||||||
|
@ -259,7 +259,7 @@ mod generic_enum {
|
||||||
let schema = schema(QueryRoot::Droid);
|
let schema = schema(QueryRoot::Droid);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"character": {"droidId": "droid-99", "primaryFunction": "run"}}),
|
graphql_value!({"character": {"droidId": "droid-99", "primaryFunction": "run"}}),
|
||||||
vec![],
|
vec![],
|
||||||
|
@ -278,7 +278,7 @@ mod generic_enum {
|
||||||
let schema = schema(QueryRoot::Human);
|
let schema = schema(QueryRoot::Human);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((graphql_value!({"__type": {"name": "Character"}}), vec![])),
|
Ok((graphql_value!({"__type": {"name": "Character"}}), vec![])),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -340,7 +340,7 @@ mod generic_lifetime_enum {
|
||||||
let schema = schema(QueryRoot::Human);
|
let schema = schema(QueryRoot::Human);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"character": {"humanId": "human-32"}}),
|
graphql_value!({"character": {"humanId": "human-32"}}),
|
||||||
vec![],
|
vec![],
|
||||||
|
@ -353,7 +353,7 @@ mod generic_lifetime_enum {
|
||||||
let schema = schema(QueryRoot::Droid);
|
let schema = schema(QueryRoot::Droid);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"character": {"droidId": "droid-99"}}),
|
graphql_value!({"character": {"droidId": "droid-99"}}),
|
||||||
vec![],
|
vec![],
|
||||||
|
@ -372,7 +372,7 @@ mod generic_lifetime_enum {
|
||||||
let schema = schema(QueryRoot::Human);
|
let schema = schema(QueryRoot::Human);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((graphql_value!({"__type": {"name": "Character"}}), vec![])),
|
Ok((graphql_value!({"__type": {"name": "Character"}}), vec![])),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -414,7 +414,7 @@ mod description_from_doc_comments {
|
||||||
let schema = schema(QueryRoot);
|
let schema = schema(QueryRoot);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"character": {"humanId": "human-32", "homePlanet": "earth"}}),
|
graphql_value!({"character": {"humanId": "human-32", "homePlanet": "earth"}}),
|
||||||
vec![],
|
vec![],
|
||||||
|
@ -433,7 +433,7 @@ mod description_from_doc_comments {
|
||||||
let schema = schema(QueryRoot);
|
let schema = schema(QueryRoot);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"__type": {"description": "Rust docs."}}),
|
graphql_value!({"__type": {"description": "Rust docs."}}),
|
||||||
vec![],
|
vec![],
|
||||||
|
@ -478,7 +478,7 @@ mod explicit_name_and_description {
|
||||||
let schema = schema(QueryRoot);
|
let schema = schema(QueryRoot);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"character": {"humanId": "human-32", "homePlanet": "earth"}}),
|
graphql_value!({"character": {"humanId": "human-32", "homePlanet": "earth"}}),
|
||||||
vec![],
|
vec![],
|
||||||
|
@ -497,7 +497,7 @@ mod explicit_name_and_description {
|
||||||
let schema = schema(QueryRoot);
|
let schema = schema(QueryRoot);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((graphql_value!({"__type": {"name": "MyChar"}}), vec![])),
|
Ok((graphql_value!({"__type": {"name": "MyChar"}}), vec![])),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -513,7 +513,7 @@ mod explicit_name_and_description {
|
||||||
let schema = schema(QueryRoot);
|
let schema = schema(QueryRoot);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"__type": {"description": "My character."}}),
|
graphql_value!({"__type": {"description": "My character."}}),
|
||||||
vec![],
|
vec![],
|
||||||
|
@ -571,7 +571,7 @@ mod explicit_scalar {
|
||||||
let schema = schema(QueryRoot::Human);
|
let schema = schema(QueryRoot::Human);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"character": {"humanId": "human-32", "homePlanet": "earth"}}),
|
graphql_value!({"character": {"humanId": "human-32", "homePlanet": "earth"}}),
|
||||||
vec![],
|
vec![],
|
||||||
|
@ -584,7 +584,7 @@ mod explicit_scalar {
|
||||||
let schema = schema(QueryRoot::Droid);
|
let schema = schema(QueryRoot::Droid);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"character": {"droidId": "droid-99", "primaryFunction": "run"}}),
|
graphql_value!({"character": {"droidId": "droid-99", "primaryFunction": "run"}}),
|
||||||
vec![],
|
vec![],
|
||||||
|
@ -644,7 +644,7 @@ mod custom_scalar {
|
||||||
let schema = schema_with_scalar::<MyScalarValue, _, _>(QueryRoot::Human);
|
let schema = schema_with_scalar::<MyScalarValue, _, _>(QueryRoot::Human);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"character": {"humanId": "human-32", "homePlanet": "earth"}}),
|
graphql_value!({"character": {"humanId": "human-32", "homePlanet": "earth"}}),
|
||||||
vec![],
|
vec![],
|
||||||
|
@ -657,7 +657,7 @@ mod custom_scalar {
|
||||||
let schema = schema_with_scalar::<MyScalarValue, _, _>(QueryRoot::Droid);
|
let schema = schema_with_scalar::<MyScalarValue, _, _>(QueryRoot::Droid);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"character": {"droidId": "droid-99", "primaryFunction": "run"}}),
|
graphql_value!({"character": {"droidId": "droid-99", "primaryFunction": "run"}}),
|
||||||
vec![],
|
vec![],
|
||||||
|
@ -717,7 +717,7 @@ mod explicit_generic_scalar {
|
||||||
let schema = schema(QueryRoot::Human);
|
let schema = schema(QueryRoot::Human);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"character": {"humanId": "human-32", "homePlanet": "earth"}}),
|
graphql_value!({"character": {"humanId": "human-32", "homePlanet": "earth"}}),
|
||||||
vec![],
|
vec![],
|
||||||
|
@ -730,7 +730,7 @@ mod explicit_generic_scalar {
|
||||||
let schema = schema(QueryRoot::Droid);
|
let schema = schema(QueryRoot::Droid);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"character": {"droidId": "droid-99", "primaryFunction": "run"}}),
|
graphql_value!({"character": {"droidId": "droid-99", "primaryFunction": "run"}}),
|
||||||
vec![],
|
vec![],
|
||||||
|
@ -788,7 +788,7 @@ mod bounded_generic_scalar {
|
||||||
let schema = schema(QueryRoot::Human);
|
let schema = schema(QueryRoot::Human);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"character": {"humanId": "human-32", "homePlanet": "earth"}}),
|
graphql_value!({"character": {"humanId": "human-32", "homePlanet": "earth"}}),
|
||||||
vec![],
|
vec![],
|
||||||
|
@ -801,7 +801,7 @@ mod bounded_generic_scalar {
|
||||||
let schema = schema(QueryRoot::Droid);
|
let schema = schema(QueryRoot::Droid);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"character": {"droidId": "droid-99", "primaryFunction": "run"}}),
|
graphql_value!({"character": {"droidId": "droid-99", "primaryFunction": "run"}}),
|
||||||
vec![],
|
vec![],
|
||||||
|
@ -857,7 +857,7 @@ mod custom_context {
|
||||||
let schema = schema(QueryRoot);
|
let schema = schema(QueryRoot);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &CustomContext::Human).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &CustomContext::Human).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"character": {"humanId": "human-32", "homePlanet": "earth"}}),
|
graphql_value!({"character": {"humanId": "human-32", "homePlanet": "earth"}}),
|
||||||
vec![],
|
vec![],
|
||||||
|
@ -870,7 +870,7 @@ mod custom_context {
|
||||||
let schema = schema(QueryRoot);
|
let schema = schema(QueryRoot);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &CustomContext::Droid).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &CustomContext::Droid).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"character": {"droidId": "droid-99", "primaryFunction": "run"}}),
|
graphql_value!({"character": {"droidId": "droid-99", "primaryFunction": "run"}}),
|
||||||
vec![],
|
vec![],
|
||||||
|
@ -926,7 +926,7 @@ mod different_context {
|
||||||
let schema = schema(QueryRoot);
|
let schema = schema(QueryRoot);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &CustomContext::Human).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &CustomContext::Human).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"character": {"humanId": "human-32", "homePlanet": "earth"}}),
|
graphql_value!({"character": {"humanId": "human-32", "homePlanet": "earth"}}),
|
||||||
vec![],
|
vec![],
|
||||||
|
@ -939,7 +939,7 @@ mod different_context {
|
||||||
let schema = schema(QueryRoot);
|
let schema = schema(QueryRoot);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &CustomContext::Droid).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &CustomContext::Droid).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"character": {"droidId": "droid-99", "primaryFunction": "run"}}),
|
graphql_value!({"character": {"droidId": "droid-99", "primaryFunction": "run"}}),
|
||||||
vec![],
|
vec![],
|
||||||
|
@ -986,7 +986,7 @@ mod ignored_enum_variants {
|
||||||
let schema = schema(QueryRoot);
|
let schema = schema(QueryRoot);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"character": {"humanId": "human-32", "homePlanet": "earth"}}),
|
graphql_value!({"character": {"humanId": "human-32", "homePlanet": "earth"}}),
|
||||||
vec![],
|
vec![],
|
||||||
|
@ -1007,7 +1007,7 @@ mod ignored_enum_variants {
|
||||||
let schema = schema(QueryRoot);
|
let schema = schema(QueryRoot);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"__type": {"possibleTypes": [{"name": "Human"}]}}),
|
graphql_value!({"__type": {"possibleTypes": [{"name": "Human"}]}}),
|
||||||
vec![],
|
vec![],
|
||||||
|
@ -1080,7 +1080,7 @@ mod external_resolver_enum {
|
||||||
let db = Database { droid: None };
|
let db = Database { droid: None };
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &db).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &db).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"character": {"humanId": "human-32", "homePlanet": "earth"}}),
|
graphql_value!({"character": {"humanId": "human-32", "homePlanet": "earth"}}),
|
||||||
vec![],
|
vec![],
|
||||||
|
@ -1099,7 +1099,7 @@ mod external_resolver_enum {
|
||||||
};
|
};
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &db).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &db).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"character": {"droidId": "droid-99", "primaryFunction": "run"}}),
|
graphql_value!({"character": {"droidId": "droid-99", "primaryFunction": "run"}}),
|
||||||
vec![],
|
vec![],
|
||||||
|
@ -1174,7 +1174,7 @@ mod external_resolver_enum_variant {
|
||||||
let db = Database { droid: None };
|
let db = Database { droid: None };
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &db).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &db).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"character": {"humanId": "human-32", "homePlanet": "earth"}}),
|
graphql_value!({"character": {"humanId": "human-32", "homePlanet": "earth"}}),
|
||||||
vec![],
|
vec![],
|
||||||
|
@ -1193,7 +1193,7 @@ mod external_resolver_enum_variant {
|
||||||
};
|
};
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &db).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &db).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"character": {"droidId": "droid-99", "primaryFunction": "run"}}),
|
graphql_value!({"character": {"droidId": "droid-99", "primaryFunction": "run"}}),
|
||||||
vec![],
|
vec![],
|
||||||
|
@ -1287,7 +1287,7 @@ mod full_featured_enum {
|
||||||
let schema = schema(QueryRoot);
|
let schema = schema(QueryRoot);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &CustomContext::Human).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &CustomContext::Human).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"character": {"humanId": "human-32", "homePlanet": "earth"}}),
|
graphql_value!({"character": {"humanId": "human-32", "homePlanet": "earth"}}),
|
||||||
vec![],
|
vec![],
|
||||||
|
@ -1300,7 +1300,7 @@ mod full_featured_enum {
|
||||||
let schema = schema(QueryRoot);
|
let schema = schema(QueryRoot);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &CustomContext::Droid).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &CustomContext::Droid).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"character": {"droidId": "droid-99", "primaryFunction": "run"}}),
|
graphql_value!({"character": {"droidId": "droid-99", "primaryFunction": "run"}}),
|
||||||
vec![],
|
vec![],
|
||||||
|
@ -1313,7 +1313,7 @@ mod full_featured_enum {
|
||||||
let schema = schema(QueryRoot);
|
let schema = schema(QueryRoot);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &CustomContext::Ewok).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &CustomContext::Ewok).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"character": {"ewokId": "ewok-1", "funny": true}}),
|
graphql_value!({"character": {"ewokId": "ewok-1", "funny": true}}),
|
||||||
vec![],
|
vec![],
|
||||||
|
@ -1332,7 +1332,7 @@ mod full_featured_enum {
|
||||||
let schema = schema(QueryRoot);
|
let schema = schema(QueryRoot);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &CustomContext::Ewok).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &CustomContext::Ewok).await,
|
||||||
Ok((graphql_value!({"__type": {"name": "MyChar"}}), vec![])),
|
Ok((graphql_value!({"__type": {"name": "MyChar"}}), vec![])),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1348,7 +1348,7 @@ mod full_featured_enum {
|
||||||
let schema = schema(QueryRoot);
|
let schema = schema(QueryRoot);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &CustomContext::Ewok).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &CustomContext::Ewok).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"__type": {"description": "My character."}}),
|
graphql_value!({"__type": {"description": "My character."}}),
|
||||||
vec![],
|
vec![],
|
||||||
|
@ -1439,7 +1439,7 @@ mod trivial_struct {
|
||||||
};
|
};
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &db).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &db).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"character": {"humanId": "human-32", "homePlanet": "earth"}}),
|
graphql_value!({"character": {"humanId": "human-32", "homePlanet": "earth"}}),
|
||||||
vec![],
|
vec![],
|
||||||
|
@ -1459,7 +1459,7 @@ mod trivial_struct {
|
||||||
};
|
};
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &db).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &db).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"character": {"droidId": "droid-99", "primaryFunction": "run"}}),
|
graphql_value!({"character": {"droidId": "droid-99", "primaryFunction": "run"}}),
|
||||||
vec![],
|
vec![],
|
||||||
|
@ -1485,7 +1485,7 @@ mod trivial_struct {
|
||||||
};
|
};
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &db).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &db).await,
|
||||||
Ok((graphql_value!({"__type": {"kind": "UNION"}}), vec![])),
|
Ok((graphql_value!({"__type": {"kind": "UNION"}}), vec![])),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1508,7 +1508,7 @@ mod trivial_struct {
|
||||||
};
|
};
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &db).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &db).await,
|
||||||
Ok((graphql_value!({"__type": {"name": "Character"}}), vec![])),
|
Ok((graphql_value!({"__type": {"name": "Character"}}), vec![])),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1531,8 +1531,8 @@ mod trivial_struct {
|
||||||
};
|
};
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &db).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &db).await,
|
||||||
Ok((graphql_value!({"__type": {"description": None}}), vec![])),
|
Ok((graphql_value!({"__type": {"description": null}}), vec![])),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1596,7 +1596,7 @@ mod generic_struct {
|
||||||
};
|
};
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &db).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &db).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"character": {"humanId": "human-32", "homePlanet": "earth"}}),
|
graphql_value!({"character": {"humanId": "human-32", "homePlanet": "earth"}}),
|
||||||
vec![],
|
vec![],
|
||||||
|
@ -1616,7 +1616,7 @@ mod generic_struct {
|
||||||
let db = Database { human: None };
|
let db = Database { human: None };
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &db).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &db).await,
|
||||||
Ok((graphql_value!({"__type": {"name": "Character"}}), vec![])),
|
Ok((graphql_value!({"__type": {"name": "Character"}}), vec![])),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1709,7 +1709,7 @@ mod full_featured_struct {
|
||||||
};
|
};
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &db).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &db).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"character": {"humanId": "human-32", "homePlanet": "earth"}}),
|
graphql_value!({"character": {"humanId": "human-32", "homePlanet": "earth"}}),
|
||||||
vec![],
|
vec![],
|
||||||
|
@ -1729,7 +1729,7 @@ mod full_featured_struct {
|
||||||
};
|
};
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &db).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &db).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"character": {"droidId": "droid-99", "primaryFunction": "run"}}),
|
graphql_value!({"character": {"droidId": "droid-99", "primaryFunction": "run"}}),
|
||||||
vec![],
|
vec![],
|
||||||
|
@ -1752,7 +1752,7 @@ mod full_featured_struct {
|
||||||
};
|
};
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &db).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &db).await,
|
||||||
Ok((graphql_value!({"__type": {"name": "MyChar"}}), vec![])),
|
Ok((graphql_value!({"__type": {"name": "MyChar"}}), vec![])),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1772,7 +1772,7 @@ mod full_featured_struct {
|
||||||
};
|
};
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &db).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &db).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"__type": {"description": "My character."}}),
|
graphql_value!({"__type": {"description": "My character."}}),
|
||||||
vec![],
|
vec![],
|
||||||
|
@ -1833,7 +1833,7 @@ mod issue_845 {
|
||||||
let schema = schema(QueryRoot::Human);
|
let schema = schema(QueryRoot::Human);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"character": {"humanId": "human-32", "homePlanet": "earth"}}),
|
graphql_value!({"character": {"humanId": "human-32", "homePlanet": "earth"}}),
|
||||||
vec![],
|
vec![],
|
||||||
|
@ -1846,7 +1846,7 @@ mod issue_845 {
|
||||||
let schema = schema(QueryRoot::Droid);
|
let schema = schema(QueryRoot::Droid);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"character": {"droidId": "droid-99", "primaryFunction": "run"}}),
|
graphql_value!({"character": {"droidId": "droid-99", "primaryFunction": "run"}}),
|
||||||
vec![],
|
vec![],
|
||||||
|
@ -1865,7 +1865,7 @@ mod issue_845 {
|
||||||
let schema = schema(QueryRoot::Human);
|
let schema = schema(QueryRoot::Human);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(DOC, None, &schema, &Variables::new(), &()).await,
|
execute(DOC, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((graphql_value!({"__type": {"kind": "UNION"}}), vec![])),
|
Ok((graphql_value!({"__type": {"kind": "UNION"}}), vec![])),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,8 +2,9 @@ use std::{convert::TryInto as _, fmt, pin::Pin};
|
||||||
|
|
||||||
use futures::{stream, Stream};
|
use futures::{stream, Stream};
|
||||||
use juniper::{
|
use juniper::{
|
||||||
execute, graphql_object, graphql_scalar, graphql_subscription,
|
execute, graphql_input_value, graphql_object, graphql_scalar, graphql_subscription,
|
||||||
parser::{ParseError, ScalarToken, Spanning, Token},
|
graphql_vars,
|
||||||
|
parser::{ParseError, ScalarToken, Token},
|
||||||
serde::{de, Deserialize, Deserializer, Serialize},
|
serde::{de, Deserialize, Deserializer, Serialize},
|
||||||
EmptyMutation, FieldResult, GraphQLScalarValue, InputValue, Object, ParseScalarResult,
|
EmptyMutation, FieldResult, GraphQLScalarValue, InputValue, Object, ParseScalarResult,
|
||||||
RootNode, ScalarValue, Value, Variables,
|
RootNode, ScalarValue, Value, Variables,
|
||||||
|
@ -201,7 +202,7 @@ async fn run_query<F>(query: &str, f: F)
|
||||||
where
|
where
|
||||||
F: Fn(&Object<MyScalarValue>) -> (),
|
F: Fn(&Object<MyScalarValue>) -> (),
|
||||||
{
|
{
|
||||||
run_variable_query(query, Variables::new(), f).await;
|
run_variable_query(query, graphql_vars! {}, f).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
|
@ -231,18 +232,14 @@ async fn querying_long_arg() {
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn querying_long_variable() {
|
async fn querying_long_variable() {
|
||||||
|
let num = i64::from(i32::MAX) + 42;
|
||||||
run_variable_query(
|
run_variable_query(
|
||||||
"query q($test: Long!){ longWithArg(longArg: $test) }",
|
"query q($test: Long!){ longWithArg(longArg: $test) }",
|
||||||
vec![(
|
graphql_vars! {"test": InputValue::<_>::scalar(num)},
|
||||||
"test".to_owned(),
|
|
||||||
InputValue::Scalar(MyScalarValue::Long(i64::from(i32::MAX) + 42)),
|
|
||||||
)]
|
|
||||||
.into_iter()
|
|
||||||
.collect(),
|
|
||||||
|result| {
|
|result| {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
result.get_field_value("longWithArg"),
|
result.get_field_value("longWithArg"),
|
||||||
Some(&Value::scalar(i64::from(i32::MAX) + 42))
|
Some(&Value::scalar(num)),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -253,14 +250,10 @@ async fn querying_long_variable() {
|
||||||
fn deserialize_variable() {
|
fn deserialize_variable() {
|
||||||
let json = format!("{{\"field\": {}}}", i64::from(i32::MAX) + 42);
|
let json = format!("{{\"field\": {}}}", i64::from(i32::MAX) + 42);
|
||||||
|
|
||||||
let input_value: InputValue<MyScalarValue> = serde_json::from_str(&json).unwrap();
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
input_value,
|
serde_json::from_str::<InputValue<MyScalarValue>>(&json).unwrap(),
|
||||||
InputValue::Object(vec![(
|
graphql_input_value!({
|
||||||
Spanning::unlocated("field".into()),
|
"field": InputValue::<_>::scalar(i64::from(i32::MAX) + 42),
|
||||||
Spanning::unlocated(InputValue::Scalar(MyScalarValue::Long(
|
}),
|
||||||
i64::from(i32::MAX) + 42
|
|
||||||
)))
|
|
||||||
)])
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use juniper::{
|
use juniper::{
|
||||||
graphql_object, graphql_value, EmptyMutation, EmptySubscription, GraphQLInputObject,
|
graphql_object, graphql_value, graphql_vars, EmptyMutation, EmptySubscription,
|
||||||
InputValue, Nullable,
|
GraphQLInputObject, Nullable, Variables,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub struct Context;
|
pub struct Context;
|
||||||
|
@ -47,36 +47,26 @@ async fn explicit_null() {
|
||||||
EmptyMutation::<Context>::new(),
|
EmptyMutation::<Context>::new(),
|
||||||
EmptySubscription::<Context>::new(),
|
EmptySubscription::<Context>::new(),
|
||||||
);
|
);
|
||||||
let vars = [
|
|
||||||
("emptyObj".to_string(), InputValue::Object(vec![])),
|
|
||||||
(
|
|
||||||
"literalNullObj".to_string(),
|
|
||||||
InputValue::object(vec![("field", InputValue::null())].into_iter().collect()),
|
|
||||||
),
|
|
||||||
];
|
|
||||||
|
|
||||||
let (data, errors) = juniper::execute(
|
let vars: Variables = graphql_vars! {
|
||||||
query,
|
"emptyObj": {},
|
||||||
None,
|
"literalNullObj": {"field": null},
|
||||||
&schema,
|
};
|
||||||
&vars.iter().cloned().collect(),
|
|
||||||
&Context,
|
|
||||||
)
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
assert_eq!(errors.len(), 0);
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
data,
|
juniper::execute(query, None, &schema, &vars, &Context).await,
|
||||||
graphql_value!({
|
Ok((
|
||||||
"literalOneIsExplicitNull": false,
|
graphql_value!({
|
||||||
"literalNullIsExplicitNull": true,
|
"literalOneIsExplicitNull": false,
|
||||||
"noArgIsExplicitNull": false,
|
"literalNullIsExplicitNull": true,
|
||||||
"literalOneFieldIsExplicitNull": false,
|
"noArgIsExplicitNull": false,
|
||||||
"literalNullFieldIsExplicitNull": true,
|
"literalOneFieldIsExplicitNull": false,
|
||||||
"noFieldIsExplicitNull": false,
|
"literalNullFieldIsExplicitNull": true,
|
||||||
"emptyVariableObjectFieldIsExplicitNull": false,
|
"noFieldIsExplicitNull": false,
|
||||||
"literalNullVariableObjectFieldIsExplicitNull": true,
|
"emptyVariableObjectFieldIsExplicitNull": false,
|
||||||
})
|
"literalNullVariableObjectFieldIsExplicitNull": true,
|
||||||
|
}),
|
||||||
|
vec![],
|
||||||
|
)),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,8 +5,8 @@
|
||||||
//! Original author of this test is [@davidpdrsn](https://github.com/davidpdrsn).
|
//! Original author of this test is [@davidpdrsn](https://github.com/davidpdrsn).
|
||||||
|
|
||||||
use juniper::{
|
use juniper::{
|
||||||
graphql_object, EmptyMutation, EmptySubscription, Executor, LookAheadMethods as _, RootNode,
|
graphql_object, graphql_vars, EmptyMutation, EmptySubscription, Executor,
|
||||||
ScalarValue, Variables,
|
LookAheadMethods as _, RootNode, ScalarValue,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub struct Context;
|
pub struct Context;
|
||||||
|
@ -57,7 +57,7 @@ async fn users() {
|
||||||
let query = "{ users { id } }";
|
let query = "{ users { id } }";
|
||||||
|
|
||||||
let schema = Schema::new(Query, EmptyMutation::new(), EmptySubscription::new());
|
let schema = Schema::new(Query, EmptyMutation::new(), EmptySubscription::new());
|
||||||
let (_, errors) = juniper::execute(query, None, &schema, &Variables::new(), &Context)
|
let (_, errors) = juniper::execute(query, None, &schema, &graphql_vars! {}, &Context)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -69,7 +69,7 @@ async fn countries() {
|
||||||
let query = "{ countries { id } }";
|
let query = "{ countries { id } }";
|
||||||
|
|
||||||
let schema = Schema::new(Query, EmptyMutation::new(), EmptySubscription::new());
|
let schema = Schema::new(Query, EmptyMutation::new(), EmptySubscription::new());
|
||||||
let (_, errors) = juniper::execute(query, None, &schema, &Variables::new(), &Context)
|
let (_, errors) = juniper::execute(query, None, &schema, &graphql_vars! {}, &Context)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -84,7 +84,7 @@ async fn both() {
|
||||||
}";
|
}";
|
||||||
|
|
||||||
let schema = Schema::new(Query, EmptyMutation::new(), EmptySubscription::new());
|
let schema = Schema::new(Query, EmptyMutation::new(), EmptySubscription::new());
|
||||||
let (_, errors) = juniper::execute(query, None, &schema, &Variables::new(), &Context)
|
let (_, errors) = juniper::execute(query, None, &schema, &graphql_vars! {}, &Context)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -99,7 +99,7 @@ async fn both_in_different_order() {
|
||||||
}";
|
}";
|
||||||
|
|
||||||
let schema = Schema::new(Query, EmptyMutation::new(), EmptySubscription::new());
|
let schema = Schema::new(Query, EmptyMutation::new(), EmptySubscription::new());
|
||||||
let (_, errors) = juniper::execute(query, None, &schema, &Variables::new(), &Context)
|
let (_, errors) = juniper::execute(query, None, &schema, &graphql_vars! {}, &Context)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
|
|
@ -3,8 +3,8 @@
|
||||||
|
|
||||||
use futures::{stream, FutureExt as _};
|
use futures::{stream, FutureExt as _};
|
||||||
use juniper::{
|
use juniper::{
|
||||||
execute, graphql_object, graphql_subscription, graphql_value, resolve_into_stream, RootNode,
|
execute, graphql_object, graphql_subscription, graphql_value, graphql_vars,
|
||||||
Variables,
|
resolve_into_stream, RootNode,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::util::extract_next;
|
use crate::util::extract_next;
|
||||||
|
@ -43,7 +43,7 @@ async fn implicit_query_typename() {
|
||||||
let schema = RootNode::new(Query, Mutation, Subscription);
|
let schema = RootNode::new(Query, Mutation, Subscription);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(query, None, &schema, &Variables::new(), &()).await,
|
execute(query, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((graphql_value!({"__typename": "Query"}), vec![])),
|
Ok((graphql_value!({"__typename": "Query"}), vec![])),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -55,7 +55,7 @@ async fn query_typename() {
|
||||||
let schema = RootNode::new(Query, Mutation, Subscription);
|
let schema = RootNode::new(Query, Mutation, Subscription);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(query, None, &schema, &Variables::new(), &()).await,
|
execute(query, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((graphql_value!({"__typename": "Query"}), vec![])),
|
Ok((graphql_value!({"__typename": "Query"}), vec![])),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -67,7 +67,7 @@ async fn explicit_query_typename() {
|
||||||
let schema = RootNode::new(Query, Mutation, Subscription);
|
let schema = RootNode::new(Query, Mutation, Subscription);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(query, None, &schema, &Variables::new(), &()).await,
|
execute(query, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((graphql_value!({"__typename": "Query"}), vec![])),
|
Ok((graphql_value!({"__typename": "Query"}), vec![])),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -79,7 +79,7 @@ async fn mutation_typename() {
|
||||||
let schema = RootNode::new(Query, Mutation, Subscription);
|
let schema = RootNode::new(Query, Mutation, Subscription);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(query, None, &schema, &Variables::new(), &()).await,
|
execute(query, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((graphql_value!({"__typename": "Mutation"}), vec![])),
|
Ok((graphql_value!({"__typename": "Mutation"}), vec![])),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -91,7 +91,7 @@ async fn explicit_mutation_typename() {
|
||||||
let schema = RootNode::new(Query, Mutation, Subscription);
|
let schema = RootNode::new(Query, Mutation, Subscription);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
execute(query, None, &schema, &Variables::new(), &()).await,
|
execute(query, None, &schema, &graphql_vars! {}, &()).await,
|
||||||
Ok((graphql_value!({"__typename": "Mutation"}), vec![])),
|
Ok((graphql_value!({"__typename": "Mutation"}), vec![])),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -103,7 +103,7 @@ async fn subscription_typename() {
|
||||||
let schema = RootNode::new(Query, Mutation, Subscription);
|
let schema = RootNode::new(Query, Mutation, Subscription);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
resolve_into_stream(query, None, &schema, &Variables::new(), &())
|
resolve_into_stream(query, None, &schema, &graphql_vars! {}, &())
|
||||||
.then(|s| extract_next(s))
|
.then(|s| extract_next(s))
|
||||||
.await,
|
.await,
|
||||||
Ok((graphql_value!({"__typename": "Subscription"}), vec![])),
|
Ok((graphql_value!({"__typename": "Subscription"}), vec![])),
|
||||||
|
@ -117,7 +117,7 @@ async fn explicit_subscription_typename() {
|
||||||
let schema = RootNode::new(Query, Mutation, Subscription);
|
let schema = RootNode::new(Query, Mutation, Subscription);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
resolve_into_stream(query, None, &schema, &Variables::new(), &())
|
resolve_into_stream(query, None, &schema, &graphql_vars! {}, &())
|
||||||
.then(|s| extract_next(s))
|
.then(|s| extract_next(s))
|
||||||
.await,
|
.await,
|
||||||
Ok((graphql_value!({"__typename": "Subscription"}), vec![])),
|
Ok((graphql_value!({"__typename": "Subscription"}), vec![])),
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
//! Original author of this test is [@davidpdrsn](https://github.com/davidpdrsn).
|
//! Original author of this test is [@davidpdrsn](https://github.com/davidpdrsn).
|
||||||
|
|
||||||
use juniper::{
|
use juniper::{
|
||||||
graphql_object, EmptyMutation, EmptySubscription, Executor, RootNode, ScalarValue, Variables,
|
graphql_object, graphql_vars, EmptyMutation, EmptySubscription, Executor, RootNode, ScalarValue,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Query;
|
struct Query;
|
||||||
|
@ -66,7 +66,7 @@ async fn lookahead_from_fragment_with_nested_type() {
|
||||||
"#,
|
"#,
|
||||||
None,
|
None,
|
||||||
&Schema::new(Query, EmptyMutation::new(), EmptySubscription::new()),
|
&Schema::new(Query, EmptyMutation::new(), EmptySubscription::new()),
|
||||||
&Variables::new(),
|
&graphql_vars! {},
|
||||||
&(),
|
&(),
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
|
|
|
@ -2,7 +2,8 @@
|
||||||
//! See [#407](https://github.com/graphql-rust/juniper/issues/407) for details.
|
//! See [#407](https://github.com/graphql-rust/juniper/issues/407) for details.
|
||||||
|
|
||||||
use juniper::{
|
use juniper::{
|
||||||
graphql_interface, graphql_object, EmptyMutation, EmptySubscription, GraphQLObject, Variables,
|
graphql_interface, graphql_object, graphql_vars, EmptyMutation, EmptySubscription,
|
||||||
|
GraphQLObject,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Query;
|
struct Query;
|
||||||
|
@ -78,12 +79,12 @@ async fn fragments_in_interface() {
|
||||||
|
|
||||||
let schema = Schema::new(Query, EmptyMutation::new(), EmptySubscription::new());
|
let schema = Schema::new(Query, EmptyMutation::new(), EmptySubscription::new());
|
||||||
|
|
||||||
let (_, errors) = juniper::execute(query, None, &schema, &Variables::new(), &())
|
let (_, errors) = juniper::execute(query, None, &schema, &graphql_vars! {}, &())
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(errors.len(), 0);
|
assert_eq!(errors.len(), 0);
|
||||||
|
|
||||||
let (_, errors) = juniper::execute_sync(query, None, &schema, &Variables::new(), &()).unwrap();
|
let (_, errors) = juniper::execute_sync(query, None, &schema, &graphql_vars! {}, &()).unwrap();
|
||||||
assert_eq!(errors.len(), 0);
|
assert_eq!(errors.len(), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -112,11 +113,11 @@ async fn inline_fragments_in_interface() {
|
||||||
|
|
||||||
let schema = Schema::new(Query, EmptyMutation::new(), EmptySubscription::new());
|
let schema = Schema::new(Query, EmptyMutation::new(), EmptySubscription::new());
|
||||||
|
|
||||||
let (_, errors) = juniper::execute(query, None, &schema, &Variables::new(), &())
|
let (_, errors) = juniper::execute(query, None, &schema, &graphql_vars! {}, &())
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(errors.len(), 0);
|
assert_eq!(errors.len(), 0);
|
||||||
|
|
||||||
let (_, errors) = juniper::execute_sync(query, None, &schema, &Variables::new(), &()).unwrap();
|
let (_, errors) = juniper::execute_sync(query, None, &schema, &graphql_vars! {}, &()).unwrap();
|
||||||
assert_eq!(errors.len(), 0);
|
assert_eq!(errors.len(), 0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
//! Checks that using nested fragments works okay.
|
//! Checks that using nested fragments works okay.
|
||||||
//! See [#500](https://github.com/graphql-rust/juniper/issues/500) for details.
|
//! See [#500](https://github.com/graphql-rust/juniper/issues/500) for details.
|
||||||
|
|
||||||
use juniper::{graphql_object, EmptyMutation, EmptySubscription, Executor, ScalarValue, Variables};
|
use juniper::{
|
||||||
|
graphql_object, graphql_vars, EmptyMutation, EmptySubscription, Executor, ScalarValue,
|
||||||
|
};
|
||||||
|
|
||||||
struct Query;
|
struct Query;
|
||||||
|
|
||||||
|
@ -82,7 +84,7 @@ async fn nested_fragments() {
|
||||||
"#;
|
"#;
|
||||||
|
|
||||||
let schema = Schema::new(Query, EmptyMutation::new(), EmptySubscription::new());
|
let schema = Schema::new(Query, EmptyMutation::new(), EmptySubscription::new());
|
||||||
let (_, errors) = juniper::execute(query, None, &schema, &Variables::new(), &())
|
let (_, errors) = juniper::execute(query, None, &schema, &graphql_vars! {}, &())
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
|
|
@ -2,8 +2,8 @@
|
||||||
//! See [#798](https://github.com/graphql-rust/juniper/issues/798) for details.
|
//! See [#798](https://github.com/graphql-rust/juniper/issues/798) for details.
|
||||||
|
|
||||||
use juniper::{
|
use juniper::{
|
||||||
graphql_interface, graphql_object, graphql_value, EmptyMutation, EmptySubscription,
|
graphql_interface, graphql_object, graphql_value, graphql_vars, EmptyMutation,
|
||||||
GraphQLObject, GraphQLUnion, RootNode, Variables,
|
EmptySubscription, GraphQLObject, GraphQLUnion, RootNode,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[graphql_interface(for = [Human, Droid])]
|
#[graphql_interface(for = [Human, Droid])]
|
||||||
|
@ -89,7 +89,7 @@ async fn interface_inline_fragment_on_union() {
|
||||||
"#;
|
"#;
|
||||||
|
|
||||||
let schema = Schema::new(Query::Human, EmptyMutation::new(), EmptySubscription::new());
|
let schema = Schema::new(Query::Human, EmptyMutation::new(), EmptySubscription::new());
|
||||||
let (res, errors) = juniper::execute(query, None, &schema, &Variables::new(), &())
|
let (res, errors) = juniper::execute(query, None, &schema, &graphql_vars! {}, &())
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -107,7 +107,7 @@ async fn interface_inline_fragment_on_union() {
|
||||||
|
|
||||||
let schema = Schema::new(Query::Droid, EmptyMutation::new(), EmptySubscription::new());
|
let schema = Schema::new(Query::Droid, EmptyMutation::new(), EmptySubscription::new());
|
||||||
let (res, errors) =
|
let (res, errors) =
|
||||||
juniper::execute_sync(query, None, &schema, &Variables::new(), &()).unwrap();
|
juniper::execute_sync(query, None, &schema, &graphql_vars! {}, &()).unwrap();
|
||||||
|
|
||||||
assert_eq!(errors.len(), 0);
|
assert_eq!(errors.len(), 0);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
@ -144,7 +144,7 @@ async fn interface_fragment_on_union() {
|
||||||
"#;
|
"#;
|
||||||
|
|
||||||
let schema = Schema::new(Query::Human, EmptyMutation::new(), EmptySubscription::new());
|
let schema = Schema::new(Query::Human, EmptyMutation::new(), EmptySubscription::new());
|
||||||
let (res, errors) = juniper::execute(query, None, &schema, &Variables::new(), &())
|
let (res, errors) = juniper::execute(query, None, &schema, &graphql_vars! {}, &())
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -162,7 +162,7 @@ async fn interface_fragment_on_union() {
|
||||||
|
|
||||||
let schema = Schema::new(Query::Droid, EmptyMutation::new(), EmptySubscription::new());
|
let schema = Schema::new(Query::Droid, EmptyMutation::new(), EmptySubscription::new());
|
||||||
let (res, errors) =
|
let (res, errors) =
|
||||||
juniper::execute_sync(query, None, &schema, &Variables::new(), &()).unwrap();
|
juniper::execute_sync(query, None, &schema, &graphql_vars! {}, &()).unwrap();
|
||||||
|
|
||||||
assert_eq!(errors.len(), 0);
|
assert_eq!(errors.len(), 0);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
//! Checks that multiple fragments on sub types don't override each other.
|
//! Checks that multiple fragments on sub types don't override each other.
|
||||||
//! See [#914](https://github.com/graphql-rust/juniper/issues/914) for details.
|
//! See [#914](https://github.com/graphql-rust/juniper/issues/914) for details.
|
||||||
|
|
||||||
use juniper::{graphql_object, EmptyMutation, EmptySubscription, GraphQLObject, Variables};
|
use juniper::{graphql_object, graphql_vars, EmptyMutation, EmptySubscription, GraphQLObject};
|
||||||
|
|
||||||
struct Query;
|
struct Query;
|
||||||
|
|
||||||
|
@ -77,13 +77,13 @@ async fn fragments_with_nested_objects_dont_override_previous_selections() {
|
||||||
|
|
||||||
let schema = Schema::new(Query, EmptyMutation::new(), EmptySubscription::new());
|
let schema = Schema::new(Query, EmptyMutation::new(), EmptySubscription::new());
|
||||||
|
|
||||||
let (async_value, errors) = juniper::execute(query, None, &schema, &Variables::new(), &())
|
let (async_value, errors) = juniper::execute(query, None, &schema, &graphql_vars! {}, &())
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(errors.len(), 0);
|
assert_eq!(errors.len(), 0);
|
||||||
|
|
||||||
let (sync_value, errors) =
|
let (sync_value, errors) =
|
||||||
juniper::execute_sync(query, None, &schema, &Variables::new(), &()).unwrap();
|
juniper::execute_sync(query, None, &schema, &graphql_vars! {}, &()).unwrap();
|
||||||
assert_eq!(errors.len(), 0);
|
assert_eq!(errors.len(), 0);
|
||||||
|
|
||||||
assert_eq!(async_value, sync_value);
|
assert_eq!(async_value, sync_value);
|
||||||
|
|
|
@ -2,8 +2,8 @@
|
||||||
//! See [#922](https://github.com/graphql-rust/juniper/issues/922) for details.
|
//! See [#922](https://github.com/graphql-rust/juniper/issues/922) for details.
|
||||||
|
|
||||||
use juniper::{
|
use juniper::{
|
||||||
graphql_interface, graphql_object, graphql_value, EmptyMutation, EmptySubscription,
|
graphql_interface, graphql_object, graphql_value, graphql_vars, EmptyMutation,
|
||||||
GraphQLObject, Variables,
|
EmptySubscription, GraphQLObject,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Query;
|
struct Query;
|
||||||
|
@ -93,7 +93,7 @@ async fn fragment_on_interface() {
|
||||||
|
|
||||||
let schema = Schema::new(Query, EmptyMutation::new(), EmptySubscription::new());
|
let schema = Schema::new(Query, EmptyMutation::new(), EmptySubscription::new());
|
||||||
|
|
||||||
let (res, errors) = juniper::execute(query, None, &schema, &Variables::new(), &())
|
let (res, errors) = juniper::execute(query, None, &schema, &graphql_vars! {}, &())
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -109,7 +109,7 @@ async fn fragment_on_interface() {
|
||||||
);
|
);
|
||||||
|
|
||||||
let (res, errors) =
|
let (res, errors) =
|
||||||
juniper::execute_sync(query, None, &schema, &Variables::new(), &()).unwrap();
|
juniper::execute_sync(query, None, &schema, &graphql_vars! {}, &()).unwrap();
|
||||||
|
|
||||||
assert_eq!(errors.len(), 0);
|
assert_eq!(errors.len(), 0);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
|
|
@ -4,8 +4,8 @@
|
||||||
|
|
||||||
use futures::stream::BoxStream;
|
use futures::stream::BoxStream;
|
||||||
use juniper::{
|
use juniper::{
|
||||||
graphql_object, graphql_subscription, graphql_value, EmptyMutation, FieldError, GraphQLObject,
|
graphql_object, graphql_subscription, graphql_value, graphql_vars, EmptyMutation, FieldError,
|
||||||
IntoFieldError, Object, ScalarValue, Value, Variables,
|
GraphQLObject, IntoFieldError, Object, ScalarValue, Value,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(GraphQLObject)]
|
#[derive(GraphQLObject)]
|
||||||
|
@ -59,7 +59,7 @@ async fn error_extensions() {
|
||||||
"#;
|
"#;
|
||||||
|
|
||||||
let schema = Schema::new(Query, EmptyMutation::new(), SubscriptionsRoot);
|
let schema = Schema::new(Query, EmptyMutation::new(), SubscriptionsRoot);
|
||||||
let (_, errors) = juniper::resolve_into_stream(sub, None, &schema, &Variables::new(), &())
|
let (_, errors) = juniper::resolve_into_stream(sub, None, &schema, &graphql_vars! {}, &())
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
|
|
@ -2,8 +2,8 @@
|
||||||
//! See [#945](https://github.com/graphql-rust/juniper/issues/945) for details.
|
//! See [#945](https://github.com/graphql-rust/juniper/issues/945) for details.
|
||||||
|
|
||||||
use juniper::{
|
use juniper::{
|
||||||
graphql_object, graphql_value, EmptyMutation, EmptySubscription, GraphQLObject, GraphQLUnion,
|
graphql_object, graphql_value, graphql_vars, EmptyMutation, EmptySubscription, GraphQLObject,
|
||||||
Variables,
|
GraphQLUnion,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Query;
|
struct Query;
|
||||||
|
@ -66,7 +66,7 @@ async fn fragment_on_union() {
|
||||||
|
|
||||||
let schema = Schema::new(Query, EmptyMutation::new(), EmptySubscription::new());
|
let schema = Schema::new(Query, EmptyMutation::new(), EmptySubscription::new());
|
||||||
|
|
||||||
let (res, errors) = juniper::execute(query, None, &schema, &Variables::new(), &())
|
let (res, errors) = juniper::execute(query, None, &schema, &graphql_vars! {}, &())
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -79,7 +79,7 @@ async fn fragment_on_union() {
|
||||||
);
|
);
|
||||||
|
|
||||||
let (res, errors) =
|
let (res, errors) =
|
||||||
juniper::execute_sync(query, None, &schema, &Variables::new(), &()).unwrap();
|
juniper::execute_sync(query, None, &schema, &graphql_vars! {}, &()).unwrap();
|
||||||
|
|
||||||
assert_eq!(errors.len(), 0);
|
assert_eq!(errors.len(), 0);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
use futures::{Stream, StreamExt, TryFutureExt};
|
use futures::{Stream, StreamExt, TryFutureExt};
|
||||||
use juniper::{
|
use juniper::{
|
||||||
executor::{execute_validated_query_async, get_operation, resolve_validated_subscription},
|
executor::{execute_validated_query_async, get_operation, resolve_validated_subscription},
|
||||||
graphql_object, graphql_subscription,
|
graphql_object, graphql_subscription, graphql_vars,
|
||||||
parser::parse_document_source,
|
parser::parse_document_source,
|
||||||
validation::{validate_input_values, visit_all_rules, ValidatorContext},
|
validation::{validate_input_values, visit_all_rules, ValidatorContext},
|
||||||
EmptyMutation, FieldError, OperationType, RootNode, Variables,
|
EmptyMutation, FieldError, OperationType, RootNode,
|
||||||
};
|
};
|
||||||
use std::pin::Pin;
|
use std::pin::Pin;
|
||||||
|
|
||||||
|
@ -61,14 +61,14 @@ async fn query_document_can_be_pre_parsed() {
|
||||||
let operation = get_operation(&document, None).unwrap();
|
let operation = get_operation(&document, None).unwrap();
|
||||||
assert!(operation.item.operation_type == OperationType::Query);
|
assert!(operation.item.operation_type == OperationType::Query);
|
||||||
|
|
||||||
let errors = validate_input_values(&juniper::Variables::new(), operation, &root_node.schema);
|
let errors = validate_input_values(&graphql_vars! {}, operation, &root_node.schema);
|
||||||
assert!(errors.is_empty());
|
assert!(errors.is_empty());
|
||||||
|
|
||||||
let (_, errors) = execute_validated_query_async(
|
let (_, errors) = execute_validated_query_async(
|
||||||
&document,
|
&document,
|
||||||
operation,
|
operation,
|
||||||
root_node,
|
root_node,
|
||||||
&Variables::new(),
|
&graphql_vars! {},
|
||||||
&Context {},
|
&Context {},
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
|
@ -91,7 +91,7 @@ async fn subscription_document_can_be_pre_parsed() {
|
||||||
&document,
|
&document,
|
||||||
&operation,
|
&operation,
|
||||||
&root_node,
|
&root_node,
|
||||||
&Variables::new(),
|
&graphql_vars! {},
|
||||||
&Context {},
|
&Context {},
|
||||||
)
|
)
|
||||||
.map_ok(|(stream, errors)| juniper_subscriptions::Connection::from_stream(stream, errors))
|
.map_ok(|(stream, errors)| juniper_subscriptions::Connection::from_stream(stream, errors))
|
||||||
|
|
|
@ -13,10 +13,14 @@
|
||||||
- Support using Rust array as GraphQL list. ([#966](https://github.com/graphql-rust/juniper/pull/966), [#918](https://github.com/graphql-rust/juniper/issues/918))
|
- Support using Rust array as GraphQL list. ([#966](https://github.com/graphql-rust/juniper/pull/966), [#918](https://github.com/graphql-rust/juniper/issues/918))
|
||||||
- Expose `GraphQLRequest` fields. ([#750](https://github.com/graphql-rust/juniper/issues/750))
|
- Expose `GraphQLRequest` fields. ([#750](https://github.com/graphql-rust/juniper/issues/750))
|
||||||
- `#[graphql_interface]` macro now supports `rename_all = "<policy>"` argument influencing its fields and their arguments. ([#971](https://github.com/graphql-rust/juniper/pull/971))
|
- `#[graphql_interface]` macro now supports `rename_all = "<policy>"` argument influencing its fields and their arguments. ([#971](https://github.com/graphql-rust/juniper/pull/971))
|
||||||
|
- Use `null` in addition to `None` to create `Value::Null` in `graphql_value!` macro to mirror `serde_json::json!`. ([#996](https://github.com/graphql-rust/juniper/pull/996))
|
||||||
|
- Add `From` impls to `InputValue` mirroring the ones for `Value` and provide better support for `Option` handling. ([#996](https://github.com/graphql-rust/juniper/pull/996))
|
||||||
|
- Implement `graphql_input_value!` and `graphql_vars!` macros. ([#996](https://github.com/graphql-rust/juniper/pull/996))
|
||||||
|
|
||||||
## Fixes
|
## Fixes
|
||||||
|
|
||||||
- Allow spreading interface fragments on unions and other interfaces. ([#965](https://github.com/graphql-rust/juniper/pull/965), [#798](https://github.com/graphql-rust/juniper/issues/798))
|
- Allow spreading interface fragments on unions and other interfaces. ([#965](https://github.com/graphql-rust/juniper/pull/965), [#798](https://github.com/graphql-rust/juniper/issues/798))
|
||||||
|
- Support expressions in `graphql_value!` macro. ([#996](https://github.com/graphql-rust/juniper/pull/996), [#503](https://github.com/graphql-rust/juniper/issues/503))
|
||||||
|
|
||||||
# [[0.15.7] 2021-07-08](https://github.com/graphql-rust/juniper/releases/tag/juniper-v0.15.7)
|
# [[0.15.7] 2021-07-08](https://github.com/graphql-rust/juniper/releases/tag/juniper-v0.15.7)
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
use bencher::{benchmark_group, benchmark_main, Bencher};
|
use bencher::{benchmark_group, benchmark_main, Bencher};
|
||||||
use juniper::{
|
use juniper::{
|
||||||
execute_sync,
|
execute_sync, graphql_vars,
|
||||||
tests::fixtures::starwars::schema::{Database, Query},
|
tests::fixtures::starwars::schema::{Database, Query},
|
||||||
DefaultScalarValue, EmptyMutation, EmptySubscription, RootNode, Variables,
|
DefaultScalarValue, EmptyMutation, EmptySubscription, RootNode,
|
||||||
};
|
};
|
||||||
|
|
||||||
fn query_type_name(b: &mut Bencher) {
|
fn query_type_name(b: &mut Bencher) {
|
||||||
|
@ -27,7 +27,7 @@ fn query_type_name(b: &mut Bencher) {
|
||||||
}
|
}
|
||||||
}"#;
|
}"#;
|
||||||
|
|
||||||
b.iter(|| execute_sync(doc, None, &schema, &Variables::new(), &database));
|
b.iter(|| execute_sync(doc, None, &schema, &graphql_vars! {}, &database));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn introspection_query(b: &mut Bencher) {
|
fn introspection_query(b: &mut Bencher) {
|
||||||
|
@ -137,7 +137,7 @@ fn introspection_query(b: &mut Bencher) {
|
||||||
}
|
}
|
||||||
"#;
|
"#;
|
||||||
|
|
||||||
b.iter(|| execute_sync(doc, None, &schema, &Variables::new(), &database));
|
b.iter(|| execute_sync(doc, None, &schema, &graphql_vars! {}, &database));
|
||||||
}
|
}
|
||||||
|
|
||||||
benchmark_group!(queries, query_type_name, introspection_query);
|
benchmark_group!(queries, query_type_name, introspection_query);
|
||||||
|
|
|
@ -34,7 +34,7 @@ pub enum Type<'a> {
|
||||||
///
|
///
|
||||||
/// Lists and objects variants are _spanned_, i.e. they contain a reference to
|
/// Lists and objects variants are _spanned_, i.e. they contain a reference to
|
||||||
/// their position in the source file, if available.
|
/// their position in the source file, if available.
|
||||||
#[derive(Debug, Clone, PartialEq)]
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
#[allow(missing_docs)]
|
#[allow(missing_docs)]
|
||||||
pub enum InputValue<S = DefaultScalarValue> {
|
pub enum InputValue<S = DefaultScalarValue> {
|
||||||
Null,
|
Null,
|
||||||
|
@ -204,12 +204,12 @@ impl<'a> Type<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> fmt::Display for Type<'a> {
|
impl<'a> fmt::Display for Type<'a> {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
match *self {
|
match self {
|
||||||
Type::Named(ref n) => write!(f, "{}", n),
|
Self::Named(n) => write!(f, "{}", n),
|
||||||
Type::NonNullNamed(ref n) => write!(f, "{}!", n),
|
Self::NonNullNamed(n) => write!(f, "{}!", n),
|
||||||
Type::List(ref t, _) => write!(f, "[{}]", t),
|
Self::List(t, _) => write!(f, "[{}]", t),
|
||||||
Type::NonNullList(ref t, _) => write!(f, "[{}]!", t),
|
Self::NonNullList(t, _) => write!(f, "[{}]!", t),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -298,7 +298,7 @@ impl<S> InputValue<S> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Shorthand form of invoking [`FromInputValue::from()`].
|
/// Shorthand form of invoking [`FromInputValue::from_input_value()`].
|
||||||
pub fn convert<T>(&self) -> Option<T>
|
pub fn convert<T>(&self) -> Option<T>
|
||||||
where
|
where
|
||||||
T: FromInputValue<S>,
|
T: FromInputValue<S>,
|
||||||
|
@ -435,7 +435,7 @@ impl<S> InputValue<S> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S: ScalarValue> fmt::Display for InputValue<S> {
|
impl<S: ScalarValue> fmt::Display for InputValue<S> {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
Self::Null => write!(f, "null"),
|
Self::Null => write!(f, "null"),
|
||||||
Self::Scalar(s) => {
|
Self::Scalar(s) => {
|
||||||
|
@ -449,33 +449,77 @@ impl<S: ScalarValue> fmt::Display for InputValue<S> {
|
||||||
Self::Variable(v) => write!(f, "${}", v),
|
Self::Variable(v) => write!(f, "${}", v),
|
||||||
Self::List(v) => {
|
Self::List(v) => {
|
||||||
write!(f, "[")?;
|
write!(f, "[")?;
|
||||||
|
|
||||||
for (i, spanning) in v.iter().enumerate() {
|
for (i, spanning) in v.iter().enumerate() {
|
||||||
spanning.item.fmt(f)?;
|
spanning.item.fmt(f)?;
|
||||||
if i < v.len() - 1 {
|
if i < v.len() - 1 {
|
||||||
write!(f, ", ")?;
|
write!(f, ", ")?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
write!(f, "]")
|
write!(f, "]")
|
||||||
}
|
}
|
||||||
Self::Object(o) => {
|
Self::Object(o) => {
|
||||||
write!(f, "{{")?;
|
write!(f, "{{")?;
|
||||||
|
for (i, (k, v)) in o.iter().enumerate() {
|
||||||
for (i, &(ref k, ref v)) in o.iter().enumerate() {
|
|
||||||
write!(f, "{}: ", k.item)?;
|
write!(f, "{}: ", k.item)?;
|
||||||
v.item.fmt(f)?;
|
v.item.fmt(f)?;
|
||||||
if i < o.len() - 1 {
|
if i < o.len() - 1 {
|
||||||
write!(f, ", ")?;
|
write!(f, ", ")?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
write!(f, "}}")
|
write!(f, "}}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<S, T> From<Option<T>> for InputValue<S>
|
||||||
|
where
|
||||||
|
Self: From<T>,
|
||||||
|
{
|
||||||
|
fn from(v: Option<T>) -> Self {
|
||||||
|
match v {
|
||||||
|
Some(v) => v.into(),
|
||||||
|
None => Self::Null,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a, S: From<String>> From<&'a str> for InputValue<S> {
|
||||||
|
fn from(s: &'a str) -> Self {
|
||||||
|
Self::scalar(s.to_owned())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a, S: From<String>> From<Cow<'a, str>> for InputValue<S> {
|
||||||
|
fn from(s: Cow<'a, str>) -> Self {
|
||||||
|
Self::scalar(s.into_owned())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<S: From<String>> From<String> for InputValue<S> {
|
||||||
|
fn from(s: String) -> Self {
|
||||||
|
Self::scalar(s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<S: From<i32>> From<i32> for InputValue<S> {
|
||||||
|
fn from(i: i32) -> Self {
|
||||||
|
Self::scalar(i)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<S: From<f64>> From<f64> for InputValue<S> {
|
||||||
|
fn from(f: f64) -> Self {
|
||||||
|
Self::scalar(f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<S: From<bool>> From<bool> for InputValue<S> {
|
||||||
|
fn from(b: bool) -> Self {
|
||||||
|
Self::scalar(b)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<'a, S> Arguments<'a, S> {
|
impl<'a, S> Arguments<'a, S> {
|
||||||
pub fn into_iter(self) -> vec::IntoIter<(Spanning<&'a str>, Spanning<InputValue<S>>)> {
|
pub fn into_iter(self) -> vec::IntoIter<(Spanning<&'a str>, Spanning<InputValue<S>>)> {
|
||||||
self.items.into_iter()
|
self.items.into_iter()
|
||||||
|
@ -510,47 +554,37 @@ impl<'a, S> VariableDefinitions<'a, S> {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
use crate::graphql_input_value;
|
||||||
|
|
||||||
use super::InputValue;
|
use super::InputValue;
|
||||||
use crate::parser::Spanning;
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_input_value_fmt() {
|
fn test_input_value_fmt() {
|
||||||
let value: InputValue = InputValue::null();
|
let value: InputValue = graphql_input_value!(null);
|
||||||
assert_eq!(format!("{}", value), "null");
|
assert_eq!(format!("{}", value), "null");
|
||||||
|
|
||||||
let value: InputValue = InputValue::scalar(123);
|
let value: InputValue = graphql_input_value!(123);
|
||||||
assert_eq!(format!("{}", value), "123");
|
assert_eq!(format!("{}", value), "123");
|
||||||
|
|
||||||
let value: InputValue = InputValue::scalar(12.3);
|
let value: InputValue = graphql_input_value!(12.3);
|
||||||
assert_eq!(format!("{}", value), "12.3");
|
assert_eq!(format!("{}", value), "12.3");
|
||||||
|
|
||||||
let value: InputValue = InputValue::scalar("FOO".to_owned());
|
let value: InputValue = graphql_input_value!("FOO");
|
||||||
assert_eq!(format!("{}", value), "\"FOO\"");
|
assert_eq!(format!("{}", value), "\"FOO\"");
|
||||||
|
|
||||||
let value: InputValue = InputValue::scalar(true);
|
let value: InputValue = graphql_input_value!(true);
|
||||||
assert_eq!(format!("{}", value), "true");
|
assert_eq!(format!("{}", value), "true");
|
||||||
|
|
||||||
let value: InputValue = InputValue::enum_value("BAR".to_owned());
|
let value: InputValue = graphql_input_value!(BAR);
|
||||||
assert_eq!(format!("{}", value), "BAR");
|
assert_eq!(format!("{}", value), "BAR");
|
||||||
|
|
||||||
let value: InputValue = InputValue::variable("baz".to_owned());
|
let value: InputValue = graphql_input_value!(@baz);
|
||||||
assert_eq!(format!("{}", value), "$baz");
|
assert_eq!(format!("{}", value), "$baz");
|
||||||
|
|
||||||
let list = vec![InputValue::scalar(1), InputValue::scalar(2)];
|
let value: InputValue = graphql_input_value!([1, 2]);
|
||||||
let value: InputValue = InputValue::list(list);
|
|
||||||
assert_eq!(format!("{}", value), "[1, 2]");
|
assert_eq!(format!("{}", value), "[1, 2]");
|
||||||
|
|
||||||
let object = vec![
|
let value: InputValue = graphql_input_value!({"foo": 1,"bar": 2});
|
||||||
(
|
|
||||||
Spanning::unlocated("foo".to_owned()),
|
|
||||||
Spanning::unlocated(InputValue::scalar(1)),
|
|
||||||
),
|
|
||||||
(
|
|
||||||
Spanning::unlocated("bar".to_owned()),
|
|
||||||
Spanning::unlocated(InputValue::scalar(2)),
|
|
||||||
),
|
|
||||||
];
|
|
||||||
let value: InputValue = InputValue::parsed_object(object);
|
|
||||||
assert_eq!(format!("{}", value), "{foo: 1, bar: 2}");
|
assert_eq!(format!("{}", value), "{foo: 1, bar: 2}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
ast::{Directive, Fragment, InputValue, Selection},
|
ast::{Directive, Fragment, InputValue, Selection},
|
||||||
parser::Spanning,
|
parser::Spanning,
|
||||||
value::ScalarValue,
|
value::ScalarValue,
|
||||||
};
|
};
|
||||||
|
|
||||||
use std::collections::HashMap;
|
|
||||||
|
|
||||||
use super::Variables;
|
use super::Variables;
|
||||||
|
|
||||||
/// An enum that describes if a field is available in all types of the interface
|
/// An enum that describes if a field is available in all types of the interface
|
||||||
|
@ -438,15 +438,18 @@ impl<'a, S> LookAheadMethods<'a, S> for LookAheadSelection<'a, S> {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
ast::{Document, OwnedDocument},
|
ast::{Document, OwnedDocument},
|
||||||
|
graphql_vars,
|
||||||
parser::UnlocatedParseResult,
|
parser::UnlocatedParseResult,
|
||||||
schema::model::SchemaType,
|
schema::model::SchemaType,
|
||||||
validation::test_harness::{MutationRoot, QueryRoot, SubscriptionRoot},
|
validation::test_harness::{MutationRoot, QueryRoot, SubscriptionRoot},
|
||||||
value::{DefaultScalarValue, ScalarValue},
|
value::{DefaultScalarValue, ScalarValue},
|
||||||
};
|
};
|
||||||
use std::collections::HashMap;
|
|
||||||
|
use super::*;
|
||||||
|
|
||||||
fn parse_document_source<S>(q: &str) -> UnlocatedParseResult<OwnedDocument<S>>
|
fn parse_document_source<S>(q: &str) -> UnlocatedParseResult<OwnedDocument<S>>
|
||||||
where
|
where
|
||||||
|
@ -488,7 +491,7 @@ query Hero {
|
||||||
let fragments = extract_fragments(&docs);
|
let fragments = extract_fragments(&docs);
|
||||||
|
|
||||||
if let crate::ast::Definition::Operation(ref op) = docs[0] {
|
if let crate::ast::Definition::Operation(ref op) = docs[0] {
|
||||||
let vars = Variables::default();
|
let vars = graphql_vars! {};
|
||||||
let look_ahead = LookAheadSelection::build_from_selection(
|
let look_ahead = LookAheadSelection::build_from_selection(
|
||||||
&op.item.selection_set[0],
|
&op.item.selection_set[0],
|
||||||
&vars,
|
&vars,
|
||||||
|
@ -542,7 +545,7 @@ query Hero {
|
||||||
let fragments = extract_fragments(&docs);
|
let fragments = extract_fragments(&docs);
|
||||||
|
|
||||||
if let crate::ast::Definition::Operation(ref op) = docs[0] {
|
if let crate::ast::Definition::Operation(ref op) = docs[0] {
|
||||||
let vars = Variables::default();
|
let vars = graphql_vars! {};
|
||||||
let look_ahead = LookAheadSelection::build_from_selection(
|
let look_ahead = LookAheadSelection::build_from_selection(
|
||||||
&op.item.selection_set[0],
|
&op.item.selection_set[0],
|
||||||
&vars,
|
&vars,
|
||||||
|
@ -600,7 +603,7 @@ query Hero {
|
||||||
let fragments = extract_fragments(&docs);
|
let fragments = extract_fragments(&docs);
|
||||||
|
|
||||||
if let crate::ast::Definition::Operation(ref op) = docs[0] {
|
if let crate::ast::Definition::Operation(ref op) = docs[0] {
|
||||||
let vars = Variables::default();
|
let vars = graphql_vars! {};
|
||||||
let look_ahead = LookAheadSelection::build_from_selection(
|
let look_ahead = LookAheadSelection::build_from_selection(
|
||||||
&op.item.selection_set[0],
|
&op.item.selection_set[0],
|
||||||
&vars,
|
&vars,
|
||||||
|
@ -682,7 +685,7 @@ query Hero {
|
||||||
let fragments = extract_fragments(&docs);
|
let fragments = extract_fragments(&docs);
|
||||||
|
|
||||||
if let crate::ast::Definition::Operation(ref op) = docs[0] {
|
if let crate::ast::Definition::Operation(ref op) = docs[0] {
|
||||||
let vars = Variables::default();
|
let vars = graphql_vars! {};
|
||||||
let look_ahead = LookAheadSelection::build_from_selection(
|
let look_ahead = LookAheadSelection::build_from_selection(
|
||||||
&op.item.selection_set[0],
|
&op.item.selection_set[0],
|
||||||
&vars,
|
&vars,
|
||||||
|
@ -742,8 +745,7 @@ query Hero($episode: Episode) {
|
||||||
let fragments = extract_fragments(&docs);
|
let fragments = extract_fragments(&docs);
|
||||||
|
|
||||||
if let crate::ast::Definition::Operation(ref op) = docs[0] {
|
if let crate::ast::Definition::Operation(ref op) = docs[0] {
|
||||||
let mut vars = Variables::default();
|
let vars = graphql_vars! {"episode": JEDI};
|
||||||
vars.insert("episode".into(), InputValue::Enum("JEDI".into()));
|
|
||||||
let look_ahead = LookAheadSelection::build_from_selection(
|
let look_ahead = LookAheadSelection::build_from_selection(
|
||||||
&op.item.selection_set[0],
|
&op.item.selection_set[0],
|
||||||
&vars,
|
&vars,
|
||||||
|
@ -799,7 +801,7 @@ query Hero($episode: Episode) {
|
||||||
let fragments = extract_fragments(&docs);
|
let fragments = extract_fragments(&docs);
|
||||||
|
|
||||||
if let crate::ast::Definition::Operation(ref op) = docs[0] {
|
if let crate::ast::Definition::Operation(ref op) = docs[0] {
|
||||||
let vars = Variables::default();
|
let vars = graphql_vars! {};
|
||||||
let look_ahead = LookAheadSelection::build_from_selection(
|
let look_ahead = LookAheadSelection::build_from_selection(
|
||||||
&op.item.selection_set[0],
|
&op.item.selection_set[0],
|
||||||
&vars,
|
&vars,
|
||||||
|
@ -849,7 +851,7 @@ fragment commonFields on Character {
|
||||||
let fragments = extract_fragments(&docs);
|
let fragments = extract_fragments(&docs);
|
||||||
|
|
||||||
if let crate::ast::Definition::Operation(ref op) = docs[0] {
|
if let crate::ast::Definition::Operation(ref op) = docs[0] {
|
||||||
let vars = Variables::default();
|
let vars = graphql_vars! {};
|
||||||
let look_ahead = LookAheadSelection::build_from_selection(
|
let look_ahead = LookAheadSelection::build_from_selection(
|
||||||
&op.item.selection_set[0],
|
&op.item.selection_set[0],
|
||||||
&vars,
|
&vars,
|
||||||
|
@ -913,7 +915,7 @@ query Hero {
|
||||||
let fragments = extract_fragments(&docs);
|
let fragments = extract_fragments(&docs);
|
||||||
|
|
||||||
if let crate::ast::Definition::Operation(ref op) = docs[0] {
|
if let crate::ast::Definition::Operation(ref op) = docs[0] {
|
||||||
let vars = Variables::default();
|
let vars = graphql_vars! {};
|
||||||
let look_ahead = LookAheadSelection::build_from_selection(
|
let look_ahead = LookAheadSelection::build_from_selection(
|
||||||
&op.item.selection_set[0],
|
&op.item.selection_set[0],
|
||||||
&vars,
|
&vars,
|
||||||
|
@ -971,7 +973,7 @@ query Hero {
|
||||||
let fragments = extract_fragments(&docs);
|
let fragments = extract_fragments(&docs);
|
||||||
|
|
||||||
if let crate::ast::Definition::Operation(ref op) = docs[0] {
|
if let crate::ast::Definition::Operation(ref op) = docs[0] {
|
||||||
let vars = Variables::default();
|
let vars = graphql_vars! {};
|
||||||
let look_ahead = LookAheadSelection::build_from_selection(
|
let look_ahead = LookAheadSelection::build_from_selection(
|
||||||
&op.item.selection_set[0],
|
&op.item.selection_set[0],
|
||||||
&vars,
|
&vars,
|
||||||
|
@ -1036,7 +1038,7 @@ query HeroAndHuman {
|
||||||
let fragments = extract_fragments(&docs);
|
let fragments = extract_fragments(&docs);
|
||||||
|
|
||||||
if let crate::ast::Definition::Operation(ref op) = docs[0] {
|
if let crate::ast::Definition::Operation(ref op) = docs[0] {
|
||||||
let vars = Variables::default();
|
let vars = graphql_vars! {};
|
||||||
let look_ahead = LookAheadSelection::build_from_selection(
|
let look_ahead = LookAheadSelection::build_from_selection(
|
||||||
&op.item.selection_set[0],
|
&op.item.selection_set[0],
|
||||||
&vars,
|
&vars,
|
||||||
|
@ -1112,13 +1114,10 @@ fragment comparisonFields on Character {
|
||||||
let fragments = extract_fragments(&docs);
|
let fragments = extract_fragments(&docs);
|
||||||
|
|
||||||
if let crate::ast::Definition::Operation(ref op) = docs[0] {
|
if let crate::ast::Definition::Operation(ref op) = docs[0] {
|
||||||
let mut vars = Variables::default();
|
let vars = graphql_vars! {
|
||||||
vars.insert("id".into(), InputValue::Scalar(DefaultScalarValue::Int(42)));
|
"id": 42,
|
||||||
// This will normally be there
|
"withFriends": true,
|
||||||
vars.insert(
|
};
|
||||||
"withFriends".into(),
|
|
||||||
InputValue::Scalar(DefaultScalarValue::Boolean(true)),
|
|
||||||
);
|
|
||||||
let look_ahead = LookAheadSelection::build_from_selection(
|
let look_ahead = LookAheadSelection::build_from_selection(
|
||||||
&op.item.selection_set[0],
|
&op.item.selection_set[0],
|
||||||
&vars,
|
&vars,
|
||||||
|
@ -1270,7 +1269,7 @@ query Hero {
|
||||||
let fragments = extract_fragments(&docs);
|
let fragments = extract_fragments(&docs);
|
||||||
|
|
||||||
if let crate::ast::Definition::Operation(ref op) = docs[0] {
|
if let crate::ast::Definition::Operation(ref op) = docs[0] {
|
||||||
let vars = Variables::default();
|
let vars = graphql_vars! {};
|
||||||
let look_ahead = LookAheadSelection::build_from_selection(
|
let look_ahead = LookAheadSelection::build_from_selection(
|
||||||
&op.item.selection_set[0],
|
&op.item.selection_set[0],
|
||||||
&vars,
|
&vars,
|
||||||
|
@ -1419,7 +1418,7 @@ fragment heroFriendNames on Hero {
|
||||||
let fragments = extract_fragments(&docs);
|
let fragments = extract_fragments(&docs);
|
||||||
|
|
||||||
if let crate::ast::Definition::Operation(ref op) = docs[0] {
|
if let crate::ast::Definition::Operation(ref op) = docs[0] {
|
||||||
let vars = Variables::default();
|
let vars = graphql_vars! {};
|
||||||
let look_ahead = LookAheadSelection::build_from_selection(
|
let look_ahead = LookAheadSelection::build_from_selection(
|
||||||
&op.item.selection_set[0],
|
&op.item.selection_set[0],
|
||||||
&vars,
|
&vars,
|
||||||
|
@ -1473,7 +1472,7 @@ query Hero {
|
||||||
let fragments = extract_fragments(&docs);
|
let fragments = extract_fragments(&docs);
|
||||||
|
|
||||||
if let crate::ast::Definition::Operation(ref op) = docs[0] {
|
if let crate::ast::Definition::Operation(ref op) = docs[0] {
|
||||||
let vars = Variables::default();
|
let vars = graphql_vars! {};
|
||||||
let look_ahead = LookAheadSelection::build_from_selection(
|
let look_ahead = LookAheadSelection::build_from_selection(
|
||||||
&op.item.selection_set[0],
|
&op.item.selection_set[0],
|
||||||
&vars,
|
&vars,
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
ast::InputValue,
|
|
||||||
executor::Variables,
|
executor::Variables,
|
||||||
|
graphql_value, graphql_vars,
|
||||||
parser::SourcePosition,
|
parser::SourcePosition,
|
||||||
schema::model::RootNode,
|
schema::model::RootNode,
|
||||||
types::scalars::{EmptyMutation, EmptySubscription},
|
types::scalars::{EmptyMutation, EmptySubscription},
|
||||||
|
@ -16,6 +16,7 @@ enum Color {
|
||||||
Green,
|
Green,
|
||||||
Blue,
|
Blue,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct TestType;
|
struct TestType;
|
||||||
|
|
||||||
#[crate::graphql_object]
|
#[crate::graphql_object]
|
||||||
|
@ -90,7 +91,7 @@ async fn does_not_accept_string_literals() {
|
||||||
);
|
);
|
||||||
|
|
||||||
let query = r#"{ toString(color: "RED") }"#;
|
let query = r#"{ toString(color: "RED") }"#;
|
||||||
let vars = vec![].into_iter().collect();
|
let vars = graphql_vars! {};
|
||||||
|
|
||||||
let error = crate::execute(query, None, &schema, &vars, &())
|
let error = crate::execute(query, None, &schema, &vars, &())
|
||||||
.await
|
.await
|
||||||
|
@ -109,9 +110,7 @@ async fn does_not_accept_string_literals() {
|
||||||
async fn accepts_strings_in_variables() {
|
async fn accepts_strings_in_variables() {
|
||||||
run_variable_query(
|
run_variable_query(
|
||||||
"query q($color: Color!) { toString(color: $color) }",
|
"query q($color: Color!) { toString(color: $color) }",
|
||||||
vec![("color".to_owned(), InputValue::scalar("RED"))]
|
graphql_vars! {"color": "RED"},
|
||||||
.into_iter()
|
|
||||||
.collect(),
|
|
||||||
|result| {
|
|result| {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
result.get_field_value("toString"),
|
result.get_field_value("toString"),
|
||||||
|
@ -131,9 +130,7 @@ async fn does_not_accept_incorrect_enum_name_in_variables() {
|
||||||
);
|
);
|
||||||
|
|
||||||
let query = r#"query q($color: Color!) { toString(color: $color) }"#;
|
let query = r#"query q($color: Color!) { toString(color: $color) }"#;
|
||||||
let vars = vec![("color".to_owned(), InputValue::scalar("BLURPLE"))]
|
let vars = graphql_vars! {"color": "BLURPLE"};
|
||||||
.into_iter()
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
let error = crate::execute(query, None, &schema, &vars, &())
|
let error = crate::execute(query, None, &schema, &vars, &())
|
||||||
.await
|
.await
|
||||||
|
@ -144,7 +141,7 @@ async fn does_not_accept_incorrect_enum_name_in_variables() {
|
||||||
ValidationError(vec![RuleError::new(
|
ValidationError(vec![RuleError::new(
|
||||||
r#"Variable "$color" got invalid value. Invalid value for enum "Color"."#,
|
r#"Variable "$color" got invalid value. Invalid value for enum "Color"."#,
|
||||||
&[SourcePosition::new(8, 0, 8)],
|
&[SourcePosition::new(8, 0, 8)],
|
||||||
)])
|
)]),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -157,9 +154,7 @@ async fn does_not_accept_incorrect_type_in_variables() {
|
||||||
);
|
);
|
||||||
|
|
||||||
let query = r#"query q($color: Color!) { toString(color: $color) }"#;
|
let query = r#"query q($color: Color!) { toString(color: $color) }"#;
|
||||||
let vars = vec![("color".to_owned(), InputValue::scalar(123))]
|
let vars = graphql_vars! {"color": 123};
|
||||||
.into_iter()
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
let error = crate::execute(query, None, &schema, &vars, &())
|
let error = crate::execute(query, None, &schema, &vars, &())
|
||||||
.await
|
.await
|
||||||
|
@ -170,6 +165,6 @@ async fn does_not_accept_incorrect_type_in_variables() {
|
||||||
ValidationError(vec![RuleError::new(
|
ValidationError(vec![RuleError::new(
|
||||||
r#"Variable "$color" got invalid value. Expected "Color", found not a string or enum."#,
|
r#"Variable "$color" got invalid value. Expected "Color", found not a string or enum."#,
|
||||||
&[SourcePosition::new(8, 0, 8)],
|
&[SourcePosition::new(8, 0, 8)],
|
||||||
)])
|
)]),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
mod field_execution {
|
mod field_execution {
|
||||||
use crate::{
|
use crate::{
|
||||||
ast::InputValue,
|
graphql_object, graphql_value, graphql_vars,
|
||||||
graphql_value,
|
|
||||||
schema::model::RootNode,
|
schema::model::RootNode,
|
||||||
types::scalars::{EmptyMutation, EmptySubscription},
|
types::scalars::{EmptyMutation, EmptySubscription},
|
||||||
};
|
};
|
||||||
|
@ -9,7 +8,7 @@ mod field_execution {
|
||||||
struct DataType;
|
struct DataType;
|
||||||
struct DeepDataType;
|
struct DeepDataType;
|
||||||
|
|
||||||
#[crate::graphql_object]
|
#[graphql_object]
|
||||||
impl DataType {
|
impl DataType {
|
||||||
fn a() -> &'static str {
|
fn a() -> &'static str {
|
||||||
"Apple"
|
"Apple"
|
||||||
|
@ -39,7 +38,7 @@ mod field_execution {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[crate::graphql_object]
|
#[graphql_object]
|
||||||
impl DeepDataType {
|
impl DeepDataType {
|
||||||
fn a() -> &'static str {
|
fn a() -> &'static str {
|
||||||
"Already Been Done"
|
"Already Been Done"
|
||||||
|
@ -89,10 +88,7 @@ mod field_execution {
|
||||||
e
|
e
|
||||||
}
|
}
|
||||||
";
|
";
|
||||||
|
let vars = graphql_vars! {"size": 100};
|
||||||
let vars = vec![("size".to_owned(), InputValue::scalar(100))]
|
|
||||||
.into_iter()
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
let (result, errs) = crate::execute(doc, None, &schema, &vars, &())
|
let (result, errs) = crate::execute(doc, None, &schema, &vars, &())
|
||||||
.await
|
.await
|
||||||
|
@ -115,13 +111,13 @@ mod field_execution {
|
||||||
"deep": {
|
"deep": {
|
||||||
"a": "Already Been Done",
|
"a": "Already Been Done",
|
||||||
"b": "Boring",
|
"b": "Boring",
|
||||||
"c": ["Contrived", None, "Confusing"],
|
"c": ["Contrived", null, "Confusing"],
|
||||||
"deeper": [
|
"deeper": [
|
||||||
{
|
{
|
||||||
"a": "Apple",
|
"a": "Apple",
|
||||||
"b": "Banana",
|
"b": "Banana",
|
||||||
},
|
},
|
||||||
None,
|
null,
|
||||||
{
|
{
|
||||||
"a": "Apple",
|
"a": "Apple",
|
||||||
"b": "Banana",
|
"b": "Banana",
|
||||||
|
@ -135,13 +131,14 @@ mod field_execution {
|
||||||
|
|
||||||
mod merge_parallel_fragments {
|
mod merge_parallel_fragments {
|
||||||
use crate::{
|
use crate::{
|
||||||
|
graphql_object, graphql_value, graphql_vars,
|
||||||
schema::model::RootNode,
|
schema::model::RootNode,
|
||||||
types::scalars::{EmptyMutation, EmptySubscription},
|
types::scalars::{EmptyMutation, EmptySubscription},
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Type;
|
struct Type;
|
||||||
|
|
||||||
#[crate::graphql_object]
|
#[graphql_object]
|
||||||
impl Type {
|
impl Type {
|
||||||
fn a() -> &'static str {
|
fn a() -> &'static str {
|
||||||
"Apple"
|
"Apple"
|
||||||
|
@ -175,8 +172,7 @@ mod merge_parallel_fragments {
|
||||||
deep { c, deeper: deep { c } }
|
deep { c, deeper: deep { c } }
|
||||||
}
|
}
|
||||||
";
|
";
|
||||||
|
let vars = graphql_vars! {};
|
||||||
let vars = vec![].into_iter().collect();
|
|
||||||
|
|
||||||
let (result, errs) = crate::execute(doc, None, &schema, &vars, &())
|
let (result, errs) = crate::execute(doc, None, &schema, &vars, &())
|
||||||
.await
|
.await
|
||||||
|
@ -207,6 +203,7 @@ mod merge_parallel_fragments {
|
||||||
|
|
||||||
mod merge_parallel_inline_fragments {
|
mod merge_parallel_inline_fragments {
|
||||||
use crate::{
|
use crate::{
|
||||||
|
graphql_object, graphql_value, graphql_vars,
|
||||||
schema::model::RootNode,
|
schema::model::RootNode,
|
||||||
types::scalars::{EmptyMutation, EmptySubscription},
|
types::scalars::{EmptyMutation, EmptySubscription},
|
||||||
};
|
};
|
||||||
|
@ -214,7 +211,7 @@ mod merge_parallel_inline_fragments {
|
||||||
struct Type;
|
struct Type;
|
||||||
struct Other;
|
struct Other;
|
||||||
|
|
||||||
#[crate::graphql_object]
|
#[graphql_object]
|
||||||
impl Type {
|
impl Type {
|
||||||
fn a() -> &'static str {
|
fn a() -> &'static str {
|
||||||
"Apple"
|
"Apple"
|
||||||
|
@ -233,7 +230,7 @@ mod merge_parallel_inline_fragments {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[crate::graphql_object]
|
#[graphql_object]
|
||||||
impl Other {
|
impl Other {
|
||||||
fn a() -> &'static str {
|
fn a() -> &'static str {
|
||||||
"Apple"
|
"Apple"
|
||||||
|
@ -283,8 +280,7 @@ mod merge_parallel_inline_fragments {
|
||||||
c
|
c
|
||||||
}
|
}
|
||||||
";
|
";
|
||||||
|
let vars = graphql_vars! {};
|
||||||
let vars = vec![].into_iter().collect();
|
|
||||||
|
|
||||||
let (result, errs) = crate::execute(doc, None, &schema, &vars, &())
|
let (result, errs) = crate::execute(doc, None, &schema, &vars, &())
|
||||||
.await
|
.await
|
||||||
|
@ -323,7 +319,7 @@ mod merge_parallel_inline_fragments {
|
||||||
mod threads_context_correctly {
|
mod threads_context_correctly {
|
||||||
use crate::{
|
use crate::{
|
||||||
executor::Context,
|
executor::Context,
|
||||||
graphql_value,
|
graphql_object, graphql_value, graphql_vars,
|
||||||
schema::model::RootNode,
|
schema::model::RootNode,
|
||||||
types::scalars::{EmptyMutation, EmptySubscription},
|
types::scalars::{EmptyMutation, EmptySubscription},
|
||||||
};
|
};
|
||||||
|
@ -336,9 +332,7 @@ mod threads_context_correctly {
|
||||||
|
|
||||||
impl Context for TestContext {}
|
impl Context for TestContext {}
|
||||||
|
|
||||||
#[crate::graphql_object(
|
#[graphql_object(context = TestContext)]
|
||||||
Context = TestContext,
|
|
||||||
)]
|
|
||||||
impl Schema {
|
impl Schema {
|
||||||
fn a(context: &TestContext) -> String {
|
fn a(context: &TestContext) -> String {
|
||||||
context.value.clone()
|
context.value.clone()
|
||||||
|
@ -353,8 +347,7 @@ mod threads_context_correctly {
|
||||||
EmptySubscription::<TestContext>::new(),
|
EmptySubscription::<TestContext>::new(),
|
||||||
);
|
);
|
||||||
let doc = r"{ a }";
|
let doc = r"{ a }";
|
||||||
|
let vars = graphql_vars! {};
|
||||||
let vars = vec![].into_iter().collect();
|
|
||||||
|
|
||||||
let (result, errs) = crate::execute(
|
let (result, errs) = crate::execute(
|
||||||
doc,
|
doc,
|
||||||
|
@ -381,7 +374,7 @@ mod dynamic_context_switching {
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
executor::{Context, ExecutionError, FieldError, FieldResult},
|
executor::{Context, ExecutionError, FieldError, FieldResult},
|
||||||
graphql_object,
|
graphql_object, graphql_value, graphql_vars,
|
||||||
parser::SourcePosition,
|
parser::SourcePosition,
|
||||||
schema::model::RootNode,
|
schema::model::RootNode,
|
||||||
types::scalars::{EmptyMutation, EmptySubscription},
|
types::scalars::{EmptyMutation, EmptySubscription},
|
||||||
|
@ -452,8 +445,7 @@ mod dynamic_context_switching {
|
||||||
EmptySubscription::<OuterContext>::new(),
|
EmptySubscription::<OuterContext>::new(),
|
||||||
);
|
);
|
||||||
let doc = r"{ first: itemOpt(key: 0) { value }, missing: itemOpt(key: 2) { value } }";
|
let doc = r"{ first: itemOpt(key: 0) { value }, missing: itemOpt(key: 2) { value } }";
|
||||||
|
let vars = graphql_vars! {};
|
||||||
let vars = vec![].into_iter().collect();
|
|
||||||
|
|
||||||
let ctx = OuterContext {
|
let ctx = OuterContext {
|
||||||
items: vec![
|
items: vec![
|
||||||
|
@ -486,7 +478,7 @@ mod dynamic_context_switching {
|
||||||
result,
|
result,
|
||||||
graphql_value!({
|
graphql_value!({
|
||||||
"first": {"value": "First value"},
|
"first": {"value": "First value"},
|
||||||
"missing": None,
|
"missing": null,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -498,13 +490,10 @@ mod dynamic_context_switching {
|
||||||
EmptyMutation::<OuterContext>::new(),
|
EmptyMutation::<OuterContext>::new(),
|
||||||
EmptySubscription::<OuterContext>::new(),
|
EmptySubscription::<OuterContext>::new(),
|
||||||
);
|
);
|
||||||
let doc = r"
|
let doc = r"{
|
||||||
{
|
|
||||||
first: itemRes(key: 0) { value }
|
first: itemRes(key: 0) { value }
|
||||||
}
|
}";
|
||||||
";
|
let vars = graphql_vars! {};
|
||||||
|
|
||||||
let vars = vec![].into_iter().collect();
|
|
||||||
|
|
||||||
let ctx = OuterContext {
|
let ctx = OuterContext {
|
||||||
items: vec![
|
items: vec![
|
||||||
|
@ -546,8 +535,7 @@ mod dynamic_context_switching {
|
||||||
let doc = r"{
|
let doc = r"{
|
||||||
missing: itemRes(key: 2) { value }
|
missing: itemRes(key: 2) { value }
|
||||||
}";
|
}";
|
||||||
|
let vars = graphql_vars! {};
|
||||||
let vars = vec![].into_iter().collect();
|
|
||||||
|
|
||||||
let ctx = OuterContext {
|
let ctx = OuterContext {
|
||||||
items: vec![
|
items: vec![
|
||||||
|
@ -577,13 +565,13 @@ mod dynamic_context_switching {
|
||||||
vec![ExecutionError::new(
|
vec![ExecutionError::new(
|
||||||
SourcePosition::new(14, 1, 12),
|
SourcePosition::new(14, 1, 12),
|
||||||
&["missing"],
|
&["missing"],
|
||||||
FieldError::new("Could not find key 2", graphql_value!(None)),
|
FieldError::new("Could not find key 2", graphql_value!(null)),
|
||||||
)]
|
)],
|
||||||
);
|
);
|
||||||
|
|
||||||
println!("Result: {:#?}", result);
|
println!("Result: {:#?}", result);
|
||||||
|
|
||||||
assert_eq!(result, graphql_value!(None));
|
assert_eq!(result, graphql_value!(null));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
|
@ -593,15 +581,12 @@ mod dynamic_context_switching {
|
||||||
EmptyMutation::<OuterContext>::new(),
|
EmptyMutation::<OuterContext>::new(),
|
||||||
EmptySubscription::<OuterContext>::new(),
|
EmptySubscription::<OuterContext>::new(),
|
||||||
);
|
);
|
||||||
let doc = r"
|
let doc = r"{
|
||||||
{
|
|
||||||
first: itemResOpt(key: 0) { value }
|
first: itemResOpt(key: 0) { value }
|
||||||
missing: itemResOpt(key: 2) { value }
|
missing: itemResOpt(key: 2) { value }
|
||||||
tooLarge: itemResOpt(key: 200) { value }
|
tooLarge: itemResOpt(key: 200) { value }
|
||||||
}
|
}";
|
||||||
";
|
let vars = graphql_vars! {};
|
||||||
|
|
||||||
let vars = vec![].into_iter().collect();
|
|
||||||
|
|
||||||
let ctx = OuterContext {
|
let ctx = OuterContext {
|
||||||
items: vec![
|
items: vec![
|
||||||
|
@ -629,10 +614,10 @@ mod dynamic_context_switching {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
errs,
|
errs,
|
||||||
[ExecutionError::new(
|
[ExecutionError::new(
|
||||||
SourcePosition::new(123, 4, 12),
|
SourcePosition::new(112, 3, 12),
|
||||||
&["tooLarge"],
|
&["tooLarge"],
|
||||||
FieldError::new("Key too large: 200", graphql_value!(None)),
|
FieldError::new("Key too large: 200", graphql_value!(null)),
|
||||||
)]
|
)],
|
||||||
);
|
);
|
||||||
|
|
||||||
println!("Result: {:#?}", result);
|
println!("Result: {:#?}", result);
|
||||||
|
@ -641,8 +626,8 @@ mod dynamic_context_switching {
|
||||||
result,
|
result,
|
||||||
graphql_value!({
|
graphql_value!({
|
||||||
"first": {"value": "First value"},
|
"first": {"value": "First value"},
|
||||||
"missing": None,
|
"missing": null,
|
||||||
"tooLarge": None,
|
"tooLarge": null,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -655,8 +640,7 @@ mod dynamic_context_switching {
|
||||||
EmptySubscription::<OuterContext>::new(),
|
EmptySubscription::<OuterContext>::new(),
|
||||||
);
|
);
|
||||||
let doc = r"{ first: itemAlways(key: 0) { value } }";
|
let doc = r"{ first: itemAlways(key: 0) { value } }";
|
||||||
|
let vars = graphql_vars! {};
|
||||||
let vars = vec![].into_iter().collect();
|
|
||||||
|
|
||||||
let ctx = OuterContext {
|
let ctx = OuterContext {
|
||||||
items: vec![
|
items: vec![
|
||||||
|
@ -692,7 +676,7 @@ mod dynamic_context_switching {
|
||||||
mod propagates_errors_to_nullable_fields {
|
mod propagates_errors_to_nullable_fields {
|
||||||
use crate::{
|
use crate::{
|
||||||
executor::{ExecutionError, FieldError, FieldResult, IntoFieldError},
|
executor::{ExecutionError, FieldError, FieldResult, IntoFieldError},
|
||||||
graphql_object,
|
graphql_object, graphql_value, graphql_vars,
|
||||||
parser::SourcePosition,
|
parser::SourcePosition,
|
||||||
schema::model::RootNode,
|
schema::model::RootNode,
|
||||||
types::scalars::{EmptyMutation, EmptySubscription},
|
types::scalars::{EmptyMutation, EmptySubscription},
|
||||||
|
@ -762,8 +746,7 @@ mod propagates_errors_to_nullable_fields {
|
||||||
EmptySubscription::<()>::new(),
|
EmptySubscription::<()>::new(),
|
||||||
);
|
);
|
||||||
let doc = r"{ inner { nullableErrorField } }";
|
let doc = r"{ inner { nullableErrorField } }";
|
||||||
|
let vars = graphql_vars! {};
|
||||||
let vars = vec![].into_iter().collect();
|
|
||||||
|
|
||||||
let (result, errs) = crate::execute(doc, None, &schema, &vars, &())
|
let (result, errs) = crate::execute(doc, None, &schema, &vars, &())
|
||||||
.await
|
.await
|
||||||
|
@ -773,7 +756,7 @@ mod propagates_errors_to_nullable_fields {
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
result,
|
result,
|
||||||
graphql_value!({ "inner": { "nullableErrorField": None } })
|
graphql_value!({"inner": {"nullableErrorField": null}}),
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
@ -781,8 +764,8 @@ mod propagates_errors_to_nullable_fields {
|
||||||
vec![ExecutionError::new(
|
vec![ExecutionError::new(
|
||||||
SourcePosition::new(10, 0, 10),
|
SourcePosition::new(10, 0, 10),
|
||||||
&["inner", "nullableErrorField"],
|
&["inner", "nullableErrorField"],
|
||||||
FieldError::new("Error for nullableErrorField", graphql_value!(None)),
|
FieldError::new("Error for nullableErrorField", graphql_value!(null)),
|
||||||
)]
|
)],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -794,8 +777,7 @@ mod propagates_errors_to_nullable_fields {
|
||||||
EmptySubscription::<()>::new(),
|
EmptySubscription::<()>::new(),
|
||||||
);
|
);
|
||||||
let doc = r"{ inner { nonNullableErrorField } }";
|
let doc = r"{ inner { nonNullableErrorField } }";
|
||||||
|
let vars = graphql_vars! {};
|
||||||
let vars = vec![].into_iter().collect();
|
|
||||||
|
|
||||||
let (result, errs) = crate::execute(doc, None, &schema, &vars, &())
|
let (result, errs) = crate::execute(doc, None, &schema, &vars, &())
|
||||||
.await
|
.await
|
||||||
|
@ -803,15 +785,15 @@ mod propagates_errors_to_nullable_fields {
|
||||||
|
|
||||||
println!("Result: {:#?}", result);
|
println!("Result: {:#?}", result);
|
||||||
|
|
||||||
assert_eq!(result, graphql_value!(None));
|
assert_eq!(result, graphql_value!(null));
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
errs,
|
errs,
|
||||||
vec![ExecutionError::new(
|
vec![ExecutionError::new(
|
||||||
SourcePosition::new(10, 0, 10),
|
SourcePosition::new(10, 0, 10),
|
||||||
&["inner", "nonNullableErrorField"],
|
&["inner", "nonNullableErrorField"],
|
||||||
FieldError::new("Error for nonNullableErrorField", graphql_value!(None)),
|
FieldError::new("Error for nonNullableErrorField", graphql_value!(null)),
|
||||||
)]
|
)],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -823,8 +805,7 @@ mod propagates_errors_to_nullable_fields {
|
||||||
EmptySubscription::<()>::new(),
|
EmptySubscription::<()>::new(),
|
||||||
);
|
);
|
||||||
let doc = r"{ inner { customErrorField } }";
|
let doc = r"{ inner { customErrorField } }";
|
||||||
|
let vars = graphql_vars! {};
|
||||||
let vars = vec![].into_iter().collect();
|
|
||||||
|
|
||||||
let (result, errs) = crate::execute(doc, None, &schema, &vars, &())
|
let (result, errs) = crate::execute(doc, None, &schema, &vars, &())
|
||||||
.await
|
.await
|
||||||
|
@ -832,15 +813,15 @@ mod propagates_errors_to_nullable_fields {
|
||||||
|
|
||||||
println!("Result: {:#?}", result);
|
println!("Result: {:#?}", result);
|
||||||
|
|
||||||
assert_eq!(result, graphql_value!(None));
|
assert_eq!(result, graphql_value!(null));
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
errs,
|
errs,
|
||||||
vec![ExecutionError::new(
|
vec![ExecutionError::new(
|
||||||
SourcePosition::new(10, 0, 10),
|
SourcePosition::new(10, 0, 10),
|
||||||
&["inner", "customErrorField"],
|
&["inner", "customErrorField"],
|
||||||
FieldError::new("Not Found", graphql_value!({ "type": "NOT_FOUND" })),
|
FieldError::new("Not Found", graphql_value!({"type": "NOT_FOUND"})),
|
||||||
)]
|
)],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -852,8 +833,7 @@ mod propagates_errors_to_nullable_fields {
|
||||||
EmptySubscription::<()>::new(),
|
EmptySubscription::<()>::new(),
|
||||||
);
|
);
|
||||||
let doc = r"{ inner { nullableField { nonNullableErrorField } } }";
|
let doc = r"{ inner { nullableField { nonNullableErrorField } } }";
|
||||||
|
let vars = graphql_vars! {};
|
||||||
let vars = vec![].into_iter().collect();
|
|
||||||
|
|
||||||
let (result, errs) = crate::execute(doc, None, &schema, &vars, &())
|
let (result, errs) = crate::execute(doc, None, &schema, &vars, &())
|
||||||
.await
|
.await
|
||||||
|
@ -861,18 +841,15 @@ mod propagates_errors_to_nullable_fields {
|
||||||
|
|
||||||
println!("Result: {:#?}", result);
|
println!("Result: {:#?}", result);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(result, graphql_value!({"inner": {"nullableField": null}}),);
|
||||||
result,
|
|
||||||
graphql_value!({ "inner": { "nullableField": None } })
|
|
||||||
);
|
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
errs,
|
errs,
|
||||||
vec![ExecutionError::new(
|
vec![ExecutionError::new(
|
||||||
SourcePosition::new(26, 0, 26),
|
SourcePosition::new(26, 0, 26),
|
||||||
&["inner", "nullableField", "nonNullableErrorField"],
|
&["inner", "nullableField", "nonNullableErrorField"],
|
||||||
FieldError::new("Error for nonNullableErrorField", graphql_value!(None)),
|
FieldError::new("Error for nonNullableErrorField", graphql_value!(null)),
|
||||||
)]
|
)],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -884,8 +861,7 @@ mod propagates_errors_to_nullable_fields {
|
||||||
EmptySubscription::<()>::new(),
|
EmptySubscription::<()>::new(),
|
||||||
);
|
);
|
||||||
let doc = r"{ inner { nonNullableField { nonNullableErrorField } } }";
|
let doc = r"{ inner { nonNullableField { nonNullableErrorField } } }";
|
||||||
|
let vars = graphql_vars! {};
|
||||||
let vars = vec![].into_iter().collect();
|
|
||||||
|
|
||||||
let (result, errs) = crate::execute(doc, None, &schema, &vars, &())
|
let (result, errs) = crate::execute(doc, None, &schema, &vars, &())
|
||||||
.await
|
.await
|
||||||
|
@ -893,15 +869,15 @@ mod propagates_errors_to_nullable_fields {
|
||||||
|
|
||||||
println!("Result: {:#?}", result);
|
println!("Result: {:#?}", result);
|
||||||
|
|
||||||
assert_eq!(result, graphql_value!(None));
|
assert_eq!(result, graphql_value!(null));
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
errs,
|
errs,
|
||||||
vec![ExecutionError::new(
|
vec![ExecutionError::new(
|
||||||
SourcePosition::new(29, 0, 29),
|
SourcePosition::new(29, 0, 29),
|
||||||
&["inner", "nonNullableField", "nonNullableErrorField"],
|
&["inner", "nonNullableField", "nonNullableErrorField"],
|
||||||
FieldError::new("Error for nonNullableErrorField", graphql_value!(None)),
|
FieldError::new("Error for nonNullableErrorField", graphql_value!(null)),
|
||||||
)]
|
)],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -913,8 +889,7 @@ mod propagates_errors_to_nullable_fields {
|
||||||
EmptySubscription::<()>::new(),
|
EmptySubscription::<()>::new(),
|
||||||
);
|
);
|
||||||
let doc = r"{ inner { nonNullableField { nullableErrorField } } }";
|
let doc = r"{ inner { nonNullableField { nullableErrorField } } }";
|
||||||
|
let vars = graphql_vars! {};
|
||||||
let vars = vec![].into_iter().collect();
|
|
||||||
|
|
||||||
let (result, errs) = crate::execute(doc, None, &schema, &vars, &())
|
let (result, errs) = crate::execute(doc, None, &schema, &vars, &())
|
||||||
.await
|
.await
|
||||||
|
@ -924,7 +899,7 @@ mod propagates_errors_to_nullable_fields {
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
result,
|
result,
|
||||||
graphql_value!({ "inner": { "nonNullableField": { "nullableErrorField": None } } })
|
graphql_value!({"inner": {"nonNullableField": {"nullableErrorField": null}}}),
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
@ -932,8 +907,8 @@ mod propagates_errors_to_nullable_fields {
|
||||||
vec![ExecutionError::new(
|
vec![ExecutionError::new(
|
||||||
SourcePosition::new(29, 0, 29),
|
SourcePosition::new(29, 0, 29),
|
||||||
&["inner", "nonNullableField", "nullableErrorField"],
|
&["inner", "nonNullableField", "nullableErrorField"],
|
||||||
FieldError::new("Error for nullableErrorField", graphql_value!(None)),
|
FieldError::new("Error for nullableErrorField", graphql_value!(null)),
|
||||||
)]
|
)],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -945,8 +920,7 @@ mod propagates_errors_to_nullable_fields {
|
||||||
EmptySubscription::<()>::new(),
|
EmptySubscription::<()>::new(),
|
||||||
);
|
);
|
||||||
let doc = r"{ inners { nonNullableErrorField } }";
|
let doc = r"{ inners { nonNullableErrorField } }";
|
||||||
|
let vars = graphql_vars! {};
|
||||||
let vars = vec![].into_iter().collect();
|
|
||||||
|
|
||||||
let (result, errs) = crate::execute(doc, None, &schema, &vars, &())
|
let (result, errs) = crate::execute(doc, None, &schema, &vars, &())
|
||||||
.await
|
.await
|
||||||
|
@ -954,15 +928,15 @@ mod propagates_errors_to_nullable_fields {
|
||||||
|
|
||||||
println!("Result: {:#?}", result);
|
println!("Result: {:#?}", result);
|
||||||
|
|
||||||
assert_eq!(result, graphql_value!(None));
|
assert_eq!(result, graphql_value!(null));
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
errs,
|
errs,
|
||||||
vec![ExecutionError::new(
|
vec![ExecutionError::new(
|
||||||
SourcePosition::new(11, 0, 11),
|
SourcePosition::new(11, 0, 11),
|
||||||
&["inners", "nonNullableErrorField"],
|
&["inners", "nonNullableErrorField"],
|
||||||
FieldError::new("Error for nonNullableErrorField", graphql_value!(None)),
|
FieldError::new("Error for nonNullableErrorField", graphql_value!(null)),
|
||||||
)]
|
)],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -974,8 +948,7 @@ mod propagates_errors_to_nullable_fields {
|
||||||
EmptySubscription::<()>::new(),
|
EmptySubscription::<()>::new(),
|
||||||
);
|
);
|
||||||
let doc = r"{ nullableInners { nonNullableErrorField } }";
|
let doc = r"{ nullableInners { nonNullableErrorField } }";
|
||||||
|
let vars = graphql_vars! {};
|
||||||
let vars = vec![].into_iter().collect();
|
|
||||||
|
|
||||||
let (result, errs) = crate::execute(doc, None, &schema, &vars, &())
|
let (result, errs) = crate::execute(doc, None, &schema, &vars, &())
|
||||||
.await
|
.await
|
||||||
|
@ -985,7 +958,7 @@ mod propagates_errors_to_nullable_fields {
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
result,
|
result,
|
||||||
graphql_value!({ "nullableInners": [None, None, None, None, None] })
|
graphql_value!({"nullableInners": [null, null, null, null, null]}),
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
@ -994,36 +967,36 @@ mod propagates_errors_to_nullable_fields {
|
||||||
ExecutionError::new(
|
ExecutionError::new(
|
||||||
SourcePosition::new(19, 0, 19),
|
SourcePosition::new(19, 0, 19),
|
||||||
&["nullableInners", "nonNullableErrorField"],
|
&["nullableInners", "nonNullableErrorField"],
|
||||||
FieldError::new("Error for nonNullableErrorField", graphql_value!(None)),
|
FieldError::new("Error for nonNullableErrorField", graphql_value!(null)),
|
||||||
),
|
),
|
||||||
ExecutionError::new(
|
ExecutionError::new(
|
||||||
SourcePosition::new(19, 0, 19),
|
SourcePosition::new(19, 0, 19),
|
||||||
&["nullableInners", "nonNullableErrorField"],
|
&["nullableInners", "nonNullableErrorField"],
|
||||||
FieldError::new("Error for nonNullableErrorField", graphql_value!(None)),
|
FieldError::new("Error for nonNullableErrorField", graphql_value!(null)),
|
||||||
),
|
),
|
||||||
ExecutionError::new(
|
ExecutionError::new(
|
||||||
SourcePosition::new(19, 0, 19),
|
SourcePosition::new(19, 0, 19),
|
||||||
&["nullableInners", "nonNullableErrorField"],
|
&["nullableInners", "nonNullableErrorField"],
|
||||||
FieldError::new("Error for nonNullableErrorField", graphql_value!(None)),
|
FieldError::new("Error for nonNullableErrorField", graphql_value!(null)),
|
||||||
),
|
),
|
||||||
ExecutionError::new(
|
ExecutionError::new(
|
||||||
SourcePosition::new(19, 0, 19),
|
SourcePosition::new(19, 0, 19),
|
||||||
&["nullableInners", "nonNullableErrorField"],
|
&["nullableInners", "nonNullableErrorField"],
|
||||||
FieldError::new("Error for nonNullableErrorField", graphql_value!(None)),
|
FieldError::new("Error for nonNullableErrorField", graphql_value!(null)),
|
||||||
),
|
),
|
||||||
ExecutionError::new(
|
ExecutionError::new(
|
||||||
SourcePosition::new(19, 0, 19),
|
SourcePosition::new(19, 0, 19),
|
||||||
&["nullableInners", "nonNullableErrorField"],
|
&["nullableInners", "nonNullableErrorField"],
|
||||||
FieldError::new("Error for nonNullableErrorField", graphql_value!(None)),
|
FieldError::new("Error for nonNullableErrorField", graphql_value!(null)),
|
||||||
),
|
),
|
||||||
]
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mod named_operations {
|
mod named_operations {
|
||||||
use crate::{
|
use crate::{
|
||||||
graphql_object, graphql_value,
|
graphql_object, graphql_value, graphql_vars,
|
||||||
schema::model::RootNode,
|
schema::model::RootNode,
|
||||||
types::scalars::{EmptyMutation, EmptySubscription},
|
types::scalars::{EmptyMutation, EmptySubscription},
|
||||||
GraphQLError,
|
GraphQLError,
|
||||||
|
@ -1047,8 +1020,7 @@ mod named_operations {
|
||||||
EmptySubscription::<()>::new(),
|
EmptySubscription::<()>::new(),
|
||||||
);
|
);
|
||||||
let doc = r"{ a }";
|
let doc = r"{ a }";
|
||||||
|
let vars = graphql_vars! {};
|
||||||
let vars = vec![].into_iter().collect();
|
|
||||||
|
|
||||||
let (res, errs) = crate::execute(doc, None, &schema, &vars, &())
|
let (res, errs) = crate::execute(doc, None, &schema, &vars, &())
|
||||||
.await
|
.await
|
||||||
|
@ -1066,8 +1038,7 @@ mod named_operations {
|
||||||
EmptySubscription::<()>::new(),
|
EmptySubscription::<()>::new(),
|
||||||
);
|
);
|
||||||
let doc = r"query Example { a }";
|
let doc = r"query Example { a }";
|
||||||
|
let vars = graphql_vars! {};
|
||||||
let vars = vec![].into_iter().collect();
|
|
||||||
|
|
||||||
let (res, errs) = crate::execute(doc, None, &schema, &vars, &())
|
let (res, errs) = crate::execute(doc, None, &schema, &vars, &())
|
||||||
.await
|
.await
|
||||||
|
@ -1086,8 +1057,7 @@ mod named_operations {
|
||||||
);
|
);
|
||||||
let doc =
|
let doc =
|
||||||
r"query Example($p: String!) { first: a(p: $p) } query OtherExample { second: a }";
|
r"query Example($p: String!) { first: a(p: $p) } query OtherExample { second: a }";
|
||||||
|
let vars = graphql_vars! {};
|
||||||
let vars = vec![].into_iter().collect();
|
|
||||||
|
|
||||||
let (res, errs) = crate::execute(doc, Some("OtherExample"), &schema, &vars, &())
|
let (res, errs) = crate::execute(doc, Some("OtherExample"), &schema, &vars, &())
|
||||||
.await
|
.await
|
||||||
|
@ -1105,8 +1075,7 @@ mod named_operations {
|
||||||
EmptySubscription::<()>::new(),
|
EmptySubscription::<()>::new(),
|
||||||
);
|
);
|
||||||
let doc = r"query Example { first: a } query OtherExample { second: a }";
|
let doc = r"query Example { first: a } query OtherExample { second: a }";
|
||||||
|
let vars = graphql_vars! {};
|
||||||
let vars = vec![].into_iter().collect();
|
|
||||||
|
|
||||||
let err = crate::execute(doc, None, &schema, &vars, &())
|
let err = crate::execute(doc, None, &schema, &vars, &())
|
||||||
.await
|
.await
|
||||||
|
@ -1123,8 +1092,7 @@ mod named_operations {
|
||||||
EmptySubscription::<()>::new(),
|
EmptySubscription::<()>::new(),
|
||||||
);
|
);
|
||||||
let doc = r"query Example { first: a } query OtherExample { second: a }";
|
let doc = r"query Example { first: a } query OtherExample { second: a }";
|
||||||
|
let vars = graphql_vars! {};
|
||||||
let vars = vec![].into_iter().collect();
|
|
||||||
|
|
||||||
let err = crate::execute(doc, Some("UnknownExample"), &schema, &vars, &())
|
let err = crate::execute(doc, Some("UnknownExample"), &schema, &vars, &())
|
||||||
.await
|
.await
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
executor::Variables,
|
graphql_value, graphql_vars,
|
||||||
graphql_value,
|
|
||||||
schema::model::RootNode,
|
schema::model::RootNode,
|
||||||
types::scalars::{EmptyMutation, EmptySubscription},
|
types::scalars::{EmptyMutation, EmptySubscription},
|
||||||
value::{DefaultScalarValue, Object, Value},
|
value::{DefaultScalarValue, Object, Value},
|
||||||
|
@ -98,7 +97,7 @@ where
|
||||||
EmptySubscription::<()>::new(),
|
EmptySubscription::<()>::new(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let (result, errs) = crate::execute(doc, None, &schema, &Variables::new(), &())
|
let (result, errs) = crate::execute(doc, None, &schema, &graphql_vars! {}, &())
|
||||||
.await
|
.await
|
||||||
.expect("Execution failed");
|
.expect("Execution failed");
|
||||||
|
|
||||||
|
@ -147,23 +146,23 @@ async fn default_name_introspection() {
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
type_info.get_field_value("description"),
|
type_info.get_field_value("description"),
|
||||||
Some(&graphql_value!(None)),
|
Some(&graphql_value!(null)),
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(values.len(), 2);
|
assert_eq!(values.len(), 2);
|
||||||
|
|
||||||
assert!(values.contains(&graphql_value!({
|
assert!(values.contains(&graphql_value!({
|
||||||
"name": "FOO",
|
"name": "FOO",
|
||||||
"description": None,
|
"description": null,
|
||||||
"isDeprecated": false,
|
"isDeprecated": false,
|
||||||
"deprecationReason": None,
|
"deprecationReason": null,
|
||||||
})));
|
})));
|
||||||
|
|
||||||
assert!(values.contains(&graphql_value!({
|
assert!(values.contains(&graphql_value!({
|
||||||
"name": "BAR",
|
"name": "BAR",
|
||||||
"description": None,
|
"description": null,
|
||||||
"isDeprecated": false,
|
"isDeprecated": false,
|
||||||
"deprecationReason": None,
|
"deprecationReason": null,
|
||||||
})));
|
})));
|
||||||
})
|
})
|
||||||
.await;
|
.await;
|
||||||
|
@ -193,23 +192,23 @@ async fn named_introspection() {
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
type_info.get_field_value("description"),
|
type_info.get_field_value("description"),
|
||||||
Some(&graphql_value!(None)),
|
Some(&graphql_value!(null)),
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(values.len(), 2);
|
assert_eq!(values.len(), 2);
|
||||||
|
|
||||||
assert!(values.contains(&graphql_value!({
|
assert!(values.contains(&graphql_value!({
|
||||||
"name": "FOO",
|
"name": "FOO",
|
||||||
"description": None,
|
"description": null,
|
||||||
"isDeprecated": false,
|
"isDeprecated": false,
|
||||||
"deprecationReason": None,
|
"deprecationReason": null,
|
||||||
})));
|
})));
|
||||||
|
|
||||||
assert!(values.contains(&graphql_value!({
|
assert!(values.contains(&graphql_value!({
|
||||||
"name": "BAR",
|
"name": "BAR",
|
||||||
"description": None,
|
"description": null,
|
||||||
"isDeprecated": false,
|
"isDeprecated": false,
|
||||||
"deprecationReason": None,
|
"deprecationReason": null,
|
||||||
})));
|
})));
|
||||||
})
|
})
|
||||||
.await;
|
.await;
|
||||||
|
@ -239,23 +238,23 @@ async fn no_trailing_comma_introspection() {
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
type_info.get_field_value("description"),
|
type_info.get_field_value("description"),
|
||||||
Some(&graphql_value!(None)),
|
Some(&graphql_value!(null)),
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(values.len(), 2);
|
assert_eq!(values.len(), 2);
|
||||||
|
|
||||||
assert!(values.contains(&graphql_value!({
|
assert!(values.contains(&graphql_value!({
|
||||||
"name": "FOO",
|
"name": "FOO",
|
||||||
"description": None,
|
"description": null,
|
||||||
"isDeprecated": false,
|
"isDeprecated": false,
|
||||||
"deprecationReason": None,
|
"deprecationReason": null,
|
||||||
})));
|
})));
|
||||||
|
|
||||||
assert!(values.contains(&graphql_value!({
|
assert!(values.contains(&graphql_value!({
|
||||||
"name": "BAR",
|
"name": "BAR",
|
||||||
"description": None,
|
"description": null,
|
||||||
"isDeprecated": false,
|
"isDeprecated": false,
|
||||||
"deprecationReason": None,
|
"deprecationReason": null,
|
||||||
})));
|
})));
|
||||||
})
|
})
|
||||||
.await;
|
.await;
|
||||||
|
@ -292,16 +291,16 @@ async fn enum_description_introspection() {
|
||||||
|
|
||||||
assert!(values.contains(&graphql_value!({
|
assert!(values.contains(&graphql_value!({
|
||||||
"name": "FOO",
|
"name": "FOO",
|
||||||
"description": None,
|
"description": null,
|
||||||
"isDeprecated": false,
|
"isDeprecated": false,
|
||||||
"deprecationReason": None,
|
"deprecationReason": null,
|
||||||
})));
|
})));
|
||||||
|
|
||||||
assert!(values.contains(&graphql_value!({
|
assert!(values.contains(&graphql_value!({
|
||||||
"name": "BAR",
|
"name": "BAR",
|
||||||
"description": None,
|
"description": null,
|
||||||
"isDeprecated": false,
|
"isDeprecated": false,
|
||||||
"deprecationReason": None,
|
"deprecationReason": null,
|
||||||
})));
|
})));
|
||||||
})
|
})
|
||||||
.await;
|
.await;
|
||||||
|
@ -331,7 +330,7 @@ async fn enum_value_description_introspection() {
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
type_info.get_field_value("description"),
|
type_info.get_field_value("description"),
|
||||||
Some(&graphql_value!(None)),
|
Some(&graphql_value!(null)),
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(values.len(), 2);
|
assert_eq!(values.len(), 2);
|
||||||
|
@ -340,14 +339,14 @@ async fn enum_value_description_introspection() {
|
||||||
"name": "FOO",
|
"name": "FOO",
|
||||||
"description": "The FOO value",
|
"description": "The FOO value",
|
||||||
"isDeprecated": false,
|
"isDeprecated": false,
|
||||||
"deprecationReason": None,
|
"deprecationReason": null,
|
||||||
})));
|
})));
|
||||||
|
|
||||||
assert!(values.contains(&graphql_value!({
|
assert!(values.contains(&graphql_value!({
|
||||||
"name": "BAR",
|
"name": "BAR",
|
||||||
"description": "The BAR value",
|
"description": "The BAR value",
|
||||||
"isDeprecated": false,
|
"isDeprecated": false,
|
||||||
"deprecationReason": None,
|
"deprecationReason": null,
|
||||||
})));
|
})));
|
||||||
})
|
})
|
||||||
.await;
|
.await;
|
||||||
|
@ -377,14 +376,14 @@ async fn enum_deprecation_introspection() {
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
type_info.get_field_value("description"),
|
type_info.get_field_value("description"),
|
||||||
Some(&graphql_value!(None)),
|
Some(&graphql_value!(null)),
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(values.len(), 2);
|
assert_eq!(values.len(), 2);
|
||||||
|
|
||||||
assert!(values.contains(&graphql_value!({
|
assert!(values.contains(&graphql_value!({
|
||||||
"name": "FOO",
|
"name": "FOO",
|
||||||
"description": None,
|
"description": null,
|
||||||
"isDeprecated": true,
|
"isDeprecated": true,
|
||||||
"deprecationReason": "Please don't use FOO any more",
|
"deprecationReason": "Please don't use FOO any more",
|
||||||
})));
|
})));
|
||||||
|
@ -423,7 +422,7 @@ async fn enum_deprecation_no_values_introspection() {
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
type_info.get_field_value("description"),
|
type_info.get_field_value("description"),
|
||||||
Some(&graphql_value!(None)),
|
Some(&graphql_value!(null)),
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(values.len(), 0);
|
assert_eq!(values.len(), 0);
|
||||||
|
|
|
@ -2,8 +2,7 @@
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
ast::{FromInputValue, InputValue},
|
ast::{FromInputValue, InputValue},
|
||||||
executor::Variables,
|
graphql_input_value, graphql_object, graphql_value, graphql_vars,
|
||||||
graphql_object, graphql_value,
|
|
||||||
schema::model::RootNode,
|
schema::model::RootNode,
|
||||||
types::scalars::{EmptyMutation, EmptySubscription},
|
types::scalars::{EmptyMutation, EmptySubscription},
|
||||||
value::{DefaultScalarValue, Object, Value},
|
value::{DefaultScalarValue, Object, Value},
|
||||||
|
@ -123,7 +122,7 @@ where
|
||||||
EmptySubscription::<()>::new(),
|
EmptySubscription::<()>::new(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let (result, errs) = crate::execute(doc, None, &schema, &Variables::new(), &())
|
let (result, errs) = crate::execute(doc, None, &schema, &graphql_vars! {}, &())
|
||||||
.await
|
.await
|
||||||
.expect("Execution failed");
|
.expect("Execution failed");
|
||||||
|
|
||||||
|
@ -174,25 +173,25 @@ async fn default_name_introspection() {
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
type_info.get_field_value("description"),
|
type_info.get_field_value("description"),
|
||||||
Some(&graphql_value!(None)),
|
Some(&graphql_value!(null)),
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(fields.len(), 2);
|
assert_eq!(fields.len(), 2);
|
||||||
assert!(fields.contains(&graphql_value!({
|
assert!(fields.contains(&graphql_value!({
|
||||||
"name": "fieldOne",
|
"name": "fieldOne",
|
||||||
"description": None,
|
"description": null,
|
||||||
"type": {
|
"type": {
|
||||||
"ofType": {"name": "String"},
|
"ofType": {"name": "String"},
|
||||||
},
|
},
|
||||||
"defaultValue": None,
|
"defaultValue": null,
|
||||||
})));
|
})));
|
||||||
assert!(fields.contains(&graphql_value!({
|
assert!(fields.contains(&graphql_value!({
|
||||||
"name": "fieldTwo",
|
"name": "fieldTwo",
|
||||||
"description": None,
|
"description": null,
|
||||||
"type": {
|
"type": {
|
||||||
"ofType": {"name": "String"},
|
"ofType": {"name": "String"},
|
||||||
},
|
},
|
||||||
"defaultValue": None,
|
"defaultValue": null,
|
||||||
})));
|
})));
|
||||||
})
|
})
|
||||||
.await;
|
.await;
|
||||||
|
@ -200,14 +199,10 @@ async fn default_name_introspection() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn default_name_input_value() {
|
fn default_name_input_value() {
|
||||||
let iv: InputValue<DefaultScalarValue> = InputValue::object(
|
let iv: InputValue = graphql_input_value!({
|
||||||
vec![
|
"fieldOne": "number one",
|
||||||
("fieldOne", InputValue::scalar("number one")),
|
"fieldTwo": "number two",
|
||||||
("fieldTwo", InputValue::scalar("number two")),
|
});
|
||||||
]
|
|
||||||
.into_iter()
|
|
||||||
.collect(),
|
|
||||||
);
|
|
||||||
|
|
||||||
let dv: Option<DefaultName> = FromInputValue::from_input_value(&iv);
|
let dv: Option<DefaultName> = FromInputValue::from_input_value(&iv);
|
||||||
|
|
||||||
|
@ -245,25 +240,25 @@ async fn no_trailing_comma_introspection() {
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
type_info.get_field_value("description"),
|
type_info.get_field_value("description"),
|
||||||
Some(&graphql_value!(None)),
|
Some(&graphql_value!(null)),
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(fields.len(), 2);
|
assert_eq!(fields.len(), 2);
|
||||||
assert!(fields.contains(&graphql_value!({
|
assert!(fields.contains(&graphql_value!({
|
||||||
"name": "fieldOne",
|
"name": "fieldOne",
|
||||||
"description": None,
|
"description": null,
|
||||||
"type": {
|
"type": {
|
||||||
"ofType": {"name": "String"},
|
"ofType": {"name": "String"},
|
||||||
},
|
},
|
||||||
"defaultValue": None,
|
"defaultValue": null,
|
||||||
})));
|
})));
|
||||||
assert!(fields.contains(&graphql_value!({
|
assert!(fields.contains(&graphql_value!({
|
||||||
"name": "fieldTwo",
|
"name": "fieldTwo",
|
||||||
"description": None,
|
"description": null,
|
||||||
"type": {
|
"type": {
|
||||||
"ofType": {"name": "String"},
|
"ofType": {"name": "String"},
|
||||||
},
|
},
|
||||||
"defaultValue": None,
|
"defaultValue": null,
|
||||||
})));
|
})));
|
||||||
})
|
})
|
||||||
.await;
|
.await;
|
||||||
|
@ -295,17 +290,17 @@ async fn derive_introspection() {
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
type_info.get_field_value("description"),
|
type_info.get_field_value("description"),
|
||||||
Some(&graphql_value!(None)),
|
Some(&graphql_value!(null)),
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(fields.len(), 1);
|
assert_eq!(fields.len(), 1);
|
||||||
assert!(fields.contains(&graphql_value!({
|
assert!(fields.contains(&graphql_value!({
|
||||||
"name": "fieldOne",
|
"name": "fieldOne",
|
||||||
"description": None,
|
"description": null,
|
||||||
"type": {
|
"type": {
|
||||||
"ofType": {"name": "String"},
|
"ofType": {"name": "String"},
|
||||||
},
|
},
|
||||||
"defaultValue": None,
|
"defaultValue": null,
|
||||||
})));
|
})));
|
||||||
})
|
})
|
||||||
.await;
|
.await;
|
||||||
|
@ -350,17 +345,17 @@ async fn named_introspection() {
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
type_info.get_field_value("description"),
|
type_info.get_field_value("description"),
|
||||||
Some(&graphql_value!(None))
|
Some(&graphql_value!(null))
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(fields.len(), 1);
|
assert_eq!(fields.len(), 1);
|
||||||
assert!(fields.contains(&graphql_value!({
|
assert!(fields.contains(&graphql_value!({
|
||||||
"name": "fieldOne",
|
"name": "fieldOne",
|
||||||
"description": None,
|
"description": null,
|
||||||
"type": {
|
"type": {
|
||||||
"ofType": {"name": "String"},
|
"ofType": {"name": "String"},
|
||||||
},
|
},
|
||||||
"defaultValue": None,
|
"defaultValue": null,
|
||||||
})));
|
})));
|
||||||
})
|
})
|
||||||
.await;
|
.await;
|
||||||
|
@ -398,11 +393,11 @@ async fn description_introspection() {
|
||||||
assert_eq!(fields.len(), 1);
|
assert_eq!(fields.len(), 1);
|
||||||
assert!(fields.contains(&graphql_value!({
|
assert!(fields.contains(&graphql_value!({
|
||||||
"name": "fieldOne",
|
"name": "fieldOne",
|
||||||
"description": None,
|
"description": null,
|
||||||
"type": {
|
"type": {
|
||||||
"ofType": {"name": "String"},
|
"ofType": {"name": "String"},
|
||||||
},
|
},
|
||||||
"defaultValue": None,
|
"defaultValue": null,
|
||||||
})));
|
})));
|
||||||
})
|
})
|
||||||
.await;
|
.await;
|
||||||
|
@ -434,7 +429,7 @@ async fn field_description_introspection() {
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
type_info.get_field_value("description"),
|
type_info.get_field_value("description"),
|
||||||
Some(&graphql_value!(None)),
|
Some(&graphql_value!(null)),
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(fields.len(), 2);
|
assert_eq!(fields.len(), 2);
|
||||||
|
@ -444,7 +439,7 @@ async fn field_description_introspection() {
|
||||||
"type": {
|
"type": {
|
||||||
"ofType": {"name": "String"},
|
"ofType": {"name": "String"},
|
||||||
},
|
},
|
||||||
"defaultValue": None,
|
"defaultValue": null,
|
||||||
})));
|
})));
|
||||||
assert!(fields.contains(&graphql_value!({
|
assert!(fields.contains(&graphql_value!({
|
||||||
"name": "fieldTwo",
|
"name": "fieldTwo",
|
||||||
|
@ -452,7 +447,7 @@ async fn field_description_introspection() {
|
||||||
"type": {
|
"type": {
|
||||||
"ofType": {"name": "String"},
|
"ofType": {"name": "String"},
|
||||||
},
|
},
|
||||||
"defaultValue": None,
|
"defaultValue": null,
|
||||||
})));
|
})));
|
||||||
})
|
})
|
||||||
.await;
|
.await;
|
||||||
|
|
|
@ -6,8 +6,7 @@ mod input_object;
|
||||||
use self::input_object::{NamedPublic, NamedPublicWithDescription};
|
use self::input_object::{NamedPublic, NamedPublicWithDescription};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
executor::Variables,
|
graphql_interface, graphql_object, graphql_scalar, graphql_value, graphql_vars,
|
||||||
graphql_interface, graphql_object, graphql_scalar, graphql_value,
|
|
||||||
schema::model::RootNode,
|
schema::model::RootNode,
|
||||||
types::scalars::{EmptyMutation, EmptySubscription},
|
types::scalars::{EmptyMutation, EmptySubscription},
|
||||||
value::{ParseScalarResult, ParseScalarValue, ScalarValue, Value},
|
value::{ParseScalarResult, ParseScalarValue, ScalarValue, Value},
|
||||||
|
@ -83,7 +82,7 @@ async fn test_execution() {
|
||||||
EmptySubscription::<()>::new(),
|
EmptySubscription::<()>::new(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let (result, errs) = crate::execute(doc, None, &schema, &Variables::new(), &())
|
let (result, errs) = crate::execute(doc, None, &schema, &graphql_vars! {}, &())
|
||||||
.await
|
.await
|
||||||
.expect("Execution failed");
|
.expect("Execution failed");
|
||||||
|
|
||||||
|
@ -128,7 +127,7 @@ async fn enum_introspection() {
|
||||||
EmptySubscription::<()>::new(),
|
EmptySubscription::<()>::new(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let (result, errs) = crate::execute(doc, None, &schema, &Variables::new(), &())
|
let (result, errs) = crate::execute(doc, None, &schema, &graphql_vars! {}, &())
|
||||||
.await
|
.await
|
||||||
.expect("Execution failed");
|
.expect("Execution failed");
|
||||||
|
|
||||||
|
@ -154,23 +153,23 @@ async fn enum_introspection() {
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
type_info.get_field_value("description"),
|
type_info.get_field_value("description"),
|
||||||
Some(&graphql_value!(None)),
|
Some(&graphql_value!(null)),
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
type_info.get_field_value("interfaces"),
|
type_info.get_field_value("interfaces"),
|
||||||
Some(&graphql_value!(None)),
|
Some(&graphql_value!(null)),
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
type_info.get_field_value("possibleTypes"),
|
type_info.get_field_value("possibleTypes"),
|
||||||
Some(&graphql_value!(None)),
|
Some(&graphql_value!(null)),
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
type_info.get_field_value("inputFields"),
|
type_info.get_field_value("inputFields"),
|
||||||
Some(&graphql_value!(None)),
|
Some(&graphql_value!(null)),
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
type_info.get_field_value("ofType"),
|
type_info.get_field_value("ofType"),
|
||||||
Some(&graphql_value!(None))
|
Some(&graphql_value!(null))
|
||||||
);
|
);
|
||||||
|
|
||||||
let values = type_info
|
let values = type_info
|
||||||
|
@ -183,16 +182,16 @@ async fn enum_introspection() {
|
||||||
|
|
||||||
assert!(values.contains(&graphql_value!({
|
assert!(values.contains(&graphql_value!({
|
||||||
"name": "ONE",
|
"name": "ONE",
|
||||||
"description": None,
|
"description": null,
|
||||||
"isDeprecated": false,
|
"isDeprecated": false,
|
||||||
"deprecationReason": None,
|
"deprecationReason": null,
|
||||||
})));
|
})));
|
||||||
|
|
||||||
assert!(values.contains(&graphql_value!({
|
assert!(values.contains(&graphql_value!({
|
||||||
"name": "TWO",
|
"name": "TWO",
|
||||||
"description": None,
|
"description": null,
|
||||||
"isDeprecated": false,
|
"isDeprecated": false,
|
||||||
"deprecationReason": None,
|
"deprecationReason": null,
|
||||||
})));
|
})));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -237,7 +236,7 @@ async fn interface_introspection() {
|
||||||
EmptySubscription::<()>::new(),
|
EmptySubscription::<()>::new(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let (result, errs) = crate::execute(doc, None, &schema, &Variables::new(), &())
|
let (result, errs) = crate::execute(doc, None, &schema, &graphql_vars! {}, &())
|
||||||
.await
|
.await
|
||||||
.expect("Execution failed");
|
.expect("Execution failed");
|
||||||
|
|
||||||
|
@ -267,19 +266,19 @@ async fn interface_introspection() {
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
type_info.get_field_value("interfaces"),
|
type_info.get_field_value("interfaces"),
|
||||||
Some(&graphql_value!(None)),
|
Some(&graphql_value!(null)),
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
type_info.get_field_value("enumValues"),
|
type_info.get_field_value("enumValues"),
|
||||||
Some(&graphql_value!(None)),
|
Some(&graphql_value!(null)),
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
type_info.get_field_value("inputFields"),
|
type_info.get_field_value("inputFields"),
|
||||||
Some(&graphql_value!(None)),
|
Some(&graphql_value!(null)),
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
type_info.get_field_value("ofType"),
|
type_info.get_field_value("ofType"),
|
||||||
Some(&graphql_value!(None))
|
Some(&graphql_value!(null))
|
||||||
);
|
);
|
||||||
|
|
||||||
let possible_types = type_info
|
let possible_types = type_info
|
||||||
|
@ -305,7 +304,7 @@ async fn interface_introspection() {
|
||||||
"description": "A sample field in the interface",
|
"description": "A sample field in the interface",
|
||||||
"args": [],
|
"args": [],
|
||||||
"type": {
|
"type": {
|
||||||
"name": None,
|
"name": null,
|
||||||
"kind": "NON_NULL",
|
"kind": "NON_NULL",
|
||||||
"ofType": {
|
"ofType": {
|
||||||
"name": "SampleEnum",
|
"name": "SampleEnum",
|
||||||
|
@ -313,7 +312,7 @@ async fn interface_introspection() {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"isDeprecated": false,
|
"isDeprecated": false,
|
||||||
"deprecationReason": None,
|
"deprecationReason": null,
|
||||||
})));
|
})));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -369,7 +368,7 @@ async fn object_introspection() {
|
||||||
EmptySubscription::<()>::new(),
|
EmptySubscription::<()>::new(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let (result, errs) = crate::execute(doc, None, &schema, &Variables::new(), &())
|
let (result, errs) = crate::execute(doc, None, &schema, &graphql_vars! {}, &())
|
||||||
.await
|
.await
|
||||||
.expect("Execution failed");
|
.expect("Execution failed");
|
||||||
|
|
||||||
|
@ -403,19 +402,19 @@ async fn object_introspection() {
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
type_info.get_field_value("enumValues"),
|
type_info.get_field_value("enumValues"),
|
||||||
Some(&graphql_value!(None)),
|
Some(&graphql_value!(null)),
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
type_info.get_field_value("inputFields"),
|
type_info.get_field_value("inputFields"),
|
||||||
Some(&graphql_value!(None)),
|
Some(&graphql_value!(null)),
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
type_info.get_field_value("ofType"),
|
type_info.get_field_value("ofType"),
|
||||||
Some(&graphql_value!(None))
|
Some(&graphql_value!(null))
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
type_info.get_field_value("possibleTypes"),
|
type_info.get_field_value("possibleTypes"),
|
||||||
Some(&graphql_value!(None)),
|
Some(&graphql_value!(null)),
|
||||||
);
|
);
|
||||||
|
|
||||||
let fields = type_info
|
let fields = type_info
|
||||||
|
@ -430,10 +429,10 @@ async fn object_introspection() {
|
||||||
|
|
||||||
assert!(fields.contains(&graphql_value!({
|
assert!(fields.contains(&graphql_value!({
|
||||||
"name": "sampleEnum",
|
"name": "sampleEnum",
|
||||||
"description": None,
|
"description": null,
|
||||||
"args": [],
|
"args": [],
|
||||||
"type": {
|
"type": {
|
||||||
"name": None,
|
"name": null,
|
||||||
"kind": "NON_NULL",
|
"kind": "NON_NULL",
|
||||||
"ofType": {
|
"ofType": {
|
||||||
"name": "SampleEnum",
|
"name": "SampleEnum",
|
||||||
|
@ -441,7 +440,7 @@ async fn object_introspection() {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"isDeprecated": false,
|
"isDeprecated": false,
|
||||||
"deprecationReason": None,
|
"deprecationReason": null,
|
||||||
})));
|
})));
|
||||||
|
|
||||||
assert!(fields.contains(&graphql_value!({
|
assert!(fields.contains(&graphql_value!({
|
||||||
|
@ -451,27 +450,27 @@ async fn object_introspection() {
|
||||||
"name": "first",
|
"name": "first",
|
||||||
"description": "The first number",
|
"description": "The first number",
|
||||||
"type": {
|
"type": {
|
||||||
"name": None,
|
"name": null,
|
||||||
"kind": "NON_NULL",
|
"kind": "NON_NULL",
|
||||||
"ofType": {
|
"ofType": {
|
||||||
"name": "Int",
|
"name": "Int",
|
||||||
"kind": "SCALAR",
|
"kind": "SCALAR",
|
||||||
"ofType": None,
|
"ofType": null,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"defaultValue": None,
|
"defaultValue": null,
|
||||||
}, {
|
}, {
|
||||||
"name": "second",
|
"name": "second",
|
||||||
"description": "The second number",
|
"description": "The second number",
|
||||||
"type": {
|
"type": {
|
||||||
"name": "Int",
|
"name": "Int",
|
||||||
"kind": "SCALAR",
|
"kind": "SCALAR",
|
||||||
"ofType": None,
|
"ofType": null,
|
||||||
},
|
},
|
||||||
"defaultValue": "123",
|
"defaultValue": "123",
|
||||||
}],
|
}],
|
||||||
"type": {
|
"type": {
|
||||||
"name": None,
|
"name": null,
|
||||||
"kind": "NON_NULL",
|
"kind": "NON_NULL",
|
||||||
"ofType": {
|
"ofType": {
|
||||||
"name": "SampleScalar",
|
"name": "SampleScalar",
|
||||||
|
@ -479,7 +478,7 @@ async fn object_introspection() {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"isDeprecated": false,
|
"isDeprecated": false,
|
||||||
"deprecationReason": None,
|
"deprecationReason": null,
|
||||||
})));
|
})));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -506,7 +505,7 @@ async fn scalar_introspection() {
|
||||||
EmptySubscription::<()>::new(),
|
EmptySubscription::<()>::new(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let (result, errs) = crate::execute(doc, None, &schema, &Variables::new(), &())
|
let (result, errs) = crate::execute(doc, None, &schema, &graphql_vars! {}, &())
|
||||||
.await
|
.await
|
||||||
.expect("Execution failed");
|
.expect("Execution failed");
|
||||||
|
|
||||||
|
@ -525,13 +524,13 @@ async fn scalar_introspection() {
|
||||||
&graphql_value!({
|
&graphql_value!({
|
||||||
"name": "SampleScalar",
|
"name": "SampleScalar",
|
||||||
"kind": "SCALAR",
|
"kind": "SCALAR",
|
||||||
"description": None,
|
"description": null,
|
||||||
"fields": None,
|
"fields": null,
|
||||||
"interfaces": None,
|
"interfaces": null,
|
||||||
"possibleTypes": None,
|
"possibleTypes": null,
|
||||||
"enumValues": None,
|
"enumValues": null,
|
||||||
"inputFields": None,
|
"inputFields": null,
|
||||||
"ofType": None,
|
"ofType": null,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
ast::InputValue,
|
|
||||||
executor::Variables,
|
executor::Variables,
|
||||||
graphql_object, graphql_scalar, graphql_value,
|
graphql_object, graphql_scalar, graphql_value, graphql_vars,
|
||||||
parser::SourcePosition,
|
parser::SourcePosition,
|
||||||
schema::model::RootNode,
|
schema::model::RootNode,
|
||||||
types::scalars::{EmptyMutation, EmptySubscription},
|
types::scalars::{EmptyMutation, EmptySubscription},
|
||||||
|
@ -147,7 +146,7 @@ async fn run_query<F>(query: &str, f: F)
|
||||||
where
|
where
|
||||||
F: Fn(&Object<DefaultScalarValue>) -> (),
|
F: Fn(&Object<DefaultScalarValue>) -> (),
|
||||||
{
|
{
|
||||||
run_variable_query(query, Variables::new(), f).await;
|
run_variable_query(query, graphql_vars! {}, f).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
|
@ -199,20 +198,13 @@ async fn inline_runs_from_input_value_on_scalar() {
|
||||||
async fn variable_complex_input() {
|
async fn variable_complex_input() {
|
||||||
run_variable_query(
|
run_variable_query(
|
||||||
r#"query q($input: TestInputObject) { fieldWithObjectInput(input: $input) }"#,
|
r#"query q($input: TestInputObject) { fieldWithObjectInput(input: $input) }"#,
|
||||||
vec![(
|
graphql_vars! {
|
||||||
"input".to_owned(),
|
"input": {
|
||||||
InputValue::object(
|
"a": "foo",
|
||||||
vec![
|
"b": ["bar"],
|
||||||
("a", InputValue::scalar("foo")),
|
"c": "baz",
|
||||||
("b", InputValue::list(vec![InputValue::scalar("bar")])),
|
},
|
||||||
("c", InputValue::scalar("baz")),
|
},
|
||||||
]
|
|
||||||
.into_iter()
|
|
||||||
.collect(),
|
|
||||||
),
|
|
||||||
)]
|
|
||||||
.into_iter()
|
|
||||||
.collect(),
|
|
||||||
|result: &Object<DefaultScalarValue>| {
|
|result: &Object<DefaultScalarValue>| {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
result.get_field_value("fieldWithObjectInput"),
|
result.get_field_value("fieldWithObjectInput"),
|
||||||
|
@ -228,20 +220,13 @@ async fn variable_complex_input() {
|
||||||
async fn variable_parse_single_value_to_list() {
|
async fn variable_parse_single_value_to_list() {
|
||||||
run_variable_query(
|
run_variable_query(
|
||||||
r#"query q($input: TestInputObject) { fieldWithObjectInput(input: $input) }"#,
|
r#"query q($input: TestInputObject) { fieldWithObjectInput(input: $input) }"#,
|
||||||
vec![(
|
graphql_vars! {
|
||||||
"input".to_owned(),
|
"input": {
|
||||||
InputValue::object(
|
"a": "foo",
|
||||||
vec![
|
"b": "bar",
|
||||||
("a", InputValue::scalar("foo")),
|
"c": "baz",
|
||||||
("b", InputValue::scalar("bar")),
|
},
|
||||||
("c", InputValue::scalar("baz")),
|
},
|
||||||
]
|
|
||||||
.into_iter()
|
|
||||||
.collect(),
|
|
||||||
),
|
|
||||||
)]
|
|
||||||
.into_iter()
|
|
||||||
.collect(),
|
|
||||||
|result: &Object<DefaultScalarValue>| {
|
|result: &Object<DefaultScalarValue>| {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
result.get_field_value("fieldWithObjectInput"),
|
result.get_field_value("fieldWithObjectInput"),
|
||||||
|
@ -257,19 +242,12 @@ async fn variable_parse_single_value_to_list() {
|
||||||
async fn variable_runs_from_input_value_on_scalar() {
|
async fn variable_runs_from_input_value_on_scalar() {
|
||||||
run_variable_query(
|
run_variable_query(
|
||||||
r#"query q($input: TestInputObject) { fieldWithObjectInput(input: $input) }"#,
|
r#"query q($input: TestInputObject) { fieldWithObjectInput(input: $input) }"#,
|
||||||
vec![(
|
graphql_vars! {
|
||||||
"input".to_owned(),
|
"input": {
|
||||||
InputValue::object(
|
"c": "baz",
|
||||||
vec![
|
"d": "SerializedValue",
|
||||||
("c", InputValue::scalar("baz")),
|
},
|
||||||
("d", InputValue::scalar("SerializedValue")),
|
},
|
||||||
]
|
|
||||||
.into_iter()
|
|
||||||
.collect(),
|
|
||||||
),
|
|
||||||
)]
|
|
||||||
.into_iter()
|
|
||||||
.collect(),
|
|
||||||
|result: &Object<DefaultScalarValue>| {
|
|result: &Object<DefaultScalarValue>| {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
result.get_field_value("fieldWithObjectInput"),
|
result.get_field_value("fieldWithObjectInput"),
|
||||||
|
@ -290,20 +268,13 @@ async fn variable_error_on_nested_non_null() {
|
||||||
);
|
);
|
||||||
|
|
||||||
let query = r#"query q($input: TestInputObject) { fieldWithObjectInput(input: $input) }"#;
|
let query = r#"query q($input: TestInputObject) { fieldWithObjectInput(input: $input) }"#;
|
||||||
let vars = vec![(
|
let vars = graphql_vars! {
|
||||||
"input".to_owned(),
|
"input": {
|
||||||
InputValue::object(
|
"a": "foo",
|
||||||
vec![
|
"b": "bar",
|
||||||
("a", InputValue::scalar("foo")),
|
"c": null,
|
||||||
("b", InputValue::scalar("bar")),
|
},
|
||||||
("c", InputValue::null()),
|
};
|
||||||
]
|
|
||||||
.into_iter()
|
|
||||||
.collect(),
|
|
||||||
),
|
|
||||||
)]
|
|
||||||
.into_iter()
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
let error = crate::execute(query, None, &schema, &vars, &())
|
let error = crate::execute(query, None, &schema, &vars, &())
|
||||||
.await
|
.await
|
||||||
|
@ -314,7 +285,7 @@ async fn variable_error_on_nested_non_null() {
|
||||||
ValidationError(vec![RuleError::new(
|
ValidationError(vec![RuleError::new(
|
||||||
r#"Variable "$input" got invalid value. In field "c": Expected "String!", found null."#,
|
r#"Variable "$input" got invalid value. In field "c": Expected "String!", found null."#,
|
||||||
&[SourcePosition::new(8, 0, 8)],
|
&[SourcePosition::new(8, 0, 8)],
|
||||||
)])
|
)]),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -327,9 +298,7 @@ async fn variable_error_on_incorrect_type() {
|
||||||
);
|
);
|
||||||
|
|
||||||
let query = r#"query q($input: TestInputObject) { fieldWithObjectInput(input: $input) }"#;
|
let query = r#"query q($input: TestInputObject) { fieldWithObjectInput(input: $input) }"#;
|
||||||
let vars = vec![("input".to_owned(), InputValue::scalar("foo bar"))]
|
let vars = graphql_vars! {"input": "foo bar"};
|
||||||
.into_iter()
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
let error = crate::execute(query, None, &schema, &vars, &())
|
let error = crate::execute(query, None, &schema, &vars, &())
|
||||||
.await
|
.await
|
||||||
|
@ -340,7 +309,7 @@ async fn variable_error_on_incorrect_type() {
|
||||||
ValidationError(vec![RuleError::new(
|
ValidationError(vec![RuleError::new(
|
||||||
r#"Variable "$input" got invalid value. Expected "TestInputObject", found not an object."#,
|
r#"Variable "$input" got invalid value. Expected "TestInputObject", found not an object."#,
|
||||||
&[SourcePosition::new(8, 0, 8)],
|
&[SourcePosition::new(8, 0, 8)],
|
||||||
),])
|
)]),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -353,19 +322,12 @@ async fn variable_error_on_omit_non_null() {
|
||||||
);
|
);
|
||||||
|
|
||||||
let query = r#"query q($input: TestInputObject) { fieldWithObjectInput(input: $input) }"#;
|
let query = r#"query q($input: TestInputObject) { fieldWithObjectInput(input: $input) }"#;
|
||||||
let vars = vec![(
|
let vars = graphql_vars! {
|
||||||
"input".to_owned(),
|
"input": {
|
||||||
InputValue::object(
|
"a": "foo",
|
||||||
vec![
|
"b": "bar",
|
||||||
("a", InputValue::scalar("foo")),
|
},
|
||||||
("b", InputValue::scalar("bar")),
|
};
|
||||||
]
|
|
||||||
.into_iter()
|
|
||||||
.collect(),
|
|
||||||
),
|
|
||||||
)]
|
|
||||||
.into_iter()
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
let error = crate::execute(query, None, &schema, &vars, &())
|
let error = crate::execute(query, None, &schema, &vars, &())
|
||||||
.await
|
.await
|
||||||
|
@ -376,7 +338,7 @@ async fn variable_error_on_omit_non_null() {
|
||||||
ValidationError(vec![RuleError::new(
|
ValidationError(vec![RuleError::new(
|
||||||
r#"Variable "$input" got invalid value. In field "c": Expected "String!", found null."#,
|
r#"Variable "$input" got invalid value. In field "c": Expected "String!", found null."#,
|
||||||
&[SourcePosition::new(8, 0, 8)],
|
&[SourcePosition::new(8, 0, 8)],
|
||||||
)])
|
)]),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -390,19 +352,11 @@ async fn variable_multiple_errors_with_nesting() {
|
||||||
|
|
||||||
let query =
|
let query =
|
||||||
r#"query q($input: TestNestedInputObject) { fieldWithNestedObjectInput(input: $input) }"#;
|
r#"query q($input: TestNestedInputObject) { fieldWithNestedObjectInput(input: $input) }"#;
|
||||||
let vars = vec![(
|
let vars = graphql_vars! {
|
||||||
"input".to_owned(),
|
"input": {
|
||||||
InputValue::object(
|
"na": {"a": "foo"},
|
||||||
vec![(
|
},
|
||||||
"na",
|
};
|
||||||
InputValue::object(vec![("a", InputValue::scalar("foo"))].into_iter().collect()),
|
|
||||||
)]
|
|
||||||
.into_iter()
|
|
||||||
.collect(),
|
|
||||||
),
|
|
||||||
)]
|
|
||||||
.into_iter()
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
let error = crate::execute(query, None, &schema, &vars, &())
|
let error = crate::execute(query, None, &schema, &vars, &())
|
||||||
.await
|
.await
|
||||||
|
@ -419,7 +373,7 @@ async fn variable_multiple_errors_with_nesting() {
|
||||||
r#"Variable "$input" got invalid value. In field "nb": Expected "String!", found null."#,
|
r#"Variable "$input" got invalid value. In field "nb": Expected "String!", found null."#,
|
||||||
&[SourcePosition::new(8, 0, 8)],
|
&[SourcePosition::new(8, 0, 8)],
|
||||||
),
|
),
|
||||||
])
|
]),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -432,21 +386,14 @@ async fn variable_error_on_additional_field() {
|
||||||
);
|
);
|
||||||
|
|
||||||
let query = r#"query q($input: TestInputObject) { fieldWithObjectInput(input: $input) }"#;
|
let query = r#"query q($input: TestInputObject) { fieldWithObjectInput(input: $input) }"#;
|
||||||
let vars = vec![(
|
let vars = graphql_vars! {
|
||||||
"input".to_owned(),
|
"input": {
|
||||||
InputValue::object(
|
"a": "foo",
|
||||||
vec![
|
"b": "bar",
|
||||||
("a", InputValue::scalar("foo")),
|
"c": "baz",
|
||||||
("b", InputValue::scalar("bar")),
|
"extra": "dog",
|
||||||
("c", InputValue::scalar("baz")),
|
},
|
||||||
("extra", InputValue::scalar("dog")),
|
};
|
||||||
]
|
|
||||||
.into_iter()
|
|
||||||
.collect(),
|
|
||||||
),
|
|
||||||
)]
|
|
||||||
.into_iter()
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
let error = crate::execute(query, None, &schema, &vars, &())
|
let error = crate::execute(query, None, &schema, &vars, &())
|
||||||
.await
|
.await
|
||||||
|
@ -457,7 +404,7 @@ async fn variable_error_on_additional_field() {
|
||||||
ValidationError(vec![RuleError::new(
|
ValidationError(vec![RuleError::new(
|
||||||
r#"Variable "$input" got invalid value. In field "extra": Unknown field."#,
|
r#"Variable "$input" got invalid value. In field "extra": Unknown field."#,
|
||||||
&[SourcePosition::new(8, 0, 8)],
|
&[SourcePosition::new(8, 0, 8)],
|
||||||
)])
|
)]),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -507,9 +454,7 @@ async fn allow_nullable_inputs_to_be_explicitly_null() {
|
||||||
async fn allow_nullable_inputs_to_be_set_to_null_in_variable() {
|
async fn allow_nullable_inputs_to_be_set_to_null_in_variable() {
|
||||||
run_variable_query(
|
run_variable_query(
|
||||||
r#"query q($value: String) { fieldWithNullableStringInput(input: $value) }"#,
|
r#"query q($value: String) { fieldWithNullableStringInput(input: $value) }"#,
|
||||||
vec![("value".to_owned(), InputValue::null())]
|
graphql_vars! {"value": null},
|
||||||
.into_iter()
|
|
||||||
.collect(),
|
|
||||||
|result: &Object<DefaultScalarValue>| {
|
|result: &Object<DefaultScalarValue>| {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
result.get_field_value("fieldWithNullableStringInput"),
|
result.get_field_value("fieldWithNullableStringInput"),
|
||||||
|
@ -524,9 +469,7 @@ async fn allow_nullable_inputs_to_be_set_to_null_in_variable() {
|
||||||
async fn allow_nullable_inputs_to_be_set_to_value_in_variable() {
|
async fn allow_nullable_inputs_to_be_set_to_value_in_variable() {
|
||||||
run_variable_query(
|
run_variable_query(
|
||||||
r#"query q($value: String) { fieldWithNullableStringInput(input: $value) }"#,
|
r#"query q($value: String) { fieldWithNullableStringInput(input: $value) }"#,
|
||||||
vec![("value".to_owned(), InputValue::scalar("a"))]
|
graphql_vars! {"value": "a"},
|
||||||
.into_iter()
|
|
||||||
.collect(),
|
|
||||||
|result: &Object<DefaultScalarValue>| {
|
|result: &Object<DefaultScalarValue>| {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
result.get_field_value("fieldWithNullableStringInput"),
|
result.get_field_value("fieldWithNullableStringInput"),
|
||||||
|
@ -560,7 +503,7 @@ async fn does_not_allow_non_nullable_input_to_be_omitted_in_variable() {
|
||||||
);
|
);
|
||||||
|
|
||||||
let query = r#"query q($value: String!) { fieldWithNonNullableStringInput(input: $value) }"#;
|
let query = r#"query q($value: String!) { fieldWithNonNullableStringInput(input: $value) }"#;
|
||||||
let vars = vec![].into_iter().collect();
|
let vars = graphql_vars! {};
|
||||||
|
|
||||||
let error = crate::execute(query, None, &schema, &vars, &())
|
let error = crate::execute(query, None, &schema, &vars, &())
|
||||||
.await
|
.await
|
||||||
|
@ -571,7 +514,7 @@ async fn does_not_allow_non_nullable_input_to_be_omitted_in_variable() {
|
||||||
ValidationError(vec![RuleError::new(
|
ValidationError(vec![RuleError::new(
|
||||||
r#"Variable "$value" of required type "String!" was not provided."#,
|
r#"Variable "$value" of required type "String!" was not provided."#,
|
||||||
&[SourcePosition::new(8, 0, 8)],
|
&[SourcePosition::new(8, 0, 8)],
|
||||||
)])
|
)]),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -584,9 +527,7 @@ async fn does_not_allow_non_nullable_input_to_be_set_to_null_in_variable() {
|
||||||
);
|
);
|
||||||
|
|
||||||
let query = r#"query q($value: String!) { fieldWithNonNullableStringInput(input: $value) }"#;
|
let query = r#"query q($value: String!) { fieldWithNonNullableStringInput(input: $value) }"#;
|
||||||
let vars = vec![("value".to_owned(), InputValue::null())]
|
let vars = graphql_vars! {"value": null};
|
||||||
.into_iter()
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
let error = crate::execute(query, None, &schema, &vars, &())
|
let error = crate::execute(query, None, &schema, &vars, &())
|
||||||
.await
|
.await
|
||||||
|
@ -597,7 +538,7 @@ async fn does_not_allow_non_nullable_input_to_be_set_to_null_in_variable() {
|
||||||
ValidationError(vec![RuleError::new(
|
ValidationError(vec![RuleError::new(
|
||||||
r#"Variable "$value" of required type "String!" was not provided."#,
|
r#"Variable "$value" of required type "String!" was not provided."#,
|
||||||
&[SourcePosition::new(8, 0, 8)],
|
&[SourcePosition::new(8, 0, 8)],
|
||||||
)])
|
)]),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -605,13 +546,11 @@ async fn does_not_allow_non_nullable_input_to_be_set_to_null_in_variable() {
|
||||||
async fn allow_non_nullable_inputs_to_be_set_to_value_in_variable() {
|
async fn allow_non_nullable_inputs_to_be_set_to_value_in_variable() {
|
||||||
run_variable_query(
|
run_variable_query(
|
||||||
r#"query q($value: String!) { fieldWithNonNullableStringInput(input: $value) }"#,
|
r#"query q($value: String!) { fieldWithNonNullableStringInput(input: $value) }"#,
|
||||||
vec![("value".to_owned(), InputValue::scalar("a"))]
|
graphql_vars! {"value": "a"},
|
||||||
.into_iter()
|
|
||||||
.collect(),
|
|
||||||
|result| {
|
|result| {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
result.get_field_value("fieldWithNonNullableStringInput"),
|
result.get_field_value("fieldWithNonNullableStringInput"),
|
||||||
Some(&graphql_value!(r#""a""#))
|
Some(&graphql_value!(r#""a""#)),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -625,7 +564,7 @@ async fn allow_non_nullable_inputs_to_be_set_to_value_directly() {
|
||||||
|result: &Object<DefaultScalarValue>| {
|
|result: &Object<DefaultScalarValue>| {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
result.get_field_value("fieldWithNonNullableStringInput"),
|
result.get_field_value("fieldWithNonNullableStringInput"),
|
||||||
Some(&graphql_value!(r#""a""#))
|
Some(&graphql_value!(r#""a""#)),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -636,13 +575,11 @@ async fn allow_non_nullable_inputs_to_be_set_to_value_directly() {
|
||||||
async fn allow_lists_to_be_null() {
|
async fn allow_lists_to_be_null() {
|
||||||
run_variable_query(
|
run_variable_query(
|
||||||
r#"query q($input: [String]) { list(input: $input) }"#,
|
r#"query q($input: [String]) { list(input: $input) }"#,
|
||||||
vec![("input".to_owned(), InputValue::null())]
|
graphql_vars! {"input": null},
|
||||||
.into_iter()
|
|
||||||
.collect(),
|
|
||||||
|result: &Object<DefaultScalarValue>| {
|
|result: &Object<DefaultScalarValue>| {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
result.get_field_value("list"),
|
result.get_field_value("list"),
|
||||||
Some(&graphql_value!(r#"None"#))
|
Some(&graphql_value!(r#"None"#)),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -653,16 +590,11 @@ async fn allow_lists_to_be_null() {
|
||||||
async fn allow_lists_to_contain_values() {
|
async fn allow_lists_to_contain_values() {
|
||||||
run_variable_query(
|
run_variable_query(
|
||||||
r#"query q($input: [String]) { list(input: $input) }"#,
|
r#"query q($input: [String]) { list(input: $input) }"#,
|
||||||
vec![(
|
graphql_vars! {"input": ["A"]},
|
||||||
"input".to_owned(),
|
|
||||||
InputValue::list(vec![InputValue::scalar("A")]),
|
|
||||||
)]
|
|
||||||
.into_iter()
|
|
||||||
.collect(),
|
|
||||||
|result| {
|
|result| {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
result.get_field_value("list"),
|
result.get_field_value("list"),
|
||||||
Some(&graphql_value!(r#"Some([Some("A")])"#))
|
Some(&graphql_value!(r#"Some([Some("A")])"#)),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -673,20 +605,11 @@ async fn allow_lists_to_contain_values() {
|
||||||
async fn allow_lists_to_contain_null() {
|
async fn allow_lists_to_contain_null() {
|
||||||
run_variable_query(
|
run_variable_query(
|
||||||
r#"query q($input: [String]) { list(input: $input) }"#,
|
r#"query q($input: [String]) { list(input: $input) }"#,
|
||||||
vec![(
|
graphql_vars! {"input": ["A", null, "B"]},
|
||||||
"input".to_owned(),
|
|
||||||
InputValue::list(vec![
|
|
||||||
InputValue::scalar("A"),
|
|
||||||
InputValue::null(),
|
|
||||||
InputValue::scalar("B"),
|
|
||||||
]),
|
|
||||||
)]
|
|
||||||
.into_iter()
|
|
||||||
.collect(),
|
|
||||||
|result| {
|
|result| {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
result.get_field_value("list"),
|
result.get_field_value("list"),
|
||||||
Some(&graphql_value!(r#"Some([Some("A"), None, Some("B")])"#))
|
Some(&graphql_value!(r#"Some([Some("A"), None, Some("B")])"#)),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -702,9 +625,7 @@ async fn does_not_allow_non_null_lists_to_be_null() {
|
||||||
);
|
);
|
||||||
|
|
||||||
let query = r#"query q($input: [String]!) { nnList(input: $input) }"#;
|
let query = r#"query q($input: [String]!) { nnList(input: $input) }"#;
|
||||||
let vars = vec![("input".to_owned(), InputValue::null())]
|
let vars = graphql_vars! {"input": null};
|
||||||
.into_iter()
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
let error = crate::execute(query, None, &schema, &vars, &())
|
let error = crate::execute(query, None, &schema, &vars, &())
|
||||||
.await
|
.await
|
||||||
|
@ -715,7 +636,7 @@ async fn does_not_allow_non_null_lists_to_be_null() {
|
||||||
ValidationError(vec![RuleError::new(
|
ValidationError(vec![RuleError::new(
|
||||||
r#"Variable "$input" of required type "[String]!" was not provided."#,
|
r#"Variable "$input" of required type "[String]!" was not provided."#,
|
||||||
&[SourcePosition::new(8, 0, 8)],
|
&[SourcePosition::new(8, 0, 8)],
|
||||||
)])
|
)]),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -723,16 +644,11 @@ async fn does_not_allow_non_null_lists_to_be_null() {
|
||||||
async fn allow_non_null_lists_to_contain_values() {
|
async fn allow_non_null_lists_to_contain_values() {
|
||||||
run_variable_query(
|
run_variable_query(
|
||||||
r#"query q($input: [String]!) { nnList(input: $input) }"#,
|
r#"query q($input: [String]!) { nnList(input: $input) }"#,
|
||||||
vec![(
|
graphql_vars! {"input": ["A"]},
|
||||||
"input".to_owned(),
|
|
||||||
InputValue::list(vec![InputValue::scalar("A")]),
|
|
||||||
)]
|
|
||||||
.into_iter()
|
|
||||||
.collect(),
|
|
||||||
|result| {
|
|result| {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
result.get_field_value("nnList"),
|
result.get_field_value("nnList"),
|
||||||
Some(&graphql_value!(r#"[Some("A")]"#))
|
Some(&graphql_value!(r#"[Some("A")]"#)),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -742,20 +658,11 @@ async fn allow_non_null_lists_to_contain_values() {
|
||||||
async fn allow_non_null_lists_to_contain_null() {
|
async fn allow_non_null_lists_to_contain_null() {
|
||||||
run_variable_query(
|
run_variable_query(
|
||||||
r#"query q($input: [String]!) { nnList(input: $input) }"#,
|
r#"query q($input: [String]!) { nnList(input: $input) }"#,
|
||||||
vec![(
|
graphql_vars! {"input": ["A", null, "B"]},
|
||||||
"input".to_owned(),
|
|
||||||
InputValue::list(vec![
|
|
||||||
InputValue::scalar("A"),
|
|
||||||
InputValue::null(),
|
|
||||||
InputValue::scalar("B"),
|
|
||||||
]),
|
|
||||||
)]
|
|
||||||
.into_iter()
|
|
||||||
.collect(),
|
|
||||||
|result| {
|
|result| {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
result.get_field_value("nnList"),
|
result.get_field_value("nnList"),
|
||||||
Some(&graphql_value!(r#"[Some("A"), None, Some("B")]"#))
|
Some(&graphql_value!(r#"[Some("A"), None, Some("B")]"#)),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -766,9 +673,7 @@ async fn allow_non_null_lists_to_contain_null() {
|
||||||
async fn allow_lists_of_non_null_to_be_null() {
|
async fn allow_lists_of_non_null_to_be_null() {
|
||||||
run_variable_query(
|
run_variable_query(
|
||||||
r#"query q($input: [String!]) { listNn(input: $input) }"#,
|
r#"query q($input: [String!]) { listNn(input: $input) }"#,
|
||||||
vec![("input".to_owned(), InputValue::null())]
|
graphql_vars! {"input": null},
|
||||||
.into_iter()
|
|
||||||
.collect(),
|
|
||||||
|result| {
|
|result| {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
result.get_field_value("listNn"),
|
result.get_field_value("listNn"),
|
||||||
|
@ -783,12 +688,7 @@ async fn allow_lists_of_non_null_to_be_null() {
|
||||||
async fn allow_lists_of_non_null_to_contain_values() {
|
async fn allow_lists_of_non_null_to_contain_values() {
|
||||||
run_variable_query(
|
run_variable_query(
|
||||||
r#"query q($input: [String!]) { listNn(input: $input) }"#,
|
r#"query q($input: [String!]) { listNn(input: $input) }"#,
|
||||||
vec![(
|
graphql_vars! {"input": ["A"]},
|
||||||
"input".to_owned(),
|
|
||||||
InputValue::list(vec![InputValue::scalar("A")]),
|
|
||||||
)]
|
|
||||||
.into_iter()
|
|
||||||
.collect(),
|
|
||||||
|result| {
|
|result| {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
result.get_field_value("listNn"),
|
result.get_field_value("listNn"),
|
||||||
|
@ -808,16 +708,7 @@ async fn does_not_allow_lists_of_non_null_to_contain_null() {
|
||||||
);
|
);
|
||||||
|
|
||||||
let query = r#"query q($input: [String!]) { listNn(input: $input) }"#;
|
let query = r#"query q($input: [String!]) { listNn(input: $input) }"#;
|
||||||
let vars = vec![(
|
let vars = graphql_vars! {"input": ["A", null, "B"]};
|
||||||
"input".to_owned(),
|
|
||||||
InputValue::list(vec![
|
|
||||||
InputValue::scalar("A"),
|
|
||||||
InputValue::null(),
|
|
||||||
InputValue::scalar("B"),
|
|
||||||
]),
|
|
||||||
)]
|
|
||||||
.into_iter()
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
let error = crate::execute(query, None, &schema, &vars, &())
|
let error = crate::execute(query, None, &schema, &vars, &())
|
||||||
.await
|
.await
|
||||||
|
@ -828,7 +719,7 @@ async fn does_not_allow_lists_of_non_null_to_contain_null() {
|
||||||
ValidationError(vec![RuleError::new(
|
ValidationError(vec![RuleError::new(
|
||||||
r#"Variable "$input" got invalid value. In element #1: Expected "String!", found null."#,
|
r#"Variable "$input" got invalid value. In element #1: Expected "String!", found null."#,
|
||||||
&[SourcePosition::new(8, 0, 8)],
|
&[SourcePosition::new(8, 0, 8)],
|
||||||
),])
|
)]),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -841,16 +732,7 @@ async fn does_not_allow_non_null_lists_of_non_null_to_contain_null() {
|
||||||
);
|
);
|
||||||
|
|
||||||
let query = r#"query q($input: [String!]!) { nnListNn(input: $input) }"#;
|
let query = r#"query q($input: [String!]!) { nnListNn(input: $input) }"#;
|
||||||
let vars = vec![(
|
let vars = graphql_vars! {"input": ["A", null, "B"]};
|
||||||
"input".to_owned(),
|
|
||||||
InputValue::list(vec![
|
|
||||||
InputValue::scalar("A"),
|
|
||||||
InputValue::null(),
|
|
||||||
InputValue::scalar("B"),
|
|
||||||
]),
|
|
||||||
)]
|
|
||||||
.into_iter()
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
let error = crate::execute(query, None, &schema, &vars, &())
|
let error = crate::execute(query, None, &schema, &vars, &())
|
||||||
.await
|
.await
|
||||||
|
@ -861,7 +743,7 @@ async fn does_not_allow_non_null_lists_of_non_null_to_contain_null() {
|
||||||
ValidationError(vec![RuleError::new(
|
ValidationError(vec![RuleError::new(
|
||||||
r#"Variable "$input" got invalid value. In element #1: Expected "String!", found null."#,
|
r#"Variable "$input" got invalid value. In element #1: Expected "String!", found null."#,
|
||||||
&[SourcePosition::new(8, 0, 8)],
|
&[SourcePosition::new(8, 0, 8)],
|
||||||
),])
|
)]),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -874,9 +756,7 @@ async fn does_not_allow_non_null_lists_of_non_null_to_be_null() {
|
||||||
);
|
);
|
||||||
|
|
||||||
let query = r#"query q($input: [String!]!) { nnListNn(input: $input) }"#;
|
let query = r#"query q($input: [String!]!) { nnListNn(input: $input) }"#;
|
||||||
let vars = vec![("value".to_owned(), InputValue::null())]
|
let vars = graphql_vars! {"input": null};
|
||||||
.into_iter()
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
let error = crate::execute(query, None, &schema, &vars, &())
|
let error = crate::execute(query, None, &schema, &vars, &())
|
||||||
.await
|
.await
|
||||||
|
@ -887,7 +767,7 @@ async fn does_not_allow_non_null_lists_of_non_null_to_be_null() {
|
||||||
ValidationError(vec![RuleError::new(
|
ValidationError(vec![RuleError::new(
|
||||||
r#"Variable "$input" of required type "[String!]!" was not provided."#,
|
r#"Variable "$input" of required type "[String!]!" was not provided."#,
|
||||||
&[SourcePosition::new(8, 0, 8)],
|
&[SourcePosition::new(8, 0, 8)],
|
||||||
)])
|
)]),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -895,12 +775,7 @@ async fn does_not_allow_non_null_lists_of_non_null_to_be_null() {
|
||||||
async fn allow_non_null_lists_of_non_null_to_contain_values() {
|
async fn allow_non_null_lists_of_non_null_to_contain_values() {
|
||||||
run_variable_query(
|
run_variable_query(
|
||||||
r#"query q($input: [String!]!) { nnListNn(input: $input) }"#,
|
r#"query q($input: [String!]!) { nnListNn(input: $input) }"#,
|
||||||
vec![(
|
graphql_vars! {"input": ["A"]},
|
||||||
"input".to_owned(),
|
|
||||||
InputValue::list(vec![InputValue::scalar("A")]),
|
|
||||||
)]
|
|
||||||
.into_iter()
|
|
||||||
.collect(),
|
|
||||||
|result| {
|
|result| {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
result.get_field_value("nnListNn"),
|
result.get_field_value("nnListNn"),
|
||||||
|
@ -940,9 +815,7 @@ async fn default_argument_when_nullable_variable_not_provided() {
|
||||||
async fn default_argument_when_nullable_variable_set_to_null() {
|
async fn default_argument_when_nullable_variable_set_to_null() {
|
||||||
run_variable_query(
|
run_variable_query(
|
||||||
r#"query q($input: String) { fieldWithDefaultArgumentValue(input: $input) }"#,
|
r#"query q($input: String) { fieldWithDefaultArgumentValue(input: $input) }"#,
|
||||||
vec![("input".to_owned(), InputValue::null())]
|
graphql_vars! {"input": null},
|
||||||
.into_iter()
|
|
||||||
.collect(),
|
|
||||||
|result| {
|
|result| {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
result.get_field_value("fieldWithDefaultArgumentValue"),
|
result.get_field_value("fieldWithDefaultArgumentValue"),
|
||||||
|
@ -976,9 +849,7 @@ async fn nullable_input_object_arguments_successful_without_variables() {
|
||||||
async fn nullable_input_object_arguments_successful_with_variables() {
|
async fn nullable_input_object_arguments_successful_with_variables() {
|
||||||
run_variable_query(
|
run_variable_query(
|
||||||
r#"query q($var: Int!) { exampleInput(arg: {b: $var}) }"#,
|
r#"query q($var: Int!) { exampleInput(arg: {b: $var}) }"#,
|
||||||
vec![("var".to_owned(), InputValue::scalar(123))]
|
graphql_vars! {"var": 123},
|
||||||
.into_iter()
|
|
||||||
.collect(),
|
|
||||||
|result| {
|
|result| {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
result.get_field_value("exampleInput"),
|
result.get_field_value("exampleInput"),
|
||||||
|
@ -990,9 +861,7 @@ async fn nullable_input_object_arguments_successful_with_variables() {
|
||||||
|
|
||||||
run_variable_query(
|
run_variable_query(
|
||||||
r#"query q($var: String) { exampleInput(arg: {a: $var, b: 1}) }"#,
|
r#"query q($var: String) { exampleInput(arg: {a: $var, b: 1}) }"#,
|
||||||
vec![("var".to_owned(), InputValue::null())]
|
graphql_vars! {"var": null},
|
||||||
.into_iter()
|
|
||||||
.collect(),
|
|
||||||
|result| {
|
|result| {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
result.get_field_value("exampleInput"),
|
result.get_field_value("exampleInput"),
|
||||||
|
@ -1004,7 +873,7 @@ async fn nullable_input_object_arguments_successful_with_variables() {
|
||||||
|
|
||||||
run_variable_query(
|
run_variable_query(
|
||||||
r#"query q($var: String) { exampleInput(arg: {a: $var, b: 1}) }"#,
|
r#"query q($var: String) { exampleInput(arg: {a: $var, b: 1}) }"#,
|
||||||
vec![].into_iter().collect(),
|
graphql_vars! {},
|
||||||
|result| {
|
|result| {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
result.get_field_value("exampleInput"),
|
result.get_field_value("exampleInput"),
|
||||||
|
@ -1024,7 +893,7 @@ async fn does_not_allow_missing_required_field() {
|
||||||
);
|
);
|
||||||
|
|
||||||
let query = r#"{ exampleInput(arg: {a: "abc"}) }"#;
|
let query = r#"{ exampleInput(arg: {a: "abc"}) }"#;
|
||||||
let vars = vec![].into_iter().collect();
|
let vars = graphql_vars! {};
|
||||||
|
|
||||||
let error = crate::execute(query, None, &schema, &vars, &())
|
let error = crate::execute(query, None, &schema, &vars, &())
|
||||||
.await
|
.await
|
||||||
|
@ -1035,7 +904,7 @@ async fn does_not_allow_missing_required_field() {
|
||||||
ValidationError(vec![RuleError::new(
|
ValidationError(vec![RuleError::new(
|
||||||
r#"Invalid value for argument "arg", expected type "ExampleInputObject!""#,
|
r#"Invalid value for argument "arg", expected type "ExampleInputObject!""#,
|
||||||
&[SourcePosition::new(20, 0, 20)],
|
&[SourcePosition::new(20, 0, 20)],
|
||||||
)])
|
)]),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1048,7 +917,7 @@ async fn does_not_allow_null_in_required_field() {
|
||||||
);
|
);
|
||||||
|
|
||||||
let query = r#"{ exampleInput(arg: {a: "abc", b: null}) }"#;
|
let query = r#"{ exampleInput(arg: {a: "abc", b: null}) }"#;
|
||||||
let vars = vec![].into_iter().collect();
|
let vars = graphql_vars! {};
|
||||||
|
|
||||||
let error = crate::execute(query, None, &schema, &vars, &())
|
let error = crate::execute(query, None, &schema, &vars, &())
|
||||||
.await
|
.await
|
||||||
|
@ -1059,7 +928,7 @@ async fn does_not_allow_null_in_required_field() {
|
||||||
ValidationError(vec![RuleError::new(
|
ValidationError(vec![RuleError::new(
|
||||||
r#"Invalid value for argument "arg", expected type "ExampleInputObject!""#,
|
r#"Invalid value for argument "arg", expected type "ExampleInputObject!""#,
|
||||||
&[SourcePosition::new(20, 0, 20)],
|
&[SourcePosition::new(20, 0, 20)],
|
||||||
)])
|
)]),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1072,7 +941,7 @@ async fn does_not_allow_missing_variable_for_required_field() {
|
||||||
);
|
);
|
||||||
|
|
||||||
let query = r#"query q($var: Int!) { exampleInput(arg: {b: $var}) }"#;
|
let query = r#"query q($var: Int!) { exampleInput(arg: {b: $var}) }"#;
|
||||||
let vars = vec![].into_iter().collect();
|
let vars = graphql_vars! {};
|
||||||
|
|
||||||
let error = crate::execute(query, None, &schema, &vars, &())
|
let error = crate::execute(query, None, &schema, &vars, &())
|
||||||
.await
|
.await
|
||||||
|
@ -1083,7 +952,7 @@ async fn does_not_allow_missing_variable_for_required_field() {
|
||||||
ValidationError(vec![RuleError::new(
|
ValidationError(vec![RuleError::new(
|
||||||
r#"Variable "$var" of required type "Int!" was not provided."#,
|
r#"Variable "$var" of required type "Int!" was not provided."#,
|
||||||
&[SourcePosition::new(8, 0, 8)],
|
&[SourcePosition::new(8, 0, 8)],
|
||||||
)])
|
)]),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1096,9 +965,7 @@ async fn does_not_allow_null_variable_for_required_field() {
|
||||||
);
|
);
|
||||||
|
|
||||||
let query = r#"query q($var: Int!) { exampleInput(arg: {b: $var}) }"#;
|
let query = r#"query q($var: Int!) { exampleInput(arg: {b: $var}) }"#;
|
||||||
let vars = vec![("var".to_owned(), InputValue::null())]
|
let vars = graphql_vars! {"var": null};
|
||||||
.into_iter()
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
let error = crate::execute(query, None, &schema, &vars, &())
|
let error = crate::execute(query, None, &schema, &vars, &())
|
||||||
.await
|
.await
|
||||||
|
@ -1109,7 +976,7 @@ async fn does_not_allow_null_variable_for_required_field() {
|
||||||
ValidationError(vec![RuleError::new(
|
ValidationError(vec![RuleError::new(
|
||||||
r#"Variable "$var" of required type "Int!" was not provided."#,
|
r#"Variable "$var" of required type "Int!" was not provided."#,
|
||||||
&[SourcePosition::new(8, 0, 8)],
|
&[SourcePosition::new(8, 0, 8)],
|
||||||
)])
|
)]),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1125,9 +992,7 @@ async fn input_object_with_default_values() {
|
||||||
|
|
||||||
run_variable_query(
|
run_variable_query(
|
||||||
r#"query q($var: Int!) { inputWithDefaults(arg: {a: $var}) }"#,
|
r#"query q($var: Int!) { inputWithDefaults(arg: {a: $var}) }"#,
|
||||||
vec![("var".to_owned(), InputValue::scalar(1))]
|
graphql_vars! {"var": 1},
|
||||||
.into_iter()
|
|
||||||
.collect(),
|
|
||||||
|result| {
|
|result| {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
result.get_field_value("inputWithDefaults"),
|
result.get_field_value("inputWithDefaults"),
|
||||||
|
@ -1139,7 +1004,7 @@ async fn input_object_with_default_values() {
|
||||||
|
|
||||||
run_variable_query(
|
run_variable_query(
|
||||||
r#"query q($var: Int = 1) { inputWithDefaults(arg: {a: $var}) }"#,
|
r#"query q($var: Int = 1) { inputWithDefaults(arg: {a: $var}) }"#,
|
||||||
vec![].into_iter().collect(),
|
graphql_vars! {},
|
||||||
|result| {
|
|result| {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
result.get_field_value("inputWithDefaults"),
|
result.get_field_value("inputWithDefaults"),
|
||||||
|
@ -1151,9 +1016,7 @@ async fn input_object_with_default_values() {
|
||||||
|
|
||||||
run_variable_query(
|
run_variable_query(
|
||||||
r#"query q($var: Int = 1) { inputWithDefaults(arg: {a: $var}) }"#,
|
r#"query q($var: Int = 1) { inputWithDefaults(arg: {a: $var}) }"#,
|
||||||
vec![("var".to_owned(), InputValue::scalar(2))]
|
graphql_vars! {"var": 2},
|
||||||
.into_iter()
|
|
||||||
.collect(),
|
|
||||||
|result| {
|
|result| {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
result.get_field_value("inputWithDefaults"),
|
result.get_field_value("inputWithDefaults"),
|
||||||
|
@ -1171,9 +1034,7 @@ mod integers {
|
||||||
async fn positive_and_negative_should_work() {
|
async fn positive_and_negative_should_work() {
|
||||||
run_variable_query(
|
run_variable_query(
|
||||||
r#"query q($var: Int!) { integerInput(value: $var) }"#,
|
r#"query q($var: Int!) { integerInput(value: $var) }"#,
|
||||||
vec![("var".to_owned(), InputValue::scalar(1))]
|
graphql_vars! {"var": 1},
|
||||||
.into_iter()
|
|
||||||
.collect(),
|
|
||||||
|result| {
|
|result| {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
result.get_field_value("integerInput"),
|
result.get_field_value("integerInput"),
|
||||||
|
@ -1185,9 +1046,7 @@ mod integers {
|
||||||
|
|
||||||
run_variable_query(
|
run_variable_query(
|
||||||
r#"query q($var: Int!) { integerInput(value: $var) }"#,
|
r#"query q($var: Int!) { integerInput(value: $var) }"#,
|
||||||
vec![("var".to_owned(), InputValue::scalar(-1))]
|
graphql_vars! {"var": -1},
|
||||||
.into_iter()
|
|
||||||
.collect(),
|
|
||||||
|result| {
|
|result| {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
result.get_field_value("integerInput"),
|
result.get_field_value("integerInput"),
|
||||||
|
@ -1207,9 +1066,7 @@ mod integers {
|
||||||
);
|
);
|
||||||
|
|
||||||
let query = r#"query q($var: Int!) { integerInput(value: $var) }"#;
|
let query = r#"query q($var: Int!) { integerInput(value: $var) }"#;
|
||||||
let vars = vec![("var".to_owned(), InputValue::scalar(10.0))]
|
let vars = graphql_vars! {"var": 10.0};
|
||||||
.into_iter()
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
let error = crate::execute(query, None, &schema, &vars, &())
|
let error = crate::execute(query, None, &schema, &vars, &())
|
||||||
.await
|
.await
|
||||||
|
@ -1220,7 +1077,7 @@ mod integers {
|
||||||
ValidationError(vec![RuleError::new(
|
ValidationError(vec![RuleError::new(
|
||||||
r#"Variable "$var" got invalid value. Expected "Int"."#,
|
r#"Variable "$var" got invalid value. Expected "Int"."#,
|
||||||
&[SourcePosition::new(8, 0, 8)],
|
&[SourcePosition::new(8, 0, 8)],
|
||||||
)])
|
)]),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1233,9 +1090,7 @@ mod integers {
|
||||||
);
|
);
|
||||||
|
|
||||||
let query = r#"query q($var: Int!) { integerInput(value: $var) }"#;
|
let query = r#"query q($var: Int!) { integerInput(value: $var) }"#;
|
||||||
let vars = vec![("var".to_owned(), InputValue::scalar("10"))]
|
let vars = graphql_vars! {"var": "10"};
|
||||||
.into_iter()
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
let error = crate::execute(query, None, &schema, &vars, &())
|
let error = crate::execute(query, None, &schema, &vars, &())
|
||||||
.await
|
.await
|
||||||
|
@ -1246,7 +1101,7 @@ mod integers {
|
||||||
ValidationError(vec![RuleError::new(
|
ValidationError(vec![RuleError::new(
|
||||||
r#"Variable "$var" got invalid value. Expected "Int"."#,
|
r#"Variable "$var" got invalid value. Expected "Int"."#,
|
||||||
&[SourcePosition::new(8, 0, 8)],
|
&[SourcePosition::new(8, 0, 8)],
|
||||||
)])
|
)]),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1258,9 +1113,7 @@ mod floats {
|
||||||
async fn float_values_should_work() {
|
async fn float_values_should_work() {
|
||||||
run_variable_query(
|
run_variable_query(
|
||||||
r#"query q($var: Float!) { floatInput(value: $var) }"#,
|
r#"query q($var: Float!) { floatInput(value: $var) }"#,
|
||||||
vec![("var".to_owned(), InputValue::scalar(10.0))]
|
graphql_vars! {"var": 10.0},
|
||||||
.into_iter()
|
|
||||||
.collect(),
|
|
||||||
|result| {
|
|result| {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
result.get_field_value("floatInput"),
|
result.get_field_value("floatInput"),
|
||||||
|
@ -1275,9 +1128,7 @@ mod floats {
|
||||||
async fn coercion_from_integers_should_work() {
|
async fn coercion_from_integers_should_work() {
|
||||||
run_variable_query(
|
run_variable_query(
|
||||||
r#"query q($var: Float!) { floatInput(value: $var) }"#,
|
r#"query q($var: Float!) { floatInput(value: $var) }"#,
|
||||||
vec![("var".to_owned(), InputValue::scalar(-1))]
|
graphql_vars! {"var": -1},
|
||||||
.into_iter()
|
|
||||||
.collect(),
|
|
||||||
|result| {
|
|result| {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
result.get_field_value("floatInput"),
|
result.get_field_value("floatInput"),
|
||||||
|
@ -1297,9 +1148,7 @@ mod floats {
|
||||||
);
|
);
|
||||||
|
|
||||||
let query = r#"query q($var: Float!) { floatInput(value: $var) }"#;
|
let query = r#"query q($var: Float!) { floatInput(value: $var) }"#;
|
||||||
let vars = vec![("var".to_owned(), InputValue::scalar("10"))]
|
let vars = graphql_vars! {"var": "10"};
|
||||||
.into_iter()
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
let error = crate::execute(query, None, &schema, &vars, &())
|
let error = crate::execute(query, None, &schema, &vars, &())
|
||||||
.await
|
.await
|
||||||
|
@ -1310,7 +1159,7 @@ mod floats {
|
||||||
ValidationError(vec![RuleError::new(
|
ValidationError(vec![RuleError::new(
|
||||||
r#"Variable "$var" got invalid value. Expected "Float"."#,
|
r#"Variable "$var" got invalid value. Expected "Float"."#,
|
||||||
&[SourcePosition::new(8, 0, 8)],
|
&[SourcePosition::new(8, 0, 8)],
|
||||||
)])
|
)]),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,12 +61,12 @@ mod test {
|
||||||
use bson::{oid::ObjectId, DateTime as UtcDateTime};
|
use bson::{oid::ObjectId, DateTime as UtcDateTime};
|
||||||
use chrono::{DateTime, Utc};
|
use chrono::{DateTime, Utc};
|
||||||
|
|
||||||
use crate::{value::DefaultScalarValue, FromInputValue, InputValue};
|
use crate::{graphql_input_value, FromInputValue, InputValue};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn objectid_from_input_value() {
|
fn objectid_from_input_value() {
|
||||||
let raw = "53e37d08776f724e42000000";
|
let raw = "53e37d08776f724e42000000";
|
||||||
let input = InputValue::<DefaultScalarValue>::scalar(raw.to_string());
|
let input: InputValue = graphql_input_value!((raw));
|
||||||
|
|
||||||
let parsed: ObjectId = FromInputValue::from_input_value(&input).unwrap();
|
let parsed: ObjectId = FromInputValue::from_input_value(&input).unwrap();
|
||||||
let id = ObjectId::parse_str(raw).unwrap();
|
let id = ObjectId::parse_str(raw).unwrap();
|
||||||
|
@ -77,7 +77,7 @@ mod test {
|
||||||
#[test]
|
#[test]
|
||||||
fn utcdatetime_from_input_value() {
|
fn utcdatetime_from_input_value() {
|
||||||
let raw = "2020-03-23T17:38:32.446+00:00";
|
let raw = "2020-03-23T17:38:32.446+00:00";
|
||||||
let input = InputValue::<DefaultScalarValue>::scalar(raw.to_string());
|
let input: InputValue = graphql_input_value!((raw));
|
||||||
|
|
||||||
let parsed: UtcDateTime = FromInputValue::from_input_value(&input).unwrap();
|
let parsed: UtcDateTime = FromInputValue::from_input_value(&input).unwrap();
|
||||||
let date_time = UtcDateTime::from_chrono(
|
let date_time = UtcDateTime::from_chrono(
|
||||||
|
|
|
@ -148,14 +148,14 @@ where
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use crate::{value::DefaultScalarValue, InputValue};
|
|
||||||
use chrono::prelude::*;
|
use chrono::prelude::*;
|
||||||
|
|
||||||
fn datetime_fixedoffset_test(raw: &'static str) {
|
use crate::{graphql_input_value, FromInputValue, InputValue};
|
||||||
let input: crate::InputValue<DefaultScalarValue> = InputValue::scalar(raw.to_string());
|
|
||||||
|
|
||||||
let parsed: DateTime<FixedOffset> =
|
fn datetime_fixedoffset_test(raw: &'static str) {
|
||||||
crate::FromInputValue::from_input_value(&input).unwrap();
|
let input: InputValue = graphql_input_value!((raw));
|
||||||
|
|
||||||
|
let parsed: DateTime<FixedOffset> = FromInputValue::from_input_value(&input).unwrap();
|
||||||
let expected = DateTime::parse_from_rfc3339(raw).unwrap();
|
let expected = DateTime::parse_from_rfc3339(raw).unwrap();
|
||||||
|
|
||||||
assert_eq!(parsed, expected);
|
assert_eq!(parsed, expected);
|
||||||
|
@ -177,9 +177,9 @@ mod test {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn datetime_utc_test(raw: &'static str) {
|
fn datetime_utc_test(raw: &'static str) {
|
||||||
let input = <InputValue<DefaultScalarValue>>::scalar(raw.to_string());
|
let input: InputValue = graphql_input_value!((raw));
|
||||||
|
|
||||||
let parsed: DateTime<Utc> = crate::FromInputValue::from_input_value(&input).unwrap();
|
let parsed: DateTime<Utc> = FromInputValue::from_input_value(&input).unwrap();
|
||||||
let expected = DateTime::parse_from_rfc3339(raw)
|
let expected = DateTime::parse_from_rfc3339(raw)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.with_timezone(&Utc);
|
.with_timezone(&Utc);
|
||||||
|
@ -204,13 +204,12 @@ mod test {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn naivedate_from_input_value() {
|
fn naivedate_from_input_value() {
|
||||||
let input: crate::InputValue<DefaultScalarValue> =
|
let input: InputValue = graphql_input_value!("1996-12-19");
|
||||||
InputValue::scalar("1996-12-19".to_string());
|
|
||||||
let y = 1996;
|
let y = 1996;
|
||||||
let m = 12;
|
let m = 12;
|
||||||
let d = 19;
|
let d = 19;
|
||||||
|
|
||||||
let parsed: NaiveDate = crate::FromInputValue::from_input_value(&input).unwrap();
|
let parsed: NaiveDate = FromInputValue::from_input_value(&input).unwrap();
|
||||||
let expected = NaiveDate::from_ymd(y, m, d);
|
let expected = NaiveDate::from_ymd(y, m, d);
|
||||||
|
|
||||||
assert_eq!(parsed, expected);
|
assert_eq!(parsed, expected);
|
||||||
|
@ -223,10 +222,9 @@ mod test {
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg(feature = "scalar-naivetime")]
|
#[cfg(feature = "scalar-naivetime")]
|
||||||
fn naivetime_from_input_value() {
|
fn naivetime_from_input_value() {
|
||||||
let input: crate::InputValue<DefaultScalarValue>;
|
let input: InputValue = graphql_input_value!("21:12:19");
|
||||||
input = InputValue::scalar("21:12:19".to_string());
|
|
||||||
let [h, m, s] = [21, 12, 19];
|
let [h, m, s] = [21, 12, 19];
|
||||||
let parsed: NaiveTime = crate::FromInputValue::from_input_value(&input).unwrap();
|
let parsed: NaiveTime = FromInputValue::from_input_value(&input).unwrap();
|
||||||
let expected = NaiveTime::from_hms(h, m, s);
|
let expected = NaiveTime::from_hms(h, m, s);
|
||||||
assert_eq!(parsed, expected);
|
assert_eq!(parsed, expected);
|
||||||
assert_eq!(parsed.hour(), h);
|
assert_eq!(parsed.hour(), h);
|
||||||
|
@ -237,9 +235,9 @@ mod test {
|
||||||
#[test]
|
#[test]
|
||||||
fn naivedatetime_from_input_value() {
|
fn naivedatetime_from_input_value() {
|
||||||
let raw = 1_000_000_000_f64;
|
let raw = 1_000_000_000_f64;
|
||||||
let input = <InputValue<DefaultScalarValue>>::scalar(raw);
|
let input: InputValue = graphql_input_value!((raw));
|
||||||
|
|
||||||
let parsed: NaiveDateTime = crate::FromInputValue::from_input_value(&input).unwrap();
|
let parsed: NaiveDateTime = FromInputValue::from_input_value(&input).unwrap();
|
||||||
let expected = NaiveDateTime::from_timestamp_opt(raw as i64, 0).unwrap();
|
let expected = NaiveDateTime::from_timestamp_opt(raw as i64, 0).unwrap();
|
||||||
|
|
||||||
assert_eq!(parsed, expected);
|
assert_eq!(parsed, expected);
|
||||||
|
@ -252,8 +250,7 @@ mod integration_test {
|
||||||
use chrono::{prelude::*, Utc};
|
use chrono::{prelude::*, Utc};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
executor::Variables,
|
graphql_object, graphql_value, graphql_vars,
|
||||||
graphql_object, graphql_value,
|
|
||||||
schema::model::RootNode,
|
schema::model::RootNode,
|
||||||
types::scalars::{EmptyMutation, EmptySubscription},
|
types::scalars::{EmptyMutation, EmptySubscription},
|
||||||
};
|
};
|
||||||
|
@ -322,7 +319,7 @@ mod integration_test {
|
||||||
EmptySubscription::<()>::new(),
|
EmptySubscription::<()>::new(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let (result, errs) = crate::execute(doc, None, &schema, &Variables::new(), &())
|
let (result, errs) = crate::execute(doc, None, &schema, &graphql_vars! {}, &())
|
||||||
.await
|
.await
|
||||||
.expect("Execution failed");
|
.expect("Execution failed");
|
||||||
|
|
||||||
|
|
|
@ -39,10 +39,10 @@ mod test {
|
||||||
mod from_input_value {
|
mod from_input_value {
|
||||||
use chrono_tz::Tz;
|
use chrono_tz::Tz;
|
||||||
|
|
||||||
use crate::{DefaultScalarValue, FromInputValue, InputValue};
|
use crate::{graphql_input_value, FromInputValue, InputValue};
|
||||||
|
|
||||||
fn tz_input_test(raw: &'static str, expected: Option<Tz>) {
|
fn tz_input_test(raw: &'static str, expected: Option<Tz>) {
|
||||||
let input = <InputValue<DefaultScalarValue>>::scalar(raw.to_string());
|
let input: InputValue = graphql_input_value!((raw));
|
||||||
let parsed: Option<Tz> = FromInputValue::from_input_value(&input);
|
let parsed: Option<Tz> = FromInputValue::from_input_value(&input);
|
||||||
|
|
||||||
assert_eq!(parsed, expected);
|
assert_eq!(parsed, expected);
|
||||||
|
|
|
@ -357,6 +357,7 @@ mod tests {
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
ast::InputValue,
|
ast::InputValue,
|
||||||
|
graphql_input_value,
|
||||||
value::{DefaultScalarValue, Object},
|
value::{DefaultScalarValue, Object},
|
||||||
FieldError, Value,
|
FieldError, Value,
|
||||||
};
|
};
|
||||||
|
@ -366,21 +367,21 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn int() {
|
fn int() {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
from_str::<InputValue<DefaultScalarValue>>("1235").unwrap(),
|
from_str::<InputValue>("1235").unwrap(),
|
||||||
InputValue::scalar(1235),
|
graphql_input_value!(1235),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn float() {
|
fn float() {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
from_str::<InputValue<DefaultScalarValue>>("2.0").unwrap(),
|
from_str::<InputValue>("2.0").unwrap(),
|
||||||
InputValue::scalar(2.0),
|
graphql_input_value!(2.0),
|
||||||
);
|
);
|
||||||
// large value without a decimal part is also float
|
// large value without a decimal part is also float
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
from_str::<InputValue<DefaultScalarValue>>("123567890123").unwrap(),
|
from_str::<InputValue>("123567890123").unwrap(),
|
||||||
InputValue::scalar(123_567_890_123.0),
|
graphql_input_value!(123_567_890_123.0),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,12 +29,12 @@ where
|
||||||
mod test {
|
mod test {
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
use crate::{DefaultScalarValue, InputValue};
|
use crate::{graphql_input_value, InputValue};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn url_from_input_value() {
|
fn url_from_input_value() {
|
||||||
let raw = "https://example.net/";
|
let raw = "https://example.net/";
|
||||||
let input = <InputValue<DefaultScalarValue>>::scalar(raw.to_string());
|
let input: InputValue = graphql_input_value!((raw));
|
||||||
|
|
||||||
let parsed: Url = crate::FromInputValue::from_input_value(&input).unwrap();
|
let parsed: Url = crate::FromInputValue::from_input_value(&input).unwrap();
|
||||||
let url = Url::parse(raw).unwrap();
|
let url = Url::parse(raw).unwrap();
|
||||||
|
|
|
@ -34,15 +34,16 @@ where
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use crate::{value::DefaultScalarValue, InputValue};
|
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
|
use crate::{graphql_input_value, FromInputValue, InputValue};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn uuid_from_input_value() {
|
fn uuid_from_input_value() {
|
||||||
let raw = "123e4567-e89b-12d3-a456-426655440000";
|
let raw = "123e4567-e89b-12d3-a456-426655440000";
|
||||||
let input = <InputValue<DefaultScalarValue>>::scalar(raw.to_string());
|
let input: InputValue = graphql_input_value!((raw));
|
||||||
|
|
||||||
let parsed: Uuid = crate::FromInputValue::from_input_value(&input).unwrap();
|
let parsed: Uuid = FromInputValue::from_input_value(&input).unwrap();
|
||||||
let id = Uuid::parse_str(raw).unwrap();
|
let id = Uuid::parse_str(raw).unwrap();
|
||||||
|
|
||||||
assert_eq!(parsed, id);
|
assert_eq!(parsed, id);
|
||||||
|
|
|
@ -90,6 +90,8 @@ Juniper has not reached 1.0 yet, thus some API instability should be expected.
|
||||||
[bson]: https://crates.io/crates/bson
|
[bson]: https://crates.io/crates/bson
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
// Due to `schema_introspection` test.
|
||||||
|
#![cfg_attr(test, recursion_limit = "256")]
|
||||||
#![doc(html_root_url = "https://docs.rs/juniper/0.15.7")]
|
#![doc(html_root_url = "https://docs.rs/juniper/0.15.7")]
|
||||||
#![warn(missing_docs)]
|
#![warn(missing_docs)]
|
||||||
|
|
||||||
|
@ -114,8 +116,6 @@ pub use juniper_codegen::{
|
||||||
GraphQLEnum, GraphQLInputObject, GraphQLObject, GraphQLScalarValue, GraphQLUnion,
|
GraphQLEnum, GraphQLInputObject, GraphQLObject, GraphQLScalarValue, GraphQLUnion,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[macro_use]
|
|
||||||
mod value;
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
mod macros;
|
mod macros;
|
||||||
mod ast;
|
mod ast;
|
||||||
|
@ -126,6 +126,7 @@ pub(crate) mod schema;
|
||||||
mod types;
|
mod types;
|
||||||
mod util;
|
mod util;
|
||||||
pub mod validation;
|
pub mod validation;
|
||||||
|
mod value;
|
||||||
// This needs to be public until docs have support for private modules:
|
// This needs to be public until docs have support for private modules:
|
||||||
// https://github.com/rust-lang/cargo/issues/1520
|
// https://github.com/rust-lang/cargo/issues/1520
|
||||||
pub mod http;
|
pub mod http;
|
||||||
|
|
613
juniper/src/macros/graphql_input_value.rs
Normal file
613
juniper/src/macros/graphql_input_value.rs
Normal file
|
@ -0,0 +1,613 @@
|
||||||
|
//! [`graphql_input_value!`] macro implementation.
|
||||||
|
//!
|
||||||
|
//! [`graphql_input_value!`]: graphql_input_value
|
||||||
|
|
||||||
|
/// Constructs [`InputValue`]s via JSON-like syntax.
|
||||||
|
///
|
||||||
|
/// # Differences from [`graphql_value!`]
|
||||||
|
///
|
||||||
|
/// - [`InputValue::Enum`] is constructed with `ident`, so to capture outer
|
||||||
|
/// variable as [`InputValue::Scalar`] surround it with parens: `(var)`.
|
||||||
|
/// ```rust
|
||||||
|
/// # use juniper::{graphql_input_value, graphql_value};
|
||||||
|
/// #
|
||||||
|
/// # type InputValue = juniper::InputValue;
|
||||||
|
/// # type Value = juniper::Value;
|
||||||
|
/// #
|
||||||
|
/// const OUTER_VAR: i32 = 42;
|
||||||
|
/// assert_eq!(graphql_value!(OUTER_VAR), Value::scalar(42));
|
||||||
|
/// assert_eq!(graphql_input_value!(OUTER_VAR), InputValue::enum_value("OUTER_VAR"));
|
||||||
|
/// assert_eq!(graphql_input_value!((OUTER_VAR)), InputValue::scalar(42));
|
||||||
|
/// ```
|
||||||
|
///
|
||||||
|
/// - [`InputValue::Variable`] is constructed by prefixing `ident` with `@`.
|
||||||
|
/// ```rust
|
||||||
|
/// # use juniper::graphql_input_value;
|
||||||
|
/// #
|
||||||
|
/// # type InputValue = juniper::InputValue;
|
||||||
|
/// #
|
||||||
|
/// assert_eq!(graphql_input_value!(@var), InputValue::variable("var"));
|
||||||
|
/// ```
|
||||||
|
///
|
||||||
|
/// - [`InputValue::Object`] key should implement [`Into`]`<`[`String`]`>`.
|
||||||
|
/// ```rust
|
||||||
|
/// # use std::borrow::Cow;
|
||||||
|
/// #
|
||||||
|
/// # use juniper::{graphql_input_value, InputValue};
|
||||||
|
/// #
|
||||||
|
/// let code = 200;
|
||||||
|
/// let features = vec!["key", "value"];
|
||||||
|
/// let key: Cow<'static, str> = "key".into();
|
||||||
|
///
|
||||||
|
/// let value: InputValue = graphql_input_value!({
|
||||||
|
/// "code": code,
|
||||||
|
/// "success": code == 200,
|
||||||
|
/// "payload": {
|
||||||
|
/// features[0]: features[1],
|
||||||
|
/// key: @var,
|
||||||
|
/// },
|
||||||
|
/// });
|
||||||
|
/// ```
|
||||||
|
///
|
||||||
|
/// > __NOTE:__ [`InputValue::List`]s and [`InputValue::Object`]s will be
|
||||||
|
/// > created in a [`Spanning::unlocated`].
|
||||||
|
///
|
||||||
|
/// # Example
|
||||||
|
///
|
||||||
|
/// ```rust
|
||||||
|
/// # use juniper::{graphql_input_value, InputValue};
|
||||||
|
/// #
|
||||||
|
/// # type V = InputValue;
|
||||||
|
/// #
|
||||||
|
/// # let _: V =
|
||||||
|
/// graphql_input_value!(null);
|
||||||
|
/// # let _: V =
|
||||||
|
/// graphql_input_value!(1234);
|
||||||
|
/// # let _: V =
|
||||||
|
/// graphql_input_value!("test");
|
||||||
|
/// # let _: V =
|
||||||
|
/// graphql_input_value!([1234, "test", true]);
|
||||||
|
/// # let _: V =
|
||||||
|
/// graphql_input_value!({"key": "value", "foo": 1234});
|
||||||
|
/// # let _: V =
|
||||||
|
/// graphql_input_value!({"key": ENUM});
|
||||||
|
/// let captured_var = 42;
|
||||||
|
/// # let _: V =
|
||||||
|
/// graphql_input_value!({"key": (captured_var)});
|
||||||
|
/// # let _: V =
|
||||||
|
/// graphql_input_value!({"key": @variable});
|
||||||
|
/// ```
|
||||||
|
///
|
||||||
|
/// [`InputValue`]: crate::InputValue
|
||||||
|
/// [`InputValue::Enum`]: crate::InputValue::Enum
|
||||||
|
/// [`InputValue::List`]: crate::InputValue::List
|
||||||
|
/// [`InputValue::Object`]: crate::InputValue::Object
|
||||||
|
/// [`InputValue::Scalar`]: crate::InputValue::Scalar
|
||||||
|
/// [`InputValue::Variable`]: crate::InputValue::Variable
|
||||||
|
/// [`Spanning::unlocated`]: crate::Spanning::unlocated
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! graphql_input_value {
|
||||||
|
///////////
|
||||||
|
// Array //
|
||||||
|
///////////
|
||||||
|
|
||||||
|
// Done with trailing comma.
|
||||||
|
(@@array [$($elems:expr,)*]) => {
|
||||||
|
$crate::InputValue::list(vec![
|
||||||
|
$( $elems, )*
|
||||||
|
])
|
||||||
|
};
|
||||||
|
|
||||||
|
// Done without trailing comma.
|
||||||
|
(@@array [$($elems:expr),*]) => {
|
||||||
|
$crate::InputValue::list(vec![
|
||||||
|
$( $elems, )*
|
||||||
|
])
|
||||||
|
};
|
||||||
|
|
||||||
|
// Next element is `null`.
|
||||||
|
(@@array [$($elems:expr,)*] null $($rest:tt)*) => {
|
||||||
|
$crate::graphql_input_value!(
|
||||||
|
@@array [$($elems,)* $crate::graphql_input_value!(null)] $($rest)*
|
||||||
|
)
|
||||||
|
};
|
||||||
|
|
||||||
|
// Next element is `None`.
|
||||||
|
(@@array [$($elems:expr,)*] None $($rest:tt)*) => {
|
||||||
|
$crate::graphql_input_value!(
|
||||||
|
@@array [$($elems,)* $crate::graphql_input_value!(None)] $($rest)*
|
||||||
|
)
|
||||||
|
};
|
||||||
|
|
||||||
|
// Next element is a variable.
|
||||||
|
(@@array [$($elems:expr,)*] @$var:ident $($rest:tt)*) => {
|
||||||
|
$crate::graphql_input_value!(
|
||||||
|
@@array [$($elems,)* $crate::graphql_input_value!(@$var)] $($rest)*
|
||||||
|
)
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// Next element is an array.
|
||||||
|
(@@array [$($elems:expr,)*] [$($array:tt)*] $($rest:tt)*) => {
|
||||||
|
$crate::graphql_input_value!(
|
||||||
|
@@array [$($elems,)* $crate::graphql_input_value!([$($array)*])] $($rest)*
|
||||||
|
)
|
||||||
|
};
|
||||||
|
|
||||||
|
// Next element is a map.
|
||||||
|
(@@array [$($elems:expr,)*] {$($map:tt)*} $($rest:tt)*) => {
|
||||||
|
$crate::graphql_input_value!(
|
||||||
|
@@array [$($elems,)* $crate::graphql_input_value!({$($map)*})] $($rest)*
|
||||||
|
)
|
||||||
|
};
|
||||||
|
|
||||||
|
// Next element is `true`, `false` or enum ident followed by comma.
|
||||||
|
(@@array [$($elems:expr,)*] $ident:ident, $($rest:tt)*) => {
|
||||||
|
$crate::graphql_input_value!(
|
||||||
|
@@array [$($elems,)* $crate::graphql_input_value!($ident),] $($rest)*
|
||||||
|
)
|
||||||
|
};
|
||||||
|
|
||||||
|
// Next element is `true`, `false` or enum ident without trailing comma.
|
||||||
|
(@@array [$($elems:expr,)*] $last:ident ) => {
|
||||||
|
$crate::graphql_input_value!(
|
||||||
|
@@array [$($elems,)* $crate::graphql_input_value!($last)]
|
||||||
|
)
|
||||||
|
};
|
||||||
|
|
||||||
|
// Next element is an expression followed by comma.
|
||||||
|
(@@array [$($elems:expr,)*] $next:expr, $($rest:tt)*) => {
|
||||||
|
$crate::graphql_input_value!(
|
||||||
|
@@array [$($elems,)* $crate::graphql_input_value!($next),] $($rest)*
|
||||||
|
)
|
||||||
|
};
|
||||||
|
|
||||||
|
// Last element is an expression with no trailing comma.
|
||||||
|
(@@array [$($elems:expr,)*] $last:expr) => {
|
||||||
|
$crate::graphql_input_value!(
|
||||||
|
@@array [$($elems,)* $crate::graphql_input_value!($last)]
|
||||||
|
)
|
||||||
|
};
|
||||||
|
|
||||||
|
// Comma after the most recent element.
|
||||||
|
(@@array [$($elems:expr),*] , $($rest:tt)*) => {
|
||||||
|
$crate::graphql_input_value!(@@array [$($elems,)*] $($rest)*)
|
||||||
|
};
|
||||||
|
|
||||||
|
// Unexpected token after most recent element.
|
||||||
|
(@@array [$($elems:expr),*] $unexpected:tt $($rest:tt)*) => {
|
||||||
|
$crate::graphql_input_value!(@unexpected $unexpected)
|
||||||
|
};
|
||||||
|
|
||||||
|
////////////
|
||||||
|
// Object //
|
||||||
|
////////////
|
||||||
|
|
||||||
|
// Done.
|
||||||
|
(@@object $object:ident () () ()) => {};
|
||||||
|
|
||||||
|
// Insert the current entry followed by trailing comma.
|
||||||
|
(@@object $object:ident [$($key:tt)+] ($value:expr) , $($rest:tt)*) => {
|
||||||
|
$object.push((
|
||||||
|
$crate::Spanning::unlocated(($($key)+).into()),
|
||||||
|
$crate::Spanning::unlocated($value),
|
||||||
|
));
|
||||||
|
$crate::graphql_input_value!(@@object $object () ($($rest)*) ($($rest)*));
|
||||||
|
};
|
||||||
|
|
||||||
|
// Current entry followed by unexpected token.
|
||||||
|
(@@object $object:ident [$($key:tt)+] ($value:expr) $unexpected:tt $($rest:tt)*) => {
|
||||||
|
$crate::graphql_input_value!(@unexpected $unexpected);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Insert the last entry without trailing comma.
|
||||||
|
(@@object $object:ident [$($key:tt)+] ($value:expr)) => {
|
||||||
|
$object.push((
|
||||||
|
$crate::Spanning::unlocated(($($key)+).into()),
|
||||||
|
$crate::Spanning::unlocated($value),
|
||||||
|
));
|
||||||
|
};
|
||||||
|
|
||||||
|
// Next value is `null`.
|
||||||
|
(@@object $object:ident ($($key:tt)+) (: null $($rest:tt)*) $copy:tt) => {
|
||||||
|
$crate::graphql_input_value!(
|
||||||
|
@@object $object
|
||||||
|
[$($key)+]
|
||||||
|
($crate::graphql_input_value!(null)) $($rest)*
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Next value is `None`.
|
||||||
|
(@@object $object:ident ($($key:tt)+) (: None $($rest:tt)*) $copy:tt) => {
|
||||||
|
$crate::graphql_input_value!(
|
||||||
|
@@object $object
|
||||||
|
[$($key)+]
|
||||||
|
($crate::graphql_input_value!(None)) $($rest)*
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Next value is a variable.
|
||||||
|
(@@object $object:ident ($($key:tt)+) (: @$var:ident $($rest:tt)*) $copy:tt) => {
|
||||||
|
$crate::graphql_input_value!(
|
||||||
|
@@object $object
|
||||||
|
[$($key)+]
|
||||||
|
($crate::graphql_input_value!(@$var)) $($rest)*
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Next value is an array.
|
||||||
|
(@@object $object:ident ($($key:tt)+) (: [$($array:tt)*] $($rest:tt)*) $copy:tt) => {
|
||||||
|
$crate::graphql_input_value!(
|
||||||
|
@@object $object
|
||||||
|
[$($key)+]
|
||||||
|
($crate::graphql_input_value!([$($array)*])) $($rest)*
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Next value is a map.
|
||||||
|
(@@object $object:ident ($($key:tt)+) (: {$($map:tt)*} $($rest:tt)*) $copy:tt) => {
|
||||||
|
$crate::graphql_input_value!(
|
||||||
|
@@object $object
|
||||||
|
[$($key)+]
|
||||||
|
($crate::graphql_input_value!({$($map)*})) $($rest)*
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Next value is `true`, `false` or enum ident followed by comma.
|
||||||
|
(@@object $object:ident ($($key:tt)+) (: $ident:ident , $($rest:tt)*) $copy:tt) => {
|
||||||
|
$crate::graphql_input_value!(
|
||||||
|
@@object $object
|
||||||
|
[$($key)+]
|
||||||
|
($crate::graphql_input_value!($ident)) , $($rest)*
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Next value is `true`, `false` or enum ident without trailing comma.
|
||||||
|
(@@object $object:ident ($($key:tt)+) (: $last:ident ) $copy:tt) => {
|
||||||
|
$crate::graphql_input_value!(
|
||||||
|
@@object $object
|
||||||
|
[$($key)+]
|
||||||
|
($crate::graphql_input_value!($last))
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Next value is an expression followed by comma.
|
||||||
|
(@@object $object:ident ($($key:tt)+) (: $value:expr , $($rest:tt)*) $copy:tt) => {
|
||||||
|
$crate::graphql_input_value!(
|
||||||
|
@@object $object
|
||||||
|
[$($key)+]
|
||||||
|
($crate::graphql_input_value!($value)) , $($rest)*
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Last value is an expression with no trailing comma.
|
||||||
|
(@@object $object:ident ($($key:tt)+) (: $value:expr) $copy:tt) => {
|
||||||
|
$crate::graphql_input_value!(
|
||||||
|
@@object $object
|
||||||
|
[$($key)+]
|
||||||
|
($crate::graphql_input_value!($value))
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Missing value for last entry. Trigger a reasonable error message.
|
||||||
|
(@@object $object:ident ($($key:tt)+) (:) $copy:tt) => {
|
||||||
|
// "unexpected end of macro invocation"
|
||||||
|
$crate::graphql_input_value!();
|
||||||
|
};
|
||||||
|
|
||||||
|
// Missing colon and value for last entry. Trigger a reasonable error
|
||||||
|
// message.
|
||||||
|
(@@object $object:ident ($($key:tt)+) () $copy:tt) => {
|
||||||
|
// "unexpected end of macro invocation"
|
||||||
|
$crate::graphql_input_value!();
|
||||||
|
};
|
||||||
|
|
||||||
|
// Misplaced colon. Trigger a reasonable error message.
|
||||||
|
(@@object $object:ident () (: $($rest:tt)*) ($colon:tt $($copy:tt)*)) => {
|
||||||
|
// Takes no arguments so "no rules expected the token `:`".
|
||||||
|
$crate::graphql_input_value!(@unexpected $colon);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Found a comma inside a key. Trigger a reasonable error message.
|
||||||
|
(@@object $object:ident ($($key:tt)*) (, $($rest:tt)*) ($comma:tt $($copy:tt)*)) => {
|
||||||
|
// Takes no arguments so "no rules expected the token `,`".
|
||||||
|
$crate::graphql_input_value!(@unexpected $comma);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Key is fully parenthesized. This avoids `clippy::double_parens` false
|
||||||
|
// positives because the parenthesization may be necessary here.
|
||||||
|
(@@object $object:ident () (($key:expr) : $($rest:tt)*) $copy:tt) => {
|
||||||
|
$crate::graphql_input_value!(
|
||||||
|
@@object $object
|
||||||
|
($key)
|
||||||
|
(: $($rest)*) (: $($rest)*)
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Refuse to absorb colon token into key expression.
|
||||||
|
(@@object $object:ident ($($key:tt)*) (: $($unexpected:tt)+) $copy:tt) => {
|
||||||
|
$crate::graphql_input_value!(@@unexpected $($unexpected)+);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Munch a token into the current key.
|
||||||
|
(@@object $object:ident ($($key:tt)*) ($tt:tt $($rest:tt)*) $copy:tt) => {
|
||||||
|
$crate::graphql_input_value!(
|
||||||
|
@@object $object
|
||||||
|
($($key)* $tt)
|
||||||
|
($($rest)*) ($($rest)*)
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
////////////
|
||||||
|
// Errors //
|
||||||
|
////////////
|
||||||
|
|
||||||
|
(@@unexpected) => {};
|
||||||
|
|
||||||
|
//////////////
|
||||||
|
// Defaults //
|
||||||
|
//////////////
|
||||||
|
|
||||||
|
([ $($arr:tt)* ]$(,)?) => {
|
||||||
|
$crate::graphql_input_value!(@@array [] $($arr)*)
|
||||||
|
};
|
||||||
|
|
||||||
|
({}$(,)?) => {
|
||||||
|
$crate::InputValue::parsed_object(vec![])
|
||||||
|
};
|
||||||
|
|
||||||
|
({ $($map:tt)+ }$(,)?) => {
|
||||||
|
$crate::InputValue::parsed_object({
|
||||||
|
let mut object = vec![];
|
||||||
|
$crate::graphql_input_value!(@@object object () ($($map)*) ($($map)*));
|
||||||
|
object
|
||||||
|
})
|
||||||
|
};
|
||||||
|
|
||||||
|
(null$(,)?) => ($crate::InputValue::null());
|
||||||
|
|
||||||
|
(None$(,)?) => ($crate::InputValue::null());
|
||||||
|
|
||||||
|
(true$(,)?) => ($crate::InputValue::from(true));
|
||||||
|
|
||||||
|
(false$(,)?) => ($crate::InputValue::from(false));
|
||||||
|
|
||||||
|
(@$var:ident$(,)?) => ($crate::InputValue::variable(stringify!($var)));
|
||||||
|
|
||||||
|
($enum:ident$(,)?) => ($crate::InputValue::enum_value(stringify!($enum)));
|
||||||
|
|
||||||
|
(($e:expr)$(,)?) => ($crate::InputValue::from($e));
|
||||||
|
|
||||||
|
($e:expr$(,)?) => ($crate::InputValue::from($e));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use indexmap::{indexmap, IndexMap};
|
||||||
|
|
||||||
|
type V = crate::InputValue;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn null() {
|
||||||
|
assert_eq!(graphql_input_value!(null), V::Null);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn scalar() {
|
||||||
|
let val = 42;
|
||||||
|
assert_eq!(graphql_input_value!(1), V::scalar(1));
|
||||||
|
assert_eq!(graphql_input_value!("val"), V::scalar("val"));
|
||||||
|
assert_eq!(graphql_input_value!(1.34), V::scalar(1.34));
|
||||||
|
assert_eq!(graphql_input_value!(false), V::scalar(false));
|
||||||
|
assert_eq!(graphql_input_value!(1 + 2), V::scalar(3));
|
||||||
|
assert_eq!(graphql_input_value!((val)), V::scalar(42));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn r#enum() {
|
||||||
|
assert_eq!(graphql_input_value!(ENUM), V::enum_value("ENUM"));
|
||||||
|
assert_eq!(graphql_input_value!(lowercase), V::enum_value("lowercase"));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn variable() {
|
||||||
|
assert_eq!(graphql_input_value!(@var), V::variable("var"));
|
||||||
|
assert_eq!(graphql_input_value!(@array), V::variable("array"));
|
||||||
|
assert_eq!(graphql_input_value!(@object), V::variable("object"));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn list() {
|
||||||
|
let val = 42;
|
||||||
|
|
||||||
|
assert_eq!(graphql_input_value!([]), V::list(vec![]));
|
||||||
|
|
||||||
|
assert_eq!(graphql_input_value!([null]), V::list(vec![V::Null]));
|
||||||
|
|
||||||
|
assert_eq!(graphql_input_value!([1]), V::list(vec![V::scalar(1)]));
|
||||||
|
assert_eq!(graphql_input_value!([1 + 2]), V::list(vec![V::scalar(3)]));
|
||||||
|
assert_eq!(graphql_input_value!([(val)]), V::list(vec![V::scalar(42)]));
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
graphql_input_value!([ENUM]),
|
||||||
|
V::list(vec![V::enum_value("ENUM")]),
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
graphql_input_value!([lowercase]),
|
||||||
|
V::list(vec![V::enum_value("lowercase")]),
|
||||||
|
);
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
graphql_input_value!([@var]),
|
||||||
|
V::list(vec![V::variable("var")]),
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
graphql_input_value!([@array]),
|
||||||
|
V::list(vec![V::variable("array")]),
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
graphql_input_value!([@object]),
|
||||||
|
V::list(vec![V::variable("object")]),
|
||||||
|
);
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
graphql_input_value!([1, [2], 3]),
|
||||||
|
V::list(vec![
|
||||||
|
V::scalar(1),
|
||||||
|
V::list(vec![V::scalar(2)]),
|
||||||
|
V::scalar(3),
|
||||||
|
]),
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
graphql_input_value!([1, [2 + 3], 3]),
|
||||||
|
V::list(vec![
|
||||||
|
V::scalar(1),
|
||||||
|
V::list(vec![V::scalar(5)]),
|
||||||
|
V::scalar(3),
|
||||||
|
]),
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
graphql_input_value!([1, [ENUM], (val)]),
|
||||||
|
V::list(vec![
|
||||||
|
V::scalar(1),
|
||||||
|
V::list(vec![V::enum_value("ENUM")]),
|
||||||
|
V::scalar(42),
|
||||||
|
]),
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
graphql_input_value!([1 + 2, [(val)], @val]),
|
||||||
|
V::list(vec![
|
||||||
|
V::scalar(3),
|
||||||
|
V::list(vec![V::scalar(42)]),
|
||||||
|
V::variable("val"),
|
||||||
|
]),
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
graphql_input_value!([1, [@val], ENUM]),
|
||||||
|
V::list(vec![
|
||||||
|
V::scalar(1),
|
||||||
|
V::list(vec![V::variable("val")]),
|
||||||
|
V::enum_value("ENUM"),
|
||||||
|
]),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn object() {
|
||||||
|
let val = 42;
|
||||||
|
assert_eq!(
|
||||||
|
graphql_input_value!({}),
|
||||||
|
V::object(IndexMap::<String, _>::new()),
|
||||||
|
);
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
graphql_input_value!({ "key": null }),
|
||||||
|
V::object(indexmap! {"key" => V::Null}),
|
||||||
|
);
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
graphql_input_value!({"key": 123}),
|
||||||
|
V::object(indexmap! {"key" => V::scalar(123)}),
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
graphql_input_value!({"key": 1 + 2}),
|
||||||
|
V::object(indexmap! {"key" => V::scalar(3)}),
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
graphql_input_value!({ "key": (val) }),
|
||||||
|
V::object(indexmap! {"key" => V::scalar(42)}),
|
||||||
|
);
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
graphql_input_value!({"key": []}),
|
||||||
|
V::object(indexmap! {"key" => V::list(vec![])}),
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
graphql_input_value!({ "key": [null] }),
|
||||||
|
V::object(indexmap! {"key" => V::list(vec![V::Null])}),
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
graphql_input_value!({"key": [1] }),
|
||||||
|
V::object(indexmap! {"key" => V::list(vec![V::scalar(1)])}),
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
graphql_input_value!({"key": [1 + 2] }),
|
||||||
|
V::object(indexmap! {"key" => V::list(vec![V::scalar(3)])}),
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
graphql_input_value!({ "key": [(val)] }),
|
||||||
|
V::object(indexmap! {"key" => V::list(vec![V::scalar(42)])}),
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
graphql_input_value!({ "key": ENUM }),
|
||||||
|
V::object(indexmap! {"key" => V::enum_value("ENUM")}),
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
graphql_input_value!({ "key": lowercase }),
|
||||||
|
V::object(indexmap! {"key" => V::enum_value("lowercase")}),
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
graphql_input_value!({"key": @val}),
|
||||||
|
V::object(indexmap! {"key" => V::variable("val")}),
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
graphql_input_value!({"key": @array }),
|
||||||
|
V::object(indexmap! {"key" => V::variable("array")}),
|
||||||
|
);
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
graphql_input_value!({
|
||||||
|
"inner": {
|
||||||
|
"key1": (val),
|
||||||
|
"key2": "val",
|
||||||
|
"key3": [{
|
||||||
|
"inner": 42,
|
||||||
|
}, {
|
||||||
|
"inner": ENUM,
|
||||||
|
"even-more": {
|
||||||
|
"var": @var,
|
||||||
|
},
|
||||||
|
}],
|
||||||
|
"key4": [1, ["val", 1 + 3], null, @array],
|
||||||
|
},
|
||||||
|
"more": @var,
|
||||||
|
}),
|
||||||
|
V::object(indexmap! {
|
||||||
|
"inner" => V::object(indexmap! {
|
||||||
|
"key1" => V::scalar(42),
|
||||||
|
"key2" => V::scalar("val"),
|
||||||
|
"key3" => V::list(vec![
|
||||||
|
V::object(indexmap! {
|
||||||
|
"inner" => V::scalar(42),
|
||||||
|
}),
|
||||||
|
V::object(indexmap! {
|
||||||
|
"inner" => V::enum_value("ENUM"),
|
||||||
|
"even-more" => V::object(indexmap! {
|
||||||
|
"var" => V::variable("var"),
|
||||||
|
}),
|
||||||
|
}),
|
||||||
|
]),
|
||||||
|
"key4" => V::list(vec![
|
||||||
|
V::scalar(1),
|
||||||
|
V::list(vec![
|
||||||
|
V::scalar("val"),
|
||||||
|
V::scalar(4),
|
||||||
|
]),
|
||||||
|
V::Null,
|
||||||
|
V::variable("array"),
|
||||||
|
]),
|
||||||
|
}),
|
||||||
|
"more" => V::variable("var"),
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn option() {
|
||||||
|
let val = Some(42);
|
||||||
|
|
||||||
|
assert_eq!(graphql_input_value!(None), V::Null);
|
||||||
|
assert_eq!(graphql_input_value!(Some(42)), V::scalar(42));
|
||||||
|
assert_eq!(graphql_input_value!((val)), V::scalar(42));
|
||||||
|
}
|
||||||
|
}
|
387
juniper/src/macros/graphql_value.rs
Normal file
387
juniper/src/macros/graphql_value.rs
Normal file
|
@ -0,0 +1,387 @@
|
||||||
|
//! [`graphql_value!`] macro implementation.
|
||||||
|
//!
|
||||||
|
//! [`graphql_value!`]: graphql_value
|
||||||
|
|
||||||
|
/// Constructs [`Value`]s via JSON-like syntax.
|
||||||
|
///
|
||||||
|
/// [`Value`] objects are used mostly when creating custom errors from fields.
|
||||||
|
///
|
||||||
|
/// [`Value::Object`] key should implement [`AsRef`]`<`[`str`]`>`.
|
||||||
|
/// ```rust
|
||||||
|
/// # use juniper::{graphql_value, Value};
|
||||||
|
/// #
|
||||||
|
/// let code = 200;
|
||||||
|
/// let features = ["key", "value"];
|
||||||
|
///
|
||||||
|
/// let value: Value = graphql_value!({
|
||||||
|
/// "code": code,
|
||||||
|
/// "success": code == 200,
|
||||||
|
/// "payload": {
|
||||||
|
/// features[0]: features[1],
|
||||||
|
/// },
|
||||||
|
/// });
|
||||||
|
/// ```
|
||||||
|
///
|
||||||
|
/// # Example
|
||||||
|
///
|
||||||
|
/// Resulting JSON will look just like what you passed in.
|
||||||
|
/// ```rust
|
||||||
|
/// # use juniper::{graphql_value, DefaultScalarValue, Value};
|
||||||
|
/// #
|
||||||
|
/// # type V = Value<DefaultScalarValue>;
|
||||||
|
/// #
|
||||||
|
/// # let _: V =
|
||||||
|
/// graphql_value!(null);
|
||||||
|
/// # let _: V =
|
||||||
|
/// graphql_value!(1234);
|
||||||
|
/// # let _: V =
|
||||||
|
/// graphql_value!("test");
|
||||||
|
/// # let _: V =
|
||||||
|
/// graphql_value!([1234, "test", true]);
|
||||||
|
/// # let _: V =
|
||||||
|
/// graphql_value!({"key": "value", "foo": 1234});
|
||||||
|
/// ```
|
||||||
|
///
|
||||||
|
/// [`Value`]: crate::Value
|
||||||
|
/// [`Value::Object`]: crate::Value::Object
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! graphql_value {
|
||||||
|
///////////
|
||||||
|
// Array //
|
||||||
|
///////////
|
||||||
|
|
||||||
|
// Done with trailing comma.
|
||||||
|
(@array [$($elems:expr,)*]) => {
|
||||||
|
$crate::Value::list(vec![
|
||||||
|
$( $elems, )*
|
||||||
|
])
|
||||||
|
};
|
||||||
|
|
||||||
|
// Done without trailing comma.
|
||||||
|
(@array [$($elems:expr),*]) => {
|
||||||
|
$crate::Value::list(vec![
|
||||||
|
$( $crate::graphql_value!($elems), )*
|
||||||
|
])
|
||||||
|
};
|
||||||
|
|
||||||
|
// Next element is `null`.
|
||||||
|
(@array [$($elems:expr,)*] null $($rest:tt)*) => {
|
||||||
|
$crate::graphql_value!(
|
||||||
|
@array [$($elems,)* $crate::graphql_value!(null)] $($rest)*
|
||||||
|
)
|
||||||
|
};
|
||||||
|
|
||||||
|
// Next element is `None`.
|
||||||
|
(@array [$($elems:expr,)*] None $($rest:tt)*) => {
|
||||||
|
$crate::graphql_value!(
|
||||||
|
@array [$($elems,)* $crate::graphql_value!(None)] $($rest)*
|
||||||
|
)
|
||||||
|
};
|
||||||
|
|
||||||
|
// Next element is an array.
|
||||||
|
(@array [$($elems:expr,)*] [$($array:tt)*] $($rest:tt)*) => {
|
||||||
|
$crate::graphql_value!(
|
||||||
|
@array [$($elems,)* $crate::graphql_value!([$($array)*])] $($rest)*
|
||||||
|
)
|
||||||
|
};
|
||||||
|
|
||||||
|
// Next element is a map.
|
||||||
|
(@array [$($elems:expr,)*] {$($map:tt)*} $($rest:tt)*) => {
|
||||||
|
$crate::graphql_value!(
|
||||||
|
@array [$($elems,)* $crate::graphql_value!({$($map)*})] $($rest)*
|
||||||
|
)
|
||||||
|
};
|
||||||
|
|
||||||
|
// Next element is an expression followed by comma.
|
||||||
|
(@array [$($elems:expr,)*] $next:expr, $($rest:tt)*) => {
|
||||||
|
$crate::graphql_value!(
|
||||||
|
@array [$($elems,)* $crate::graphql_value!($next),] $($rest)*
|
||||||
|
)
|
||||||
|
};
|
||||||
|
|
||||||
|
// Last element is an expression with no trailing comma.
|
||||||
|
(@array [$($elems:expr,)*] $last:expr) => {
|
||||||
|
$crate::graphql_value!(
|
||||||
|
@array [$($elems,)* $crate::graphql_value!($last)]
|
||||||
|
)
|
||||||
|
};
|
||||||
|
|
||||||
|
// Comma after the most recent element.
|
||||||
|
(@array [$($elems:expr),*] , $($rest:tt)*) => {
|
||||||
|
$crate::graphql_value!(@array [$($elems,)*] $($rest)*)
|
||||||
|
};
|
||||||
|
|
||||||
|
// Unexpected token after most recent element.
|
||||||
|
(@array [$($elems:expr),*] $unexpected:tt $($rest:tt)*) => {
|
||||||
|
$crate::graphql_value!(@unexpected $unexpected)
|
||||||
|
};
|
||||||
|
|
||||||
|
////////////
|
||||||
|
// Object //
|
||||||
|
////////////
|
||||||
|
|
||||||
|
// Done.
|
||||||
|
(@object $object:ident () () ()) => {};
|
||||||
|
|
||||||
|
// Insert the current entry followed by trailing comma.
|
||||||
|
(@object $object:ident [$($key:tt)+] ($value:expr) , $($rest:tt)*) => {
|
||||||
|
let _ = $object.add_field(($($key)+), $value);
|
||||||
|
$crate::graphql_value!(@object $object () ($($rest)*) ($($rest)*));
|
||||||
|
};
|
||||||
|
|
||||||
|
// Current entry followed by unexpected token.
|
||||||
|
(@object $object:ident [$($key:tt)+] ($value:expr) $unexpected:tt $($rest:tt)*) => {
|
||||||
|
$crate::graphql_value!(@unexpected $unexpected);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Insert the last entry without trailing comma.
|
||||||
|
(@object $object:ident [$($key:tt)+] ($value:expr)) => {
|
||||||
|
let _ = $object.add_field(($($key)+), $value);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Next value is `null`.
|
||||||
|
(@object $object:ident ($($key:tt)+) (: null $($rest:tt)*) $copy:tt) => {
|
||||||
|
$crate::graphql_value!(
|
||||||
|
@object $object
|
||||||
|
[$($key)+]
|
||||||
|
($crate::graphql_value!(null)) $($rest)*
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Next value is `None`.
|
||||||
|
(@object $object:ident ($($key:tt)+) (: None $($rest:tt)*) $copy:tt) => {
|
||||||
|
$crate::graphql_value!(
|
||||||
|
@object $object
|
||||||
|
[$($key)+]
|
||||||
|
($crate::graphql_value!(None)) $($rest)*
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Next value is an array.
|
||||||
|
(@object $object:ident ($($key:tt)+) (: [$($array:tt)*] $($rest:tt)*) $copy:tt) => {
|
||||||
|
$crate::graphql_value!(
|
||||||
|
@object $object
|
||||||
|
[$($key)+]
|
||||||
|
($crate::graphql_value!([$($array)*])) $($rest)*
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Next value is a map.
|
||||||
|
(@object $object:ident ($($key:tt)+) (: {$($map:tt)*} $($rest:tt)*) $copy:tt) => {
|
||||||
|
$crate::graphql_value!(
|
||||||
|
@object $object
|
||||||
|
[$($key)+]
|
||||||
|
($crate::graphql_value!({$($map)*})) $($rest)*
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Next value is an expression followed by comma.
|
||||||
|
(@object $object:ident ($($key:tt)+) (: $value:expr , $($rest:tt)*) $copy:tt) => {
|
||||||
|
$crate::graphql_value!(
|
||||||
|
@object $object
|
||||||
|
[$($key)+]
|
||||||
|
($crate::graphql_value!($value)) , $($rest)*
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Last value is an expression with no trailing comma.
|
||||||
|
(@object $object:ident ($($key:tt)+) (: $value:expr) $copy:tt) => {
|
||||||
|
$crate::graphql_value!(
|
||||||
|
@object $object
|
||||||
|
[$($key)+]
|
||||||
|
($crate::graphql_value!($value))
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Missing value for last entry. Trigger a reasonable error message.
|
||||||
|
(@object $object:ident ($($key:tt)+) (:) $copy:tt) => {
|
||||||
|
// "unexpected end of macro invocation"
|
||||||
|
$crate::graphql_value!();
|
||||||
|
};
|
||||||
|
|
||||||
|
// Missing colon and value for last entry. Trigger a reasonable error
|
||||||
|
// message.
|
||||||
|
(@object $object:ident ($($key:tt)+) () $copy:tt) => {
|
||||||
|
// "unexpected end of macro invocation"
|
||||||
|
$crate::graphql_value!();
|
||||||
|
};
|
||||||
|
|
||||||
|
// Misplaced colon. Trigger a reasonable error message.
|
||||||
|
(@object $object:ident () (: $($rest:tt)*) ($colon:tt $($copy:tt)*)) => {
|
||||||
|
// Takes no arguments so "no rules expected the token `:`".
|
||||||
|
$crate::graphql_value!(@unexpected $colon);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Found a comma inside a key. Trigger a reasonable error message.
|
||||||
|
(@object $object:ident ($($key:tt)*) (, $($rest:tt)*) ($comma:tt $($copy:tt)*)) => {
|
||||||
|
// Takes no arguments so "no rules expected the token `,`".
|
||||||
|
$crate::graphql_value!(@unexpected $comma);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Key is fully parenthesized. This avoids `clippy::double_parens` false
|
||||||
|
// positives because the parenthesization may be necessary here.
|
||||||
|
(@object $object:ident () (($key:expr) : $($rest:tt)*) $copy:tt) => {
|
||||||
|
$crate::graphql_value!(@object $object ($key) (: $($rest)*) (: $($rest)*));
|
||||||
|
};
|
||||||
|
|
||||||
|
// Refuse to absorb colon token into key expression.
|
||||||
|
(@object $object:ident ($($key:tt)*) (: $($unexpected:tt)+) $copy:tt) => {
|
||||||
|
$crate::graphql_value!(@unexpected $($unexpected)+);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Munch a token into the current key.
|
||||||
|
(@object $object:ident ($($key:tt)*) ($tt:tt $($rest:tt)*) $copy:tt) => {
|
||||||
|
$crate::graphql_value!(
|
||||||
|
@object $object
|
||||||
|
($($key)* $tt)
|
||||||
|
($($rest)*) ($($rest)*)
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
////////////
|
||||||
|
// Errors //
|
||||||
|
////////////
|
||||||
|
|
||||||
|
(@unexpected) => {};
|
||||||
|
|
||||||
|
//////////////
|
||||||
|
// Defaults //
|
||||||
|
//////////////
|
||||||
|
|
||||||
|
([ $($arr:tt)* ]$(,)?) => {
|
||||||
|
$crate::graphql_value!(@array [] $($arr)*)
|
||||||
|
};
|
||||||
|
|
||||||
|
({}$(,)?) => {
|
||||||
|
$crate::Value::object($crate::Object::with_capacity(0))
|
||||||
|
};
|
||||||
|
|
||||||
|
({ $($map:tt)+ }$(,)?) => {
|
||||||
|
$crate::Value::object({
|
||||||
|
let mut object = $crate::Object::with_capacity(0);
|
||||||
|
$crate::graphql_value!(@object object () ($($map)*) ($($map)*));
|
||||||
|
object
|
||||||
|
})
|
||||||
|
};
|
||||||
|
|
||||||
|
(null$(,)?) => ($crate::Value::null());
|
||||||
|
|
||||||
|
(None$(,)?) => ($crate::Value::null());
|
||||||
|
|
||||||
|
($e:expr$(,)?) => ($crate::Value::from($e));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
type V = crate::Value;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn null() {
|
||||||
|
assert_eq!(graphql_value!(null), V::Null);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn scalar() {
|
||||||
|
let val = 42;
|
||||||
|
|
||||||
|
assert_eq!(graphql_value!(1), V::scalar(1));
|
||||||
|
assert_eq!(graphql_value!("val"), V::scalar("val"));
|
||||||
|
assert_eq!(graphql_value!(1.34), V::scalar(1.34));
|
||||||
|
assert_eq!(graphql_value!(false), V::scalar(false));
|
||||||
|
assert_eq!(graphql_value!(1 + 2), V::scalar(3));
|
||||||
|
assert_eq!(graphql_value!(val), V::scalar(42));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn list() {
|
||||||
|
let val = 42;
|
||||||
|
|
||||||
|
assert_eq!(graphql_value!([]), V::list(vec![]));
|
||||||
|
|
||||||
|
assert_eq!(graphql_value!([null]), V::list(vec![V::Null]));
|
||||||
|
|
||||||
|
assert_eq!(graphql_value!([1]), V::list(vec![V::scalar(1)]));
|
||||||
|
assert_eq!(graphql_value!([1 + 2]), V::list(vec![V::scalar(3)]));
|
||||||
|
assert_eq!(graphql_value!([val]), V::list(vec![V::scalar(42)]));
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
graphql_value!([1, [2], 3]),
|
||||||
|
V::list(vec![
|
||||||
|
V::scalar(1),
|
||||||
|
V::list(vec![V::scalar(2)]),
|
||||||
|
V::scalar(3),
|
||||||
|
]),
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
graphql_value!(["string", [2 + 3], true]),
|
||||||
|
V::list(vec![
|
||||||
|
V::scalar("string"),
|
||||||
|
V::list(vec![V::scalar(5)]),
|
||||||
|
V::scalar(true),
|
||||||
|
]),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn object() {
|
||||||
|
let val = 42;
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
graphql_value!({}),
|
||||||
|
V::object(Vec::<(String, _)>::new().into_iter().collect()),
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
graphql_value!({ "key": null }),
|
||||||
|
V::object(vec![("key", V::Null)].into_iter().collect()),
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
graphql_value!({ "key": 123 }),
|
||||||
|
V::object(vec![("key", V::scalar(123))].into_iter().collect()),
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
graphql_value!({ "key": 1 + 2 }),
|
||||||
|
V::object(vec![("key", V::scalar(3))].into_iter().collect()),
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
graphql_value!({ "key": [] }),
|
||||||
|
V::object(vec![("key", V::list(vec![]))].into_iter().collect()),
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
graphql_value!({ "key": [null] }),
|
||||||
|
V::object(vec![("key", V::list(vec![V::Null]))].into_iter().collect()),
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
graphql_value!({ "key": [1] }),
|
||||||
|
V::object(
|
||||||
|
vec![("key", V::list(vec![V::scalar(1)]))]
|
||||||
|
.into_iter()
|
||||||
|
.collect(),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
graphql_value!({ "key": [1 + 2] }),
|
||||||
|
V::object(
|
||||||
|
vec![("key", V::list(vec![V::scalar(3)]))]
|
||||||
|
.into_iter()
|
||||||
|
.collect(),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
graphql_value!({ "key": [val] }),
|
||||||
|
V::object(
|
||||||
|
vec![("key", V::list(vec![V::scalar(42)]))]
|
||||||
|
.into_iter()
|
||||||
|
.collect(),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn option() {
|
||||||
|
let val = Some(42);
|
||||||
|
|
||||||
|
assert_eq!(graphql_value!(None), V::Null);
|
||||||
|
assert_eq!(graphql_value!(Some(42)), V::scalar(42));
|
||||||
|
assert_eq!(graphql_value!(val), V::scalar(42));
|
||||||
|
}
|
||||||
|
}
|
611
juniper/src/macros/graphql_vars.rs
Normal file
611
juniper/src/macros/graphql_vars.rs
Normal file
|
@ -0,0 +1,611 @@
|
||||||
|
//! [`graphql_vars!`] macro implementation.
|
||||||
|
//!
|
||||||
|
//! [`graphql_vars!`]: graphql_vars
|
||||||
|
|
||||||
|
/// Constructs [`Variables`] via JSON-like syntax.
|
||||||
|
///
|
||||||
|
/// [`Variables`] key should implement [`Into`]`<`[`String`]`>`.
|
||||||
|
/// ```rust
|
||||||
|
/// # use std::borrow::Cow;
|
||||||
|
/// #
|
||||||
|
/// # use juniper::{graphql_vars, Variables};
|
||||||
|
/// #
|
||||||
|
/// let code = 200;
|
||||||
|
/// let features = vec!["key", "value"];
|
||||||
|
/// let key: Cow<'static, str> = "key".into();
|
||||||
|
///
|
||||||
|
/// let value: Variables = graphql_vars! {
|
||||||
|
/// "code": code,
|
||||||
|
/// "success": code == 200,
|
||||||
|
/// features[0]: features[1],
|
||||||
|
/// key: @var,
|
||||||
|
/// };
|
||||||
|
/// ```
|
||||||
|
///
|
||||||
|
/// See [`graphql_input_value!`] for more info on syntax of value after `:`.
|
||||||
|
///
|
||||||
|
/// [`graphql_input_value!`]: crate::graphql_input_value
|
||||||
|
/// [`Variables`]: crate::Variables
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! graphql_vars {
|
||||||
|
////////////
|
||||||
|
// Object //
|
||||||
|
////////////
|
||||||
|
|
||||||
|
// Done.
|
||||||
|
(@object $object:ident () () ()) => {};
|
||||||
|
|
||||||
|
// Insert the current entry followed by trailing comma.
|
||||||
|
(@object $object:ident [$($key:tt)+] ($value:expr) , $($rest:tt)*) => {
|
||||||
|
let _ = $object.insert(($($key)+).into(), $value);
|
||||||
|
$crate::graphql_vars! {@object $object () ($($rest)*) ($($rest)*)};
|
||||||
|
};
|
||||||
|
|
||||||
|
// Current entry followed by unexpected token.
|
||||||
|
(@object $object:ident [$($key:tt)+] ($value:expr) $unexpected:tt $($rest:tt)*) => {
|
||||||
|
$crate::graphql_vars! {@unexpected $unexpected};
|
||||||
|
};
|
||||||
|
|
||||||
|
// Insert the last entry without trailing comma.
|
||||||
|
(@object $object:ident [$($key:tt)+] ($value:expr)) => {
|
||||||
|
let _ = $object.insert(($($key)+).into(), $value);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Next value is `null`.
|
||||||
|
(@object $object:ident ($($key:tt)+) (: null $($rest:tt)*) $copy:tt) => {
|
||||||
|
$crate::graphql_vars! {
|
||||||
|
@object $object
|
||||||
|
[$($key)+]
|
||||||
|
($crate::graphql_input_value!(null)) $($rest)*
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
// Next value is `None`.
|
||||||
|
(@object $object:ident ($($key:tt)+) (: None $($rest:tt)*) $copy:tt) => {
|
||||||
|
$crate::graphql_vars! {
|
||||||
|
@object $object
|
||||||
|
[$($key)+]
|
||||||
|
($crate::graphql_input_value!(None)) $($rest)*
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
// Next value is a variable.
|
||||||
|
(@object $object:ident ($($key:tt)+) (: @$var:ident $($rest:tt)*) $copy:tt) => {
|
||||||
|
$crate::graphql_vars! {
|
||||||
|
@object $object
|
||||||
|
[$($key)+]
|
||||||
|
($crate::graphql_input_value!(@$var)) $($rest)*
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
// Next value is an array.
|
||||||
|
(@object $object:ident ($($key:tt)+) (: [$($array:tt)*] $($rest:tt)*) $copy:tt) => {
|
||||||
|
$crate::graphql_vars! {
|
||||||
|
@object $object
|
||||||
|
[$($key)+]
|
||||||
|
($crate::graphql_input_value!([$($array)*])) $($rest)*
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
// Next value is a map.
|
||||||
|
(@object $object:ident ($($key:tt)+) (: {$($map:tt)*} $($rest:tt)*) $copy:tt) => {
|
||||||
|
$crate::graphql_vars! {
|
||||||
|
@object $object
|
||||||
|
[$($key)+]
|
||||||
|
($crate::graphql_input_value!({$($map)*})) $($rest)*
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
// Next value is `true`, `false` or enum ident followed by a comma.
|
||||||
|
(@object $object:ident ($($key:tt)+) (: $ident:ident , $($rest:tt)*) $copy:tt) => {
|
||||||
|
$crate::graphql_vars! {
|
||||||
|
@object $object
|
||||||
|
[$($key)+]
|
||||||
|
($crate::graphql_input_value!($ident)) , $($rest)*
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
// Next value is `true`, `false` or enum ident without trailing comma.
|
||||||
|
(@object $object:ident ($($key:tt)+) (: $last:ident ) $copy:tt) => {
|
||||||
|
$crate::graphql_vars! {
|
||||||
|
@object $object
|
||||||
|
[$($key)+]
|
||||||
|
($crate::graphql_input_value!($last))
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
// Next value is an expression followed by comma.
|
||||||
|
(@object $object:ident ($($key:tt)+) (: $value:expr , $($rest:tt)*) $copy:tt) => {
|
||||||
|
$crate::graphql_vars! {
|
||||||
|
@object $object
|
||||||
|
[$($key)+]
|
||||||
|
($crate::graphql_input_value!($value)) , $($rest)*
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
// Last value is an expression with no trailing comma.
|
||||||
|
(@object $object:ident ($($key:tt)+) (: $value:expr) $copy:tt) => {
|
||||||
|
$crate::graphql_vars! {
|
||||||
|
@object $object
|
||||||
|
[$($key)+]
|
||||||
|
($crate::graphql_input_value!($value))
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
// Missing value for last entry. Trigger a reasonable error message.
|
||||||
|
(@object $object:ident ($($key:tt)+) (:) $copy:tt) => {
|
||||||
|
// "unexpected end of macro invocation"
|
||||||
|
$crate::graphql_vars! {};
|
||||||
|
};
|
||||||
|
|
||||||
|
// Missing colon and value for last entry. Trigger a reasonable error
|
||||||
|
// message.
|
||||||
|
(@object $object:ident ($($key:tt)+) () $copy:tt) => {
|
||||||
|
// "unexpected end of macro invocation"
|
||||||
|
$crate::graphql_vars! {};
|
||||||
|
};
|
||||||
|
|
||||||
|
// Misplaced colon. Trigger a reasonable error message.
|
||||||
|
(@object $object:ident () (: $($rest:tt)*) ($colon:tt $($copy:tt)*)) => {
|
||||||
|
// Takes no arguments so "no rules expected the token `:`".
|
||||||
|
$crate::graphql_vars! {@unexpected $colon};
|
||||||
|
};
|
||||||
|
|
||||||
|
// Found a comma inside a key. Trigger a reasonable error message.
|
||||||
|
(@object $object:ident ($($key:tt)*) (, $($rest:tt)*) ($comma:tt $($copy:tt)*)) => {
|
||||||
|
// Takes no arguments so "no rules expected the token `,`".
|
||||||
|
$crate::graphql_vars! {@unexpected $comma};
|
||||||
|
};
|
||||||
|
|
||||||
|
// Key is fully parenthesized. This avoids clippy double_parens false
|
||||||
|
// positives because the parenthesization may be necessary here.
|
||||||
|
(@object $object:ident () (($key:expr) : $($rest:tt)*) $copy:tt) => {
|
||||||
|
$crate::graphql_vars! {
|
||||||
|
@object $object ($key) (: $($rest)*) (: $($rest)*)
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
// Refuse to absorb colon token into key expression.
|
||||||
|
(@object $object:ident ($($key:tt)*) (: $($unexpected:tt)+) $copy:tt) => {
|
||||||
|
$crate::graphql_vars! {@unexpected $($unexpected)+};
|
||||||
|
};
|
||||||
|
|
||||||
|
// Munch a token into the current key.
|
||||||
|
(@object $object:ident ($($key:tt)*) ($tt:tt $($rest:tt)*) $copy:tt) => {
|
||||||
|
$crate::graphql_vars! {
|
||||||
|
@object $object
|
||||||
|
($($key)* $tt)
|
||||||
|
($($rest)*) ($($rest)*)
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
////////////
|
||||||
|
// Errors //
|
||||||
|
////////////
|
||||||
|
|
||||||
|
(@unexpected) => {};
|
||||||
|
|
||||||
|
//////////////
|
||||||
|
// Defaults //
|
||||||
|
//////////////
|
||||||
|
|
||||||
|
() => {{ $crate::Variables::<_>::new() }};
|
||||||
|
|
||||||
|
( $($map:tt)+ ) => {{
|
||||||
|
let mut object = $crate::Variables::<_>::new();
|
||||||
|
$crate::graphql_vars! {@object object () ($($map)*) ($($map)*)};
|
||||||
|
object
|
||||||
|
}};
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use indexmap::{indexmap, IndexMap};
|
||||||
|
|
||||||
|
type V = crate::Variables;
|
||||||
|
|
||||||
|
type IV = crate::InputValue;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn empty() {
|
||||||
|
assert_eq!(graphql_vars! {}, V::new());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn scalar() {
|
||||||
|
let val = 42;
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
graphql_vars! {"key": 123},
|
||||||
|
vec![("key".to_owned(), IV::scalar(123))]
|
||||||
|
.into_iter()
|
||||||
|
.collect::<V>(),
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
graphql_vars! {"key": "val"},
|
||||||
|
vec![("key".to_owned(), IV::scalar("val"))]
|
||||||
|
.into_iter()
|
||||||
|
.collect::<V>(),
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
graphql_vars! {"key": 1.23},
|
||||||
|
vec![("key".to_owned(), IV::scalar(1.23))]
|
||||||
|
.into_iter()
|
||||||
|
.collect::<V>(),
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
graphql_vars! {"key": 1 + 2},
|
||||||
|
vec![("key".to_owned(), IV::scalar(3))]
|
||||||
|
.into_iter()
|
||||||
|
.collect(),
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
graphql_vars! {"key": false},
|
||||||
|
vec![("key".to_owned(), IV::scalar(false))]
|
||||||
|
.into_iter()
|
||||||
|
.collect::<V>(),
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
graphql_vars! {"key": (val)},
|
||||||
|
vec![("key".to_owned(), IV::scalar(42))]
|
||||||
|
.into_iter()
|
||||||
|
.collect::<V>(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn r#enum() {
|
||||||
|
assert_eq!(
|
||||||
|
graphql_vars! {"key": ENUM},
|
||||||
|
vec![("key".to_owned(), IV::enum_value("ENUM"))]
|
||||||
|
.into_iter()
|
||||||
|
.collect::<V>(),
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
graphql_vars! {"key": lowercase},
|
||||||
|
vec![("key".to_owned(), IV::enum_value("lowercase"))]
|
||||||
|
.into_iter()
|
||||||
|
.collect::<V>(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn variable() {
|
||||||
|
assert_eq!(
|
||||||
|
graphql_vars! {"key": @var},
|
||||||
|
vec![("key".to_owned(), IV::variable("var"))]
|
||||||
|
.into_iter()
|
||||||
|
.collect::<V>(),
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
graphql_vars! {"key": @array},
|
||||||
|
vec![("key".to_owned(), IV::variable("array"))]
|
||||||
|
.into_iter()
|
||||||
|
.collect::<V>(),
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
graphql_vars! {"key": @object},
|
||||||
|
vec![("key".to_owned(), IV::variable("object"))]
|
||||||
|
.into_iter()
|
||||||
|
.collect::<V>(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn list() {
|
||||||
|
let val = 42;
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
graphql_vars! {"key": []},
|
||||||
|
vec![("key".to_owned(), IV::list(vec![]))]
|
||||||
|
.into_iter()
|
||||||
|
.collect::<V>(),
|
||||||
|
);
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
graphql_vars! {"key": [null]},
|
||||||
|
vec![("key".to_owned(), IV::list(vec![IV::Null]))]
|
||||||
|
.into_iter()
|
||||||
|
.collect::<V>(),
|
||||||
|
);
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
graphql_vars! {"key": [1]},
|
||||||
|
vec![("key".to_owned(), IV::list(vec![IV::scalar(1)]))]
|
||||||
|
.into_iter()
|
||||||
|
.collect::<V>(),
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
graphql_vars! {"key": [1 + 2]},
|
||||||
|
vec![("key".to_owned(), IV::list(vec![IV::scalar(3)]))]
|
||||||
|
.into_iter()
|
||||||
|
.collect::<V>(),
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
graphql_vars! {"key": [(val)]},
|
||||||
|
vec![("key".to_owned(), IV::list(vec![IV::scalar(42)]))]
|
||||||
|
.into_iter()
|
||||||
|
.collect::<V>(),
|
||||||
|
);
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
graphql_vars! {"key": [ENUM]},
|
||||||
|
vec![("key".to_owned(), IV::list(vec![IV::enum_value("ENUM")]))]
|
||||||
|
.into_iter()
|
||||||
|
.collect::<V>(),
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
graphql_vars! {"key": [lowercase]},
|
||||||
|
vec![(
|
||||||
|
"key".to_owned(),
|
||||||
|
IV::list(vec![IV::enum_value("lowercase")])
|
||||||
|
)]
|
||||||
|
.into_iter()
|
||||||
|
.collect::<V>(),
|
||||||
|
);
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
graphql_vars! {"key": [@var]},
|
||||||
|
vec![("key".to_owned(), IV::list(vec![IV::variable("var")]))]
|
||||||
|
.into_iter()
|
||||||
|
.collect::<V>(),
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
graphql_vars! {"key": [@array]},
|
||||||
|
vec![("key".to_owned(), IV::list(vec![IV::variable("array")]))]
|
||||||
|
.into_iter()
|
||||||
|
.collect::<V>(),
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
graphql_vars! {"key": [@object]},
|
||||||
|
vec![("key".to_owned(), IV::list(vec![IV::variable("object")]))]
|
||||||
|
.into_iter()
|
||||||
|
.collect::<V>(),
|
||||||
|
);
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
graphql_vars! {"key": [1, [2], 3]},
|
||||||
|
vec![(
|
||||||
|
"key".to_owned(),
|
||||||
|
IV::list(vec![
|
||||||
|
IV::scalar(1),
|
||||||
|
IV::list(vec![IV::scalar(2)]),
|
||||||
|
IV::scalar(3),
|
||||||
|
]),
|
||||||
|
)]
|
||||||
|
.into_iter()
|
||||||
|
.collect::<V>(),
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
graphql_vars! {"key": [1, [2 + 3], 3]},
|
||||||
|
vec![(
|
||||||
|
"key".to_owned(),
|
||||||
|
IV::list(vec![
|
||||||
|
IV::scalar(1),
|
||||||
|
IV::list(vec![IV::scalar(5)]),
|
||||||
|
IV::scalar(3),
|
||||||
|
]),
|
||||||
|
)]
|
||||||
|
.into_iter()
|
||||||
|
.collect::<V>(),
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
graphql_vars! {"key": [1, [ENUM], (val)]},
|
||||||
|
vec![(
|
||||||
|
"key".to_owned(),
|
||||||
|
IV::list(vec![
|
||||||
|
IV::scalar(1),
|
||||||
|
IV::list(vec![IV::enum_value("ENUM")]),
|
||||||
|
IV::scalar(42),
|
||||||
|
]),
|
||||||
|
)]
|
||||||
|
.into_iter()
|
||||||
|
.collect::<V>(),
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
graphql_vars! {"key": [1 + 2, [(val)], @val]},
|
||||||
|
vec![(
|
||||||
|
"key".to_owned(),
|
||||||
|
IV::list(vec![
|
||||||
|
IV::scalar(3),
|
||||||
|
IV::list(vec![IV::scalar(42)]),
|
||||||
|
IV::variable("val"),
|
||||||
|
]),
|
||||||
|
)]
|
||||||
|
.into_iter()
|
||||||
|
.collect::<V>(),
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
graphql_vars! {"key": [1, [@val], ENUM]},
|
||||||
|
vec![(
|
||||||
|
"key".to_owned(),
|
||||||
|
IV::list(vec![
|
||||||
|
IV::scalar(1),
|
||||||
|
IV::list(vec![IV::variable("val")]),
|
||||||
|
IV::enum_value("ENUM"),
|
||||||
|
]),
|
||||||
|
)]
|
||||||
|
.into_iter()
|
||||||
|
.collect::<V>(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn object() {
|
||||||
|
let val = 42;
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
graphql_vars! {"key": {}},
|
||||||
|
vec![("key".to_owned(), IV::object(IndexMap::<String, _>::new()))]
|
||||||
|
.into_iter()
|
||||||
|
.collect::<V>(),
|
||||||
|
);
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
graphql_vars! {"key": {"key": null}},
|
||||||
|
vec![("key".to_owned(), IV::object(indexmap! {"key" => IV::Null}))]
|
||||||
|
.into_iter()
|
||||||
|
.collect::<V>(),
|
||||||
|
);
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
graphql_vars! {"key": {"key": 123}},
|
||||||
|
vec![(
|
||||||
|
"key".to_owned(),
|
||||||
|
IV::object(indexmap! {"key" => IV::scalar(123)}),
|
||||||
|
)]
|
||||||
|
.into_iter()
|
||||||
|
.collect::<V>(),
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
graphql_vars! {"key": {"key": 1 + 2}},
|
||||||
|
vec![(
|
||||||
|
"key".to_owned(),
|
||||||
|
IV::object(indexmap! {"key" => IV::scalar(3)}),
|
||||||
|
)]
|
||||||
|
.into_iter()
|
||||||
|
.collect::<V>(),
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
graphql_vars! {"key": {"key": (val)}},
|
||||||
|
vec![(
|
||||||
|
"key".to_owned(),
|
||||||
|
IV::object(indexmap! {"key" => IV::scalar(42)}),
|
||||||
|
)]
|
||||||
|
.into_iter()
|
||||||
|
.collect::<V>(),
|
||||||
|
);
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
graphql_vars! {"key": {"key": []}},
|
||||||
|
vec![(
|
||||||
|
"key".to_owned(),
|
||||||
|
IV::object(indexmap! {"key" => IV::list(vec![])}),
|
||||||
|
)]
|
||||||
|
.into_iter()
|
||||||
|
.collect::<V>(),
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
graphql_vars! {"key": {"key": [null]}},
|
||||||
|
vec![(
|
||||||
|
"key".to_owned(),
|
||||||
|
IV::object(indexmap! {"key" => IV::list(vec![IV::Null])}),
|
||||||
|
)]
|
||||||
|
.into_iter()
|
||||||
|
.collect::<V>(),
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
graphql_vars! {"key": {"key": [1]}},
|
||||||
|
vec![(
|
||||||
|
"key".to_owned(),
|
||||||
|
IV::object(indexmap! {"key" => IV::list(vec![IV::scalar(1)])}),
|
||||||
|
)]
|
||||||
|
.into_iter()
|
||||||
|
.collect::<V>(),
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
graphql_vars! {"key": {"key": [1 + 2]}},
|
||||||
|
vec![(
|
||||||
|
"key".to_owned(),
|
||||||
|
IV::object(indexmap! {"key" => IV::list(vec![IV::scalar(3)])}),
|
||||||
|
)]
|
||||||
|
.into_iter()
|
||||||
|
.collect::<V>(),
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
graphql_vars! {"key": {"key": [(val)]}},
|
||||||
|
vec![(
|
||||||
|
"key".to_owned(),
|
||||||
|
IV::object(indexmap! {"key" => IV::list(vec![IV::scalar(42)])}),
|
||||||
|
)]
|
||||||
|
.into_iter()
|
||||||
|
.collect::<V>(),
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
graphql_vars! {"key": {"key": ENUM}},
|
||||||
|
vec![(
|
||||||
|
"key".to_owned(),
|
||||||
|
IV::object(indexmap! {"key" => IV::enum_value("ENUM")}),
|
||||||
|
)]
|
||||||
|
.into_iter()
|
||||||
|
.collect::<V>(),
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
graphql_vars! {"key": {"key": lowercase}},
|
||||||
|
vec![(
|
||||||
|
"key".to_owned(),
|
||||||
|
IV::object(indexmap! {"key" => IV::enum_value("lowercase")}),
|
||||||
|
)]
|
||||||
|
.into_iter()
|
||||||
|
.collect::<V>(),
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
graphql_vars! {"key": {"key": @val}},
|
||||||
|
vec![(
|
||||||
|
"key".to_owned(),
|
||||||
|
IV::object(indexmap! {"key" => IV::variable("val")}),
|
||||||
|
)]
|
||||||
|
.into_iter()
|
||||||
|
.collect::<V>(),
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
graphql_vars! {"key": {"key": @array}},
|
||||||
|
vec![(
|
||||||
|
"key".to_owned(),
|
||||||
|
IV::object(indexmap! {"key" => IV::variable("array")}),
|
||||||
|
)]
|
||||||
|
.into_iter()
|
||||||
|
.collect::<V>(),
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
graphql_vars! {
|
||||||
|
"inner": {
|
||||||
|
"key1": (val),
|
||||||
|
"key2": "val",
|
||||||
|
"key3": [{
|
||||||
|
"inner": 42,
|
||||||
|
}, {
|
||||||
|
"inner": ENUM,
|
||||||
|
"even-more": {
|
||||||
|
"var": @var,
|
||||||
|
},
|
||||||
|
}],
|
||||||
|
"key4": [1, ["val", 1 + 3], null, @array],
|
||||||
|
},
|
||||||
|
"more": @var,
|
||||||
|
},
|
||||||
|
vec![
|
||||||
|
(
|
||||||
|
"inner".to_owned(),
|
||||||
|
IV::object(indexmap! {
|
||||||
|
"key1" => IV::scalar(42),
|
||||||
|
"key2" => IV::scalar("val"),
|
||||||
|
"key3" => IV::list(vec![
|
||||||
|
IV::object(indexmap! {
|
||||||
|
"inner" => IV::scalar(42),
|
||||||
|
}),
|
||||||
|
IV::object(indexmap! {
|
||||||
|
"inner" => IV::enum_value("ENUM"),
|
||||||
|
"even-more" => IV::object(indexmap! {
|
||||||
|
"var" => IV::variable("var"),
|
||||||
|
}),
|
||||||
|
}),
|
||||||
|
]),
|
||||||
|
"key4" => IV::list(vec![
|
||||||
|
IV::scalar(1),
|
||||||
|
IV::list(vec![
|
||||||
|
IV::scalar("val"),
|
||||||
|
IV::scalar(4),
|
||||||
|
]),
|
||||||
|
IV::Null,
|
||||||
|
IV::variable("array"),
|
||||||
|
]),
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
("more".to_owned(), IV::variable("var")),
|
||||||
|
]
|
||||||
|
.into_iter()
|
||||||
|
.collect::<V>(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,3 +1,10 @@
|
||||||
//! Helper definitions for macros.
|
//! Declarative macros and helper definitions for procedural macros.
|
||||||
|
|
||||||
pub mod helper;
|
pub mod helper;
|
||||||
|
|
||||||
|
#[macro_use]
|
||||||
|
mod graphql_input_value;
|
||||||
|
#[macro_use]
|
||||||
|
mod graphql_value;
|
||||||
|
#[macro_use]
|
||||||
|
mod graphql_vars;
|
||||||
|
|
|
@ -3,6 +3,7 @@ use crate::{
|
||||||
Arguments, Definition, Field, InputValue, Operation, OperationType, OwnedDocument,
|
Arguments, Definition, Field, InputValue, Operation, OperationType, OwnedDocument,
|
||||||
Selection,
|
Selection,
|
||||||
},
|
},
|
||||||
|
graphql_input_value,
|
||||||
parser::{document::parse_document_source, ParseError, SourcePosition, Spanning, Token},
|
parser::{document::parse_document_source, ParseError, SourcePosition, Spanning, Token},
|
||||||
schema::model::SchemaType,
|
schema::model::SchemaType,
|
||||||
types::scalars::{EmptyMutation, EmptySubscription},
|
types::scalars::{EmptyMutation, EmptySubscription},
|
||||||
|
@ -78,7 +79,7 @@ fn simple_ast() {
|
||||||
Spanning::start_end(
|
Spanning::start_end(
|
||||||
&SourcePosition::new(40, 2, 25),
|
&SourcePosition::new(40, 2, 25),
|
||||||
&SourcePosition::new(41, 2, 26),
|
&SourcePosition::new(41, 2, 26),
|
||||||
InputValue::scalar(4),
|
graphql_input_value!(4),
|
||||||
),
|
),
|
||||||
)],
|
)],
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
use indexmap::IndexMap;
|
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
ast::{FromInputValue, InputValue, Type},
|
ast::{FromInputValue, InputValue, Type},
|
||||||
|
graphql_input_value,
|
||||||
parser::{value::parse_value_literal, Lexer, Parser, SourcePosition, Spanning},
|
parser::{value::parse_value_literal, Lexer, Parser, SourcePosition, Spanning},
|
||||||
schema::{
|
schema::{
|
||||||
meta::{Argument, EnumMeta, EnumValue, InputObjectMeta, MetaType, ScalarMeta},
|
meta::{Argument, EnumMeta, EnumValue, InputObjectMeta, MetaType, ScalarMeta},
|
||||||
|
@ -79,40 +78,40 @@ fn input_value_literals() {
|
||||||
Spanning::start_end(
|
Spanning::start_end(
|
||||||
&SourcePosition::new(0, 0, 0),
|
&SourcePosition::new(0, 0, 0),
|
||||||
&SourcePosition::new(3, 0, 3),
|
&SourcePosition::new(3, 0, 3),
|
||||||
InputValue::scalar(123)
|
graphql_input_value!(123),
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
parse_value::<DefaultScalarValue>("123.45", &scalar_meta::<f64>("Float")),
|
parse_value::<DefaultScalarValue>("123.45", &scalar_meta::<f64>("Float")),
|
||||||
Spanning::start_end(
|
Spanning::start_end(
|
||||||
&SourcePosition::new(0, 0, 0),
|
&SourcePosition::new(0, 0, 0),
|
||||||
&SourcePosition::new(6, 0, 6),
|
&SourcePosition::new(6, 0, 6),
|
||||||
InputValue::scalar(123.45)
|
graphql_input_value!(123.45),
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
parse_value::<DefaultScalarValue>("true", &scalar_meta::<bool>("Bool")),
|
parse_value::<DefaultScalarValue>("true", &scalar_meta::<bool>("Bool")),
|
||||||
Spanning::start_end(
|
Spanning::start_end(
|
||||||
&SourcePosition::new(0, 0, 0),
|
&SourcePosition::new(0, 0, 0),
|
||||||
&SourcePosition::new(4, 0, 4),
|
&SourcePosition::new(4, 0, 4),
|
||||||
InputValue::scalar(true)
|
graphql_input_value!(true),
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
parse_value::<DefaultScalarValue>("false", &scalar_meta::<bool>("Bool")),
|
parse_value::<DefaultScalarValue>("false", &scalar_meta::<bool>("Bool")),
|
||||||
Spanning::start_end(
|
Spanning::start_end(
|
||||||
&SourcePosition::new(0, 0, 0),
|
&SourcePosition::new(0, 0, 0),
|
||||||
&SourcePosition::new(5, 0, 5),
|
&SourcePosition::new(5, 0, 5),
|
||||||
InputValue::scalar(false)
|
graphql_input_value!(false),
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
parse_value::<DefaultScalarValue>(r#""test""#, &scalar_meta::<String>("String")),
|
parse_value::<DefaultScalarValue>(r#""test""#, &scalar_meta::<String>("String")),
|
||||||
Spanning::start_end(
|
Spanning::start_end(
|
||||||
&SourcePosition::new(0, 0, 0),
|
&SourcePosition::new(0, 0, 0),
|
||||||
&SourcePosition::new(6, 0, 6),
|
&SourcePosition::new(6, 0, 6),
|
||||||
InputValue::scalar("test")
|
graphql_input_value!("test"),
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
let values = &[EnumValue::new("enum_value")];
|
let values = &[EnumValue::new("enum_value")];
|
||||||
let e: EnumMeta<DefaultScalarValue> = EnumMeta::new::<Enum>("TestEnum".into(), values);
|
let e: EnumMeta<DefaultScalarValue> = EnumMeta::new::<Enum>("TestEnum".into(), values);
|
||||||
|
@ -122,24 +121,24 @@ fn input_value_literals() {
|
||||||
Spanning::start_end(
|
Spanning::start_end(
|
||||||
&SourcePosition::new(0, 0, 0),
|
&SourcePosition::new(0, 0, 0),
|
||||||
&SourcePosition::new(10, 0, 10),
|
&SourcePosition::new(10, 0, 10),
|
||||||
InputValue::enum_value("enum_value")
|
graphql_input_value!(enum_value),
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
parse_value::<DefaultScalarValue>("$variable", &scalar_meta::<i32>("Int")),
|
parse_value::<DefaultScalarValue>("$variable", &scalar_meta::<i32>("Int")),
|
||||||
Spanning::start_end(
|
Spanning::start_end(
|
||||||
&SourcePosition::new(0, 0, 0),
|
&SourcePosition::new(0, 0, 0),
|
||||||
&SourcePosition::new(9, 0, 9),
|
&SourcePosition::new(9, 0, 9),
|
||||||
InputValue::variable("variable")
|
graphql_input_value!(@variable),
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
parse_value::<DefaultScalarValue>("[]", &scalar_meta::<i32>("Int")),
|
parse_value::<DefaultScalarValue>("[]", &scalar_meta::<i32>("Int")),
|
||||||
Spanning::start_end(
|
Spanning::start_end(
|
||||||
&SourcePosition::new(0, 0, 0),
|
&SourcePosition::new(0, 0, 0),
|
||||||
&SourcePosition::new(2, 0, 2),
|
&SourcePosition::new(2, 0, 2),
|
||||||
InputValue::list(vec![])
|
graphql_input_value!([]),
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
parse_value::<DefaultScalarValue>("[1, [2, 3]]", &scalar_meta::<i32>("Int")),
|
parse_value::<DefaultScalarValue>("[1, [2, 3]]", &scalar_meta::<i32>("Int")),
|
||||||
|
@ -150,7 +149,7 @@ fn input_value_literals() {
|
||||||
Spanning::start_end(
|
Spanning::start_end(
|
||||||
&SourcePosition::new(1, 0, 1),
|
&SourcePosition::new(1, 0, 1),
|
||||||
&SourcePosition::new(2, 0, 2),
|
&SourcePosition::new(2, 0, 2),
|
||||||
InputValue::scalar(1),
|
graphql_input_value!(1),
|
||||||
),
|
),
|
||||||
Spanning::start_end(
|
Spanning::start_end(
|
||||||
&SourcePosition::new(4, 0, 4),
|
&SourcePosition::new(4, 0, 4),
|
||||||
|
@ -159,17 +158,17 @@ fn input_value_literals() {
|
||||||
Spanning::start_end(
|
Spanning::start_end(
|
||||||
&SourcePosition::new(5, 0, 5),
|
&SourcePosition::new(5, 0, 5),
|
||||||
&SourcePosition::new(6, 0, 6),
|
&SourcePosition::new(6, 0, 6),
|
||||||
InputValue::scalar(2),
|
graphql_input_value!(2),
|
||||||
),
|
),
|
||||||
Spanning::start_end(
|
Spanning::start_end(
|
||||||
&SourcePosition::new(8, 0, 8),
|
&SourcePosition::new(8, 0, 8),
|
||||||
&SourcePosition::new(9, 0, 9),
|
&SourcePosition::new(9, 0, 9),
|
||||||
InputValue::scalar(3),
|
graphql_input_value!(3),
|
||||||
),
|
),
|
||||||
]),
|
]),
|
||||||
),
|
),
|
||||||
])
|
]),
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
let fields = [
|
let fields = [
|
||||||
Argument::new("key", Type::NonNullNamed("Int".into())),
|
Argument::new("key", Type::NonNullNamed("Int".into())),
|
||||||
|
@ -181,8 +180,8 @@ fn input_value_literals() {
|
||||||
Spanning::start_end(
|
Spanning::start_end(
|
||||||
&SourcePosition::new(0, 0, 0),
|
&SourcePosition::new(0, 0, 0),
|
||||||
&SourcePosition::new(2, 0, 2),
|
&SourcePosition::new(2, 0, 2),
|
||||||
InputValue::object(IndexMap::<String, InputValue<DefaultScalarValue>>::new())
|
graphql_input_value!({}),
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
@ -200,7 +199,7 @@ fn input_value_literals() {
|
||||||
Spanning::start_end(
|
Spanning::start_end(
|
||||||
&SourcePosition::new(6, 0, 6),
|
&SourcePosition::new(6, 0, 6),
|
||||||
&SourcePosition::new(9, 0, 9),
|
&SourcePosition::new(9, 0, 9),
|
||||||
InputValue::scalar(123),
|
graphql_input_value!(123),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
|
@ -221,12 +220,12 @@ fn input_value_literals() {
|
||||||
Spanning::start_end(
|
Spanning::start_end(
|
||||||
&SourcePosition::new(24, 0, 24),
|
&SourcePosition::new(24, 0, 24),
|
||||||
&SourcePosition::new(29, 0, 29),
|
&SourcePosition::new(29, 0, 29),
|
||||||
InputValue::scalar("bar"),
|
graphql_input_value!("bar"),
|
||||||
),
|
),
|
||||||
)]),
|
)]),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
])
|
]),
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
executor::Variables,
|
graphql_vars,
|
||||||
introspection::IntrospectionFormat,
|
introspection::IntrospectionFormat,
|
||||||
schema::model::RootNode,
|
schema::model::RootNode,
|
||||||
tests::fixtures::starwars::schema::{Database, Query},
|
tests::fixtures::starwars::schema::{Database, Query},
|
||||||
|
@ -28,7 +28,7 @@ async fn test_introspection_query_type_name() {
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
crate::execute(doc, None, &schema, &Variables::new(), &database).await,
|
crate::execute(doc, None, &schema, &graphql_vars! {}, &database).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({
|
graphql_value!({
|
||||||
"__schema": {
|
"__schema": {
|
||||||
|
@ -59,7 +59,7 @@ async fn test_introspection_type_name() {
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
crate::execute(doc, None, &schema, &Variables::new(), &database).await,
|
crate::execute(doc, None, &schema, &graphql_vars! {}, &database).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({
|
graphql_value!({
|
||||||
"__type": {
|
"__type": {
|
||||||
|
@ -89,7 +89,7 @@ async fn test_introspection_specific_object_type_name_and_kind() {
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
crate::execute(doc, None, &schema, &Variables::new(), &database).await,
|
crate::execute(doc, None, &schema, &graphql_vars! {}, &database).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({
|
graphql_value!({
|
||||||
"__type": {
|
"__type": {
|
||||||
|
@ -120,7 +120,7 @@ async fn test_introspection_specific_interface_type_name_and_kind() {
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
crate::execute(doc, None, &schema, &Variables::new(), &database).await,
|
crate::execute(doc, None, &schema, &graphql_vars! {}, &database).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({
|
graphql_value!({
|
||||||
"__type": {
|
"__type": {
|
||||||
|
@ -151,7 +151,7 @@ async fn test_introspection_documentation() {
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
crate::execute(doc, None, &schema, &Variables::new(), &database).await,
|
crate::execute(doc, None, &schema, &graphql_vars! {}, &database).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({
|
graphql_value!({
|
||||||
"__type": {
|
"__type": {
|
||||||
|
@ -184,7 +184,7 @@ async fn test_introspection_directives() {
|
||||||
EmptySubscription::<Database>::new(),
|
EmptySubscription::<Database>::new(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let mut result = crate::execute(q, None, &schema, &Variables::new(), &database)
|
let mut result = crate::execute(q, None, &schema, &graphql_vars! {}, &database)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
sort_schema_value(&mut result.0);
|
sort_schema_value(&mut result.0);
|
||||||
|
@ -234,7 +234,7 @@ async fn test_introspection_possible_types() {
|
||||||
EmptySubscription::<Database>::new(),
|
EmptySubscription::<Database>::new(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let result = crate::execute(doc, None, &schema, &Variables::new(), &database).await;
|
let result = crate::execute(doc, None, &schema, &graphql_vars! {}, &database).await;
|
||||||
|
|
||||||
let (result, errors) = result.ok().expect("Query returned error");
|
let (result, errors) = result.ok().expect("Query returned error");
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
ast::InputValue,
|
graphql_value, graphql_vars,
|
||||||
executor::Variables,
|
|
||||||
graphql_value,
|
|
||||||
schema::model::RootNode,
|
schema::model::RootNode,
|
||||||
tests::fixtures::starwars::schema::{Database, Query},
|
tests::fixtures::starwars::schema::{Database, Query},
|
||||||
types::scalars::{EmptyMutation, EmptySubscription},
|
types::scalars::{EmptyMutation, EmptySubscription},
|
||||||
|
@ -22,7 +20,7 @@ async fn test_hero_name() {
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
crate::execute(doc, None, &schema, &Variables::new(), &database).await,
|
crate::execute(doc, None, &schema, &graphql_vars! {}, &database).await,
|
||||||
Ok((graphql_value!({"hero": {"name": "R2-D2"}}), vec![])),
|
Ok((graphql_value!({"hero": {"name": "R2-D2"}}), vec![])),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -43,7 +41,7 @@ async fn test_hero_field_order() {
|
||||||
}
|
}
|
||||||
}"#;
|
}"#;
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
crate::execute(doc, None, &schema, &Variables::new(), &database).await,
|
crate::execute(doc, None, &schema, &graphql_vars! {}, &database).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"hero": {"id": "2001", "name": "R2-D2"}}),
|
graphql_value!({"hero": {"id": "2001", "name": "R2-D2"}}),
|
||||||
vec![],
|
vec![],
|
||||||
|
@ -57,7 +55,7 @@ async fn test_hero_field_order() {
|
||||||
}
|
}
|
||||||
}"#;
|
}"#;
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
crate::execute(doc_reversed, None, &schema, &Variables::new(), &database).await,
|
crate::execute(doc_reversed, None, &schema, &graphql_vars! {}, &database).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"hero": {"name": "R2-D2", "id": "2001"}}),
|
graphql_value!({"hero": {"name": "R2-D2", "id": "2001"}}),
|
||||||
vec![],
|
vec![],
|
||||||
|
@ -84,7 +82,7 @@ async fn test_hero_name_and_friends() {
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
crate::execute(doc, None, &schema, &Variables::new(), &database).await,
|
crate::execute(doc, None, &schema, &graphql_vars! {}, &database).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"hero": {
|
graphql_value!({"hero": {
|
||||||
"id": "2001",
|
"id": "2001",
|
||||||
|
@ -123,7 +121,7 @@ async fn test_hero_name_and_friends_and_friends_of_friends() {
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
crate::execute(doc, None, &schema, &Variables::new(), &database).await,
|
crate::execute(doc, None, &schema, &graphql_vars! {}, &database).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"hero": {
|
graphql_value!({"hero": {
|
||||||
"id": "2001",
|
"id": "2001",
|
||||||
|
@ -172,7 +170,7 @@ async fn test_query_name() {
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
crate::execute(doc, None, &schema, &Variables::new(), &database).await,
|
crate::execute(doc, None, &schema, &graphql_vars! {}, &database).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"human": {"name": "Luke Skywalker"}}),
|
graphql_value!({"human": {"name": "Luke Skywalker"}}),
|
||||||
vec![],
|
vec![],
|
||||||
|
@ -191,7 +189,7 @@ async fn test_query_alias_single() {
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
crate::execute(doc, None, &schema, &Variables::new(), &database).await,
|
crate::execute(doc, None, &schema, &graphql_vars! {}, &database).await,
|
||||||
Ok((graphql_value!({"luke": {"name": "Luke Skywalker"}}), vec![])),
|
Ok((graphql_value!({"luke": {"name": "Luke Skywalker"}}), vec![])),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -210,7 +208,7 @@ async fn test_query_alias_multiple() {
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
crate::execute(doc, None, &schema, &Variables::new(), &database).await,
|
crate::execute(doc, None, &schema, &graphql_vars! {}, &database).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({
|
graphql_value!({
|
||||||
"luke": {"name": "Luke Skywalker"},
|
"luke": {"name": "Luke Skywalker"},
|
||||||
|
@ -241,7 +239,7 @@ async fn test_query_alias_multiple_with_fragment() {
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
crate::execute(doc, None, &schema, &Variables::new(), &database).await,
|
crate::execute(doc, None, &schema, &graphql_vars! {}, &database).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({
|
graphql_value!({
|
||||||
"luke": {"name": "Luke Skywalker", "homePlanet": "Tatooine"},
|
"luke": {"name": "Luke Skywalker", "homePlanet": "Tatooine"},
|
||||||
|
@ -261,10 +259,7 @@ async fn test_query_name_variable() {
|
||||||
EmptyMutation::<Database>::new(),
|
EmptyMutation::<Database>::new(),
|
||||||
EmptySubscription::<Database>::new(),
|
EmptySubscription::<Database>::new(),
|
||||||
);
|
);
|
||||||
|
let vars = graphql_vars! {"someId": "1000"};
|
||||||
let vars = vec![("someId".to_owned(), InputValue::scalar("1000"))]
|
|
||||||
.into_iter()
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
crate::execute(doc, None, &schema, &vars, &database).await,
|
crate::execute(doc, None, &schema, &vars, &database).await,
|
||||||
|
@ -284,14 +279,11 @@ async fn test_query_name_invalid_variable() {
|
||||||
EmptyMutation::<Database>::new(),
|
EmptyMutation::<Database>::new(),
|
||||||
EmptySubscription::<Database>::new(),
|
EmptySubscription::<Database>::new(),
|
||||||
);
|
);
|
||||||
|
let vars = graphql_vars! {"someId": "some invalid id"};
|
||||||
let vars = vec![("someId".to_owned(), InputValue::scalar("some invalid id"))]
|
|
||||||
.into_iter()
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
crate::execute(doc, None, &schema, &vars, &database).await,
|
crate::execute(doc, None, &schema, &vars, &database).await,
|
||||||
Ok((graphql_value!({ "human": None }), vec![])),
|
Ok((graphql_value!({ "human": null }), vec![])),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -306,7 +298,7 @@ async fn test_query_friends_names() {
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
crate::execute(doc, None, &schema, &Variables::new(), &database).await,
|
crate::execute(doc, None, &schema, &graphql_vars! {}, &database).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"human": {
|
graphql_value!({"human": {
|
||||||
"friends": [
|
"friends": [
|
||||||
|
@ -341,7 +333,7 @@ async fn test_query_inline_fragments_droid() {
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
crate::execute(doc, None, &schema, &Variables::new(), &database).await,
|
crate::execute(doc, None, &schema, &graphql_vars! {}, &database).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"hero": {
|
graphql_value!({"hero": {
|
||||||
"__typename": "Droid",
|
"__typename": "Droid",
|
||||||
|
@ -369,7 +361,7 @@ async fn test_query_inline_fragments_human() {
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
crate::execute(doc, None, &schema, &Variables::new(), &database).await,
|
crate::execute(doc, None, &schema, &graphql_vars! {}, &database).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"hero": {
|
graphql_value!({"hero": {
|
||||||
"__typename": "Human",
|
"__typename": "Human",
|
||||||
|
@ -395,7 +387,7 @@ async fn test_object_typename() {
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
crate::execute(doc, None, &schema, &Variables::new(), &database).await,
|
crate::execute(doc, None, &schema, &graphql_vars! {}, &database).await,
|
||||||
Ok((graphql_value!({"human": {"__typename": "Human"}}), vec![])),
|
Ok((graphql_value!({"human": {"__typename": "Human"}}), vec![])),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -419,7 +411,7 @@ async fn interface_inline_fragment_friends() {
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
crate::execute(doc, None, &schema, &Variables::new(), &database).await,
|
crate::execute(doc, None, &schema, &graphql_vars! {}, &database).await,
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({"human": {
|
graphql_value!({"human": {
|
||||||
"friends": [
|
"friends": [
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,8 +1,8 @@
|
||||||
use indexmap::IndexMap;
|
use indexmap::IndexMap;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
executor::{ExecutionResult, Executor, Registry, Variables},
|
executor::{ExecutionResult, Executor, Registry},
|
||||||
graphql_value,
|
graphql_value, graphql_vars,
|
||||||
schema::{meta::MetaType, model::RootNode},
|
schema::{meta::MetaType, model::RootNode},
|
||||||
types::{
|
types::{
|
||||||
base::{Arguments, GraphQLType, GraphQLValue},
|
base::{Arguments, GraphQLType, GraphQLValue},
|
||||||
|
@ -94,7 +94,7 @@ fn test_node() {
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
crate::execute_sync(doc, None, &schema, &Variables::new(), &()),
|
crate::execute_sync(doc, None, &schema, &graphql_vars! {}, &()),
|
||||||
Ok((
|
Ok((
|
||||||
graphql_value!({
|
graphql_value!({
|
||||||
"foo": "1",
|
"foo": "1",
|
||||||
|
|
|
@ -1,11 +1,7 @@
|
||||||
mod object;
|
mod object;
|
||||||
mod scalar;
|
mod scalar;
|
||||||
|
|
||||||
use std::{
|
use std::{any::TypeId, borrow::Cow, fmt, mem};
|
||||||
any::TypeId,
|
|
||||||
fmt::{self, Display, Formatter},
|
|
||||||
mem,
|
|
||||||
};
|
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
ast::{InputValue, ToInputValue},
|
ast::{InputValue, ToInputValue},
|
||||||
|
@ -194,8 +190,8 @@ impl<S: Clone> ToInputValue<S> for Value<S> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S: ScalarValue> Display for Value<S> {
|
impl<S: ScalarValue> fmt::Display for Value<S> {
|
||||||
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
Self::Null => write!(f, "null"),
|
Self::Null => write!(f, "null"),
|
||||||
Self::Scalar(s) => {
|
Self::Scalar(s) => {
|
||||||
|
@ -252,6 +248,12 @@ impl<'a, S: From<String>> From<&'a str> for Value<S> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'a, S: From<String>> From<Cow<'a, str>> for Value<S> {
|
||||||
|
fn from(s: Cow<'a, str>) -> Self {
|
||||||
|
Self::scalar(s.into_owned())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<S: From<String>> From<String> for Value<S> {
|
impl<S: From<String>> From<String> for Value<S> {
|
||||||
fn from(s: String) -> Self {
|
fn from(s: String) -> Self {
|
||||||
Self::scalar(s)
|
Self::scalar(s)
|
||||||
|
@ -276,173 +278,68 @@ impl<S: From<bool>> From<bool> for Value<S> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Construct JSON-like values by using JSON syntax
|
|
||||||
///
|
|
||||||
/// This macro can be used to create `Value` instances using a JSON syntax.
|
|
||||||
/// Value objects are used mostly when creating custom errors from fields.
|
|
||||||
///
|
|
||||||
/// Here are some examples; the resulting JSON will look just like what you
|
|
||||||
/// passed in.
|
|
||||||
/// ```rust
|
|
||||||
/// # use juniper::{Value, DefaultScalarValue, graphql_value};
|
|
||||||
/// # type V = Value<DefaultScalarValue>;
|
|
||||||
/// #
|
|
||||||
/// # fn main() {
|
|
||||||
/// # let _: V =
|
|
||||||
/// graphql_value!(None);
|
|
||||||
/// # let _: V =
|
|
||||||
/// graphql_value!(1234);
|
|
||||||
/// # let _: V =
|
|
||||||
/// graphql_value!("test");
|
|
||||||
/// # let _: V =
|
|
||||||
/// graphql_value!([ 1234, "test", true ]);
|
|
||||||
/// # let _: V =
|
|
||||||
/// graphql_value!({ "key": "value", "foo": 1234 });
|
|
||||||
/// # }
|
|
||||||
/// ```
|
|
||||||
#[macro_export]
|
|
||||||
macro_rules! graphql_value {
|
|
||||||
([ $($arg:tt),* $(,)* ]) => {
|
|
||||||
$crate::Value::list(vec![
|
|
||||||
$( graphql_value!($arg), )*
|
|
||||||
])
|
|
||||||
};
|
|
||||||
({ $($key:tt : $val:tt ),* $(,)* }) => {
|
|
||||||
$crate::Value::object(vec![
|
|
||||||
$( ($key, graphql_value!($val)), )*
|
|
||||||
].into_iter().collect())
|
|
||||||
};
|
|
||||||
(None) => ($crate::Value::null());
|
|
||||||
($e:expr) => ($crate::Value::from($e))
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use crate::graphql_value;
|
||||||
|
|
||||||
#[test]
|
use super::Value;
|
||||||
fn value_macro_string() {
|
|
||||||
let s: Value<DefaultScalarValue> = graphql_value!("test");
|
|
||||||
assert_eq!(s, Value::scalar("test"));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn value_macro_int() {
|
|
||||||
let s: Value<DefaultScalarValue> = graphql_value!(123);
|
|
||||||
assert_eq!(s, Value::scalar(123));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn value_macro_float() {
|
|
||||||
let s: Value<DefaultScalarValue> = graphql_value!(123.5);
|
|
||||||
assert_eq!(s, Value::scalar(123.5));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn value_macro_boolean() {
|
|
||||||
let s: Value<DefaultScalarValue> = graphql_value!(false);
|
|
||||||
assert_eq!(s, Value::scalar(false));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn value_macro_option() {
|
|
||||||
let s: Value<DefaultScalarValue> = graphql_value!(Some("test"));
|
|
||||||
assert_eq!(s, Value::scalar("test"));
|
|
||||||
let s: Value<DefaultScalarValue> = graphql_value!(None);
|
|
||||||
assert_eq!(s, Value::null());
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn value_macro_list() {
|
|
||||||
let s: Value<DefaultScalarValue> = graphql_value!([123, "Test", false]);
|
|
||||||
assert_eq!(
|
|
||||||
s,
|
|
||||||
Value::list(vec![
|
|
||||||
Value::scalar(123),
|
|
||||||
Value::scalar("Test"),
|
|
||||||
Value::scalar(false),
|
|
||||||
])
|
|
||||||
);
|
|
||||||
let s: Value<DefaultScalarValue> = graphql_value!([123, [456], 789]);
|
|
||||||
assert_eq!(
|
|
||||||
s,
|
|
||||||
Value::list(vec![
|
|
||||||
Value::scalar(123),
|
|
||||||
Value::list(vec![Value::scalar(456)]),
|
|
||||||
Value::scalar(789),
|
|
||||||
])
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn value_macro_object() {
|
|
||||||
let s: Value<DefaultScalarValue> = graphql_value!({ "key": 123, "next": true });
|
|
||||||
assert_eq!(
|
|
||||||
s,
|
|
||||||
Value::object(
|
|
||||||
vec![("key", Value::scalar(123)), ("next", Value::scalar(true))]
|
|
||||||
.into_iter()
|
|
||||||
.collect(),
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn display_null() {
|
fn display_null() {
|
||||||
let s: Value<DefaultScalarValue> = graphql_value!(None);
|
let s: Value = graphql_value!(null);
|
||||||
assert_eq!("null", format!("{}", s));
|
assert_eq!("null", format!("{}", s));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn display_int() {
|
fn display_int() {
|
||||||
let s: Value<DefaultScalarValue> = graphql_value!(123);
|
let s: Value = graphql_value!(123);
|
||||||
assert_eq!("123", format!("{}", s));
|
assert_eq!("123", format!("{}", s));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn display_float() {
|
fn display_float() {
|
||||||
let s: Value<DefaultScalarValue> = graphql_value!(123.456);
|
let s: Value = graphql_value!(123.456);
|
||||||
assert_eq!("123.456", format!("{}", s));
|
assert_eq!("123.456", format!("{}", s));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn display_string() {
|
fn display_string() {
|
||||||
let s: Value<DefaultScalarValue> = graphql_value!("foo");
|
let s: Value = graphql_value!("foo");
|
||||||
assert_eq!("\"foo\"", format!("{}", s));
|
assert_eq!("\"foo\"", format!("{}", s));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn display_bool() {
|
fn display_bool() {
|
||||||
let s: Value<DefaultScalarValue> = graphql_value!(false);
|
let s: Value = graphql_value!(false);
|
||||||
assert_eq!("false", format!("{}", s));
|
assert_eq!("false", format!("{}", s));
|
||||||
|
|
||||||
let s: Value<DefaultScalarValue> = graphql_value!(true);
|
let s: Value = graphql_value!(true);
|
||||||
assert_eq!("true", format!("{}", s));
|
assert_eq!("true", format!("{}", s));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn display_list() {
|
fn display_list() {
|
||||||
let s: Value<DefaultScalarValue> = graphql_value!([1, None, "foo"]);
|
let s: Value = graphql_value!([1, null, "foo"]);
|
||||||
assert_eq!("[1, null, \"foo\"]", format!("{}", s));
|
assert_eq!("[1, null, \"foo\"]", format!("{}", s));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn display_list_one_element() {
|
fn display_list_one_element() {
|
||||||
let s: Value<DefaultScalarValue> = graphql_value!([1]);
|
let s: Value = graphql_value!([1]);
|
||||||
assert_eq!("[1]", format!("{}", s));
|
assert_eq!("[1]", format!("{}", s));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn display_list_empty() {
|
fn display_list_empty() {
|
||||||
let s: Value<DefaultScalarValue> = graphql_value!([]);
|
let s: Value = graphql_value!([]);
|
||||||
assert_eq!("[]", format!("{}", s));
|
assert_eq!("[]", format!("{}", s));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn display_object() {
|
fn display_object() {
|
||||||
let s: Value<DefaultScalarValue> = graphql_value!({
|
let s: Value = graphql_value!({
|
||||||
"int": 1,
|
"int": 1,
|
||||||
"null": None,
|
"null": null,
|
||||||
"string": "foo",
|
"string": "foo",
|
||||||
});
|
});
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
@ -453,7 +350,7 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn display_object_one_field() {
|
fn display_object_one_field() {
|
||||||
let s: Value<DefaultScalarValue> = graphql_value!({
|
let s: Value = graphql_value!({
|
||||||
"int": 1,
|
"int": 1,
|
||||||
});
|
});
|
||||||
assert_eq!(r#"{"int": 1}"#, format!("{}", s));
|
assert_eq!(r#"{"int": 1}"#, format!("{}", s));
|
||||||
|
@ -461,7 +358,7 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn display_object_empty() {
|
fn display_object_empty() {
|
||||||
let s = Value::<DefaultScalarValue>::object(Object::with_capacity(0));
|
let s: Value = graphql_value!({});
|
||||||
assert_eq!(r#"{}"#, format!("{}", s));
|
assert_eq!(r#"{}"#, format!("{}", s));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use std::fmt;
|
use std::{borrow::Cow, fmt};
|
||||||
|
|
||||||
use serde::{de::DeserializeOwned, Serialize};
|
use serde::{de::DeserializeOwned, Serialize};
|
||||||
|
|
||||||
|
@ -196,6 +196,8 @@ pub trait ScalarValue:
|
||||||
/// This function is used for implementing [`GraphQLValue`] for [`i32`] for
|
/// This function is used for implementing [`GraphQLValue`] for [`i32`] for
|
||||||
/// all possible [`ScalarValue`]s. Implementations should convert all the
|
/// all possible [`ScalarValue`]s. Implementations should convert all the
|
||||||
/// supported integer types with 32 bit or less to an integer, if requested.
|
/// supported integer types with 32 bit or less to an integer, if requested.
|
||||||
|
///
|
||||||
|
/// [`GraphQLValue`]: crate::GraphQLValue
|
||||||
#[must_use]
|
#[must_use]
|
||||||
fn as_int(&self) -> Option<i32>;
|
fn as_int(&self) -> Option<i32>;
|
||||||
|
|
||||||
|
@ -203,6 +205,8 @@ pub trait ScalarValue:
|
||||||
///
|
///
|
||||||
/// This function is used for implementing [`GraphQLValue`] for [`String`]
|
/// This function is used for implementing [`GraphQLValue`] for [`String`]
|
||||||
/// for all possible [`ScalarValue`]s.
|
/// for all possible [`ScalarValue`]s.
|
||||||
|
///
|
||||||
|
/// [`GraphQLValue`]: crate::GraphQLValue
|
||||||
#[must_use]
|
#[must_use]
|
||||||
fn as_string(&self) -> Option<String>;
|
fn as_string(&self) -> Option<String>;
|
||||||
|
|
||||||
|
@ -217,6 +221,8 @@ pub trait ScalarValue:
|
||||||
///
|
///
|
||||||
/// This function is used for implementing [`GraphQLValue`] for [`str`] for
|
/// This function is used for implementing [`GraphQLValue`] for [`str`] for
|
||||||
/// all possible [`ScalarValue`]s.
|
/// all possible [`ScalarValue`]s.
|
||||||
|
///
|
||||||
|
/// [`GraphQLValue`]: crate::GraphQLValue
|
||||||
#[must_use]
|
#[must_use]
|
||||||
fn as_str(&self) -> Option<&str>;
|
fn as_str(&self) -> Option<&str>;
|
||||||
|
|
||||||
|
@ -226,6 +232,8 @@ pub trait ScalarValue:
|
||||||
/// all possible [`ScalarValue`]s. Implementations should convert all
|
/// all possible [`ScalarValue`]s. Implementations should convert all
|
||||||
/// supported integer types with 64 bit or less and all floating point
|
/// supported integer types with 64 bit or less and all floating point
|
||||||
/// values with 64 bit or less to a float, if requested.
|
/// values with 64 bit or less to a float, if requested.
|
||||||
|
///
|
||||||
|
/// [`GraphQLValue`]: crate::GraphQLValue
|
||||||
#[must_use]
|
#[must_use]
|
||||||
fn as_float(&self) -> Option<f64>;
|
fn as_float(&self) -> Option<f64>;
|
||||||
|
|
||||||
|
@ -233,6 +241,8 @@ pub trait ScalarValue:
|
||||||
///
|
///
|
||||||
/// This function is used for implementing [`GraphQLValue`] for [`bool`] for
|
/// This function is used for implementing [`GraphQLValue`] for [`bool`] for
|
||||||
/// all possible [`ScalarValue`]s.
|
/// all possible [`ScalarValue`]s.
|
||||||
|
///
|
||||||
|
/// [`GraphQLValue`]: crate::GraphQLValue
|
||||||
fn as_boolean(&self) -> Option<bool>;
|
fn as_boolean(&self) -> Option<bool>;
|
||||||
|
|
||||||
/// Converts this [`ScalarValue`] into another one.
|
/// Converts this [`ScalarValue`] into another one.
|
||||||
|
@ -342,3 +352,9 @@ impl<'a> From<&'a str> for DefaultScalarValue {
|
||||||
Self::String(s.into())
|
Self::String(s.into())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'a> From<Cow<'a, str>> for DefaultScalarValue {
|
||||||
|
fn from(s: Cow<'a, str>) -> Self {
|
||||||
|
Self::String(s.into())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -53,8 +53,9 @@ pub enum ClientMessage<S> {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
|
use juniper::{graphql_vars, DefaultScalarValue};
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
use juniper::{DefaultScalarValue, InputValue};
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_deserialization() {
|
fn test_deserialization() {
|
||||||
|
@ -62,10 +63,7 @@ mod test {
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
ClientMessage::ConnectionInit {
|
ClientMessage::ConnectionInit {
|
||||||
payload: [("foo".to_string(), InputValue::scalar("bar"))]
|
payload: graphql_vars! {"foo": "bar"},
|
||||||
.iter()
|
|
||||||
.cloned()
|
|
||||||
.collect(),
|
|
||||||
},
|
},
|
||||||
serde_json::from_str(r##"{"type": "connection_init", "payload": {"foo": "bar"}}"##)
|
serde_json::from_str(r##"{"type": "connection_init", "payload": {"foo": "bar"}}"##)
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
|
@ -73,7 +71,7 @@ mod test {
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
ClientMessage::ConnectionInit {
|
ClientMessage::ConnectionInit {
|
||||||
payload: Variables::default(),
|
payload: graphql_vars! {},
|
||||||
},
|
},
|
||||||
serde_json::from_str(r##"{"type": "connection_init"}"##).unwrap(),
|
serde_json::from_str(r##"{"type": "connection_init"}"##).unwrap(),
|
||||||
);
|
);
|
||||||
|
@ -83,10 +81,7 @@ mod test {
|
||||||
id: "foo".to_string(),
|
id: "foo".to_string(),
|
||||||
payload: StartPayload {
|
payload: StartPayload {
|
||||||
query: "query MyQuery { __typename }".to_string(),
|
query: "query MyQuery { __typename }".to_string(),
|
||||||
variables: [("foo".to_string(), InputValue::scalar("bar"))]
|
variables: graphql_vars! {"foo": "bar"},
|
||||||
.iter()
|
|
||||||
.cloned()
|
|
||||||
.collect(),
|
|
||||||
operation_name: Some("MyQuery".to_string()),
|
operation_name: Some("MyQuery".to_string()),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -107,7 +102,7 @@ mod test {
|
||||||
id: "foo".to_string(),
|
id: "foo".to_string(),
|
||||||
payload: StartPayload {
|
payload: StartPayload {
|
||||||
query: "query MyQuery { __typename }".to_string(),
|
query: "query MyQuery { __typename }".to_string(),
|
||||||
variables: Variables::default(),
|
variables: graphql_vars! {},
|
||||||
operation_name: None,
|
operation_name: None,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -139,7 +134,7 @@ mod test {
|
||||||
|
|
||||||
let expected = StartPayload {
|
let expected = StartPayload {
|
||||||
query: "query".into(),
|
query: "query".into(),
|
||||||
variables: Variables::default(),
|
variables: graphql_vars! {},
|
||||||
operation_name: None,
|
operation_name: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -633,9 +633,9 @@ mod test {
|
||||||
|
|
||||||
use juniper::{
|
use juniper::{
|
||||||
futures::sink::SinkExt,
|
futures::sink::SinkExt,
|
||||||
graphql_object, graphql_subscription, graphql_value,
|
graphql_input_value, graphql_object, graphql_subscription, graphql_value, graphql_vars,
|
||||||
parser::{ParseError, Spanning, Token},
|
parser::{ParseError, Spanning, Token},
|
||||||
DefaultScalarValue, EmptyMutation, FieldError, FieldResult, InputValue, RootNode,
|
DefaultScalarValue, EmptyMutation, FieldError, FieldResult, RootNode,
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
@ -681,7 +681,7 @@ mod test {
|
||||||
async fn error(_context: &Context) -> BoxStream<'static, FieldResult<i32>> {
|
async fn error(_context: &Context) -> BoxStream<'static, FieldResult<i32>> {
|
||||||
stream::once(future::ready(Err(FieldError::new(
|
stream::once(future::ready(Err(FieldError::new(
|
||||||
"field error",
|
"field error",
|
||||||
graphql_value!(None),
|
graphql_value!(null),
|
||||||
))))
|
))))
|
||||||
.chain(
|
.chain(
|
||||||
tokio::time::sleep(Duration::from_secs(10000))
|
tokio::time::sleep(Duration::from_secs(10000))
|
||||||
|
@ -707,7 +707,7 @@ mod test {
|
||||||
);
|
);
|
||||||
|
|
||||||
conn.send(ClientMessage::ConnectionInit {
|
conn.send(ClientMessage::ConnectionInit {
|
||||||
payload: Variables::default(),
|
payload: graphql_vars! {},
|
||||||
})
|
})
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
@ -718,7 +718,7 @@ mod test {
|
||||||
id: "foo".to_string(),
|
id: "foo".to_string(),
|
||||||
payload: StartPayload {
|
payload: StartPayload {
|
||||||
query: "{context}".to_string(),
|
query: "{context}".to_string(),
|
||||||
variables: Variables::default(),
|
variables: graphql_vars! {},
|
||||||
operation_name: None,
|
operation_name: None,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
@ -752,7 +752,7 @@ mod test {
|
||||||
);
|
);
|
||||||
|
|
||||||
conn.send(ClientMessage::ConnectionInit {
|
conn.send(ClientMessage::ConnectionInit {
|
||||||
payload: Variables::default(),
|
payload: graphql_vars! {},
|
||||||
})
|
})
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
@ -763,7 +763,7 @@ mod test {
|
||||||
id: "foo".to_string(),
|
id: "foo".to_string(),
|
||||||
payload: StartPayload {
|
payload: StartPayload {
|
||||||
query: "subscription Foo {context}".to_string(),
|
query: "subscription Foo {context}".to_string(),
|
||||||
variables: Variables::default(),
|
variables: graphql_vars! {},
|
||||||
operation_name: None,
|
operation_name: None,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
@ -785,7 +785,7 @@ mod test {
|
||||||
id: "bar".to_string(),
|
id: "bar".to_string(),
|
||||||
payload: StartPayload {
|
payload: StartPayload {
|
||||||
query: "subscription Bar {context}".to_string(),
|
query: "subscription Bar {context}".to_string(),
|
||||||
variables: Variables::default(),
|
variables: graphql_vars! {},
|
||||||
operation_name: None,
|
operation_name: None,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
@ -820,15 +820,12 @@ mod test {
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_init_params_ok() {
|
async fn test_init_params_ok() {
|
||||||
let mut conn = Connection::new(new_test_schema(), |params: Variables| async move {
|
let mut conn = Connection::new(new_test_schema(), |params: Variables| async move {
|
||||||
assert_eq!(params.get("foo"), Some(&InputValue::scalar("bar")));
|
assert_eq!(params.get("foo"), Some(&graphql_input_value!("bar")));
|
||||||
Ok(ConnectionConfig::new(Context(1))) as Result<_, Infallible>
|
Ok(ConnectionConfig::new(Context(1))) as Result<_, Infallible>
|
||||||
});
|
});
|
||||||
|
|
||||||
conn.send(ClientMessage::ConnectionInit {
|
conn.send(ClientMessage::ConnectionInit {
|
||||||
payload: [("foo".to_string(), InputValue::scalar("bar".to_string()))]
|
payload: graphql_vars! {"foo": "bar"},
|
||||||
.iter()
|
|
||||||
.cloned()
|
|
||||||
.collect(),
|
|
||||||
})
|
})
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
@ -839,15 +836,12 @@ mod test {
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_init_params_error() {
|
async fn test_init_params_error() {
|
||||||
let mut conn = Connection::new(new_test_schema(), |params: Variables| async move {
|
let mut conn = Connection::new(new_test_schema(), |params: Variables| async move {
|
||||||
assert_eq!(params.get("foo"), Some(&InputValue::scalar("bar")));
|
assert_eq!(params.get("foo"), Some(&graphql_input_value!("bar")));
|
||||||
Err(io::Error::new(io::ErrorKind::Other, "init error"))
|
Err(io::Error::new(io::ErrorKind::Other, "init error"))
|
||||||
});
|
});
|
||||||
|
|
||||||
conn.send(ClientMessage::ConnectionInit {
|
conn.send(ClientMessage::ConnectionInit {
|
||||||
payload: [("foo".to_string(), InputValue::scalar("bar".to_string()))]
|
payload: graphql_vars! {"foo": "bar"},
|
||||||
.iter()
|
|
||||||
.cloned()
|
|
||||||
.collect(),
|
|
||||||
})
|
})
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
@ -872,7 +866,7 @@ mod test {
|
||||||
);
|
);
|
||||||
|
|
||||||
conn.send(ClientMessage::ConnectionInit {
|
conn.send(ClientMessage::ConnectionInit {
|
||||||
payload: Variables::default(),
|
payload: graphql_vars! {},
|
||||||
})
|
})
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
@ -883,7 +877,7 @@ mod test {
|
||||||
id: "foo".to_string(),
|
id: "foo".to_string(),
|
||||||
payload: StartPayload {
|
payload: StartPayload {
|
||||||
query: "subscription Foo {never}".to_string(),
|
query: "subscription Foo {never}".to_string(),
|
||||||
variables: Variables::default(),
|
variables: graphql_vars! {},
|
||||||
operation_name: None,
|
operation_name: None,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
@ -894,7 +888,7 @@ mod test {
|
||||||
id: "bar".to_string(),
|
id: "bar".to_string(),
|
||||||
payload: StartPayload {
|
payload: StartPayload {
|
||||||
query: "subscription Bar {never}".to_string(),
|
query: "subscription Bar {never}".to_string(),
|
||||||
variables: Variables::default(),
|
variables: graphql_vars! {},
|
||||||
operation_name: None,
|
operation_name: None,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
@ -917,7 +911,7 @@ mod test {
|
||||||
);
|
);
|
||||||
|
|
||||||
conn.send(ClientMessage::ConnectionInit {
|
conn.send(ClientMessage::ConnectionInit {
|
||||||
payload: Variables::default(),
|
payload: graphql_vars! {},
|
||||||
})
|
})
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
@ -928,7 +922,7 @@ mod test {
|
||||||
id: "foo".to_string(),
|
id: "foo".to_string(),
|
||||||
payload: StartPayload {
|
payload: StartPayload {
|
||||||
query: "asd".to_string(),
|
query: "asd".to_string(),
|
||||||
variables: Variables::default(),
|
variables: graphql_vars! {},
|
||||||
operation_name: None,
|
operation_name: None,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
@ -958,7 +952,7 @@ mod test {
|
||||||
);
|
);
|
||||||
|
|
||||||
conn.send(ClientMessage::ConnectionInit {
|
conn.send(ClientMessage::ConnectionInit {
|
||||||
payload: Variables::default(),
|
payload: graphql_vars! {},
|
||||||
})
|
})
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
@ -981,7 +975,7 @@ mod test {
|
||||||
);
|
);
|
||||||
|
|
||||||
conn.send(ClientMessage::ConnectionInit {
|
conn.send(ClientMessage::ConnectionInit {
|
||||||
payload: Variables::default(),
|
payload: graphql_vars! {},
|
||||||
})
|
})
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
@ -991,7 +985,7 @@ mod test {
|
||||||
id: "foo".to_string(),
|
id: "foo".to_string(),
|
||||||
payload: StartPayload {
|
payload: StartPayload {
|
||||||
query: "{context}".to_string(),
|
query: "{context}".to_string(),
|
||||||
variables: Variables::default(),
|
variables: graphql_vars! {},
|
||||||
operation_name: None,
|
operation_name: None,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
@ -1020,7 +1014,7 @@ mod test {
|
||||||
);
|
);
|
||||||
|
|
||||||
conn.send(ClientMessage::ConnectionInit {
|
conn.send(ClientMessage::ConnectionInit {
|
||||||
payload: Variables::default(),
|
payload: graphql_vars! {},
|
||||||
})
|
})
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
@ -1031,7 +1025,7 @@ mod test {
|
||||||
id: "foo".to_string(),
|
id: "foo".to_string(),
|
||||||
payload: StartPayload {
|
payload: StartPayload {
|
||||||
query: "subscription Foo {error}".to_string(),
|
query: "subscription Foo {error}".to_string(),
|
||||||
variables: Variables::default(),
|
variables: graphql_vars! {},
|
||||||
operation_name: None,
|
operation_name: None,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
@ -1044,7 +1038,7 @@ mod test {
|
||||||
payload: DataPayload { data, errors },
|
payload: DataPayload { data, errors },
|
||||||
} => {
|
} => {
|
||||||
assert_eq!(id, "foo");
|
assert_eq!(id, "foo");
|
||||||
assert_eq!(data, graphql_value!({ "error": None }),);
|
assert_eq!(data, graphql_value!({ "error": null }));
|
||||||
assert_eq!(errors.len(), 1);
|
assert_eq!(errors.len(), 1);
|
||||||
}
|
}
|
||||||
msg @ _ => panic!("expected data, got: {:?}", msg),
|
msg @ _ => panic!("expected data, got: {:?}", msg),
|
||||||
|
|
|
@ -159,7 +159,7 @@ mod test {
|
||||||
serde_json::to_string(&ServerMessage::Data {
|
serde_json::to_string(&ServerMessage::Data {
|
||||||
id: "foo".to_string(),
|
id: "foo".to_string(),
|
||||||
payload: DataPayload {
|
payload: DataPayload {
|
||||||
data: graphql_value!(None),
|
data: graphql_value!(null),
|
||||||
errors: vec![],
|
errors: vec![],
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
|
@ -261,10 +261,10 @@ mod whole_responses_stream {
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn with_error() {
|
async fn with_error() {
|
||||||
let expected: Vec<ExecutionOutput<DefaultScalarValue>> = vec![ExecutionOutput {
|
let expected: Vec<ExecutionOutput<DefaultScalarValue>> = vec![ExecutionOutput {
|
||||||
data: graphql_value!(None),
|
data: graphql_value!(null),
|
||||||
errors: vec![ExecutionError::at_origin(FieldError::new(
|
errors: vec![ExecutionError::at_origin(FieldError::new(
|
||||||
"field error",
|
"field error",
|
||||||
graphql_value!(None),
|
graphql_value!(null),
|
||||||
))],
|
))],
|
||||||
}];
|
}];
|
||||||
let expected = serde_json::to_string(&expected).unwrap();
|
let expected = serde_json::to_string(&expected).unwrap();
|
||||||
|
@ -273,7 +273,7 @@ mod whole_responses_stream {
|
||||||
Value::Null,
|
Value::Null,
|
||||||
vec![ExecutionError::at_origin(FieldError::new(
|
vec![ExecutionError::at_origin(FieldError::new(
|
||||||
"field error",
|
"field error",
|
||||||
graphql_value!(None),
|
graphql_value!(null),
|
||||||
))],
|
))],
|
||||||
)
|
)
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
|
@ -286,7 +286,7 @@ mod whole_responses_stream {
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn value_null() {
|
async fn value_null() {
|
||||||
let expected: Vec<ExecutionOutput<DefaultScalarValue>> =
|
let expected: Vec<ExecutionOutput<DefaultScalarValue>> =
|
||||||
vec![ExecutionOutput::from_data(graphql_value!(None))];
|
vec![ExecutionOutput::from_data(graphql_value!(null))];
|
||||||
let expected = serde_json::to_string(&expected).unwrap();
|
let expected = serde_json::to_string(&expected).unwrap();
|
||||||
|
|
||||||
let result = whole_responses_stream::<DefaultScalarValue>(Value::Null, vec![])
|
let result = whole_responses_stream::<DefaultScalarValue>(Value::Null, vec![])
|
||||||
|
@ -333,7 +333,7 @@ mod whole_responses_stream {
|
||||||
let expected: Vec<ExecutionOutput<DefaultScalarValue>> = vec![
|
let expected: Vec<ExecutionOutput<DefaultScalarValue>> = vec![
|
||||||
ExecutionOutput::from_data(graphql_value!(1)),
|
ExecutionOutput::from_data(graphql_value!(1)),
|
||||||
ExecutionOutput::from_data(graphql_value!(2)),
|
ExecutionOutput::from_data(graphql_value!(2)),
|
||||||
ExecutionOutput::from_data(graphql_value!(None)),
|
ExecutionOutput::from_data(graphql_value!(null)),
|
||||||
ExecutionOutput::from_data(graphql_value!(4)),
|
ExecutionOutput::from_data(graphql_value!(4)),
|
||||||
];
|
];
|
||||||
let expected = serde_json::to_string(&expected).unwrap();
|
let expected = serde_json::to_string(&expected).unwrap();
|
||||||
|
|
Loading…
Reference in a new issue