How to Order by Nested Data using GraphQL

Did you figure out how to do this @Matthias_Baetens ? I’m struggling with this too.

EDIT: Nevermind, figured it out. Converted my working code so it maps to your example, this should work:

{
  assetData as var(func: type(Asset)) @filter(uid("0x11e88")) @cascade {
    Asset.price {
      Price.date (orderdesc: Date.date) {
        dateVar as Date.date
      }
      dateValMap as min(val(dateVar))
    }
  }

  q(func: uid(assetData)) @cascade {
    price: Asset.price (orderdesc: val(dateValMap), first: 10, offset: 0) {
      date: Price.date (orderdesc: Date.date) {
        date: Date.date
      }
    }
  }
}

My understanding is that the @cascade directive forces the order from the nested nodes onto the parent—so in this case (orderdesc: val(dateValMap)) combined with @cascade means that the order of price: level is ‘filtered’ back up to the assetData level. Actually that doesn’t make sense because there is only one Asset in the above example, but the prices should be ordered by the nested dates. I don’t understand how this works, but it works on my machine™.

1 Like