Skip to content

Commit 708781a

Browse files
authored
Merge pull request #207 from graphql-rust/snake-case-fragment
Fix fragments on unions
2 parents bfb27f0 + 8a2a29e commit 708781a

30 files changed

+861
-647
lines changed

graphql_client/tests/input_object_variables.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub struct InputObjectVariablesQuery;
1515

1616
#[test]
1717
fn input_object_variables_query_variables_struct() {
18-
input_object_variables_query::Variables {
18+
let _ = input_object_variables_query::Variables {
1919
msg: Some(input_object_variables_query::Message {
2020
content: None,
2121
to: Some(input_object_variables_query::Recipient {

graphql_client/tests/interfaces.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ fn fragment_in_interface() {
103103
name: "Audrey Lorde".to_string(),
104104
public_status: PublicStatus {
105105
display_name: false,
106+
on: PublicStatusOn::Person,
106107
},
107108
on: InterfaceWithFragmentQueryEverythingOn::Person(
108109
InterfaceWithFragmentQueryEverythingOnPerson {
@@ -112,21 +113,28 @@ fn fragment_in_interface() {
112113
},
113114
InterfaceWithFragmentQueryEverything {
114115
name: "Laïka".to_string(),
115-
public_status: PublicStatus { display_name: true },
116+
public_status: PublicStatus {
117+
display_name: true,
118+
on: PublicStatusOn::Dog
119+
},
116120
on: InterfaceWithFragmentQueryEverythingOn::Dog(
117121
InterfaceWithFragmentQueryEverythingOnDog { is_good_dog: true }
118122
)
119123
},
120124
InterfaceWithFragmentQueryEverything {
121125
name: "Mozilla".to_string(),
122126
public_status: PublicStatus {
123-
display_name: false
127+
display_name: false,
128+
on: PublicStatusOn::Organization
124129
},
125130
on: InterfaceWithFragmentQueryEverythingOn::Organization,
126131
},
127132
InterfaceWithFragmentQueryEverything {
128133
name: "Norbert".to_string(),
129-
public_status: PublicStatus { display_name: true },
134+
public_status: PublicStatus {
135+
display_name: true,
136+
on: PublicStatusOn::Dog
137+
},
130138
on: InterfaceWithFragmentQueryEverythingOn::Dog(
131139
InterfaceWithFragmentQueryEverythingOnDog { is_good_dog: true }
132140
),

graphql_client/tests/interfaces/interface_with_fragment_query.graphql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
fragment PublicStatus on Named {
2+
__typename
23
displayName
34
}
45

graphql_client/tests/introspection.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,9 @@ extern crate serde_json;
1414
pub struct IntrospectionQuery;
1515

1616
#[test]
17-
fn introspection_schema() {
18-
()
19-
}
17+
fn introspection_schema() {}
2018

21-
const INTROSPECTION_RESPONSE: &'static str =
22-
include_str!("./introspection/introspection_response.json");
19+
const INTROSPECTION_RESPONSE: &str = include_str!("./introspection/introspection_response.json");
2320

2421
#[test]
2522
fn leading_underscores_are_preserved() {

graphql_client/tests/operation_selection.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ pub struct Unrelated;
4141
)]
4242
pub struct SelectedOperation;
4343

44-
const HEIGHTS_RESPONSE: &'static str = r##"{"mountainHeight": 224, "buildingHeight": 12}"##;
45-
const ECHO_RESPONSE: &'static str = r##"{"echo": "tiramisù"}"##;
44+
const HEIGHTS_RESPONSE: &str = r##"{"mountainHeight": 224, "buildingHeight": 12}"##;
45+
const ECHO_RESPONSE: &str = r##"{"echo": "tiramisù"}"##;
4646

4747
#[test]
4848
fn operation_selection_works() {

graphql_client/tests/scalar_variables.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub struct ScalarVariablesQuery;
1414

1515
#[test]
1616
fn scalar_variables_query_variables_struct() {
17-
scalar_variables_query::Variables {
17+
let _ = scalar_variables_query::Variables {
1818
msg: "hello".to_string(),
1919
reps: Some(32),
2020
};

graphql_client/tests/union_query.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@ const RESPONSE: &'static str = include_str!("unions/union_query_response.json");
1515
)]
1616
pub struct UnionQuery;
1717

18+
#[derive(GraphQLQuery)]
19+
#[graphql(
20+
query_path = "tests/unions/union_query.graphql",
21+
schema_path = "tests/unions/union_schema.graphql",
22+
response_derives = "PartialEq, Debug"
23+
)]
24+
pub struct FragmentOnUnion;
25+
1826
#[test]
1927
fn union_query_deserialization() {
2028
let response_data: union_query::ResponseData = serde_json::from_str(RESPONSE).unwrap();
@@ -41,3 +49,35 @@ fn union_query_deserialization() {
4149

4250
assert_eq!(response_data.names.map(|names| names.len()), Some(4));
4351
}
52+
53+
#[test]
54+
fn fragment_on_union() {
55+
let response_data: fragment_on_union::ResponseData = serde_json::from_str(RESPONSE).unwrap();
56+
57+
let expected = fragment_on_union::ResponseData {
58+
names: Some(vec![
59+
fragment_on_union::FragmentOnUnionNames::Person(
60+
fragment_on_union::FragmentOnUnionNamesOnPerson {
61+
first_name: "Audrey".to_string(),
62+
},
63+
),
64+
fragment_on_union::FragmentOnUnionNames::Dog(
65+
fragment_on_union::FragmentOnUnionNamesOnDog {
66+
name: "Laïka".to_string(),
67+
},
68+
),
69+
fragment_on_union::FragmentOnUnionNames::Organization(
70+
fragment_on_union::FragmentOnUnionNamesOnOrganization {
71+
title: "Mozilla".to_string(),
72+
},
73+
),
74+
fragment_on_union::FragmentOnUnionNames::Dog(
75+
fragment_on_union::FragmentOnUnionNamesOnDog {
76+
name: "Norbert".to_string(),
77+
},
78+
),
79+
]),
80+
};
81+
82+
assert_eq!(response_data, expected);
83+
}

graphql_client/tests/unions/union_query.graphql

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,22 @@ query MyQuery {
1313
}
1414
}
1515
}
16+
17+
fragment NamesFragment on NamedThing {
18+
__typename
19+
... on Dog {
20+
name
21+
}
22+
... on Person {
23+
firstName
24+
}
25+
... on Organization {
26+
title
27+
}
28+
}
29+
30+
query FragmentOnUnion {
31+
names {
32+
...NamesFragment
33+
}
34+
}

graphql_client_cli/src/generate.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ use failure;
22
use graphql_client_codegen::*;
33
use std::fs::File;
44
use std::io::Write as IoWrite;
5-
use std::path::PathBuf;
5+
use std::path::{Path, PathBuf};
66
use syn;
77

88
#[allow(clippy::too_many_arguments)]
99
pub fn generate_code(
1010
query_path: PathBuf,
11-
schema_path: PathBuf,
11+
schema_path: &Path,
1212
module_name: String,
1313
selected_operation: Option<String>,
1414
additional_derives: Option<String>,
@@ -47,7 +47,7 @@ pub fn generate_code(
4747
module_visibility,
4848
};
4949

50-
let gen = generate_module_token_stream(query_path, schema_path, Some(options))?;
50+
let gen = generate_module_token_stream(query_path, &schema_path, Some(options))?;
5151

5252
let mut file = File::create(output.clone())?;
5353

graphql_client_cli/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ fn main() -> Result<(), failure::Error> {
9696
output,
9797
} => generate::generate_code(
9898
query_path,
99-
schema_path,
99+
&schema_path,
100100
module_name,
101101
selected_operation,
102102
additional_derives,

0 commit comments

Comments
 (0)