Skip to content

Commit f6f5b6c

Browse files
committed
Tie the struct name to the operation name in derives
The generated code was too confusing when they were disjoint. This will be documented in a subsequent commit.
1 parent 1c42792 commit f6f5b6c

29 files changed

+255
-343
lines changed

graphql_client/tests/custom_scalars.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ type NetworkAddress = Ipv4Addr;
1616
query_path = "tests/custom_scalars/query.graphql",
1717
schema_path = "tests/custom_scalars/schema.graphql"
1818
)]
19-
pub struct CustomScalarsQuery;
19+
pub struct CustomScalarQuery;
2020

2121
#[test]
2222
fn custom_scalars() {
@@ -25,7 +25,7 @@ fn custom_scalars() {
2525
});
2626

2727
let valid_addr =
28-
serde_json::from_value::<custom_scalars_query::ResponseData>(valid_response).unwrap();
28+
serde_json::from_value::<custom_scalar_query::ResponseData>(valid_response).unwrap();
2929

3030
assert_eq!(
3131
valid_addr.address.unwrap(),
@@ -36,7 +36,5 @@ fn custom_scalars() {
3636
"address": "localhost",
3737
});
3838

39-
assert!(
40-
serde_json::from_value::<custom_scalars_query::ResponseData>(invalid_response).is_err()
41-
);
39+
assert!(serde_json::from_value::<custom_scalar_query::ResponseData>(invalid_response).is_err());
4240
}

graphql_client/tests/deprecation.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ fn deprecation_allow() {
3636
// as deprecated.
3737
#![deny(deprecated)]
3838
let _ = allow_deprecation::ResponseData {
39-
current_user: Some(allow_deprecation::TestCurrentUser {
39+
current_user: Some(allow_deprecation::AllowDeprecationCurrentUser {
4040
id: Some("abcd".to_owned()),
4141
name: Some("Angela Merkel".to_owned()),
4242
deprecated_with_reason: Some("foo".to_owned()),
@@ -48,7 +48,7 @@ fn deprecation_allow() {
4848
#[test]
4949
fn deprecation_deny() {
5050
let _ = deny_deprecation::ResponseData {
51-
current_user: Some(deny_deprecation::TestCurrentUser {
51+
current_user: Some(deny_deprecation::DenyDeprecationCurrentUser {
5252
id: Some("abcd".to_owned()),
5353
name: Some("Angela Merkel".to_owned()),
5454
// Notice the deprecated fields are not included here.
@@ -63,7 +63,7 @@ fn deprecation_deny() {
6363
fn deprecation_warn() {
6464
#![allow(deprecated)]
6565
let _ = warn_deprecation::ResponseData {
66-
current_user: Some(warn_deprecation::TestCurrentUser {
66+
current_user: Some(warn_deprecation::WarnDeprecationCurrentUser {
6767
id: Some("abcd".to_owned()),
6868
name: Some("Angela Merkel".to_owned()),
6969
deprecated_with_reason: Some("foo".to_owned()),

graphql_client/tests/deprecation/query.graphql

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,22 @@
1-
query Test {
1+
query DenyDeprecation {
2+
currentUser {
3+
name
4+
id
5+
deprecatedWithReason
6+
deprecatedNoReason
7+
}
8+
}
9+
10+
query AllowDeprecation {
11+
currentUser {
12+
name
13+
id
14+
deprecatedWithReason
15+
deprecatedNoReason
16+
}
17+
}
18+
19+
query WarnDeprecation {
220
currentUser {
321
name
422
id

graphql_client/tests/input_object_variables/input_object_variables_query.graphql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
query VariablesQuery($msg: Message) {
1+
query InputObjectVariablesQuery($msg: Message) {
22
echo(message: $msg) {
33
result
44
}

graphql_client/tests/input_object_variables/input_object_variables_query_defaults.graphql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
query VariablesQuery(
1+
query DefaultInputObjectVariablesQuery(
22
$msg: Message = { to: { email: "[email protected]" } }
33
) {
44
echo(message: $msg) {

graphql_client/tests/interfaces.rs

Lines changed: 49 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,25 +26,31 @@ fn interface_deserialization() {
2626

2727
let expected = ResponseData {
2828
everything: Some(vec![
29-
MyQueryEverything {
29+
InterfaceQueryEverything {
3030
name: "Audrey Lorde".to_string(),
31-
on: MyQueryEverythingOn::Person(MyQueryEverythingOnPerson {
31+
on: InterfaceQueryEverythingOn::Person(InterfaceQueryEverythingOnPerson {
3232
birthday: Some("1934-02-18".to_string()),
3333
}),
3434
},
35-
MyQueryEverything {
35+
InterfaceQueryEverything {
3636
name: "Laïka".to_string(),
37-
on: MyQueryEverythingOn::Dog(MyQueryEverythingOnDog { is_good_dog: true }),
37+
on: InterfaceQueryEverythingOn::Dog(InterfaceQueryEverythingOnDog {
38+
is_good_dog: true,
39+
}),
3840
},
39-
MyQueryEverything {
41+
InterfaceQueryEverything {
4042
name: "Mozilla".to_string(),
41-
on: MyQueryEverythingOn::Organization(MyQueryEverythingOnOrganization {
42-
industry: Industry::OTHER,
43-
}),
43+
on: InterfaceQueryEverythingOn::Organization(
44+
InterfaceQueryEverythingOnOrganization {
45+
industry: Industry::OTHER,
46+
},
47+
),
4448
},
45-
MyQueryEverything {
49+
InterfaceQueryEverything {
4650
name: "Norbert".to_string(),
47-
on: MyQueryEverythingOn::Dog(MyQueryEverythingOnDog { is_good_dog: true }),
51+
on: InterfaceQueryEverythingOn::Dog(InterfaceQueryEverythingOnDog {
52+
is_good_dog: true,
53+
}),
4854
},
4955
]),
5056
};
@@ -56,7 +62,7 @@ fn interface_deserialization() {
5662
#[graphql(
5763
query_path = "tests/interfaces/interface_not_on_everything_query.graphql",
5864
schema_path = "tests/interfaces/interface_schema.graphql",
59-
response_derives = "Debug"
65+
response_derives = "Debug,PartialEq"
6066
)]
6167
pub struct InterfaceNotOnEverythingQuery;
6268

@@ -65,15 +71,43 @@ const RESPONSE_NOT_ON_EVERYTHING: &'static str =
6571

6672
#[test]
6773
fn interface_not_on_everything_deserialization() {
68-
println!("{:?}", RESPONSE);
74+
use interface_not_on_everything_query::*;
75+
6976
let response_data: interface_not_on_everything_query::ResponseData =
7077
serde_json::from_str(RESPONSE_NOT_ON_EVERYTHING).unwrap();
7178

72-
println!("{:?}", response_data);
79+
let expected = ResponseData {
80+
everything: Some(vec![
81+
InterfaceNotOnEverythingQueryEverything {
82+
name: "Audrey Lorde".to_string(),
83+
on: InterfaceNotOnEverythingQueryEverythingOn::Person(
84+
InterfaceNotOnEverythingQueryEverythingOnPerson {
85+
birthday: Some("1934-02-18".to_string()),
86+
},
87+
),
88+
},
89+
InterfaceNotOnEverythingQueryEverything {
90+
name: "Laïka".to_string(),
91+
on: InterfaceNotOnEverythingQueryEverythingOn::Dog,
92+
},
93+
InterfaceNotOnEverythingQueryEverything {
94+
name: "Mozilla".to_string(),
95+
on: InterfaceNotOnEverythingQueryEverythingOn::Organization(
96+
InterfaceNotOnEverythingQueryEverythingOnOrganization {
97+
industry: Industry::OTHER,
98+
},
99+
),
100+
},
101+
InterfaceNotOnEverythingQueryEverything {
102+
name: "Norbert".to_string(),
103+
on: InterfaceNotOnEverythingQueryEverythingOn::Dog,
104+
},
105+
]),
106+
};
73107

74-
let expected = r##"ResponseData { everything: Some([MyQueryEverything { name: "Audrey Lorde", on: Person(MyQueryEverythingOnPerson { birthday: Some("1934-02-18") }) }, MyQueryEverything { name: "Laïka", on: Dog }, MyQueryEverything { name: "Mozilla", on: Organization(MyQueryEverythingOnOrganization { industry: OTHER }) }, MyQueryEverything { name: "Norbert", on: Dog }]) }"##;
108+
// let expected = r##"ResponseData { everything: Some([InterfaceQueryEverything { name: "Audrey Lorde", on: Person(InterfaceQueryEverythingOnPerson { birthday: Some("1934-02-18") }) }, InterfaceQueryEverything { name: "Laïka", on: Dog }, InterfaceQueryEverything { name: "Mozilla", on: Organization(InterfaceQueryEverythingOnOrganization { industry: OTHER }) }, InterfaceQueryEverything { name: "Norbert", on: Dog }]) }"##;
75109

76-
assert_eq!(format!("{:?}", response_data), expected);
110+
assert_eq!(response_data, expected);
77111

78112
assert_eq!(response_data.everything.map(|names| names.len()), Some(4));
79113
}

graphql_client/tests/interfaces/interface_not_on_everything_query.graphql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
query MyQuery {
1+
query InterfaceNotOnEverythingQuery {
22
everything {
33
__typename
44
name

graphql_client/tests/interfaces/interface_query.graphql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
query MyQuery {
1+
query InterfaceQuery {
22
everything {
33
__typename
44
name

graphql_client/tests/interfaces/interface_with_type_refining_fragment_query.graphql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ fragment Birthday on Person {
22
birthday
33
}
44

5-
query MyQuery {
5+
query QueryOnInterface {
66
everything {
77
__typename
88
name

graphql_client/tests/json_schema.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub struct WithSchema1;
1818

1919
#[derive(GraphQLQuery)]
2020
#[graphql(
21-
query_path = "tests/json_schema/query.graphql",
21+
query_path = "tests/json_schema/query_2.graphql",
2222
schema_path = "tests/json_schema/schema_2.json",
2323
response_derives = "Debug"
2424
)]

0 commit comments

Comments
 (0)