use fraiseql_core::schema::{CompiledSchema, FieldType};
use serde_json::json;
#[must_use]
pub(super) fn coerce_path_param_value(
value: &str,
declared: Option<&FieldType>,
) -> serde_json::Value {
match declared {
Some(FieldType::Int) => value.parse::<i64>().map_or_else(|_| json!(value), |n| json!(n)),
Some(FieldType::Float) => value.parse::<f64>().map_or_else(|_| json!(value), |n| json!(n)),
Some(FieldType::Boolean) => match value {
"true" => json!(true),
"false" => json!(false),
other => json!(other),
},
_ => json!(value),
}
}
#[must_use]
pub(super) fn declared_arg_type<'a>(
schema: &'a CompiledSchema,
mutation_name: &str,
arg_name: &str,
) -> Option<&'a FieldType> {
schema
.find_mutation(mutation_name)?
.arguments
.iter()
.find(|a| a.name == arg_name)
.map(|a| &a.arg_type)
}