Sorting the results

You might want to sort you result in a specific order. To do that, you need to use the sort argument:

query {
  SalesOrders(
      sort:{
          by:"id"
          direction:"DESC"
      }
  ){
    edges {
      node {
        id
      }
    }
  }
}
  • by is the field used to order the results. It can be any field available for the entity.
  • direction decides what order is used for the sorting. ASC (ascending) sort the results from smaller to larger, while DESC (descending) does the opposite)

You can choose to pass only the by argument without a specifying the direction since ASC will be used as default, however the direction always requires to also pass the by and cannot be used by itself.

Sort by multiple fields

You might want to sort your results by multiple fields, you can do it like this:

query {
  SalesOrders(
      sort:
        [
            {
          		by:"discount"
          		direction:"DESC"
            },
            {
          		by:"label"
          		direction:"ASC"
            },
        ]
  ){
    edges {
      node {
        id
      }
    }
  }
}

You can pass an array of sort objects to the sort argument, each object being used like in the previous example.