Basic Queries
GraphQL queries in Directus are automatically generated based on your collections. For each collection, several query types are available.Query a Collection
Retrieve multiple items from a collection:Query by ID
Retrieve a single item by its primary key:Query System Collections
Use the/graphql/system endpoint to query system collections:
System collection names in the
/graphql/system endpoint don’t include the directus_ prefix.Filtering
Directus provides powerful filtering capabilities through GraphQL query arguments.Basic Filters
Filter Operators
Directus supports a comprehensive set of filter operators:Logical Operators
Combine multiple filters with logical operators:_and: All conditions must be true_or: At least one condition must be true
Nested Filters
Filter on related items:Sorting
Sort results using thesort argument:
- Prefix with
-for descending order - No prefix for ascending order
- Multiple sort fields are evaluated in order
Pagination
Control how many items are returned:Limit and Offset
Page-Based Pagination
Searching
Perform full-text search across multiple fields:The
search parameter performs a case-insensitive search across all string fields in the collection.Relationships
Directus automatically resolves relationships in GraphQL.Many-to-One (M2O)
One-to-Many (O2M)
Many-to-Many (M2M)
Filtering Related Items
Apply filters to related items:Aggregation
Query aggregated data using the_aggregated suffix:
Grouping
Group aggregations by field values:Available Aggregate Functions
count: Count of itemsavg: Average value (numeric fields)sum: Sum of values (numeric fields)min: Minimum valuemax: Maximum valueavgDistinct: Average of distinct valuessumDistinct: Sum of distinct valuescountDistinct: Count of distinct values
Versioning
Query content versions using the_by_version suffix:
The
_by_version queries are only available on the /graphql endpoint for item collections, not on /graphql/system.Deep Filtering
Filter parent items based on related item properties:Using Variables
Make queries reusable with variables:Fragments
Define reusable field selections:Aliases
Query the same collection multiple times with different arguments:Singleton Collections
For singleton collections, query without the_by_id suffix:
Example: Complex Query
Here’s a comprehensive example combining multiple features:Next Steps
GraphQL Mutations
Learn how to create, update, and delete data
GraphQL Subscriptions
Get real-time updates with subscriptions