Skip to content

Commit d4fda78

Browse files
authored
Fixes panic when spreading untyped union fragment. (#946)
* Fixes panic when spreading untyped union fragment. closes #945 * Fix ci breakage with explicit lifetime annotation in juniper_rocket_async
1 parent 2241da7 commit d4fda78

File tree

5 files changed

+100
-3
lines changed

5 files changed

+100
-3
lines changed
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
use juniper::*;
2+
3+
struct Query;
4+
5+
#[graphql_object]
6+
impl Query {
7+
fn artoo() -> Character {
8+
Character::Droid(Droid {
9+
id: 1,
10+
name: "R2-D2".to_owned(),
11+
sensor_color: "red".to_owned(),
12+
})
13+
}
14+
}
15+
16+
#[derive(GraphQLUnion)]
17+
enum Character {
18+
Droid(Droid),
19+
#[allow(dead_code)]
20+
Human(Human),
21+
}
22+
23+
#[derive(GraphQLObject)]
24+
struct Human {
25+
pub id: i32,
26+
pub name: String,
27+
pub eye_color: String,
28+
}
29+
30+
#[derive(GraphQLObject)]
31+
struct Droid {
32+
pub id: i32,
33+
pub name: String,
34+
pub sensor_color: String,
35+
}
36+
37+
type Schema = RootNode<'static, Query, EmptyMutation<()>, EmptySubscription<()>>;
38+
39+
#[tokio::test]
40+
async fn test_fragment_on_interface() {
41+
let query = r#"
42+
query Query {
43+
artoo {
44+
...CharacterFragment
45+
}
46+
}
47+
48+
fragment CharacterFragment on Character {
49+
__typename
50+
... on Human {
51+
id
52+
eyeColor
53+
}
54+
... on Droid {
55+
id
56+
sensorColor
57+
}
58+
}
59+
"#;
60+
61+
let (res, errors) = execute(
62+
query,
63+
None,
64+
&Schema::new(Query, EmptyMutation::new(), EmptySubscription::new()),
65+
&Variables::new(),
66+
&(),
67+
)
68+
.await
69+
.unwrap();
70+
71+
assert_eq!(errors.len(), 0);
72+
assert_eq!(
73+
res,
74+
graphql_value!({
75+
"artoo": {"__typename": "Droid", "id": 1, "sensorColor": "red"}
76+
}),
77+
);
78+
79+
let (res, errors) = execute_sync(
80+
query,
81+
None,
82+
&Schema::new(Query, EmptyMutation::new(), EmptySubscription::new()),
83+
&Variables::new(),
84+
&(),
85+
)
86+
.unwrap();
87+
88+
assert_eq!(errors.len(), 0);
89+
assert_eq!(
90+
res,
91+
graphql_value!({
92+
"artoo": {"__typename": "Droid", "id": 1, "sensorColor": "red"}
93+
}),
94+
);
95+
}

integration_tests/juniper_tests/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,6 @@ mod issue_922;
2525
#[cfg(test)]
2626
mod issue_925;
2727
#[cfg(test)]
28+
mod issue_945;
29+
#[cfg(test)]
2830
mod pre_parse;

juniper/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# master
22

3-
- No changes yet
3+
- Fix panic on spreading untyped union fragments ([#945](https://github.com/graphql-rust/juniper/issues/945))
44

55
# [[0.15.6] 2021-06-07](https://github.com/graphql-rust/juniper/releases/tag/juniper-v0.15.6)
66

juniper/src/types/async_await.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ where
313313
let sub_result = instance
314314
.resolve_into_type_async(
315315
info,
316-
fragment.type_condition.item,
316+
&concrete_type_name,
317317
Some(&fragment.selection_set[..]),
318318
&sub_exec,
319319
)

juniper/src/types/base.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ where
521521
{
522522
let sub_result = instance.resolve_into_type(
523523
info,
524-
fragment.type_condition.item,
524+
&concrete_type_name,
525525
Some(&fragment.selection_set[..]),
526526
&sub_exec,
527527
);

0 commit comments

Comments
 (0)