Skip to content

rustfmt: apply fixes #424

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/web/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
3 changes: 3 additions & 0 deletions graphql-introspection-query/src/introspection_response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ pub struct FullType {
#[serde(rename_all = "camelCase")]
pub struct FullTypeFieldsArgs {
#[serde(flatten)]
#[allow(dead_code)]
input_value: InputValue,
}

Expand Down Expand Up @@ -242,6 +243,7 @@ pub struct SchemaTypes {
#[serde(rename_all = "camelCase")]
pub struct SchemaDirectivesArgs {
#[serde(flatten)]
#[allow(dead_code)]
input_value: InputValue,
}

Expand All @@ -261,6 +263,7 @@ pub struct Schema {
pub mutation_type: Option<SchemaMutationType>,
pub subscription_type: Option<SchemaSubscriptionType>,
pub types: Option<Vec<Option<SchemaTypes>>>,
#[allow(dead_code)]
directives: Option<Vec<Option<SchemaDirectives>>>,
}

Expand Down
8 changes: 6 additions & 2 deletions graphql_client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion graphql_client/src/reqwest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub async fn post_graphql<Q: GraphQLQuery, U: reqwest::IntoUrl>(
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.
Expand Down
28 changes: 20 additions & 8 deletions graphql_client_codegen/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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()),
};
Expand Down Expand Up @@ -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(),
))
})?;

Expand Down Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand Down Expand Up @@ -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 {
Expand Down
11 changes: 9 additions & 2 deletions graphql_client_codegen/src/query/selection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
Expand Down
47 changes: 34 additions & 13 deletions graphql_client_codegen/src/schema/graphql_parser_conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<str>,
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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<Item = &'a mut parser::ObjectType<'doc, T>>
fn objects_mut<'a, 'doc: 'a, T>(
doc: &'a mut Document<'doc, T>,
) -> impl Iterator<Item = &'a mut parser::ObjectType<'doc, T>>
where
T: graphql_parser::query::Text<'doc>,
{
Expand All @@ -309,7 +322,9 @@ where
})
}

fn interfaces_mut<'a, 'doc: 'a, T>(doc: &'a mut Document<'doc, T>) -> impl Iterator<Item = &'a mut parser::InterfaceType<'doc, T>>
fn interfaces_mut<'a, 'doc: 'a, T>(
doc: &'a mut Document<'doc, T>,
) -> impl Iterator<Item = &'a mut parser::InterfaceType<'doc, T>>
where
T: graphql_parser::query::Text<'doc>,
{
Expand All @@ -319,7 +334,9 @@ where
})
}

fn unions_mut<'a, 'doc: 'a, T>(doc: &'a mut Document<'doc, T>) -> impl Iterator<Item = &'a mut parser::UnionType<'doc, T>>
fn unions_mut<'a, 'doc: 'a, T>(
doc: &'a mut Document<'doc, T>,
) -> impl Iterator<Item = &'a mut parser::UnionType<'doc, T>>
where
T: graphql_parser::query::Text<'doc>,
{
Expand All @@ -329,7 +346,9 @@ where
})
}

fn enums_mut<'a, 'doc: 'a, T>(doc: &'a mut Document<'doc, T>) -> impl Iterator<Item = &'a mut parser::EnumType<'doc, T>>
fn enums_mut<'a, 'doc: 'a, T>(
doc: &'a mut Document<'doc, T>,
) -> impl Iterator<Item = &'a mut parser::EnumType<'doc, T>>
where
T: graphql_parser::query::Text<'doc>,
{
Expand All @@ -339,7 +358,9 @@ where
})
}

fn inputs_mut<'a, 'doc: 'a, T>(doc: &'a mut Document<'doc, T>) -> impl Iterator<Item = &'a mut parser::InputObjectType<'doc, T>>
fn inputs_mut<'a, 'doc: 'a, T>(
doc: &'a mut Document<'doc, T>,
) -> impl Iterator<Item = &'a mut parser::InputObjectType<'doc, T>>
where
T: graphql_parser::query::Text<'doc>,
{
Expand Down
4 changes: 3 additions & 1 deletion graphql_client_codegen/src/schema/tests/github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
9 changes: 6 additions & 3 deletions graphql_client_codegen/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion graphql_query_derive/src/attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ pub fn extract_normalization(ast: &syn::DeriveInput) -> Result<Normalization, sy
}

pub fn extract_fragments_other_variant(ast: &syn::DeriveInput) -> 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)
Expand Down