Skip to content

Commit 6df0545

Browse files
committed
general refactoring
1 parent 9e51754 commit 6df0545

File tree

6 files changed

+20
-23
lines changed

6 files changed

+20
-23
lines changed

graphql_client_cli/src/generate.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ pub(crate) fn generate_code(params: CliCodegenParams) -> CliResult<()> {
7777
options.set_custom_scalars_module(custom_scalars_module);
7878
}
7979

80-
let gen = generate_module_token_stream(query_path.clone(), &schema_path, options)
80+
let gen = generate_module_token_stream(&query_path, &schema_path, &options)
8181
.map_err(|err| Error::message(format!("Error generating module code: {err}")))?;
8282

8383
let generated_code = format!("{WARNING_SUPPRESSION}\n{gen}");

graphql_client_codegen/src/lib.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,11 @@ fn get_set_schema_from_file(schema_path: &std::path::Path) -> Schema {
9696

9797
/// Generates Rust code given a path to a query file, a path to a schema file, and options.
9898
pub fn generate_module_token_stream(
99-
query_path: std::path::PathBuf,
99+
query_path: &std::path::Path,
100100
schema_path: &std::path::Path,
101-
options: GraphQLClientCodegenOptions,
101+
options: &GraphQLClientCodegenOptions,
102102
) -> Result<TokenStream, BoxError> {
103-
let query = get_set_query_from_file(query_path.as_path());
103+
let query = get_set_query_from_file(query_path);
104104
let schema = get_set_schema_from_file(schema_path);
105105

106106
generate_module_token_stream_inner(&query, &schema, options)
@@ -110,7 +110,7 @@ pub fn generate_module_token_stream(
110110
pub fn generate_module_token_stream_from_string(
111111
query_string: &str,
112112
schema_path: &std::path::Path,
113-
options: GraphQLClientCodegenOptions,
113+
options: &GraphQLClientCodegenOptions,
114114
) -> Result<TokenStream, BoxError> {
115115
let query = (query_string.to_string(), query_document(query_string)?);
116116
let schema = get_set_schema_from_file(schema_path);
@@ -122,7 +122,7 @@ pub fn generate_module_token_stream_from_string(
122122
fn generate_module_token_stream_inner(
123123
query: &(String, QueryDocument),
124124
schema: &Schema,
125-
options: GraphQLClientCodegenOptions,
125+
options: &GraphQLClientCodegenOptions,
126126
) -> Result<TokenStream, BoxError> {
127127
let (query_string, query_document) = query;
128128

@@ -157,7 +157,7 @@ fn generate_module_token_stream_inner(
157157
schema,
158158
resolved_query: &query,
159159
operation: &operation.1.name,
160-
options: &options,
160+
options,
161161
}
162162
.to_token_stream()?;
163163
modules.push(generated);

graphql_client_codegen/src/schema.rs

+6-9
Original file line numberDiff line numberDiff line change
@@ -362,15 +362,12 @@ impl Schema {
362362
}
363363

364364
fn find_type_id(&self, type_name: &str) -> TypeId {
365-
match self.names.get(type_name) {
366-
Some(id) => *id,
367-
None => {
368-
panic!(
369-
"graphql-client-codegen internal error: failed to resolve TypeId for `{}°.",
370-
type_name
371-
);
372-
}
373-
}
365+
self.names.get(type_name).copied().unwrap_or_else(|| {
366+
panic!(
367+
"graphql-client-codegen internal error: failed to resolve TypeId for `{}°.",
368+
type_name
369+
)
370+
})
374371
}
375372
}
376373

graphql_client_codegen/src/schema/json_conversion.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ fn ingest_interface(schema: &mut Schema, iface: &mut FullType) {
172172
schema,
173173
&mut field.type_.as_mut().expect("take field type").type_ref,
174174
),
175-
deprecation: if let Some(true) = field.is_deprecated {
175+
deprecation: if field.is_deprecated == Some(true) {
176176
Some(field.deprecation_reason.clone())
177177
} else {
178178
None
@@ -207,7 +207,7 @@ fn ingest_object(schema: &mut Schema, object: &mut FullType) {
207207
schema,
208208
&mut field.type_.as_mut().expect("take field type").type_ref,
209209
),
210-
deprecation: if let Some(true) = field.is_deprecated {
210+
deprecation: if field.is_deprecated == Some(true) {
211211
Some(field.deprecation_reason.clone())
212212
} else {
213213
None

graphql_client_codegen/src/tests/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ fn schema_with_keywords_works() {
2323
let options = GraphQLClientCodegenOptions::new(CodegenMode::Cli);
2424

2525
let generated_tokens =
26-
generate_module_token_stream_from_string(query_string, &schema_path, options)
26+
generate_module_token_stream_from_string(query_string, &schema_path, &options)
2727
.expect("Generate keywords module");
2828

2929
let generated_code = generated_tokens.to_string();
@@ -52,7 +52,7 @@ fn fragments_other_variant_should_generate_unknown_other_variant() {
5252
options.set_fragments_other_variant(true);
5353

5454
let generated_tokens =
55-
generate_module_token_stream_from_string(query_string, &schema_path, options)
55+
generate_module_token_stream_from_string(query_string, &schema_path, &options)
5656
.expect("Generate foobars module");
5757

5858
let generated_code = generated_tokens.to_string();
@@ -80,7 +80,7 @@ fn fragments_other_variant_false_should_not_generate_unknown_other_variant() {
8080
options.set_fragments_other_variant(false);
8181

8282
let generated_tokens =
83-
generate_module_token_stream_from_string(query_string, &schema_path, options)
83+
generate_module_token_stream_from_string(query_string, &schema_path, &options)
8484
.expect("Generate foobars module token stream");
8585

8686
let generated_code = generated_tokens.to_string();
@@ -108,7 +108,7 @@ fn skip_serializing_none_should_generate_serde_skip_serializing() {
108108
options.set_skip_serializing_none(true);
109109

110110
let generated_tokens =
111-
generate_module_token_stream_from_string(query_string, &schema_path, options)
111+
generate_module_token_stream_from_string(query_string, &schema_path, &options)
112112
.expect("Generate foobars module");
113113

114114
let generated_code = generated_tokens.to_string();

graphql_query_derive/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ fn graphql_query_derive_inner(
2929
let (query_path, schema_path) = build_query_and_schema_path(&ast)?;
3030
let options = build_graphql_client_derive_options(&ast, query_path.clone())?;
3131

32-
generate_module_token_stream(query_path, &schema_path, options)
32+
generate_module_token_stream(&query_path, &schema_path, &options)
3333
.map(Into::into)
3434
.map_err(|err| {
3535
syn::Error::new_spanned(ast, format!("Failed to generate GraphQLQuery impl: {err}"))

0 commit comments

Comments
 (0)