MCPcopy Create free account
hub / github.com/GraphLite-AI/GraphLite / validate_edge

Method validate_edge

graphlite/src/schema/validator.rs:165–213  ·  view source on GitHub ↗

ROADMAP v0.4.0 - Edge validation for graph type DDL enforcement (endpoint constraints, edge properties)

(
        &self,
        graph_type: &GraphTypeDefinition,
        edge_type: &str,
        from_label: &str,
        to_label: &str,
        properties: &HashMap<String, Value>,
    )

Source from the content-addressed store, hash-verified

163 /// Validate that an edge matches the graph type schema
164 #[allow(dead_code)] // ROADMAP v0.4.0 - Edge validation for graph type DDL enforcement (endpoint constraints, edge properties)
165 pub fn validate_edge(
166 &self,
167 graph_type: &GraphTypeDefinition,
168 edge_type: &str,
169 from_label: &str,
170 to_label: &str,
171 properties: &HashMap<String, Value>,
172 ) -> Result<(), ValidationError> {
173 // Find edge type definition
174 let edge_def = graph_type
175 .edge_types
176 .iter()
177 .find(|et| et.type_name == edge_type)
178 .ok_or_else(|| ValidationError::UnknownLabel(edge_type.to_string()))?;
179
180 // Validate from/to node types
181 if !edge_def.from_node_types.contains(&from_label.to_string()) {
182 return Err(ValidationError::InvalidValue(format!(
183 "Edge type '{}' cannot originate from node type '{}'",
184 edge_type, from_label
185 )));
186 }
187
188 if !edge_def.to_node_types.contains(&to_label.to_string()) {
189 return Err(ValidationError::InvalidValue(format!(
190 "Edge type '{}' cannot terminate at node type '{}'",
191 edge_type, to_label
192 )));
193 }
194
195 // Validate required properties
196 for prop_def in &edge_def.properties {
197 if prop_def.required && !properties.contains_key(&prop_def.name) {
198 return Err(ValidationError::MissingRequiredProperty {
199 label: edge_type.to_string(),
200 property: prop_def.name.clone(),
201 });
202 }
203 }
204
205 // Validate property types
206 for (prop_name, prop_value) in properties {
207 if let Some(prop_def) = edge_def.properties.iter().find(|p| p.name == *prop_name) {
208 self.validate_property_type(prop_value, &prop_def.data_type)?;
209 }
210 }
211
212 Ok(())
213 }
214
215 /// Validate that an index references valid schema elements
216 #[allow(dead_code)] // ROADMAP v0.4.0 - Index schema validation for CREATE INDEX on graph type properties

Callers 2

validate_edge_batchMethod · 0.80
validate_edge_insertMethod · 0.80

Calls 5

containsMethod · 0.80
cloneMethod · 0.80
iterMethod · 0.45
contains_keyMethod · 0.45

Tested by

no test coverage detected