Skip to main content

Traverse Relations (Outbound + Backlinks)

An entity has two relation views: outbound (relations starting at this entity) and backlinks (relations pointing to this entity from elsewhere). Both are needed to fully understand how a node sits in the graph.

Outbound: entity.relations

Returns relations where this entity is the from. Use this to see "what does this entity link to?".

query Outbound($id: UUID!) {
entity(id: $id) {
name
relations(first: 50) {
totalCount
nodes {
id
typeEntity { name }
toEntity { id name }
position
}
}
}
}

Example output for the Stable Diffusion project entity:

{
"data": {
"entity": {
"name": "Stable Diffusion",
"relations": {
"totalCount": 13,
"nodes": [
{ "typeEntity": { "name": "Blocks" }, "toEntity": { "id": "...", "name": null } },
{ "typeEntity": { "name": "Topics" }, "toEntity": { "id": "...", "name": "Generative AI" } },
{ "typeEntity": { "name": "Authors" }, "toEntity": { "id": "...", "name": "Robin Rombach" } }
]
}
}
}
}
Loading interactive query runner…

Returns relations where this entity is the to. Use this to see "what links to this entity?".

query Backlinks($id: UUID!) {
entity(id: $id) {
name
backlinks(first: 50) {
totalCount
nodes {
typeEntity { name }
fromEntity { id name }
}
}
}
}

Example: querying the Project type entity returns the entities tagged with it:

{
"data": {
"entity": {
"name": "Project",
"backlinks": {
"totalCount": 3414,
"nodes": [
{ "typeEntity": { "name": "Types" }, "fromEntity": { "name": "One concern" } },
{ "typeEntity": { "name": "Types" }, "fromEntity": { "name": "Santiago Roel Santos" } }
]
}
}
}
}
Loading interactive query runner…

Filtering relations

Both relations and backlinks accept a filter argument that takes the same shape as RelationFilter:

# Just the Authors relations from this project
relations(
first: 50
filter: { typeId: { is: "$AUTHORS_PROPERTY_ID" } }
) { ... }

# Just the type-tag backlinks (i.e. "what's tagged with this type?")
backlinks(
first: 50
filter: { typeId: { is: "$TYPES_PROPERTY_ID" } }
) { ... }

Common patterns

GoalFieldFilter
What types is this entity tagged with?relationstypeId: { is: TYPES_PROPERTY }
Who authored this paper?relationstypeId: { is: AUTHORS_PROPERTY }
What papers did this person author?backlinkstypeId: { is: AUTHORS_PROPERTY }
What's tagged with this topic?backlinkstypeId: { is: TYPES_PROPERTY } (assuming Topic-as-Type)
What blocks are attached here?relationstypeId: { is: BLOCKS_PROPERTY }

Notes

  • Relations have their own IDs. If you need to delete or update a specific edge, use the relation's id (not its endpoints). See Graph.deleteRelation in the SDK.
  • toEntity { name } can be null. Block entities, anonymous entities, and partial publishes often lack a Name — the relation still resolves, the target just has no label.
  • position is for ordered collections. Relations on a parent entity (e.g. Blocks) have a fractional-index position so the consumer can render them in order. See Position.generateBetween in the SDK.