Pluggable Storage
Swap storage backends without changing application code. In-memory built-in, MongoDB available separately.
Cypher Queries
OpenCypher-compatible query language with aggregations, variable-length paths, and query plan inspection.
Multi-Hop Traversal
BFS and DFS traversal with type and property filtering. Find paths between any nodes.
Transaction Support
Atomic multi-operation updates with automatic rollback on failure.
Smart Caching
LRU/LFU/FIFO caching with budget enforcement. In-memory or Redis backends.
Graph Analysis
DAG validation, topological sorting, and Mermaid diagram export.
See Grafio in Action
Real-world use cases powered by Cypher queries
- Social Network
- E-Commerce
- Healthcare
import { CypherEngine } from 'grafio';
import { InMemoryGraphFactory } from 'grafio/storage';
const graph = new InMemoryGraphFactory().forGraph('social');
const cypher = new CypherEngine(graph);
graph.addNode({ id: 'alice', label: 'Person', properties: { name: 'Alice' } });
graph.addNode({ id: 'bob', label: 'Person', properties: { name: 'Bob' } });
graph.addNode({ id: 'charlie', label: 'Person', properties: { name: 'Charlie' } });
graph.addEdge({ from: 'alice', to: 'bob', label: 'KNOWS' });
graph.addEdge({ from: 'bob', to: 'charlie', label: 'KNOWS' });
const suggestions = cypher.execute(`
MATCH (p:Person)-[:KNOWS]->(f)-[:KNOWS]->(s)
WHERE p.name = 'Alice' AND p <> s
RETURN s.name as suggested
`);
// Result: [{ suggested: 'Charlie' }]
import { CypherEngine } from 'grafio';
import { InMemoryGraphFactory } from 'grafio/storage';
const graph = new InMemoryGraphFactory().forGraph('shop');
const cypher = new CypherEngine(graph);
graph.addNode({ id: 'laptop', label: 'Product', properties: { name: 'Laptop', price: 999 } });
graph.addNode({ id: 'mouse', label: 'Product', properties: { name: 'Mouse', price: 29 } });
graph.addNode({ id: 'john', label: 'Customer', properties: { name: 'John' } });
graph.addNode({ id: 'order1', label: 'Order', properties: { total: 1028 } });
graph.addEdge({ from: 'john', to: 'order1', label: 'PLACED' });
graph.addEdge({ from: 'order1', to: 'laptop', label: 'CONTAINS' });
graph.addEdge({ from: 'order1', to: 'mouse', label: 'CONTAINS' });
const orders = cypher.execute(`
MATCH (c:Customer)-[:PLACED]->(o:Order)-[:CONTAINS]->(p:Product)
RETURN c.name as customer, collect(p.name) as products
`);
// Result: [{ customer: 'John', products: ['Laptop', 'Mouse'] }]
import { CypherEngine } from 'grafio';
import { InMemoryGraphFactory } from 'grafio/storage';
const graph = new InMemoryGraphFactory().forGraph('clinic');
const cypher = new CypherEngine(graph);
graph.addNode({ id: 'john', label: 'Patient', properties: { name: 'John' } });
graph.addNode({ id: 'emily', label: 'Patient', properties: { name: 'Emily' } });
graph.addNode({ id: 'dr_chen', label: 'Doctor', properties: { name: 'Dr. Chen' } });
graph.addNode({ id: 'hbp', label: 'Condition', properties: { name: 'Hypertension' } });
graph.addNode({ id: 'migraine', label: 'Condition', properties: { name: 'Migraine' } });
graph.addEdge({ from: 'john', to: 'dr_chen', label: 'SEES' });
graph.addEdge({ from: 'john', to: 'hbp', label: 'DIAGNOSED_WITH' });
graph.addEdge({ from: 'emily', to: 'dr_chen', label: 'SEES' });
graph.addEdge({ from: 'emily', to: 'migraine', label: 'DIAGNOSED_WITH' });
const patients = cypher.execute(`
MATCH (doc)-[:SEES]-(p:Patient)-[:DIAGNOSED_WITH]-(c)
RETURN doc.name as doctor, p.name as patient, c.name as condition
`);
// Result: [{ doctor: 'Dr. Chen', patient: 'John', condition: 'Hypertension' }, ...]