Skip to content

Commit 8a2a29e

Browse files
committed
Fix fragments on unions
1 parent 5af572e commit 8a2a29e

File tree

22 files changed

+105
-184
lines changed

22 files changed

+105
-184
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/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: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,22 +57,25 @@ fn fragment_on_union() {
5757
let expected = fragment_on_union::ResponseData {
5858
names: Some(vec![
5959
fragment_on_union::FragmentOnUnionNames::Person(
60-
fragment_on_union::MyQueryNamesOnPerson {
60+
fragment_on_union::FragmentOnUnionNamesOnPerson {
6161
first_name: "Audrey".to_string(),
62-
last_name: Some("Lorde".to_string()),
6362
},
6463
),
65-
fragment_on_union::FragmentOnUnionNames::Dog(fragment_on_union::MyQueryNamesOnDog {
66-
name: "Laïka".to_string(),
67-
}),
64+
fragment_on_union::FragmentOnUnionNames::Dog(
65+
fragment_on_union::FragmentOnUnionNamesOnDog {
66+
name: "Laïka".to_string(),
67+
},
68+
),
6869
fragment_on_union::FragmentOnUnionNames::Organization(
69-
fragment_on_union::MyQueryNamesOnOrganization {
70+
fragment_on_union::FragmentOnUnionNamesOnOrganization {
7071
title: "Mozilla".to_string(),
7172
},
7273
),
73-
fragment_on_union::MyQueryNames::Dog(fragment_on_union::MyQueryNamesOnDog {
74-
name: "Norbert".to_string(),
75-
}),
74+
fragment_on_union::FragmentOnUnionNames::Dog(
75+
fragment_on_union::FragmentOnUnionNamesOnDog {
76+
name: "Norbert".to_string(),
77+
},
78+
),
7679
]),
7780
};
7881

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,

graphql_client_codegen/src/codegen.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ pub(crate) fn response_for_query(
6060
GqlFragment {
6161
name: &fragment.name,
6262
selection: Selection::from(&fragment.selection_set),
63-
on: on,
63+
on,
6464
is_required: false.into(),
6565
},
6666
);

graphql_client_codegen/src/field_type.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,7 @@ impl<'schema> ::std::convert::From<&'schema graphql_parser::schema::Type> for Fi
8383
}
8484
}
8585

86-
fn from_schema_type_inner<'schema>(
87-
inner: &'schema graphql_parser::schema::Type,
88-
non_null: bool,
89-
) -> FieldType<'schema> {
86+
fn from_schema_type_inner(inner: &graphql_parser::schema::Type, non_null: bool) -> FieldType {
9087
match inner {
9188
graphql_parser::schema::Type::ListType(inner) => {
9289
let inner = from_schema_type_inner(&*inner, false);

0 commit comments

Comments
 (0)