diff --git a/.cargo/config b/.cargo/config.toml similarity index 100% rename from .cargo/config rename to .cargo/config.toml diff --git a/.github/workflows/pre-commit.yaml b/.github/workflows/pre-commit.yaml index 4695504a..e21de312 100644 --- a/.github/workflows/pre-commit.yaml +++ b/.github/workflows/pre-commit.yaml @@ -1,7 +1,7 @@ name: pre-commit on: pull_request: - push: { branches: master } + push: { branches: [master] } jobs: build: diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 22691baa..039c4bfc 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,7 +1,7 @@ name: tests on: pull_request: - push: { branches: master } + push: { branches: [master] } jobs: test: diff --git a/src/builder.rs b/src/builder.rs index 00951d87..6bd3b20c 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -12,8 +12,6 @@ use std::sync::Arc; #[derive(Clone, Debug)] pub struct InsertBuilder { - pub alias: String, - // args pub objects: Vec, @@ -272,7 +270,6 @@ where .name() .ok_or("Encountered type without name in connection builder")?; let field_map = field_map(&type_); - let alias = alias_or_name(query_field); match &type_ { __Type::InsertResponse(xtype) => { @@ -320,7 +317,6 @@ where } } Ok(InsertBuilder { - alias, table: Arc::clone(&xtype.table), objects, selections: builder_fields, @@ -335,8 +331,6 @@ where #[derive(Clone, Debug)] pub struct UpdateBuilder { - pub alias: String, - // args pub filter: FilterBuilder, pub set: SetBuilder, @@ -438,7 +432,6 @@ where .name() .ok_or("Encountered type without name in update builder")?; let field_map = field_map(&type_); - let alias = alias_or_name(query_field); match &type_ { __Type::UpdateResponse(xtype) => { @@ -490,7 +483,6 @@ where } } Ok(UpdateBuilder { - alias, filter, set, at_most, @@ -507,8 +499,6 @@ where #[derive(Clone, Debug)] pub struct DeleteBuilder { - pub alias: String, - // args pub filter: FilterBuilder, pub at_most: i64, @@ -544,7 +534,6 @@ where .name() .ok_or("Encountered type without name in delete builder")?; let field_map = field_map(&type_); - let alias = alias_or_name(query_field); match &type_ { __Type::DeleteResponse(xtype) => { @@ -594,7 +583,6 @@ where } } Ok(DeleteBuilder { - alias, filter, at_most, table: Arc::clone(&xtype.table), @@ -609,8 +597,6 @@ where } pub struct FunctionCallBuilder { - pub alias: String, - // metadata pub function: Arc, @@ -650,7 +636,6 @@ where T::Value: Hash, { let type_ = field.type_().unmodified_type(); - let alias = alias_or_name(query_field); match &type_ { __Type::FuncCallResponse(func_call_resp_type) => { @@ -703,7 +688,6 @@ where }; Ok(FunctionCallBuilder { - alias, function: Arc::clone(&func_call_resp_type.function), args_builder: args, return_type_builder, @@ -1311,7 +1295,7 @@ where )?; let _: Scalar = match field .get_arg(arg_name) - .expect(&format!("failed to get {} argument", arg_name)) + .unwrap_or_else(|| panic!("failed to get {} argument", arg_name)) .type_() .unmodified_type() { @@ -1977,7 +1961,6 @@ pub struct __SchemaSelection { #[derive(Clone)] pub struct __SchemaBuilder { - pub schema: __Schema, pub selections: Vec<__SchemaSelection>, } @@ -2618,7 +2601,6 @@ impl __Schema { } Ok(__SchemaBuilder { - schema: self.clone(), selections: builder_fields, }) } diff --git a/src/graphql.rs b/src/graphql.rs index d91fea97..6da211d7 100644 --- a/src/graphql.rs +++ b/src/graphql.rs @@ -4,6 +4,7 @@ use cached::SizedCache; use itertools::Itertools; use serde::Serialize; use std::collections::{HashMap, HashSet}; +use std::fmt::Display; use std::ops::Deref; use std::sync::Arc; @@ -345,15 +346,6 @@ pub trait ___Field { fn deprecation_reason(&self) -> Option { None } - - fn arg_map(&self) -> HashMap { - let mut amap = HashMap::new(); - let args = self.args(); - for arg in args { - amap.insert(arg.name_.clone(), arg.clone()); - } - amap - } } #[derive(Clone, Debug)] @@ -528,8 +520,10 @@ pub enum __Type { // Constant PageInfo(PageInfoType), // Introspection + #[allow(clippy::enum_variant_names)] __TypeKind(__TypeKindType), __Schema(__SchemaType), + #[allow(clippy::enum_variant_names)] __Type(__TypeType), __Field(__FieldType), __InputValue(__InputValueType), @@ -3342,9 +3336,9 @@ pub enum FilterOp { Overlap, } -impl ToString for FilterOp { - fn to_string(&self) -> String { - match self { +impl Display for FilterOp { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + let res = match self { Self::Equal => "eq", Self::NotEqual => "neq", Self::LessThan => "lt", @@ -3361,8 +3355,8 @@ impl ToString for FilterOp { Self::Contains => "contains", Self::ContainedBy => "containedBy", Self::Overlap => "overlaps", - } - .to_string() + }; + write!(f, "{res}") } } @@ -3604,7 +3598,7 @@ impl ___Type for FilterTypeType { ] } FilterableType::List(list_type) => { - let supported_ops = vec![ + let supported_ops = [ FilterOp::Contains, FilterOp::ContainedBy, FilterOp::Equal, @@ -3717,7 +3711,7 @@ impl ___Type for FilterEntityType { }), __Type::List(l) => match l.type_.nullable_type() { // Only non-json scalars are supported in list types - __Type::Scalar(s) => match s { + __Type::Scalar( Scalar::Int | Scalar::Float | Scalar::String(_) @@ -3727,18 +3721,17 @@ impl ___Type for FilterEntityType { | Scalar::BigFloat | Scalar::Time | Scalar::Date - | Scalar::Datetime => Some(__InputValue { - name_: column_graphql_name, - type_: __Type::FilterType(FilterTypeType { - entity: FilterableType::List(l), - schema: Arc::clone(&self.schema), - }), - description: None, - default_value: None, - sql_type: Some(NodeSQLType::Column(Arc::clone(col))), + | Scalar::Datetime, + ) => Some(__InputValue { + name_: column_graphql_name, + type_: __Type::FilterType(FilterTypeType { + entity: FilterableType::List(l), + schema: Arc::clone(&self.schema), }), - _ => None, - }, + description: None, + default_value: None, + sql_type: Some(NodeSQLType::Column(Arc::clone(col))), + }), _ => None, }, _ => None,