diff --git a/examples/web/src/lib.rs b/examples/web/src/lib.rs index 2e9b0be2..cfb23020 100644 --- a/examples/web/src/lib.rs +++ b/examples/web/src/lib.rs @@ -60,7 +60,7 @@ fn add_load_more_button() { ); btn.add_event_listener_with_callback( "click", - &on_click + on_click .as_ref() .dyn_ref() .expect_throw("on click is not a Function"), diff --git a/graphql-introspection-query/src/introspection_response.rs b/graphql-introspection-query/src/introspection_response.rs index 2ed287b8..adde64aa 100644 --- a/graphql-introspection-query/src/introspection_response.rs +++ b/graphql-introspection-query/src/introspection_response.rs @@ -141,6 +141,7 @@ pub struct FullType { #[serde(rename_all = "camelCase")] pub struct FullTypeFieldsArgs { #[serde(flatten)] + #[allow(dead_code)] input_value: InputValue, } @@ -242,6 +243,7 @@ pub struct SchemaTypes { #[serde(rename_all = "camelCase")] pub struct SchemaDirectivesArgs { #[serde(flatten)] + #[allow(dead_code)] input_value: InputValue, } @@ -261,6 +263,7 @@ pub struct Schema { pub mutation_type: Option, pub subscription_type: Option, pub types: Option>>, + #[allow(dead_code)] directives: Option>>, } diff --git a/graphql_client/src/lib.rs b/graphql_client/src/lib.rs index d7ff9118..0dbae617 100644 --- a/graphql_client/src/lib.rs +++ b/graphql_client/src/lib.rs @@ -23,7 +23,11 @@ extern crate graphql_query_derive; #[doc(hidden)] pub use graphql_query_derive::*; -#[cfg(any(feature = "reqwest", feature = "reqwest-rustls", feature = "reqwest-blocking"))] +#[cfg(any( + feature = "reqwest", + feature = "reqwest-rustls", + feature = "reqwest-blocking" +))] pub mod reqwest; use serde::{Deserialize, Serialize}; @@ -225,7 +229,7 @@ impl Display for Error { .as_ref() .and_then(|locations| locations.iter().next()) .cloned() - .unwrap_or_else(Location::default); + .unwrap_or_default(); write!(f, "{}:{}:{}: {}", path, loc.line, loc.column, self.message) } diff --git a/graphql_client/src/reqwest.rs b/graphql_client/src/reqwest.rs index 0a95819a..3541915e 100644 --- a/graphql_client/src/reqwest.rs +++ b/graphql_client/src/reqwest.rs @@ -13,7 +13,7 @@ pub async fn post_graphql( let body = Q::build_query(variables); let reqwest_response = client.post(url).json(&body).send().await?; - Ok(reqwest_response.json().await?) + reqwest_response.json().await } /// Use the provided reqwest::Client to post a GraphQL request. diff --git a/graphql_client_codegen/src/query.rs b/graphql_client_codegen/src/query.rs index 9f177b3f..12741dae 100644 --- a/graphql_client_codegen/src/query.rs +++ b/graphql_client_codegen/src/query.rs @@ -119,7 +119,8 @@ where on: schema.find_type(on.as_ref()).ok_or_else(|| { QueryValidationError::new(format!( "Could not find type {} for fragment {} in schema.", - on.as_ref(), fragment.name.as_ref() + on.as_ref(), + fragment.name.as_ref(), )) })?, selection_set: Vec::new(), @@ -136,7 +137,12 @@ where })?; let resolved_operation: ResolvedOperation = ResolvedOperation { object_id: on, - name: m.name.as_ref().expect("mutation without name").as_ref().into(), + name: m + .name + .as_ref() + .expect("mutation without name") + .as_ref() + .into(), _operation_type: operations::OperationType::Mutation, selection_set: Vec::with_capacity(m.selection_set.items.len()), }; @@ -210,7 +216,8 @@ where let on = schema.find_type(on.as_ref()).ok_or_else(|| { QueryValidationError::new(format!( "Could not find type `{}` referenced by fragment `{}`", - on.as_ref(), fragment_definition.name.as_ref() + on.as_ref(), + fragment_definition.name.as_ref(), )) })?; @@ -446,7 +453,9 @@ where })?; let on = schema.get_object(on); - let (id, _) = query.find_operation(m.name.as_ref().map(|name| name.as_ref()).unwrap()).unwrap(); + let (id, _) = query + .find_operation(m.name.as_ref().map(|name| name.as_ref()).unwrap()) + .unwrap(); resolve_variables(query, &m.variable_definitions, schema, id); resolve_object_selection( @@ -459,7 +468,9 @@ where } graphql_parser::query::OperationDefinition::Query(q) => { let on = schema.get_object(schema.query_type()); - let (id, _) = query.find_operation(q.name.as_ref().map(|name| name.as_ref()).unwrap()).unwrap(); + let (id, _) = query + .find_operation(q.name.as_ref().map(|name| name.as_ref()).unwrap()) + .unwrap(); resolve_variables(query, &q.variable_definitions, schema, id); resolve_object_selection( @@ -473,7 +484,9 @@ where graphql_parser::query::OperationDefinition::Subscription(s) => { let on = schema.subscription_type().ok_or_else(|| QueryValidationError::new("Query contains a subscription operation, but the schema has no subscription type.".into()))?; let on = schema.get_object(on); - let (id, _) = query.find_operation(s.name.as_ref().map(|name| name.as_ref()).unwrap()).unwrap(); + let (id, _) = query + .find_operation(s.name.as_ref().map(|name| name.as_ref()).unwrap()) + .unwrap(); resolve_variables(query, &s.variable_definitions, schema, id); resolve_object_selection( @@ -652,8 +665,7 @@ fn resolve_variables<'doc, T>( variables: &[graphql_parser::query::VariableDefinition<'doc, T>], schema: &Schema, operation_id: OperationId, -) -where +) where T: graphql_parser::query::Text<'doc>, { for var in variables { diff --git a/graphql_client_codegen/src/query/selection.rs b/graphql_client_codegen/src/query/selection.rs index 17ae796f..018e6f22 100644 --- a/graphql_client_codegen/src/query/selection.rs +++ b/graphql_client_codegen/src/query/selection.rs @@ -228,11 +228,18 @@ impl Selection { .as_ref() .map(|alias| alias.to_upper_camel_case()) .unwrap_or_else(move || { - query.schema.get_field(field.field_id).name.to_upper_camel_case() + query + .schema + .get_field(field.field_id) + .name + .to_upper_camel_case() }), Selection::InlineFragment(inline_fragment) => format!( "On{}", - inline_fragment.type_id.name(query.schema).to_upper_camel_case() + inline_fragment + .type_id + .name(query.schema) + .to_upper_camel_case() ), other => unreachable!("{:?} in to_path_segment", other), } diff --git a/graphql_client_codegen/src/schema/graphql_parser_conversion.rs b/graphql_client_codegen/src/schema/graphql_parser_conversion.rs index 1384be10..a2e5b6ed 100644 --- a/graphql_client_codegen/src/schema/graphql_parser_conversion.rs +++ b/graphql_client_codegen/src/schema/graphql_parser_conversion.rs @@ -2,7 +2,9 @@ use super::{Schema, StoredInputFieldType, TypeId}; use crate::schema::resolve_field_type; use graphql_parser::schema::{self as parser, Definition, Document, TypeDefinition, UnionType}; -pub(super) fn build_schema<'doc, T>(mut src: graphql_parser::schema::Document<'doc, T>) -> super::Schema +pub(super) fn build_schema<'doc, T>( + mut src: graphql_parser::schema::Document<'doc, T>, +) -> super::Schema where T: graphql_parser::query::Text<'doc>, T::Value: AsRef, @@ -161,11 +163,16 @@ where schema.stored_unions.push(stored_union); } -fn ingest_object<'doc, T>(schema: &mut Schema, obj: &mut graphql_parser::schema::ObjectType<'doc, T>) -where +fn ingest_object<'doc, T>( + schema: &mut Schema, + obj: &mut graphql_parser::schema::ObjectType<'doc, T>, +) where T: graphql_parser::query::Text<'doc>, { - let object_id = schema.find_type_id(obj.name.as_ref()).as_object_id().unwrap(); + let object_id = schema + .find_type_id(obj.name.as_ref()) + .as_object_id() + .unwrap(); let mut field_ids = Vec::with_capacity(obj.fields.len()); for field in obj.fields.iter_mut() { @@ -193,8 +200,10 @@ where schema.push_object(object); } -fn ingest_scalar<'doc, T>(schema: &mut Schema, scalar: &mut graphql_parser::schema::ScalarType<'doc, T>) -where +fn ingest_scalar<'doc, T>( + schema: &mut Schema, + scalar: &mut graphql_parser::schema::ScalarType<'doc, T>, +) where T: graphql_parser::query::Text<'doc>, { let name: String = scalar.name.as_ref().into(); @@ -225,8 +234,10 @@ where schema.push_enum(enm); } -fn ingest_interface<'doc, T>(schema: &mut Schema, interface: &mut graphql_parser::schema::InterfaceType<'doc, T>) -where +fn ingest_interface<'doc, T>( + schema: &mut Schema, + interface: &mut graphql_parser::schema::InterfaceType<'doc, T>, +) where T: graphql_parser::query::Text<'doc>, { let interface_id = schema @@ -299,7 +310,9 @@ where schema.stored_inputs.push(input); } -fn objects_mut<'a, 'doc: 'a, T>(doc: &'a mut Document<'doc, T>) -> impl Iterator> +fn objects_mut<'a, 'doc: 'a, T>( + doc: &'a mut Document<'doc, T>, +) -> impl Iterator> where T: graphql_parser::query::Text<'doc>, { @@ -309,7 +322,9 @@ where }) } -fn interfaces_mut<'a, 'doc: 'a, T>(doc: &'a mut Document<'doc, T>) -> impl Iterator> +fn interfaces_mut<'a, 'doc: 'a, T>( + doc: &'a mut Document<'doc, T>, +) -> impl Iterator> where T: graphql_parser::query::Text<'doc>, { @@ -319,7 +334,9 @@ where }) } -fn unions_mut<'a, 'doc: 'a, T>(doc: &'a mut Document<'doc, T>) -> impl Iterator> +fn unions_mut<'a, 'doc: 'a, T>( + doc: &'a mut Document<'doc, T>, +) -> impl Iterator> where T: graphql_parser::query::Text<'doc>, { @@ -329,7 +346,9 @@ where }) } -fn enums_mut<'a, 'doc: 'a, T>(doc: &'a mut Document<'doc, T>) -> impl Iterator> +fn enums_mut<'a, 'doc: 'a, T>( + doc: &'a mut Document<'doc, T>, +) -> impl Iterator> where T: graphql_parser::query::Text<'doc>, { @@ -339,7 +358,9 @@ where }) } -fn inputs_mut<'a, 'doc: 'a, T>(doc: &'a mut Document<'doc, T>) -> impl Iterator> +fn inputs_mut<'a, 'doc: 'a, T>( + doc: &'a mut Document<'doc, T>, +) -> impl Iterator> where T: graphql_parser::query::Text<'doc>, { diff --git a/graphql_client_codegen/src/schema/tests/github.rs b/graphql_client_codegen/src/schema/tests/github.rs index e0094b64..9feee098 100644 --- a/graphql_client_codegen/src/schema/tests/github.rs +++ b/graphql_client_codegen/src/schema/tests/github.rs @@ -7,7 +7,9 @@ const SCHEMA_GRAPHQL: &str = include_str!("github_schema.graphql"); fn ast_from_graphql_and_json_produce_the_same_schema() { let json: graphql_introspection_query::introspection_response::IntrospectionResponse = serde_json::from_str(SCHEMA_JSON).unwrap(); - let graphql_parser_schema = graphql_parser::parse_schema(SCHEMA_GRAPHQL).unwrap().into_static(); + let graphql_parser_schema = graphql_parser::parse_schema(SCHEMA_GRAPHQL) + .unwrap() + .into_static(); let mut json = Schema::from(json); let mut gql = Schema::from(graphql_parser_schema); diff --git a/graphql_client_codegen/src/tests/mod.rs b/graphql_client_codegen/src/tests/mod.rs index da6a16fd..fdc331e0 100644 --- a/graphql_client_codegen/src/tests/mod.rs +++ b/graphql_client_codegen/src/tests/mod.rs @@ -5,7 +5,8 @@ fn schema_with_keywords_works() { let query_string = include_str!("keywords_query.graphql"); let query = graphql_parser::parse_query::<&str>(query_string).expect("Parse keywords query"); let schema = graphql_parser::parse_schema(include_str!("keywords_schema.graphql")) - .expect("Parse keywords schema").into_static(); + .expect("Parse keywords schema") + .into_static(); let schema = Schema::from(schema); let options = GraphQLClientCodegenOptions::new(CodegenMode::Cli); @@ -43,7 +44,8 @@ fn fragments_other_variant_should_generate_unknown_other_variant() { let query_string = include_str!("foobars_query.graphql"); let query = graphql_parser::parse_query::<&str>(query_string).expect("Parse foobars query"); let schema = graphql_parser::parse_schema(include_str!("foobars_schema.graphql")) - .expect("Parse foobars schema").into_static(); + .expect("Parse foobars schema") + .into_static(); let schema = Schema::from(schema); let mut options = GraphQLClientCodegenOptions::new(CodegenMode::Cli); @@ -82,7 +84,8 @@ fn fragments_other_variant_false_should_not_generate_unknown_other_variant() { let query_string = include_str!("foobars_query.graphql"); let query = graphql_parser::parse_query::<&str>(query_string).expect("Parse foobars query"); let schema = graphql_parser::parse_schema(include_str!("foobars_schema.graphql")) - .expect("Parse foobars schema").into_static(); + .expect("Parse foobars schema") + .into_static(); let schema = Schema::from(schema); let options = GraphQLClientCodegenOptions::new(CodegenMode::Cli); diff --git a/graphql_query_derive/src/attributes.rs b/graphql_query_derive/src/attributes.rs index 547632a1..fde66a89 100644 --- a/graphql_query_derive/src/attributes.rs +++ b/graphql_query_derive/src/attributes.rs @@ -97,7 +97,7 @@ pub fn extract_normalization(ast: &syn::DeriveInput) -> Result bool { - extract_attr(&ast, "fragments_other_variant") + extract_attr(ast, "fragments_other_variant") .ok() .and_then(|s| FromStr::from_str(s.as_str()).ok()) .unwrap_or(false)