Run your first graph traversal
A graph here is not a separate database. You declare that one column points at another table, and the rows you already store become traversable.
Before you start
An instance, an API key, and a table where one column already holds another table’s key. That column is the edge; nothing is copied into a separate graph store.
export OC_URL='https://<your-instance>'
export OC_TENANT='<your-tenant>'
export OC_TOKEN='<your-api-key>'The four steps
- 1.Have the rows
Any table works. A follow graph is two identifier columns on one table.
social.follows (id PK, follower, followee) // follower and followee both name a user id - 2.Declare the relation
The relation tells the engine which column is an edge. Declared once in the schema — see graph schema for the full form.
[[relations]] name = "followee" column = "followee" target = "social.users" - 3.Ask for neighbors
One hop from a starting node, along the relation you named.
curl "$OC_URL/v1/tenants/$OC_TENANT/graph/social.follows/neighbors?rel=followee&from=u-1" \ -H "Authorization: Bearer $OC_TOKEN" - 4.Go further, or find a path
Breadth-first search walks several hops; Dijkstra finds the cheapest path when the edges carry a weight.
# everyone within three hops curl "$OC_URL/v1/tenants/$OC_TENANT/graph/social.follows/bfs?rel=followee&from=u-1&depth=3" \ -H "Authorization: Bearer $OC_TOKEN" # cheapest route between two nodes curl "$OC_URL/v1/tenants/$OC_TENANT/graph/social.follows/dijkstra?rel=followee&from=u-1&to=u-9" \ -H "Authorization: Bearer $OC_TOKEN"
The edges are columns on rows you already write. There is no separate graph store to load, sync or keep consistent, and a row inserted a second ago is traversable now.