# Sorting https://api-docs.lumar.io/docs/graphql/sorting To sort our results we can make use of the `orderBy` parameter, which takes as a value an array of the corresponding `Order` types. These types are defined as: ```graphql type ExampleOrder { field: ExampleOrderField! direction: OrderDirection! } ``` Where `ExampleOrderField` is the group (an `enum`) of available fields to sort a particular entity, and `OrderDirection` is defined as follows: ```graphql enum OrderDirection { ASC DESC } ``` For example, for `Project` it would be: ```graphql type ProjectOrder { field: ProjectOrderField! direction: OrderDirection! } ``` ### Example - getting projects sorted by name and maxLinks ```graphql query getProjects { me { accounts(first: 1) { nodes { projects( first: 3 orderBy: [ { field: name, direction: ASC } { field: maxLinks, direction: DESC } ] ) { nodes { name maxLinks } } } } } } ``` **Response:** ```json { "data": { "me": { "accounts": { "nodes": [ { "projects": { "nodes": [ { "name": "100k Marathon", "maxLinks": 250 }, { "name": "212 Project", "maxLinks": 150 }, { "name": "A New Hope", "maxLinks": 100 } ] } } ] } } } } ``` ### Multi-field sorting You can sort by multiple fields by passing an array of order objects. The first field is the primary sort key, and subsequent fields break ties. ```graphql query GetCrawlsSorted($projectId: ObjectID!) { getProject(id: $projectId) { crawls( first: 5 orderBy: [ { field: status, direction: ASC } { field: finishedAt, direction: DESC } ] ) { nodes { id status finishedAt } } } } ``` **Variables:** ```json { "projectId": "TjAwN1Byb2plY3Q2MTMy" } ``` **Response:** ```json { "data": { "getProject": { "crawls": { "nodes": [ { "id": "TjAwNUNyYXdsMTU4MzI0Ng", "status": "Crawling", "finishedAt": null }, { "id": "TjAwNUNyYXdsMTU4MzI0NQ", "status": "Finished", "finishedAt": "2025-01-15T10:30:00.000Z" }, { "id": "TjAwNUNyYXdsMTU4MzI0NA", "status": "Finished", "finishedAt": "2025-01-14T09:00:00.000Z" } ] } } } } ``` In this example, crawls are first sorted by `status` alphabetically, then by `finishedAt` in descending order within each status group. ### Sorting tips - The `orderBy` argument is always an array, even when sorting by a single field. - Not all fields are sortable. Check the corresponding `OrderField` enum in the schema for available sort fields (e.g., `ProjectOrderField`, `CrawlOrderField`). - Sorting is applied server-side before pagination, so the first page always contains the top-ranked results.