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
This commit is contained in:
Idan Mintz 2021-06-14 00:52:41 -07:00 committed by GitHub
parent 2241da7901
commit d4fda786ba
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 100 additions and 3 deletions

View file

@ -0,0 +1,95 @@
use juniper::*;
struct Query;
#[graphql_object]
impl Query {
fn artoo() -> Character {
Character::Droid(Droid {
id: 1,
name: "R2-D2".to_owned(),
sensor_color: "red".to_owned(),
})
}
}
#[derive(GraphQLUnion)]
enum Character {
Droid(Droid),
#[allow(dead_code)]
Human(Human),
}
#[derive(GraphQLObject)]
struct Human {
pub id: i32,
pub name: String,
pub eye_color: String,
}
#[derive(GraphQLObject)]
struct Droid {
pub id: i32,
pub name: String,
pub sensor_color: String,
}
type Schema = RootNode<'static, Query, EmptyMutation<()>, EmptySubscription<()>>;
#[tokio::test]
async fn test_fragment_on_interface() {
let query = r#"
query Query {
artoo {
...CharacterFragment
}
}
fragment CharacterFragment on Character {
__typename
... on Human {
id
eyeColor
}
... on Droid {
id
sensorColor
}
}
"#;
let (res, errors) = execute(
query,
None,
&Schema::new(Query, EmptyMutation::new(), EmptySubscription::new()),
&Variables::new(),
&(),
)
.await
.unwrap();
assert_eq!(errors.len(), 0);
assert_eq!(
res,
graphql_value!({
"artoo": {"__typename": "Droid", "id": 1, "sensorColor": "red"}
}),
);
let (res, errors) = execute_sync(
query,
None,
&Schema::new(Query, EmptyMutation::new(), EmptySubscription::new()),
&Variables::new(),
&(),
)
.unwrap();
assert_eq!(errors.len(), 0);
assert_eq!(
res,
graphql_value!({
"artoo": {"__typename": "Droid", "id": 1, "sensorColor": "red"}
}),
);
}

View file

@ -25,4 +25,6 @@ mod issue_922;
#[cfg(test)]
mod issue_925;
#[cfg(test)]
mod issue_945;
#[cfg(test)]
mod pre_parse;

View file

@ -1,6 +1,6 @@
# master
- No changes yet
- Fix panic on spreading untyped union fragments ([#945](https://github.com/graphql-rust/juniper/issues/945))
# [[0.15.6] 2021-06-07](https://github.com/graphql-rust/juniper/releases/tag/juniper-v0.15.6)

View file

@ -313,7 +313,7 @@ where
let sub_result = instance
.resolve_into_type_async(
info,
fragment.type_condition.item,
&concrete_type_name,
Some(&fragment.selection_set[..]),
&sub_exec,
)

View file

@ -521,7 +521,7 @@ where
{
let sub_result = instance.resolve_into_type(
info,
fragment.type_condition.item,
&concrete_type_name,
Some(&fragment.selection_set[..]),
&sub_exec,
);