Skip to content

Commit 71986d1

Browse files
committed
Add selected_operation test case
1 parent e7f2ebb commit 71986d1

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

graphql_client/tests/operation_selection.rs

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ use graphql_client::GraphQLQuery;
1111
#[graphql(
1212
query_path = "tests/operation_selection/queries.graphql",
1313
schema_path = "tests/operation_selection/schema.graphql",
14-
response_derives = "Debug,PartialEq",
14+
response_derives = "Debug,PartialEq"
1515
)]
1616
pub struct Heights;
1717

1818
#[derive(GraphQLQuery)]
1919
#[graphql(
2020
query_path = "tests/operation_selection/queries.graphql",
2121
schema_path = "tests/operation_selection/schema.graphql",
22-
response_derives = "Debug,PartialEq",
22+
response_derives = "Debug,PartialEq"
2323
)]
2424
pub struct Echo;
2525

@@ -28,10 +28,19 @@ pub struct Echo;
2828
#[graphql(
2929
query_path = "tests/operation_selection/queries.graphql",
3030
schema_path = "tests/operation_selection/schema.graphql",
31-
response_derives = "Debug,PartialEq",
31+
response_derives = "Debug,PartialEq"
3232
)]
3333
pub struct Unrelated;
3434

35+
#[derive(GraphQLQuery)]
36+
#[graphql(
37+
query_path = "tests/operation_selection/queries.graphql",
38+
schema_path = "tests/operation_selection/schema.graphql",
39+
response_derives = "Debug,PartialEq",
40+
selected_operation = "Echo"
41+
)]
42+
pub struct SelectedOperation;
43+
3544
const HEIGHTS_RESPONSE: &'static str = r##"{"mountainHeight": 224, "buildingHeight": 12}"##;
3645
const ECHO_RESPONSE: &'static str = r##"{"echo": "tiramisù"}"##;
3746

@@ -42,6 +51,8 @@ fn operation_selection_works() {
4251
let heights_unrelated_response_data: unrelated::ResponseData =
4352
serde_json::from_str(HEIGHTS_RESPONSE).unwrap();
4453
let echo_response_data: echo::ResponseData = serde_json::from_str(ECHO_RESPONSE).unwrap();
54+
let selected_operation_response_data: selected_operation::ResponseData =
55+
serde_json::from_str(ECHO_RESPONSE).unwrap();
4556

4657
let _echo_variables = echo::Variables {
4758
msg: Some("hi".to_string()),
@@ -56,9 +67,14 @@ fn operation_selection_works() {
5667
mountain_name: Some("canigou".to_string()),
5768
};
5869

70+
let _selected_operation_variables = selected_operation::Variables {
71+
msg: Some("hi".to_string()),
72+
};
73+
5974
let expected_echo = echo::ResponseData {
6075
echo: Some("tiramisù".to_string()),
6176
};
77+
6278
let expected_heights = heights::ResponseData {
6379
mountain_height: Some(224),
6480
building_height: Some(12),
@@ -69,9 +85,17 @@ fn operation_selection_works() {
6985
building_height: Some(12),
7086
};
7187

88+
let expected_selected_operation = selected_operation::ResponseData {
89+
echo: Some("tiramisù".to_string()),
90+
};
91+
7292
assert_eq!(expected_echo, echo_response_data);
7393
assert_eq!(expected_heights, heights_response_data);
7494
assert_eq!(expected_heights_unrelated, heights_unrelated_response_data);
95+
assert_eq!(
96+
expected_selected_operation,
97+
selected_operation_response_data
98+
);
7599
}
76100

77101
#[test]

0 commit comments

Comments
 (0)