Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sorting query examples #5377

Merged
merged 3 commits into from
Sep 15, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
43 changes: 41 additions & 2 deletions website/src/docs/hotchocolate/fetching-data/sorting.md
Original file line number Diff line number Diff line change
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