# Sorting

{% hint style="info" %}
&#x20;**Note**: Be sure to install the `HotChocolate.Types.Sorting`NuGet package.
{% endhint %}

Next we will add sorting to the users query, so we can sort on fields provided in the entity.

This is simply done by adding `.UseSorting()` on the field we want to sort, like seen below. You can chain sorting and filtering.

{% code title="./GraphQL/QueryType.cs" %}

```csharp
using HotChocolate.Types;

namespace SlackClone.GraphQL
{
    public class QueryType : ObjectType<Query>
    {
        protected override void Configure(IObjectTypeDescriptor<Query> descriptor)
        {
            descriptor.Field(t => t.GetUsers())
                .UseFiltering()
                .UseSorting();
            descriptor.Field(t => t.GetUserStatuses());
        }
    }
}
```

{% endcode %}

Now we can run the server again and test what we have added. Reading the schema documentation you can see the sorting capabilities added to users query.

![](/files/-LuzokAq4dQUJMcy8vp0)

Lets test the sorting with the following query in the playground.

```csharp
{
  users(order_by: { email: ASC }) {
    id
    firstName
    lastName
    fullName
    email
    username
  }
}
```

If everything went well you should see the following response.

```csharp
{
  "data": {
    "users": [
      {
        "id": "eabf53a0-3101-4599-90fa-9db68620af81",
        "firstName": "Barack",
        "lastName": "Obama",
        "fullName": "Barack Obama",
        "email": "bobama@us.gov",
        "username": "bobama"
      },
      {
        "id": "1964199a-e8be-440a-a178-8998d114fd12",
        "firstName": "Donald",
        "lastName": "Trump",
        "fullName": "Donald Trump",
        "email": "dtrump@us.gov",
        "username": "dtrump"
      },
      {
        "id": "f58e8993-430d-4fd7-8281-4fab3fc3a086",
        "firstName": "George",
        "lastName": "Bush",
        "fullName": "George Bush",
        "email": "gbush@us.gov",
        "username": "gbush"
      }
    ]
  }
}
```


---

# 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://arif-hanif.gitbook.io/slackclone/server/api/data-modeling/queries/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.
