Skip to main content

Filter Entities by Relation

Find every entity that has a relation pointing to a specific target — e.g. "every project backed by Stability AI", "every entity tagged with the Generative AI topic", "every Person who authored a paper".

Query

query LinkedTo($targetId: UUID!) {
entities(
first: 50
filter: {
relations: {
some: {
toEntityId: { is: $targetId }
}
}
}
) {
id
name
}
}
{ "targetId": "e059a29e6f6b437bbc15c7983d078c0d" }

Response (excerpt)

{
"data": {
"entities": [
{ "id": "01322830b0db46d784fe3ca6a6b6c1a5", "name": "Independet Contributor" },
{ "id": "013b3d5f4a8949db88eb79072c8d0d33", "name": "Geo" },
{ "id": "01c752f8c128f2d392a13ebed1fad6c6", "name": "Gemini" }
]
}
}
Loading interactive query runner…

Refining the filter

The relations.some predicate accepts the same fields as a RelationFilter. Combine them to be more specific:

Pass type/property IDs as variables ($authorsPropId, $topicsPropId, etc.) and reference them like any other variable:

# Entities that have an "Authors" relation to a specific person
filter: {
relations: {
some: {
typeId: { is: $authorsPropId }
toEntityId: { is: $personId }
}
}
}

# Entities in a specific space, with any relation to the target
filter: {
spaceIds: { anyEqualTo: $spaceId }
relations: {
some: {
toEntityId: { is: $targetId }
}
}
}

# Entities that have BOTH a Topic relation to "AI" AND a Type of "Project"
filter: {
and: [
{ relations: { some: { typeId: { is: $topicsPropId }, toEntityId: { is: $aiTopicId } } } }
{ typeIds: { anyEqualTo: $projectTypeId } }
]
}

If your starting point is the target entity (e.g. "I have the Stability AI entity, what links to it?"), use entity.backlinks instead — it's a single-hop traversal and fast:

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

The Project type entity has 3,414 backlinks — every entity that's typed as a Project shows up here.

Loading interactive query runner…

Notes

  • some vs every vs none: filter by some for "has at least one relation matching", every for "all relations match", none for "no relations match". some is by far the most common.
  • Performance: relations.some filters can be slow on connection queries (entitiesConnection). For one-off lookups, the plain entities array variant works fine. For large pagination, prefer backlinks from the target entity instead.
  • toEntityId vs toEntity: filter on toEntityId (the UUID); the toEntity field is a select field returning the joined entity, not a filter input.