2
votes

I'm new to both ArangoDB and Graph based traversal query.

Here is how my graph is currently structured. Each vertex will have atleast one attributes(key-value pair). You can think of it has a dependency tree. Every parent node(with its own properties) is dependent on child node(again with its own properties). There is no inheritance just relation of parent to child.

Lets say for this example:

vertex1 has { key1: value1 }

vertex2 has { key2 : value2, key3: value3 }

vertex3 has { key4 : value4 }

vertex4 has { key5 : value5 }

enter image description here

I've figured out the basic graph traversal from the docs however I have a specific requirement structuring the RETURNed object structure based on the vertices present(visited) starting from vertex1 till the maxDepth.

RETURN object must have following structure: as you can see as the vertex depth increases the object gets nested under the parent node.

{
  vertex1: {
    key1:value1
    vertex2: {
      key2:value2,
      key3:value3,
      vertex3: {
        key4:value4
      }
    }
    vertex4: {
      key5:value5
    }
  }
}

I can't ask you to write the query for me but any help is much appreciated and would set me in the right direction.

Based on my current understanding:

FOR v IN 1..2 OUTBOUND 'vertex1' GRAPH 'grapgName'
//I'm guessing I would have to COLLECT and GROUP 
//on the existing vertex to projected object structure. 
//I just don't know how :(
RETURN returnObj

Let me know if you need additional info

1
Now that I think of it.. is it even possible to achieve the above result with a single query.. does aql support recursion? If not does it make sense to add recursion logic in the foxx service? - Pramodh
In my opinion it makes sense the implement the recursion in a foxx service. - fceller

1 Answers

2
votes

It is not possible to return the above result exclusively with AQL because recursion is not supported. One solution would be to extend AQL with a self-invoking user-defined function (UDF). More information about UDFs can be found at https://docs.arangodb.com/3.2/AQL/Extending/.