Skip to content

Commit e237572

Browse files
fix: ci clippy and fmt
1 parent ae83817 commit e237572

File tree

6 files changed

+41
-22
lines changed

6 files changed

+41
-22
lines changed

graphql_client_cli/src/generate.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,13 @@ pub(crate) fn generate_code(params: CliCodegenParams) -> CliResult<()> {
9393

9494
options.set_custom_scalars_module(custom_scalars_module);
9595
}
96-
96+
9797
if let Some(custom_variable_types) = custom_variable_types {
98-
options.set_custom_variable_types(custom_variable_types.split(",").map(String::from).collect());
98+
options.set_custom_variable_types(
99+
custom_variable_types.split(",").map(String::from).collect(),
100+
);
99101
}
100-
102+
101103
if let Some(custom_response_type) = custom_response_type {
102104
options.set_custom_response_type(custom_response_type);
103105
}

graphql_client_cli/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,8 @@ fn main() -> CliResult<()> {
139139
selected_operation,
140140
custom_scalars_module,
141141
fragments_other_variant,
142-
external_enums,
143-
custom_variable_types,
142+
external_enums,
143+
custom_variable_types,
144144
custom_response_type,
145145
} => generate::generate_code(generate::CliCodegenParams {
146146
query_path,

graphql_client_codegen/src/codegen/inputs.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@ pub(super) fn generate_input_object_definitions(
1919
all_used_types
2020
.inputs(query.schema)
2121
.map(|(input_id, input)| {
22-
let custom_variable_type = query.query.variables.iter()
22+
let custom_variable_type = query
23+
.query
24+
.variables
25+
.iter()
2326
.enumerate()
24-
.find(|(_, v) | v.r#type.id.as_input_id().is_some_and(|i| i == input_id))
25-
.map(|(index, _)| custom_variable_types.get(index))
26-
.flatten();
27+
.find(|(_, v)| v.r#type.id.as_input_id().is_some_and(|i| i == input_id))
28+
.and_then(|(index, _)| custom_variable_types.get(index));
2729
if let Some(custom_type) = custom_variable_type {
2830
generate_type_def(input, options, custom_type)
2931
} else if input.is_one_of {
@@ -38,7 +40,7 @@ pub(super) fn generate_input_object_definitions(
3840
fn generate_type_def(
3941
input: &StoredInputType,
4042
options: &GraphQLClientCodegenOptions,
41-
custom_type: &String,
43+
custom_type: &str,
4244
) -> TokenStream {
4345
let custom_type = syn::parse_str::<syn::Path>(custom_type).unwrap();
4446
let normalized_name = options.normalization().input_name(input.name.as_str());

graphql_client_codegen/src/codegen/selection.rs

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ use crate::{
1212
},
1313
schema::{Schema, TypeId},
1414
type_qualifiers::GraphqlTypeQualifier,
15-
GraphQLClientCodegenOptions,
16-
GeneralError,
15+
GeneralError, GraphQLClientCodegenOptions,
1716
};
1817
use heck::*;
1918
use proc_macro2::{Ident, Span, TokenStream};
@@ -43,12 +42,27 @@ pub(crate) fn render_response_data_fields<'a>(
4342
if let Some(custom_response_type) = options.custom_response_type() {
4443
if operation.selection_set.len() == 1 {
4544
let selection_id = operation.selection_set[0];
46-
let selection_field = query.query.get_selection(selection_id).as_selected_field()
47-
.ok_or_else(|| GeneralError(format!("Custom response type {custom_response_type} will only work on fields")))?;
48-
calculate_custom_response_type_selection(&mut expanded_selection, response_data_type_id, custom_response_type, selection_id, selection_field);
45+
let selection_field = query
46+
.query
47+
.get_selection(selection_id)
48+
.as_selected_field()
49+
.ok_or_else(|| {
50+
GeneralError(format!(
51+
"Custom response type {custom_response_type} will only work on fields"
52+
))
53+
})?;
54+
calculate_custom_response_type_selection(
55+
&mut expanded_selection,
56+
response_data_type_id,
57+
custom_response_type,
58+
selection_id,
59+
selection_field,
60+
);
4961
return Ok(expanded_selection);
5062
} else {
51-
return Err(GeneralError(format!("Custom response type {custom_response_type} requires single selection field")));
63+
return Err(GeneralError(format!(
64+
"Custom response type {custom_response_type} requires single selection field"
65+
)));
5266
}
5367
}
5468

@@ -66,10 +80,10 @@ pub(crate) fn render_response_data_fields<'a>(
6680
fn calculate_custom_response_type_selection<'a>(
6781
context: &mut ExpandedSelection<'a>,
6882
struct_id: ResponseTypeId,
69-
custom_response_type: &'a String,
83+
custom_response_type: &'a str,
7084
selection_id: SelectionId,
71-
field: &'a SelectedField)
72-
{
85+
field: &'a SelectedField,
86+
) {
7387
let (graphql_name, rust_name) = context.field_name(field);
7488
let struct_name_string = full_path_prefix(selection_id, context.query);
7589
let field = context.query.schema.get_field(field.field_id);
@@ -88,7 +102,7 @@ fn calculate_custom_response_type_selection<'a>(
88102
name: struct_name_string.into(),
89103
});
90104
context.push_type_alias(TypeAlias {
91-
name: custom_response_type.as_str(),
105+
name: custom_response_type,
92106
struct_id,
93107
boxed: false,
94108
});

graphql_client_codegen/src/tests/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ fn blended_custom_types_works() {
6262
match r {
6363
Ok(_) => {
6464
// Variables and returns should be replaced with custom types
65-
assert!(generated_code.contains("pub type SearchQuerySearch = external_crate :: Transaction"));
65+
assert!(generated_code
66+
.contains("pub type SearchQuerySearch = external_crate :: Transaction"));
6667
assert!(generated_code.contains("pub type extern_ = external_crate :: ID"));
6768
}
6869
Err(e) => {

graphql_query_derive/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ fn build_graphql_client_derive_options(
106106
if let Some(custom_variable_types) = custom_variable_types {
107107
options.set_custom_variable_types(custom_variable_types);
108108
}
109-
109+
110110
if let Some(custom_response_type) = custom_response_type {
111111
options.set_custom_response_type(custom_response_type);
112112
}

0 commit comments

Comments
 (0)