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

Function validate_basic_query_path_patterns

graphlite/src/ast/validator.rs:979–1047  ·  view source on GitHub ↗
(
    query: &BasicQuery,
    _ctx: &mut ValidationContext,
    errors: &mut Vec<ValidationError>,
)

Source from the content-addressed store, hash-verified

977}
978
979fn validate_basic_query_path_patterns(
980 query: &BasicQuery,
981 _ctx: &mut ValidationContext,
982 errors: &mut Vec<ValidationError>,
983) {
984 for pattern in &query.match_clause.patterns {
985 if pattern.elements.is_empty() {
986 errors.push(ValidationError {
987 message: "Path pattern cannot be empty".to_string(),
988 location: None,
989 error_type: ValidationErrorType::Structural,
990 });
991 continue;
992 }
993
994 // Check alternating pattern: Node -> Edge -> Node -> Edge -> Node
995 for (i, element) in pattern.elements.iter().enumerate() {
996 match element {
997 PatternElement::Node(_) => {
998 // Nodes should be at even indices (0, 2, 4, ...)
999 if i % 2 != 0 {
1000 errors.push(ValidationError {
1001 message: format!(
1002 "Invalid path pattern: expected edge at position {}",
1003 i
1004 ),
1005 location: None,
1006 error_type: ValidationErrorType::Structural,
1007 });
1008 }
1009 }
1010 PatternElement::Edge(_) => {
1011 // Edges should be at odd indices (1, 3, 5, ...)
1012 if i % 2 != 1 {
1013 errors.push(ValidationError {
1014 message: format!(
1015 "Invalid path pattern: expected node at position {}",
1016 i
1017 ),
1018 location: None,
1019 error_type: ValidationErrorType::Structural,
1020 });
1021 }
1022 }
1023 }
1024 }
1025
1026 // Validate that path starts and ends with nodes
1027 if let Some(first) = pattern.elements.first() {
1028 if matches!(first, PatternElement::Edge(_)) {
1029 errors.push(ValidationError {
1030 message: "Path pattern must start with a node".to_string(),
1031 location: None,
1032 error_type: ValidationErrorType::Structural,
1033 });
1034 }
1035 }
1036

Callers 2

validate_path_patternsFunction · 0.85
validate_procedure_queryFunction · 0.85

Calls 3

is_emptyMethod · 0.45
iterMethod · 0.45
firstMethod · 0.45

Tested by

no test coverage detected