sort argument on pagination queries.
Basic Sorting
Sort results using thesort argument with a field and direction.
Sort by Year (Ascending)
Sort by Year (Descending)
Sort Directions
Two sort directions are available:| Direction | Description |
|---|---|
ASC | Ascending order (A-Z, 0-9, oldest to newest) |
DESC | Descending order (Z-A, 9-0, newest to oldest) |
Multiple Sort Fields
You can sort by multiple fields. Results are sorted by the first field, then by the second field for rows with matching values, and so on.Sortable Fields
Each resource type has specific sortable fields. Use the GraphiQL sandbox to explore available fields.Common Sortable Fields
Anime:IDNAMESLUGYEARSEASONMEDIA_FORMATCREATED_ATUPDATED_AT
IDNAMESLUGCREATED_ATUPDATED_AT
IDBASENAMEFILENAMERESOLUTIONNCSUBBEDLYRICSUNCENSOURCEOVERLAPCREATED_ATUPDATED_AT
IDTYPESEQUENCEGROUPSLUGCREATED_ATUPDATED_AT
Combining Sort with Filters
Sorting works seamlessly with filtering:Sorting Relations
You can also sort nested relations:Random Sorting
Some resources support random sorting for shuffled results. This is useful for features like “random theme” or “shuffle playlist”.Random sorting may have performance implications on large datasets. Use it with appropriate pagination limits.
Pivot Table Sorting
When querying many-to-many relationships, you can sort by fields on the pivot table:Practical Examples
Latest Anime First
Alphabetical Listing
Themes by Type and Sequence
Recent Videos by Resolution
Sort with Pagination
Sorting is particularly useful with pagination to ensure consistent ordering across pages:Best Practices
Always Sort When Paginating
Always Sort When Paginating
Specify a sort order when using pagination to ensure consistent results across pages.
Sort by Indexed Fields First
Sort by Indexed Fields First
For better performance, use indexed fields like
ID, CREATED_AT, or YEAR as the primary sort field.Use Stable Sort Fields
Use Stable Sort Fields
Include a unique field like
ID as the last sort criterion to ensure stable, deterministic ordering.Consider Performance
Consider Performance
Sorting large datasets can be expensive. Combine with filters to reduce the dataset before sorting.
Next Steps
Pagination
Learn how to paginate sorted results
Filtering
Filter data before sorting