Sorting

A sorting input type is generated for every object type defined in your type definitions. It allows for query results to be sorted by each individual field.

Using this example type definition:

type Movie {
    title: String!
    runtime: Int!
}

The following sorting input type and query should be generated:

type Movie {
    title: String!
    runtime: Int!
}

enum SortDirection {
    ASC
    DESC
}

input MovieSort {
    title: SortDirection
    runtime: SortDirection
}

input MovieOptions {
    """Specify one or more MovieSort objects to sort Movies by. The sorts will be applied in the order in which they are arranged in the array."""
    sort: [MovieSort!]
    limit: Int
    offset: Int
}

type Query {
    movies(where: MovieWhere, options: MovieOptions): [Movie!]!
}

The resulting query should then allow fetching all movies sorted by runtime in ascending order:

query {
    movies(options: {
        sort: [
            {
                runtime: ASC
            }
        ]
    }) {
        title
        runtime
    }
}

Additionally, in case there was a relationship between the Movie and an Actor type, sorting can also be applied when fetching the actors field:

query {
    movies {
        title
        runtime
        actors(options: {
            sort: [
                {
                    surname: ASC
                }
            ]
        }) {
            surname
        }
    }
}