Recursive GraphDB Query

There's the apoc.convert.toTree() procedure, that might be close to what you want. Here are a few threads on its usage:

and

1 Like