(body: &[u8])
| 118 | } |
| 119 | |
| 120 | fn classify_post(body: &[u8]) -> std::result::Result<Vec<GraphqlOperationInfo>, String> { |
| 121 | if body.is_empty() { |
| 122 | return Err("GraphQL POST body is empty".to_string()); |
| 123 | } |
| 124 | let value: Value = serde_json::from_slice(body) |
| 125 | .map_err(|err| format!("GraphQL request body is not valid JSON: {err}"))?; |
| 126 | |
| 127 | match value { |
| 128 | Value::Array(items) => { |
| 129 | if items.is_empty() { |
| 130 | return Err("GraphQL batch request is empty".to_string()); |
| 131 | } |
| 132 | let mut operations = Vec::new(); |
| 133 | for item in items { |
| 134 | operations.extend(classify_json_envelope(&item)?); |
| 135 | } |
| 136 | Ok(operations) |
| 137 | } |
| 138 | Value::Object(_) => classify_json_envelope(&value), |
| 139 | _ => Err("GraphQL JSON envelope must be an object or array".to_string()), |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | fn classify_json_envelope(value: &Value) -> std::result::Result<Vec<GraphqlOperationInfo>, String> { |
| 144 | let obj = value |
no test coverage detected