Skip to content

Commit 4682fe2

Browse files
authored
Add missing marker trait impls for container types (#847)
1 parent 516c720 commit 4682fe2

File tree

2 files changed

+276
-35
lines changed

2 files changed

+276
-35
lines changed

integration_tests/juniper_tests/src/codegen/union_derive.rs

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1472,3 +1472,91 @@ mod full_featured_struct {
14721472
);
14731473
}
14741474
}
1475+
1476+
mod issue_845 {
1477+
use std::sync::Arc;
1478+
1479+
use super::*;
1480+
1481+
#[derive(GraphQLUnion)]
1482+
enum Character {
1483+
A(Box<Human>),
1484+
B(Arc<Droid>),
1485+
}
1486+
1487+
enum QueryRoot {
1488+
Human,
1489+
Droid,
1490+
}
1491+
1492+
#[graphql_object]
1493+
impl QueryRoot {
1494+
fn character(&self) -> Character {
1495+
match self {
1496+
Self::Human => Character::A(Box::new(Human {
1497+
id: "human-32".to_string(),
1498+
home_planet: "earth".to_string(),
1499+
})),
1500+
Self::Droid => Character::B(Arc::new(Droid {
1501+
id: "droid-99".to_string(),
1502+
primary_function: "run".to_string(),
1503+
})),
1504+
}
1505+
}
1506+
}
1507+
1508+
const DOC: &str = r#"{
1509+
character {
1510+
... on Human {
1511+
humanId: id
1512+
homePlanet
1513+
}
1514+
... on Droid {
1515+
droidId: id
1516+
primaryFunction
1517+
}
1518+
}
1519+
}"#;
1520+
1521+
#[tokio::test]
1522+
async fn resolves_human() {
1523+
let schema = schema(QueryRoot::Human);
1524+
1525+
assert_eq!(
1526+
execute(DOC, None, &schema, &Variables::new(), &()).await,
1527+
Ok((
1528+
graphql_value!({"character": {"humanId": "human-32", "homePlanet": "earth"}}),
1529+
vec![],
1530+
)),
1531+
);
1532+
}
1533+
1534+
#[tokio::test]
1535+
async fn resolves_droid() {
1536+
let schema = schema(QueryRoot::Droid);
1537+
1538+
assert_eq!(
1539+
execute(DOC, None, &schema, &Variables::new(), &()).await,
1540+
Ok((
1541+
graphql_value!({"character": {"droidId": "droid-99", "primaryFunction": "run"}}),
1542+
vec![],
1543+
)),
1544+
);
1545+
}
1546+
1547+
#[tokio::test]
1548+
async fn is_graphql_union() {
1549+
const DOC: &str = r#"{
1550+
__type(name: "Character") {
1551+
kind
1552+
}
1553+
}"#;
1554+
1555+
let schema = schema(QueryRoot::Human);
1556+
1557+
assert_eq!(
1558+
execute(DOC, None, &schema, &Variables::new(), &()).await,
1559+
Ok((graphql_value!({"__type": {"kind": "UNION"}}), vec![])),
1560+
);
1561+
}
1562+
}

0 commit comments

Comments
 (0)