Order of `@Recurse`

Is there some order in a recursive query that one can rely on?
For example, assuming a virtual filesystem, I want to traverse from an arbitrary child to the root node.
Naively, I would use a query like that, assuming that the parent knows its children and the children know their parent:

{
  foo(func:uid(0x1)) @recurse {
    RES as uid
    ~children {
      uid
    }
  }
}

Will the result be in any order?

Moreover, what if I want to retrieve associated Nodes for each Node?
For Example:

{
  var(func:uid(0x1)) @recurse {
    RES as uid
    ~children {
      uid
    }
  }
  foo(func:uid(RES)) {
    metadata {
      name
    }
  }
}

Metadata might be several nodes, or none. Also, there are more metadata information than just name
I think, I can not include this in the top-level query, because of the @recurse keyword.

What I want in the end, is kind of retrieving a list of uid that have some order, except sorted by uid, and then mapping each uid to multiple uids, in Haskell terms:
[a] -> (a -> [b]) -> [[b]]
or
[a] -> (a -> [b]) -> [b].

I found a partial solution for my problem:

Using the k-shortest-path-queries, I can obtain an ordered list of nodes that I visited.
This leads to the desired form [a] -> (a -> [b]) -> [(a, [b])] which I can process in the application afterwards.

Also, for answering my initial question if @recurse has any ordering, it does have ordering by uid, as far as as I can tell.

1 Like

There is @cascade for the purpose, have a look at it in documentation.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.