@@ -5,29 +5,42 @@ extern crate serde_derive;
5
5
extern crate serde;
6
6
extern crate serde_json;
7
7
8
+ use graphql_client:: GraphQLQuery ;
9
+
8
10
#[ derive( GraphQLQuery ) ]
9
11
#[ graphql(
10
12
query_path = "tests/operation_selection/queries.graphql" ,
11
13
schema_path = "tests/operation_selection/schema.graphql" ,
12
- response_derives = "Debug" ,
14
+ response_derives = "Debug,PartialEq " ,
13
15
) ]
14
16
pub struct Heights ;
15
17
16
18
#[ derive( GraphQLQuery ) ]
17
19
#[ graphql(
18
20
query_path = "tests/operation_selection/queries.graphql" ,
19
21
schema_path = "tests/operation_selection/schema.graphql" ,
20
- response_derives = "Debug" ,
22
+ response_derives = "Debug,PartialEq " ,
21
23
) ]
22
24
pub struct Echo ;
23
25
26
+ // The default is the first operation so this should be the same as Heights
27
+ #[ derive( GraphQLQuery ) ]
28
+ #[ graphql(
29
+ query_path = "tests/operation_selection/queries.graphql" ,
30
+ schema_path = "tests/operation_selection/schema.graphql" ,
31
+ response_derives = "Debug,PartialEq" ,
32
+ ) ]
33
+ pub struct Unrelated ;
34
+
24
35
const HEIGHTS_RESPONSE : & ' static str = r##"{"mountainHeight": 224, "buildingHeight": 12}"## ;
25
36
const ECHO_RESPONSE : & ' static str = r##"{"echo": "tiramisù"}"## ;
26
37
27
38
#[ test]
28
39
fn operation_selection_works ( ) {
29
40
let heights_response_data: heights:: ResponseData =
30
41
serde_json:: from_str ( HEIGHTS_RESPONSE ) . unwrap ( ) ;
42
+ let heights_unrelated_response_data: unrelated:: ResponseData =
43
+ serde_json:: from_str ( HEIGHTS_RESPONSE ) . unwrap ( ) ;
31
44
let echo_response_data: echo:: ResponseData = serde_json:: from_str ( ECHO_RESPONSE ) . unwrap ( ) ;
32
45
33
46
let _echo_variables = echo:: Variables {
@@ -38,11 +51,51 @@ fn operation_selection_works() {
38
51
building_id : "12" . to_string ( ) ,
39
52
mountain_name : Some ( "canigou" . to_string ( ) ) ,
40
53
} ;
54
+ let _unrelated_variables = unrelated:: Variables {
55
+ building_id : "12" . to_string ( ) ,
56
+ mountain_name : Some ( "canigou" . to_string ( ) ) ,
57
+ } ;
58
+
59
+ let expected_echo = echo:: ResponseData {
60
+ echo : Some ( "tiramisù" . to_string ( ) ) ,
61
+ } ;
62
+ let expected_heights = heights:: ResponseData {
63
+ mountain_height : Some ( 224 ) ,
64
+ building_height : Some ( 12 ) ,
65
+ } ;
41
66
42
- let expected_echo = r##"ResponseData { echo: Some("tiramisù") }"## ;
43
- let expected_heights =
44
- r##"ResponseData { mountain_height: Some(224), building_height: Some(12) }"## ;
67
+ let expected_heights_unrelated = unrelated:: ResponseData {
68
+ mountain_height : Some ( 224 ) ,
69
+ building_height : Some ( 12 ) ,
70
+ } ;
71
+
72
+ assert_eq ! ( expected_echo, echo_response_data) ;
73
+ assert_eq ! ( expected_heights, heights_response_data) ;
74
+ assert_eq ! ( expected_heights_unrelated, heights_unrelated_response_data) ;
75
+ }
76
+
77
+ #[ test]
78
+ fn operation_name_is_correct ( ) {
79
+ let echo_variables = echo:: Variables {
80
+ msg : Some ( "hi" . to_string ( ) ) ,
81
+ } ;
82
+
83
+ let height_variables = heights:: Variables {
84
+ building_id : "12" . to_string ( ) ,
85
+ mountain_name : Some ( "canigou" . to_string ( ) ) ,
86
+ } ;
87
+ let unrelated_variables = unrelated:: Variables {
88
+ building_id : "12" . to_string ( ) ,
89
+ mountain_name : Some ( "canigou" . to_string ( ) ) ,
90
+ } ;
45
91
46
- assert_eq ! ( expected_echo, format!( "{:?}" , echo_response_data) ) ;
47
- assert_eq ! ( expected_heights, format!( "{:?}" , heights_response_data) ) ;
92
+ assert_eq ! ( Echo :: build_query( echo_variables) . operation_name, "Echo" ) ;
93
+ assert_eq ! (
94
+ Heights :: build_query( height_variables) . operation_name,
95
+ "Heights"
96
+ ) ;
97
+ assert_eq ! (
98
+ Unrelated :: build_query( unrelated_variables) . operation_name,
99
+ "Heights"
100
+ ) ;
48
101
}
0 commit comments