@@ -5,29 +5,42 @@ extern crate serde_derive;
55extern crate serde;
66extern crate serde_json;
77
8+ use graphql_client:: GraphQLQuery ;
9+
810#[ derive( GraphQLQuery ) ]
911#[ graphql(
1012 query_path = "tests/operation_selection/queries.graphql" ,
1113 schema_path = "tests/operation_selection/schema.graphql" ,
12- response_derives = "Debug" ,
14+ response_derives = "Debug,PartialEq " ,
1315) ]
1416pub struct Heights ;
1517
1618#[ derive( GraphQLQuery ) ]
1719#[ graphql(
1820 query_path = "tests/operation_selection/queries.graphql" ,
1921 schema_path = "tests/operation_selection/schema.graphql" ,
20- response_derives = "Debug" ,
22+ response_derives = "Debug,PartialEq " ,
2123) ]
2224pub struct Echo ;
2325
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+
2435const HEIGHTS_RESPONSE : & ' static str = r##"{"mountainHeight": 224, "buildingHeight": 12}"## ;
2536const ECHO_RESPONSE : & ' static str = r##"{"echo": "tiramisù"}"## ;
2637
2738#[ test]
2839fn operation_selection_works ( ) {
2940 let heights_response_data: heights:: ResponseData =
3041 serde_json:: from_str ( HEIGHTS_RESPONSE ) . unwrap ( ) ;
42+ let heights_unrelated_response_data: unrelated:: ResponseData =
43+ serde_json:: from_str ( HEIGHTS_RESPONSE ) . unwrap ( ) ;
3144 let echo_response_data: echo:: ResponseData = serde_json:: from_str ( ECHO_RESPONSE ) . unwrap ( ) ;
3245
3346 let _echo_variables = echo:: Variables {
@@ -38,11 +51,51 @@ fn operation_selection_works() {
3851 building_id : "12" . to_string ( ) ,
3952 mountain_name : Some ( "canigou" . to_string ( ) ) ,
4053 } ;
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+ } ;
4166
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+ } ;
4591
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+ ) ;
48101}
0 commit comments