File tree Expand file tree Collapse file tree 1 file changed +71
-0
lines changed Expand file tree Collapse file tree 1 file changed +71
-0
lines changed Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments