Sorting data

Sorting is currently intended to be used the same way as filters, just in separate argument, near by the filters.

We provide basic abstract sorting DataType implementation that should be extended. It can be configured with specific protected fields you would like to use for sorting your data:

use OxidEsales\GraphQL\Base\DataType\Sorting as BaseSorting;

final class CountrySorting extends BaseSorting
     * @Factory()
    public static function fromUserInput(
        ?string $title = null,
        ?string $iso = null
    ): self {
        return new self([
            'OXTITLE' => $title,
            'OXISOALPHA2' => $iso,

Now in our controller we would like to ask for sorting parameter, as we did with filters earlier:

public function exampleCountryQuery(
    ?CountryFilterList $filterList = null
    ?CountrySorting $sorting = null
): array {
    if ($sorting) {

Simple as that! Now we can add sorting to our query:

query {
    exampleCountryQuery (
        filterList: {
            title: {
                beginsWith: "D"
        sorting: {
            iso: "DESC"

And the result will be sorted by iso descending:

    "data": {
        "exampleCountryQuery": [
                "Dominikanische Republik",
            ], [
            ], [
            ], [
            ], [

Some of the lists have default sorting depending on their position. In case you want to sort by other field you need to reset the default sorting. Let’s say you want to sort the categories by title and not by position. You will have to set the position to an empty string otherwise its default value will be taken into account. Here is an example:

query {
    categories (
        sort: {
            position: "",
            title: "ASC"
    ) {