# Sorting

You can sort GraphQL query results by specifying an `orderBy` argument.

The value of this argument should be an array of objects that specify a property to sort by and a sort direction. For example, to sort all products by the alphabetical order of their names, use the following query:

```graphql
query {
    products (orderBy: [{ name: ASC }]) {
        items {
            ... on Product {
                id
                name
                category
            }
        }
    }
}
```

Use `ASC` for ascending order or `DESC` for descending order.

## Multiple Sorting

It is possible to specify multiple sort criteria. Results are ordered first by properties defined earlier in the array. Later properties apply only when higher-priority values are equal.

For example, to order products alphabetically by category, then by name, use the following query:

```graphql
query {
    products (orderBy: [
        { category: ASC }
        { name: ASC }
    ])
    {
        items {
            ... on Product {
                id
                name
                category
            }
        }
    }
}
```

## Nested Sorting

You can also sort by nested properties using an object with the same nesting structure.

For example, to order books by the name of their author, use the following query:

```graphql
query {
    books (orderBy: [{
        author: {
            name: ASC
        }
    }])
    {
        items {
            ... on Book {
                name
                author {
                    name
                }
            }
        }
    }
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.umbraco.com/umbraco-compose/apis/graphql/sorting.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
