Skip to content
~/docs/guides/traversal
DOCUMENTATION

Graph Traversal

Navigate relationships in your graph

KiteDB provides powerful graph traversal capabilities to navigate relationships between nodes.

Basic Traversal

typescript
// Find all users that Alice follows (outgoing edges)
const following = db
  .from(alice.id)
  .out('follows')
  .nodes();

// Find all followers of Alice (incoming edges)
const followers = db
  .from(alice.id)
  .in('follows')
  .nodes();

// Follow edges in both directions
const connections = db
  .from(alice.id)
  .both('knows')
  .nodes();

Multi-Hop Traversal

typescript
// Find friends of friends (2-hop)
const friendsOfFriends = db
  .from(alice.id)
  .out('follows')
  .out('follows')
  .nodes();

// Chain different edge types
const authorsOfLikedArticles = db
  .from(alice.id)
  .out('likes')     // Alice -> Articles
  .in('authored')   // Articles <- Users
  .nodes();

Variable Depth Traversal

typescript
// Traverse 1-3 hops
const network = db
  .from(alice.id)
  .traverse('follows', { minDepth: 1, maxDepth: 3 })
  .nodes();

// Limit results
const topConnections = db
  .from(alice.id)
  .out('follows')
  .take(10)
  .nodes();

Next Steps