Skip to content

Commit d769960

Browse files
committed
Showcase
1 parent 2089ba6 commit d769960

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
//! Checks that error is propagated from a fragment the same way as without it.
2+
//! See [#1287](https://github.com/graphql-rust/juniper/issues/1287) for details.
3+
4+
use juniper::{EmptyMutation, EmptySubscription, Variables, graphql_object};
5+
6+
struct MyObject;
7+
8+
#[graphql_object]
9+
impl MyObject {
10+
fn erroring_field() -> Result<i32, &'static str> {
11+
Err("This field always errors")
12+
}
13+
}
14+
15+
struct Query;
16+
17+
#[graphql_object]
18+
impl Query {
19+
fn my_object() -> MyObject {
20+
MyObject {}
21+
}
22+
23+
fn just_a_field() -> i32 {
24+
3
25+
}
26+
}
27+
28+
type Schema = juniper::RootNode<'static, Query, EmptyMutation, EmptySubscription>;
29+
30+
#[tokio::test]
31+
async fn error_propagates_same_way() {
32+
// language=GraphQL
33+
let without_fragment = r"{
34+
myObject { erroringField }
35+
justAField
36+
}";
37+
// language=GraphQL
38+
let with_fragment = r"
39+
query {
40+
myObject {
41+
...MyObjectFragment
42+
}
43+
justAField
44+
}
45+
46+
fragment MyObjectFragment on MyObject {
47+
erroringField
48+
}
49+
";
50+
51+
let (expected, _) = juniper::execute(
52+
without_fragment,
53+
None,
54+
&Schema::new(Query, EmptyMutation::new(), EmptySubscription::new()),
55+
&Variables::new(),
56+
&(),
57+
)
58+
.await
59+
.unwrap();
60+
let (actual, _) = juniper::execute(
61+
with_fragment,
62+
None,
63+
&Schema::new(Query, EmptyMutation::new(), EmptySubscription::new()),
64+
&Variables::new(),
65+
&(),
66+
)
67+
.await
68+
.unwrap();
69+
70+
assert_eq!(actual, expected);
71+
}

0 commit comments

Comments
 (0)