Paths throw several nodes

Hello! I’m working on a project where I need to find the route between two nodes, but this path must contains several nodes. For example:

  set {
    _:1 <name> "test1" .
    _:1 <next> _:2 .
    _:1 <next> _:5 .

    _:2 <name> "test2" .
    _:2 <next> _:3 .
    _:2 <next> _:4 .
    _2 <next> _:5 .

    _:3 <name> "test3" .
    _:3 <next> _:5 .
    _:4 <name> "test4" .
    _:4 <next> _:5 .

    _:5 <name> "test5" .

    _:6 <name> "test6" .

 function(from "test1", to "test5", contains = ["test2", "test4"]) = [["test1" ,"test2" , "test4", "test5"], ["test1" ,"test2", "test3" , "test4", "test5"] ]

 function(from "test1", to "test5", contains = ["test2"]) =  [ ["test1" ,"test2", "test5"],  ["test1" ,"test2" , "test3", "test5"], ["test1" ,"test2" , "test4", "test5"], ["test1" ,"test2", "test3" , "test4", "test5"] ]

 function(from "test1", to "test5", contains = []) =  [ ["test1", "test5"], ["test1" ,"test2", "test5"],  ["test1" ,"test2" , "test3", "test5"], ["test1" ,"test2" , "test4", "test5"], ["test1" ,"test2", "test3" , "test4", "test5"] ]

 function(from "test1", to "test5", contains = [ "test6"]) =  []

So I’m wondering is dgraph a good solution? And if it is how would you do that? I watched on function “K Shortest Path Query”. It gives me the shortest path between a source ( from ) node and destination ( to ) node. But I can’t influence on this way.

You can use Recurse query

and apply rules like

	me(func: somefunc..) @recurse(...your params here...) { @filter(do some func as a kind of "constraint" to the several nodes) 
        #This filter will be applied recursively on this edge

If your need is too complex to a single block with recurse, you should do it piece by piece (block by block)

Hello! Thanks for answer. I understand how I have to use Recurse query if I now all function for filter. I mean if I now all restriction on next step in path, it is ok. But what about this situation?

function(from “test1”, to “test5”, contains = [“test2”]) = [ [“test1” ,“test2”, “test5”], [“test1” ,“test2” , “test3”, “test5”], [“test1” ,“test2” , “test4”, “test5”], [“test1” ,“test2”, “test3” , “test4”, “test5”] ]

I now only one node which includes on path. What should the filter be like?

Excuse me for my English.