ROADMAP v0.5.0 - Coercion strategy selection
(
&self,
value: &Value,
_from_type: &GqlType,
to_type: &GqlType,
strategy: &CoercionStrategy,
)
| 8155 | /// Apply a specific coercion strategy to convert a value |
| 8156 | #[allow(dead_code)] // ROADMAP v0.5.0 - Coercion strategy selection |
| 8157 | fn apply_coercion_strategy( |
| 8158 | &self, |
| 8159 | value: &Value, |
| 8160 | _from_type: &GqlType, |
| 8161 | to_type: &GqlType, |
| 8162 | strategy: &CoercionStrategy, |
| 8163 | ) -> Result<Value, ExecutionError> { |
| 8164 | match strategy { |
| 8165 | CoercionStrategy::None => Ok(value.clone()), |
| 8166 | |
| 8167 | CoercionStrategy::IntegerWidening => { |
| 8168 | // Value should already be compatible for integer widening |
| 8169 | Ok(value.clone()) |
| 8170 | } |
| 8171 | |
| 8172 | CoercionStrategy::IntegerToDecimal => { |
| 8173 | // Convert integer to decimal representation |
| 8174 | match value { |
| 8175 | Value::Number(n) => Ok(Value::Number(*n)), |
| 8176 | _ => Ok(value.clone()), |
| 8177 | } |
| 8178 | } |
| 8179 | |
| 8180 | CoercionStrategy::IntegerToFloat => { |
| 8181 | // Convert integer to float |
| 8182 | match value { |
| 8183 | Value::Number(n) => Ok(Value::Number(*n)), |
| 8184 | _ => Ok(value.clone()), |
| 8185 | } |
| 8186 | } |
| 8187 | |
| 8188 | CoercionStrategy::FloatWidening => { |
| 8189 | // Float widening preserves value |
| 8190 | Ok(value.clone()) |
| 8191 | } |
| 8192 | |
| 8193 | CoercionStrategy::StringToOther => { |
| 8194 | // Convert string to target type |
| 8195 | match (value, to_type) { |
| 8196 | (Value::String(s), GqlType::Integer) => s |
| 8197 | .parse::<i64>() |
| 8198 | .map(|i| Value::Number(i as f64)) |
| 8199 | .map_err(|_| { |
| 8200 | ExecutionError::RuntimeError(format!( |
| 8201 | "Cannot coerce '{}' to integer", |
| 8202 | s |
| 8203 | )) |
| 8204 | }), |
| 8205 | (Value::String(s), GqlType::Double) => { |
| 8206 | s.parse::<f64>().map(Value::Number).map_err(|_| { |
| 8207 | ExecutionError::RuntimeError(format!("Cannot coerce '{}' to number", s)) |
| 8208 | }) |
| 8209 | } |
| 8210 | (Value::String(s), GqlType::Boolean) => match s.to_lowercase().as_str() { |
| 8211 | "true" => Ok(Value::Boolean(true)), |
| 8212 | "false" => Ok(Value::Boolean(false)), |
| 8213 | _ => Err(ExecutionError::RuntimeError(format!( |
| 8214 | "Cannot coerce '{}' to boolean", |
no test coverage detected