Skip to content

Commit 0f9fff9

Browse files
authored
Merge pull request #424 from mathstuf/rustfmt-fixes
2 parents f2faa9f + 1583e7c commit 0f9fff9

File tree

10 files changed

+84
-32
lines changed

10 files changed

+84
-32
lines changed

examples/web/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ fn add_load_more_button() {
6060
);
6161
btn.add_event_listener_with_callback(
6262
"click",
63-
&on_click
63+
on_click
6464
.as_ref()
6565
.dyn_ref()
6666
.expect_throw("on click is not a Function"),

graphql-introspection-query/src/introspection_response.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ pub struct FullType {
141141
#[serde(rename_all = "camelCase")]
142142
pub struct FullTypeFieldsArgs {
143143
#[serde(flatten)]
144+
#[allow(dead_code)]
144145
input_value: InputValue,
145146
}
146147

@@ -242,6 +243,7 @@ pub struct SchemaTypes {
242243
#[serde(rename_all = "camelCase")]
243244
pub struct SchemaDirectivesArgs {
244245
#[serde(flatten)]
246+
#[allow(dead_code)]
245247
input_value: InputValue,
246248
}
247249

@@ -261,6 +263,7 @@ pub struct Schema {
261263
pub mutation_type: Option<SchemaMutationType>,
262264
pub subscription_type: Option<SchemaSubscriptionType>,
263265
pub types: Option<Vec<Option<SchemaTypes>>>,
266+
#[allow(dead_code)]
264267
directives: Option<Vec<Option<SchemaDirectives>>>,
265268
}
266269

graphql_client/src/lib.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ extern crate graphql_query_derive;
2323
#[doc(hidden)]
2424
pub use graphql_query_derive::*;
2525

26-
#[cfg(any(feature = "reqwest", feature = "reqwest-rustls", feature = "reqwest-blocking"))]
26+
#[cfg(any(
27+
feature = "reqwest",
28+
feature = "reqwest-rustls",
29+
feature = "reqwest-blocking"
30+
))]
2731
pub mod reqwest;
2832

2933
use serde::{Deserialize, Serialize};
@@ -225,7 +229,7 @@ impl Display for Error {
225229
.as_ref()
226230
.and_then(|locations| locations.iter().next())
227231
.cloned()
228-
.unwrap_or_else(Location::default);
232+
.unwrap_or_default();
229233

230234
write!(f, "{}:{}:{}: {}", path, loc.line, loc.column, self.message)
231235
}

graphql_client/src/reqwest.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pub async fn post_graphql<Q: GraphQLQuery, U: reqwest::IntoUrl>(
1313
let body = Q::build_query(variables);
1414
let reqwest_response = client.post(url).json(&body).send().await?;
1515

16-
Ok(reqwest_response.json().await?)
16+
reqwest_response.json().await
1717
}
1818

1919
/// Use the provided reqwest::Client to post a GraphQL request.

graphql_client_codegen/src/query.rs

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ where
119119
on: schema.find_type(on.as_ref()).ok_or_else(|| {
120120
QueryValidationError::new(format!(
121121
"Could not find type {} for fragment {} in schema.",
122-
on.as_ref(), fragment.name.as_ref()
122+
on.as_ref(),
123+
fragment.name.as_ref(),
123124
))
124125
})?,
125126
selection_set: Vec::new(),
@@ -136,7 +137,12 @@ where
136137
})?;
137138
let resolved_operation: ResolvedOperation = ResolvedOperation {
138139
object_id: on,
139-
name: m.name.as_ref().expect("mutation without name").as_ref().into(),
140+
name: m
141+
.name
142+
.as_ref()
143+
.expect("mutation without name")
144+
.as_ref()
145+
.into(),
140146
_operation_type: operations::OperationType::Mutation,
141147
selection_set: Vec::with_capacity(m.selection_set.items.len()),
142148
};
@@ -210,7 +216,8 @@ where
210216
let on = schema.find_type(on.as_ref()).ok_or_else(|| {
211217
QueryValidationError::new(format!(
212218
"Could not find type `{}` referenced by fragment `{}`",
213-
on.as_ref(), fragment_definition.name.as_ref()
219+
on.as_ref(),
220+
fragment_definition.name.as_ref(),
214221
))
215222
})?;
216223

@@ -446,7 +453,9 @@ where
446453
})?;
447454
let on = schema.get_object(on);
448455

449-
let (id, _) = query.find_operation(m.name.as_ref().map(|name| name.as_ref()).unwrap()).unwrap();
456+
let (id, _) = query
457+
.find_operation(m.name.as_ref().map(|name| name.as_ref()).unwrap())
458+
.unwrap();
450459

451460
resolve_variables(query, &m.variable_definitions, schema, id);
452461
resolve_object_selection(
@@ -459,7 +468,9 @@ where
459468
}
460469
graphql_parser::query::OperationDefinition::Query(q) => {
461470
let on = schema.get_object(schema.query_type());
462-
let (id, _) = query.find_operation(q.name.as_ref().map(|name| name.as_ref()).unwrap()).unwrap();
471+
let (id, _) = query
472+
.find_operation(q.name.as_ref().map(|name| name.as_ref()).unwrap())
473+
.unwrap();
463474

464475
resolve_variables(query, &q.variable_definitions, schema, id);
465476
resolve_object_selection(
@@ -473,7 +484,9 @@ where
473484
graphql_parser::query::OperationDefinition::Subscription(s) => {
474485
let on = schema.subscription_type().ok_or_else(|| QueryValidationError::new("Query contains a subscription operation, but the schema has no subscription type.".into()))?;
475486
let on = schema.get_object(on);
476-
let (id, _) = query.find_operation(s.name.as_ref().map(|name| name.as_ref()).unwrap()).unwrap();
487+
let (id, _) = query
488+
.find_operation(s.name.as_ref().map(|name| name.as_ref()).unwrap())
489+
.unwrap();
477490

478491
resolve_variables(query, &s.variable_definitions, schema, id);
479492
resolve_object_selection(
@@ -652,8 +665,7 @@ fn resolve_variables<'doc, T>(
652665
variables: &[graphql_parser::query::VariableDefinition<'doc, T>],
653666
schema: &Schema,
654667
operation_id: OperationId,
655-
)
656-
where
668+
) where
657669
T: graphql_parser::query::Text<'doc>,
658670
{
659671
for var in variables {

graphql_client_codegen/src/query/selection.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,11 +228,18 @@ impl Selection {
228228
.as_ref()
229229
.map(|alias| alias.to_upper_camel_case())
230230
.unwrap_or_else(move || {
231-
query.schema.get_field(field.field_id).name.to_upper_camel_case()
231+
query
232+
.schema
233+
.get_field(field.field_id)
234+
.name
235+
.to_upper_camel_case()
232236
}),
233237
Selection::InlineFragment(inline_fragment) => format!(
234238
"On{}",
235-
inline_fragment.type_id.name(query.schema).to_upper_camel_case()
239+
inline_fragment
240+
.type_id
241+
.name(query.schema)
242+
.to_upper_camel_case()
236243
),
237244
other => unreachable!("{:?} in to_path_segment", other),
238245
}

graphql_client_codegen/src/schema/graphql_parser_conversion.rs

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ use super::{Schema, StoredInputFieldType, TypeId};
22
use crate::schema::resolve_field_type;
33
use graphql_parser::schema::{self as parser, Definition, Document, TypeDefinition, UnionType};
44

5-
pub(super) fn build_schema<'doc, T>(mut src: graphql_parser::schema::Document<'doc, T>) -> super::Schema
5+
pub(super) fn build_schema<'doc, T>(
6+
mut src: graphql_parser::schema::Document<'doc, T>,
7+
) -> super::Schema
68
where
79
T: graphql_parser::query::Text<'doc>,
810
T::Value: AsRef<str>,
@@ -161,11 +163,16 @@ where
161163
schema.stored_unions.push(stored_union);
162164
}
163165

164-
fn ingest_object<'doc, T>(schema: &mut Schema, obj: &mut graphql_parser::schema::ObjectType<'doc, T>)
165-
where
166+
fn ingest_object<'doc, T>(
167+
schema: &mut Schema,
168+
obj: &mut graphql_parser::schema::ObjectType<'doc, T>,
169+
) where
166170
T: graphql_parser::query::Text<'doc>,
167171
{
168-
let object_id = schema.find_type_id(obj.name.as_ref()).as_object_id().unwrap();
172+
let object_id = schema
173+
.find_type_id(obj.name.as_ref())
174+
.as_object_id()
175+
.unwrap();
169176
let mut field_ids = Vec::with_capacity(obj.fields.len());
170177

171178
for field in obj.fields.iter_mut() {
@@ -193,8 +200,10 @@ where
193200
schema.push_object(object);
194201
}
195202

196-
fn ingest_scalar<'doc, T>(schema: &mut Schema, scalar: &mut graphql_parser::schema::ScalarType<'doc, T>)
197-
where
203+
fn ingest_scalar<'doc, T>(
204+
schema: &mut Schema,
205+
scalar: &mut graphql_parser::schema::ScalarType<'doc, T>,
206+
) where
198207
T: graphql_parser::query::Text<'doc>,
199208
{
200209
let name: String = scalar.name.as_ref().into();
@@ -225,8 +234,10 @@ where
225234
schema.push_enum(enm);
226235
}
227236

228-
fn ingest_interface<'doc, T>(schema: &mut Schema, interface: &mut graphql_parser::schema::InterfaceType<'doc, T>)
229-
where
237+
fn ingest_interface<'doc, T>(
238+
schema: &mut Schema,
239+
interface: &mut graphql_parser::schema::InterfaceType<'doc, T>,
240+
) where
230241
T: graphql_parser::query::Text<'doc>,
231242
{
232243
let interface_id = schema
@@ -299,7 +310,9 @@ where
299310
schema.stored_inputs.push(input);
300311
}
301312

302-
fn objects_mut<'a, 'doc: 'a, T>(doc: &'a mut Document<'doc, T>) -> impl Iterator<Item = &'a mut parser::ObjectType<'doc, T>>
313+
fn objects_mut<'a, 'doc: 'a, T>(
314+
doc: &'a mut Document<'doc, T>,
315+
) -> impl Iterator<Item = &'a mut parser::ObjectType<'doc, T>>
303316
where
304317
T: graphql_parser::query::Text<'doc>,
305318
{
@@ -309,7 +322,9 @@ where
309322
})
310323
}
311324

312-
fn interfaces_mut<'a, 'doc: 'a, T>(doc: &'a mut Document<'doc, T>) -> impl Iterator<Item = &'a mut parser::InterfaceType<'doc, T>>
325+
fn interfaces_mut<'a, 'doc: 'a, T>(
326+
doc: &'a mut Document<'doc, T>,
327+
) -> impl Iterator<Item = &'a mut parser::InterfaceType<'doc, T>>
313328
where
314329
T: graphql_parser::query::Text<'doc>,
315330
{
@@ -319,7 +334,9 @@ where
319334
})
320335
}
321336

322-
fn unions_mut<'a, 'doc: 'a, T>(doc: &'a mut Document<'doc, T>) -> impl Iterator<Item = &'a mut parser::UnionType<'doc, T>>
337+
fn unions_mut<'a, 'doc: 'a, T>(
338+
doc: &'a mut Document<'doc, T>,
339+
) -> impl Iterator<Item = &'a mut parser::UnionType<'doc, T>>
323340
where
324341
T: graphql_parser::query::Text<'doc>,
325342
{
@@ -329,7 +346,9 @@ where
329346
})
330347
}
331348

332-
fn enums_mut<'a, 'doc: 'a, T>(doc: &'a mut Document<'doc, T>) -> impl Iterator<Item = &'a mut parser::EnumType<'doc, T>>
349+
fn enums_mut<'a, 'doc: 'a, T>(
350+
doc: &'a mut Document<'doc, T>,
351+
) -> impl Iterator<Item = &'a mut parser::EnumType<'doc, T>>
333352
where
334353
T: graphql_parser::query::Text<'doc>,
335354
{
@@ -339,7 +358,9 @@ where
339358
})
340359
}
341360

342-
fn inputs_mut<'a, 'doc: 'a, T>(doc: &'a mut Document<'doc, T>) -> impl Iterator<Item = &'a mut parser::InputObjectType<'doc, T>>
361+
fn inputs_mut<'a, 'doc: 'a, T>(
362+
doc: &'a mut Document<'doc, T>,
363+
) -> impl Iterator<Item = &'a mut parser::InputObjectType<'doc, T>>
343364
where
344365
T: graphql_parser::query::Text<'doc>,
345366
{

graphql_client_codegen/src/schema/tests/github.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ const SCHEMA_GRAPHQL: &str = include_str!("github_schema.graphql");
77
fn ast_from_graphql_and_json_produce_the_same_schema() {
88
let json: graphql_introspection_query::introspection_response::IntrospectionResponse =
99
serde_json::from_str(SCHEMA_JSON).unwrap();
10-
let graphql_parser_schema = graphql_parser::parse_schema(SCHEMA_GRAPHQL).unwrap().into_static();
10+
let graphql_parser_schema = graphql_parser::parse_schema(SCHEMA_GRAPHQL)
11+
.unwrap()
12+
.into_static();
1113
let mut json = Schema::from(json);
1214
let mut gql = Schema::from(graphql_parser_schema);
1315

graphql_client_codegen/src/tests/mod.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ fn schema_with_keywords_works() {
55
let query_string = include_str!("keywords_query.graphql");
66
let query = graphql_parser::parse_query::<&str>(query_string).expect("Parse keywords query");
77
let schema = graphql_parser::parse_schema(include_str!("keywords_schema.graphql"))
8-
.expect("Parse keywords schema").into_static();
8+
.expect("Parse keywords schema")
9+
.into_static();
910
let schema = Schema::from(schema);
1011

1112
let options = GraphQLClientCodegenOptions::new(CodegenMode::Cli);
@@ -43,7 +44,8 @@ fn fragments_other_variant_should_generate_unknown_other_variant() {
4344
let query_string = include_str!("foobars_query.graphql");
4445
let query = graphql_parser::parse_query::<&str>(query_string).expect("Parse foobars query");
4546
let schema = graphql_parser::parse_schema(include_str!("foobars_schema.graphql"))
46-
.expect("Parse foobars schema").into_static();
47+
.expect("Parse foobars schema")
48+
.into_static();
4749
let schema = Schema::from(schema);
4850

4951
let mut options = GraphQLClientCodegenOptions::new(CodegenMode::Cli);
@@ -82,7 +84,8 @@ fn fragments_other_variant_false_should_not_generate_unknown_other_variant() {
8284
let query_string = include_str!("foobars_query.graphql");
8385
let query = graphql_parser::parse_query::<&str>(query_string).expect("Parse foobars query");
8486
let schema = graphql_parser::parse_schema(include_str!("foobars_schema.graphql"))
85-
.expect("Parse foobars schema").into_static();
87+
.expect("Parse foobars schema")
88+
.into_static();
8689
let schema = Schema::from(schema);
8790

8891
let options = GraphQLClientCodegenOptions::new(CodegenMode::Cli);

graphql_query_derive/src/attributes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ pub fn extract_normalization(ast: &syn::DeriveInput) -> Result<Normalization, sy
9797
}
9898

9999
pub fn extract_fragments_other_variant(ast: &syn::DeriveInput) -> bool {
100-
extract_attr(&ast, "fragments_other_variant")
100+
extract_attr(ast, "fragments_other_variant")
101101
.ok()
102102
.and_then(|s| FromStr::from_str(s.as_str()).ok())
103103
.unwrap_or(false)

0 commit comments

Comments
 (0)