Skip to content

Commit

Permalink
Merge pull request #429 from supabase/fix/clippy
Browse files Browse the repository at this point in the history
fix clippy warnings
  • Loading branch information
imor authored Oct 4, 2023
2 parents d7802a4 + 22579cd commit 7d708e1
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 38 deletions.
20 changes: 10 additions & 10 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ where
let args = field.args();
let allowed_args: Vec<&str> = args.iter().map(|a| a.name_.as_str()).collect();
restrict_allowed_arguments(&allowed_args, query_field)?;
let args = read_func_call_args(field, query_field, variables, &func_call_resp_type)?;
let args = read_func_call_args(field, query_field, variables, func_call_resp_type)?;

let return_type_builder = match func_call_resp_type.return_type.deref() {
__Type::Scalar(_) => FuncCallReturnTypeBuilder::Scalar,
Expand Down Expand Up @@ -660,13 +660,13 @@ where
for arg in field.args() {
let arg_value = read_argument(&arg.name(), field, query_field, variables)?;
if !arg_value.is_absent() {
let func_call_sql_arg_name = match inflected_to_sql_args.get(&arg.name()) {
Some((type_name, name)) => Some(FuncCallSqlArgName {
type_name: type_name.clone(),
name: name.clone(),
}),
None => None,
};
let func_call_sql_arg_name =
inflected_to_sql_args
.get(&arg.name())
.map(|(type_name, name)| FuncCallSqlArgName {
type_name: type_name.clone(),
name: name.clone(),
});
args.push((func_call_sql_arg_name, gson::gson_to_json(&arg_value)?));
};
}
Expand Down Expand Up @@ -1234,7 +1234,7 @@ where
let type_name = type_
.name()
.ok_or("Encountered type without name in connection builder")?;
let field_map = field_map(&type_);
let field_map = field_map(type_);
let alias = alias_or_name(query_field);

match &type_ {
Expand Down Expand Up @@ -2097,7 +2097,7 @@ impl __Schema {
let mut f_builders: Vec<__FieldBuilder> = vec![];

for vec_field in vec_fields {
if vec!["__type".to_string(), "__schema".to_string()]
if ["__type".to_string(), "__schema".to_string()]
.contains(&vec_field.name())
{
continue;
Expand Down
28 changes: 13 additions & 15 deletions src/graphql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ impl __Schema {

fn graphql_function_arg_name(&self, function: &Function, arg_name: &str) -> String {
let base_type_name =
to_base_type_name(&arg_name, &None, self.inflect_names(function.schema_oid));
to_base_type_name(arg_name, &None, self.inflect_names(function.schema_oid));
lowercase_first_letter(&base_type_name)
}

Expand Down Expand Up @@ -989,9 +989,8 @@ impl FuncCallResponseType {
let inflected_name_to_sql_name: HashMap<String, (String, String)> = self
.function
.args()
.filter_map(|(_, arg_type_name, arg_name)| match arg_name {
None => None,
Some(arg_name) => Some((arg_type_name, arg_name)),
.filter_map(|(_, arg_type_name, arg_name)| {
arg_name.map(|arg_name| (arg_type_name, arg_name))
})
.map(|(arg_type_name, arg_name)| {
(
Expand Down Expand Up @@ -1294,7 +1293,7 @@ fn function_fields(schema: &Arc<__Schema>, volatilities: &[FunctionVolatility])
}

Some(__Field {
name_: schema.graphql_function_field_name(&func),
name_: schema.graphql_function_field_name(func),
type_: __Type::FuncCallResponse(FuncCallResponseType {
function: Arc::clone(func),
schema: Arc::clone(schema),
Expand Down Expand Up @@ -1328,12 +1327,11 @@ fn function_args(schema: &Arc<__Schema>, func: &Arc<Function>) -> Vec<__InputVal
}
None => None,
})
.filter_map(
|(arg_type, arg_name)| match arg_type.to_graphql_type(None, false, schema) {
Some(t) => Some((t, arg_name)),
None => None,
},
)
.filter_map(|(arg_type, arg_name)| {
arg_type
.to_graphql_type(None, false, schema)
.map(|t| (t, arg_name))
})
.map(|(arg_type, arg_name)| __InputValue {
name_: schema.graphql_function_arg_name(func, arg_name),
type_: arg_type,
Expand Down Expand Up @@ -3582,7 +3580,7 @@ impl ___Type for FilterEntityType {
// No filtering on composites
.filter(|x| !self.schema.context.is_composite(x.type_oid))
// No filtering on json/b. they do not support = or <>
.filter(|x| !vec!["json", "jsonb"].contains(&x.type_name.as_ref()))
.filter(|x| !["json", "jsonb"].contains(&x.type_name.as_ref()))
.filter_map(|col| {
// Should be a scalar
if let Some(utype) = sql_column_to_graphql_type(col, &self.schema) {
Expand Down Expand Up @@ -3791,7 +3789,7 @@ impl ___Type for OrderByEntityType {
// No filtering on composites
.filter(|x| !self.schema.context.is_composite(x.type_oid))
// No filtering on json/b. they do not support = or <>
.filter(|x| !vec!["json", "jsonb"].contains(&x.type_name.as_ref()))
.filter(|x| !["json", "jsonb"].contains(&x.type_name.as_ref()))
// TODO filter out arrays, json and composites
.map(|col| __InputValue {
name_: self.schema.graphql_column_field_name(col),
Expand Down Expand Up @@ -4032,11 +4030,11 @@ impl __Schema {
schema: Arc::new(self.clone()),
};
if let Some(fields) = mutation.fields(true) {
if fields.len() > 0 {
if !fields.is_empty() {
return true;
}
}
return false;
false
}

// queryType: __Type!
Expand Down
5 changes: 1 addition & 4 deletions src/gson.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@ pub enum Value {

impl Value {
pub(crate) fn is_absent(&self) -> bool {
match self {
Value::Absent => true,
_ => false,
}
matches!(self, Value::Absent)
}
}

Expand Down
13 changes: 5 additions & 8 deletions src/sql_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ impl<'a> Iterator for ArgsIterator<'a> {
let arg_name = if let Some(arg_names) = self.arg_names {
debug_assert!(arg_names.len() >= self.arg_types.len());
let arg_name = arg_names[self.index].as_str();
if arg_name != "" {
if !arg_name.is_empty() {
Some(arg_name)
} else {
None
Expand Down Expand Up @@ -813,15 +813,12 @@ pub fn load_sql_context(_config: &Config) -> Result<Arc<Context>, String> {
let functions = arg_type_to_func.entry(function.arg_types[0]).or_default();
functions.push(function);
}
for (_, table) in &mut context.tables {
for table in &mut context.tables.values_mut() {
if let Some(table) = Arc::get_mut(table) {
match arg_type_to_func.get(&table.reltype) {
Some(functions) => {
for function in functions {
table.functions.push(Arc::clone(function));
}
if let Some(functions) = arg_type_to_func.get(&table.reltype) {
for function in functions {
table.functions.push(Arc::clone(function));
}
None => {}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/transpile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ impl FunctionCallBuilder {
None,
Some(from_clause),
)?;
format!("{select_clause}")
select_clause.to_string()
}
};

Expand Down

0 comments on commit 7d708e1

Please sign in to comment.