mod memory;
pub use memory::InMemoryGraphStore;
#[cfg(feature = "neo4j")]
mod neo4j;
pub use converge_core::capability::{
CapabilityError, GraphEdge, GraphNode, GraphQuery, GraphRecall, GraphResult,
};
#[cfg(test)]
mod tests {
use super::*;
use serde_json::json;
#[test]
fn basic_graph_operations() {
let store = InMemoryGraphStore::new();
store
.add_node(&GraphNode {
id: "acme".into(),
label: "Company".into(),
properties: json!({"name": "Acme Corp", "revenue": 1_000_000}),
})
.unwrap();
store
.add_node(&GraphNode {
id: "globex".into(),
label: "Company".into(),
properties: json!({"name": "Globex Inc", "revenue": 2_000_000}),
})
.unwrap();
store
.add_node(&GraphNode {
id: "alice".into(),
label: "Person".into(),
properties: json!({"name": "Alice", "role": "CEO"}),
})
.unwrap();
store
.add_edge(&GraphEdge {
from: "alice".into(),
to: "acme".into(),
relationship: "WORKS_FOR".into(),
properties: Some(json!({"since": 2020})),
})
.unwrap();
store
.add_edge(&GraphEdge {
from: "acme".into(),
to: "globex".into(),
relationship: "COMPETES_WITH".into(),
properties: None,
})
.unwrap();
let companies = store.find_nodes("Company", None).unwrap();
assert_eq!(companies.len(), 2);
let result = store
.traverse(&GraphQuery::from_node("alice").with_max_depth(2))
.unwrap();
assert_eq!(result.nodes.len(), 3);
assert_eq!(result.edges.len(), 2);
}
}