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);
// Build graph
await cypher.execute(`
CREATE (alice:Person {name: 'Alice'}),
(bob:Person {name: 'Bob'}),
(charlie:Person {name: 'Charlie'})
`);
await cypher.execute(`
MATCH (a:Person {name: 'Alice'}), (b:Person {name: 'Bob'})
CREATE (a)-[:KNOWS]->(b)
`);
await cypher.execute(`
MATCH (a:Person {name: 'Bob'}), (b:Person {name: 'Charlie'})
CREATE (a)-[:KNOWS]->(b)
`);
// Query
const suggestions = await 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);
// Build graph
await cypher.execute(`
CREATE (laptop:Product {name: 'Laptop', price: 999}),
(mouse:Product {name: 'Mouse', price: 29}),
(john:Customer {name: 'John'}),
(order1:Order {total: 1028})
`);
await cypher.execute(`MATCH (c:Customer {name: 'John'}), (o:Order {total: 1028}) CREATE (c)-[:PLACED]->(o)`);
await cypher.execute(`MATCH (o:Order {total: 1028}), (p:Product {name: 'Laptop'}) CREATE (o)-[:CONTAINS]->(p)`);
await cypher.execute(`MATCH (o:Order {total: 1028}), (p:Product {name: 'Mouse'}) CREATE (o)-[:CONTAINS]->(p)`);
// Query
const orders = await 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);
// Build graph
await cypher.execute(`
CREATE (john:Patient {name: 'John'}),
(emily:Patient {name: 'Emily'}),
(dr_chen:Doctor {name: 'Dr. Chen'}),
(hbp:Condition {name: 'Hypertension'}),
(migraine:Condition {name: 'Migraine'})
`);
await cypher.execute(`MATCH (j:Patient {name: 'John'}), (d:Doctor {name: 'Dr. Chen'}) CREATE (j)-[:SEES]->(d)`);
await cypher.execute(`MATCH (j:Patient {name: 'John'}), (c:Condition {name: 'Hypertension'}) CREATE (j)-[:DIAGNOSED_WITH]->(c)`);
await cypher.execute(`MATCH (e:Patient {name: 'Emily'}), (d:Doctor {name: 'Dr. Chen'}) CREATE (e)-[:SEES]->(d)`);
await cypher.execute(`MATCH (e:Patient {name: 'Emily'}), (c:Condition {name: 'Migraine'}) CREATE (e)-[:DIAGNOSED_WITH]->(c)`);
// Query
const patients = await 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' }, ...]