Documentation Index
Fetch the complete documentation index at: https://mintlify.com/directus/directus/llms.txt
Use this file to discover all available pages before exploring further.
Introduction
Directus provides a full-featured GraphQL API that dynamically generates a complete GraphQL schema based on your database structure. The GraphQL API offers an alternative to the REST API with powerful querying capabilities, type safety, and the ability to request exactly the data you need.GraphQL Endpoints
Directus exposes two GraphQL endpoints:Items Endpoint
System Endpoint
HTTP Methods
Directus supports bothGET and POST requests for GraphQL queries:
- POST: Send queries, mutations, and subscriptions with variables in the request body
- GET: Send queries only with parameters in the URL query string (mutations are not allowed via GET)
Authentication
GraphQL requests are authenticated the same way as REST API requests: Bearer Token:GraphQL Request Format
POST Request
Send a JSON payload with the following structure:GET Request
Send query parameters in the URL:Schema Generation
Directus automatically generates a complete GraphQL schema based on your database structure:- Collections become GraphQL types
- Fields become type fields with appropriate GraphQL types
- Relationships are automatically resolved
- Permissions are enforced at the schema level
Automatic Type Mapping
Directus maps database field types to GraphQL types:| Database Type | GraphQL Type |
|---|---|
string, text | String |
integer | Int |
bigInteger | BigInt |
float, decimal | Float |
boolean | Boolean |
uuid | ID |
json | JSON |
dateTime, date, time, timestamp | Date |
geometry | GeoJSON |
hash (passwords) | Hash (concealed) |
csv | [String] (array) |
Permission-Based Schema
The GraphQL schema is dynamically generated based on the authenticated user’s permissions:- Fields you don’t have read access to are excluded from the schema
- Collections you can’t access won’t appear in queries
- Mutations are only available for collections you can create/update/delete
Schema Introspection
GraphQL introspection allows you to explore the schema programmatically. By default, introspection is enabled in Directus.Disable Introspection
For production environments, you may want to disable introspection for security:Using Introspection
You can use introspection to discover available types, fields, and operations:Configuration Options
Directus provides several environment variables for configuring GraphQL:Query Token Limit
Limit the number of tokens in a GraphQL query to prevent overly complex queries:Schema Generation Concurrency
Control how many schema generations can happen concurrently:Introspection
Enable or disable schema introspection:GraphQL Scope
The GraphQL implementation in Directus uses two scopes:items: Your custom collections (available at/graphql)system: System collections like users, roles, files (available at/graphql/system)
Error Handling
GraphQL errors are returned in the standard GraphQL error format:- Error messages
- Error codes
- Field paths where errors occurred
- Original error extensions
GraphQL Playground
For development and testing, you can use GraphQL clients like: These tools provide features like:- Interactive query building
- Schema exploration
- Auto-completion
- Query history
- Variable management
Best Practices
Request Only What You Need
Request Only What You Need
One of GraphQL’s main benefits is requesting exactly the fields you need:
Use Variables for Dynamic Values
Use Variables for Dynamic Values
Always use variables instead of hardcoding values in queries:
Use Fragments for Reusable Fields
Use Fragments for Reusable Fields
Define fragments for commonly used field sets:
Leverage Aliases for Multiple Queries
Leverage Aliases for Multiple Queries
Use aliases when fetching the same collection with different filters:
Next Steps
GraphQL Queries
Learn how to query data with GraphQL
GraphQL Mutations
Create, update, and delete data with mutations
GraphQL Subscriptions
Real-time updates with GraphQL subscriptions