Find all possible dependencies

Hello,

Could you advise me how to write a query that finds all possible dependency for a Vertex.
For example if I have following :

A–>B
B–>C
C–>D

And as output I should get:

A–>B–>C–>D

I managed to find only dependencies for point from A to B. But how to show as above ?

Here is my query :

CREATE QUERY find_dependencies(STRING table_name) FOR GRAPH tables{ 

  SetAccum<edge> @@edgeSet;
  INT ite = 0;
  seed={table.*};
  
  WHILE  ite < 5 DO
    set_of_dependencies= SELECT t from seed:s - (fromto:d) -> table:t WHERE s.name == table_name
    ACCUM @@edgeSet += d;
    ite = ite + 1;
  END;
  
  PRINT @@edgeSet; 
}

@tkrol Here is a simple example. I didn’t name everything the same and you need to add the where condition.

CREATE QUERY findAll(/* Parameters here */) FOR GRAPH myGraph { 
  ListAccum<EDGE> @@edgeList;
  OrAccum @visited;
  reachableVertices = {};        # empty vertex set
  visitedVertices (v_type) = {v_type.*};  # set that can contain ANY type of vertex
  
  WHILE visitedVertices.size() !=0 DO        # loop terminates when all neighbors are visited
        visitedVertices = SELECT s              # s is all neighbors of visitedVertices which have not been visited
                FROM visitedVertices-(:e)->:s
                WHERE s.@visited == false
                ACCUM @@edgeList += e
                POST-ACCUM s.@visited = true;
        reachableVertices = reachableVertices UNION visitedVertices;
  END;
  PRINT reachableVertices, @@edgeList;

}