GraphQL sort by nested field possible?

Hi Sebastian,

I was just wondering if it is possible to sort by a property that is nested way down in the structure?

Example query:

{
  queryResultContents (
    orderby: "data/active/iv[0].data.option.en asc" 
  ) {
etc.

I tried orderby: "data/active/iv asc" and it sorts my collection but I later found out that it’s not sorting by the actual value but by some other value/object; not exactly sure what exactly…

I’m assuming iv[0] won’t work at all (GraphiQL confirms this)? Or some other method to try to reference the first object in the array that is nested deep in my structure?

My last resort would be to query without orderby and handle the sorting on the client side. Or do you have any other ideas maybe that you could share?

Thanks!

Hi,

it is not possible. It is due the nature of NoSQL and GraphQL in general. Because at the beginning the first level is queried and then the next level is resolved and so on.

If you can, I would just change the direction.

Lets say you have articles and authors:

You can either query like this

authors {
   articles {
    }
}

or like this

articles {
   authors {
   }
}

Hm, never thought about doing it that way… will give it some thought and try it.

Again, super thanks for the quick reply, fastest response of all time I think :sunglasses: :sunglasses:

1 Like