2020-04-22 13:31:44 +00:00
|
|
|
use async_graphql::*;
|
|
|
|
|
|
|
|
#[async_std::test]
|
|
|
|
pub async fn test_directive_skip() {
|
|
|
|
struct QueryRoot;
|
|
|
|
|
2020-09-18 00:52:13 +00:00
|
|
|
#[Object]
|
2020-04-22 13:31:44 +00:00
|
|
|
impl QueryRoot {
|
|
|
|
pub async fn value(&self) -> i32 {
|
|
|
|
10
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let schema = Schema::new(QueryRoot, EmptyMutation, EmptySubscription);
|
|
|
|
let resp = schema
|
|
|
|
.execute(
|
|
|
|
r#"
|
|
|
|
{
|
|
|
|
value1: value @skip(if: true)
|
|
|
|
value2: value @skip(if: false)
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
)
|
2020-09-10 11:35:48 +00:00
|
|
|
.await;
|
2020-04-22 13:31:44 +00:00
|
|
|
assert_eq!(
|
|
|
|
resp.data,
|
|
|
|
serde_json::json!({
|
|
|
|
"value2": 10,
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[async_std::test]
|
|
|
|
pub async fn test_directive_include() {
|
|
|
|
struct QueryRoot;
|
|
|
|
|
2020-09-18 00:52:13 +00:00
|
|
|
#[Object]
|
2020-04-22 13:31:44 +00:00
|
|
|
impl QueryRoot {
|
|
|
|
pub async fn value(&self) -> i32 {
|
|
|
|
10
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let schema = Schema::new(QueryRoot, EmptyMutation, EmptySubscription);
|
|
|
|
let resp = schema
|
|
|
|
.execute(
|
|
|
|
r#"
|
|
|
|
{
|
|
|
|
value1: value @include(if: true)
|
|
|
|
value2: value @include(if: false)
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
)
|
2020-09-10 11:35:48 +00:00
|
|
|
.await;
|
2020-04-22 13:31:44 +00:00
|
|
|
assert_eq!(
|
|
|
|
resp.data,
|
|
|
|
serde_json::json!({
|
|
|
|
"value1": 10,
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
2020-08-06 06:52:54 +00:00
|
|
|
|
|
|
|
#[async_std::test]
|
|
|
|
pub async fn test_directive_ifdef() {
|
|
|
|
struct QueryRoot;
|
|
|
|
|
2020-09-18 00:52:13 +00:00
|
|
|
#[Object]
|
2020-08-06 06:52:54 +00:00
|
|
|
impl QueryRoot {
|
|
|
|
pub async fn value1(&self) -> i32 {
|
|
|
|
10
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct MutationRoot;
|
|
|
|
|
2020-09-18 00:52:13 +00:00
|
|
|
#[Object]
|
2020-08-06 06:52:54 +00:00
|
|
|
impl MutationRoot {
|
|
|
|
pub async fn action1(&self) -> i32 {
|
|
|
|
10
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let schema = Schema::new(QueryRoot, MutationRoot, EmptySubscription);
|
|
|
|
let resp = schema
|
|
|
|
.execute(
|
|
|
|
r#"
|
|
|
|
{
|
|
|
|
value1 @ifdef
|
|
|
|
value2 @ifdef
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
)
|
2020-09-10 11:35:48 +00:00
|
|
|
.await;
|
2020-08-06 06:52:54 +00:00
|
|
|
assert_eq!(
|
|
|
|
resp.data,
|
|
|
|
serde_json::json!({
|
|
|
|
"value1": 10,
|
|
|
|
})
|
|
|
|
);
|
|
|
|
|
|
|
|
let resp = schema
|
|
|
|
.execute(
|
|
|
|
r#"
|
|
|
|
mutation {
|
|
|
|
action1 @ifdef
|
|
|
|
action2 @ifdef
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
)
|
2020-09-10 11:35:48 +00:00
|
|
|
.await;
|
2020-08-06 06:52:54 +00:00
|
|
|
assert_eq!(
|
|
|
|
resp.data,
|
|
|
|
serde_json::json!({
|
|
|
|
"action1": 10,
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|