Entity Query
Query one or more entities.
Schema
Base
graphql
enum EntityQuerySortOrder {
ASC
DESC
}
enum EntityQueryConjunction {
AND
OR
}
enum EntityQueryOperator {
BETWEEN
CONTAINS
ENDS_WITH
EQUAL
GREATER_THAN
GREATER_THAN_OR_EQUAL
IN
IS_NOT_NULL
IS_NULL
LIKE
NOT_BETWEEN
NOT_EQUAL
NOT_IN
NOT_LIKE
REGEXP
SMALLER_THAN
SMALLER_THAN_OR_EQUAL
STARTS_WITH
}
enum EntityQueryRevisionMode {
"""
Loads all revisions.
"""
ALL
"""
Loads the current (default) revisions.
"""
DEFAULT
"""
Loads latest revision.
"""
LATEST
}
enum EntityQueryBundleMode {
"""
Loads entities across all bundles.
"""
ALL
"""
Loads only entities that share the same bundle with the parent entity.
"""
SAME
}
type EntityQueryResult {
total: Int!
items: [Entity]
}
input EntityQuerySortInput {
direction: EntityQuerySortOrder
field: String!
language: String
}
input EntityQueryFilterConditionInput {
enabled: Boolean
field: String!
language: String
operator: EntityQueryOperator
value: [String]
}
input EntityQueryFilterInput {
conditions: [EntityQueryFilterConditionInput]
conjunction: EntityQueryConjunction
groups: [EntityQueryFilterInput]
}
Extension
graphql
extend type Query {
entityQuery(
""" The machine name of the entity type (e.g. "node", "taxonomy_term", etc.) """
entityType: EntityType!
""" The maximum amount of items to return. """
limit: Int = 10
""" Index of the first item. """
offset: Int = 0
revisions: EntityQueryRevisionMode = DEFAULT
""" Sort results. """
sort: [EntityQuerySortInput!] = null
""" Filter results. """
filter: EntityQueryFilterInput = null
): EntityQueryResult!
entityById(entityType: EntityType!, id: ID!, langcode: Langcode): Entity
entityByUuid(entityType: EntityType!, uuid: String!, langcode: Langcode): Entity
}
entityById
graphql
query getNode {
node: entityById(entityType: NODE, id: 5) {
... on Node {
title
body
}
}
}
entityQuery
Basic example
The items
field has the type Entity
, so you can easily get only the label or id without having to define a type.
graphql
query getAllTerms {
entityQuery(entityType: TAXONOMY_TERM, limit: 100) {
items {
label
}
}
}
Advanced example
Here we fetch nodes of type "article" that are not older than the given timestamp. Results are sorted by created
.
graphql
query postsFromToday {
entityQuery(
entityType: NODE
limit: 5
sort: { field: "created", direction: DESC }
filter: {
conditions: [
{ field: "type", value: "article" }
{ field: "created", value: "1680072947", operator: GREATER_THAN }
]
}
) {
total
items {
... on NodeArticle {
title
teaserText
url {
path
}
}
}
}
}