Sorting Primitive List-Fields

It would be great to be able to sort on primitive list fields, e.g.:

type Foo {
   indices: [Int!]! @sort(by: asc)

Currently, the client has to do the sorting. When clients have no knowledge about which field needs sorting and which not, things will get problematic. Of course, you could always document this in your API description but I feel that this is a basic and nice feature to have.

1 Like

or, at least have a way to sort in GraphQL without needing this directive:

  queryFoo {
    indices(order: asc)

I’m actually a little confused as to what is being asked for:

  1. A directive that sorts a field’s value (assuming it’s only applicable if the field is a [T]) and stores it.
  2. A directive that returns the tagged field with a sorted value (also same assumption as above)
  3. A directive that sorts the results based on the tagged field

#1 and #2 can be done before a mutation is done, right?

Currently lists are stored in arbitrary order.
Meaning, that if you create an object with:

addFoo(input: [
   {indices: [1,2,3,4]}
   ]) {

The query will not necessarily return the same order.

I think it would be sufficient that if fields are tagged with @sorted(by: asc) the list will be sorted before returning it to the client.