Find connected groups of three
The language tabs use earlier client interfaces. Check SDK versions and connection setup before running them.
Find triples where every pair is linked. This can reveal tightly connected parts of a network.
Before you run it: The engine work budget can stop a large calculation. There is no custom depth setting on this route.
First load the five-person social graph. It creates the exact social.users table and follows relation used below.
Alice, Bob and Carol form a triangle when directions are ignored. Check that the three returned keys are arrays, such as ["alice"], rather than assuming they are plain strings.
- Load the social linksInclude the links between Alice, Bob and Carol.
- Check every pairKeep triples where each pair is connected.
- Read each triple onceInspect the canonical ordering of the three record keys.
Follow the example
- Use a relationship from a table to itself.
- Load records and links.
- Run the triangle request.
- Read each returned triple.
Set up the relationship
The relation must be declared in the schema's [[relations]] block and must target the table it is declared on - triangle enumeration walks one table's own edge set, and a relation pointing at another table is refused. See schemas/reference#relations.
Run the request
rel is the only parameter this endpoint accepts. There is no depth, no start node and no cap: the answer is every triangle in the relation.
curl -G "https://$OC_HOST/v1/tenants/$OC_TENANT/graph/social.users/triangles" \
--data-urlencode "rel=follows" \
-H "Authorization: Bearer $OC_TOKEN"Check the result
The calculation treats the relationship as undirected and ignores self-links.
[
{ "a": ["alice"], "b": ["bob"], "c": ["carol"] },
{ "a": ["heidi"], "b": ["ivan"], "c": ["judy"] }
]One object per triangle. a, b and c are primary-key arrays, not strings - the array is what a composite primary key needs, so a single-column key arrives as a one-element array. The three keys come back in canonical order, so the same triangle is always reported the same way and you can deduplicate on the triple.
Understand the behavior
- The relation is symmetrised before enumeration, so a triangle is found whether its three edges point around the ring or at each other.
- Enumeration runs inside the query executor rather than as a standalone library call, so it inherits the same cancellation and result-budget handling as the rest of the read path.
- A self-loop is not an edge for this purpose and contributes no triangle.
- On a graph big enough to blow the scan budget the request is refused with a tagged
graph_work_budget_exceeded400 instead of being allowed to exhaust memory.
Important limits and checks
- Expecting direction to matter. The relation is walked as undirected.
alicepointing atbobandbobpointing ataliceare the same edge here. If direction is the question, triangles is the wrong endpoint. - Reading
aas a string. Each ofa,bandcis an array. For a single-column primary key you wantrow.a[0]. - Pointing
relat another table. The relation has to target the table it is declared on. A cross-table relation is refused rather than quietly returning nothing.