Skip to content

Commit

Permalink
Added examples of sorting queries, including sorting on nested proper…
Browse files Browse the repository at this point in the history
…ties and sorting on multiple fields (#5377)
  • Loading branch information
aristotelos committed Sep 15, 2022
1 parent 138f128 commit 5991f99
Showing 1 changed file with 41 additions and 2 deletions.
43 changes: 41 additions & 2 deletions website/src/docs/hotchocolate/fetching-data/sorting.md
Expand Up @@ -113,8 +113,47 @@ public class Query
</Schema>
</ExampleTabs>

> ⚠️ **Note:** If you use more than one middleware, keep in mind that **ORDER MATTERS**. The correct order is UsePaging > UseProjections > UseFiltering > UseSorting
> ⚠️ **Note:** If you use more than one middleware, keep in mind that **ORDER MATTERS**. The correct order is UsePaging > UseProjections > UseFiltering > UseSorting
The type can be sorted using the `order` field in the query:

```graphql
query {
users(order: [{name: ASC}]) {
name
address {
street
}
}
}
```

Properties of nested objects can be sorted as well:

```graphql
query {
users(order: [{address: {street: ASC}}]) {
name
address {
street
}
}
}
```

Note that it is possible to sort on a field and then by another field:

```graphql
query {
users(order: [{name: ASC}, {address: {street: DESC}}]) {
name
address {
street
}
}
}
```

# Customization

Under the hood, sorting is based on top of normal Hot Chocolate input types. You can easily customize them with a very familiar fluent interface. The sorting input types follow the same `descriptor` scheme as you are used to from the normal input types. Just extend the base class `SortInputType<T>` and override the descriptor method.
Expand Down

0 comments on commit 5991f99

Please sign in to comment.