Nested sorting mapped to var

qq @Anurag (as you worked on k-path) @Ashish @pawan

Some context How to store ordered data? - #4 by MichelDiz if needed.

k shortest path also has this very same structure

Considering this structure taken from a recurse query. would it be possible to extract the order presented to generate an order in a next block? e.g

{
  var(func: eq(title, "Series ABC" )){
    G as articles @filter(not has(<~next>)) 
  }
  q(func: uid(G)) @recurse  {
    uid
    title
    next
  }
}

The structure

"q": [
      {
        "title": "first article",
        "next": {
          "title": "second article",
          "next": {
            "title": "third article",
            "next": {
              "title": "fourth article",
              "next": {
                "title": "fifth article",
                "next": {
                  "title": "sixth article"
                }
              }
            }
          }
        }
      }
    ]
  articles(func: uid(GET_ALL), orderdesc: val(GET_ALL)) {
    title
  }

The response I have is

    "articles": [
      {
        "uid": "0x9c82",
        "title": "sixth article"
      },
      {
        "uid": "0x9c83",
        "title": "fifth article"
      },
      {
        "uid": "0x9c84",
        "title": "fourth article"
      },
      {
        "uid": "0x9c85",
        "title": "third article"
      },
      {
        "uid": "0x9c86",
        "title": "second article"
      }
    ]

But the desirable would be:

    "articles": [
   {
      "uid": "0x9c86",
      "title": "second article"
   },
   {
      "uid": "0x9c85",
      "title": "third article"
   },
   {
      "uid": "0x9c84",
      "title": "fourth article"
   },
   {
      "uid": "0x9c83",
      "title": "fifth article"
   },
   {
      "uid": "0x9c82",
      "title": "sixth article"
   }
]
1 Like

I too have run into this limitation for several use cases… the @recurse clearly is a depth-first traversal, which is very useful, but whenever you assign the uids to a variable, ordering is lost as it falls back to sorting by uids, this feels like a bug, is it ?