Find directly linked records
The language tabs use earlier client interfaces. Check SDK versions and connection setup before running them.
Read records one relationship away. In a graph, rows are nodes and declared relationships are edges.
Before you run it: A foreign-key-shaped column alone is not enough: declare the relationship.
First load the order-to-product sample dataset. It creates shop.orders.bought_product with the exact IDs used below.
With that sample dataset, the source is order o001 and the one target is product p001. The result contains the target key, not the product fields.
- Start at order o001Use the order's primary key.
- Follow bought_productTraverse the declared outgoing relation once.
- Receive product p001The result identifies the target record.
- Fetch product fieldsRead the product row when you need its details.
Follow the example
- Declare the relationship.
- Write the linked sample rows.
- Pass the source key and relationship name.
- Read the target keys.
Set up the relationship
The schema for shop.orders must declare a [[relations]] block with name = "bought_product". See schemas/reference#relations. Without it, the engine returns 404.
Run the request
curl "https://$OC_HOST/v1/tenants/$OC_TENANT/graph/shop.orders/neighbors?rel=bought_product&pk=o001" \
-H "Authorization: Bearer $OC_TOKEN"Check the result
The response lists forward neighbors, without a ranking guarantee.
[
"p001",
"p014",
"p027"
]A flat array of target primary keys. Order is the insertion order of the edges; do not rely on it being sorted.
Understand the behavior
- Adjacency is laid down at write time, keyed by
(tenant, relation, source_pk). - The read is a single point lookup against that key - no scan, no join.
- Cost is independent of total table size; it scales only with the fan-out of this one row.
Important limits and checks
- Relation not declared. Adding a foreign-key column isn't enough - the relation must be in the schema's
[[relations]]table. - Wrong direction. neighbors is forward only. For "who points at this row?", use reverse.