Find paths between one node and a group of nodes

Hi again @Anurag

I’ve explored this further by setting Dgraph up locally and filling it up with some data, so I got some more information and knowledge now.

I’ve encountered a problem. Below you’ll see an image of an example query, let me explain the issue.

To get this Graph I’ve queried for the shortest path between the nodes inside of the Green Circles.
The issue is that in the real world I’d want to query for the paths between the nodes inside of the Red Circles. But when I do that (even with numpath: 2) all the nodes striked with a purple line is removed from the query, since it’s a circular path. But without those nodes I’m unable to determine if the removed node is in the path or not.

Your example works because there is no circular dependency.

From this thread (Identify all the paths between two nodes - #3 by AlBar) I gather that this isn’t a feature that’s supported yet. Or did I query the data wrongly?

For reference here is the query that I’ve been using:

{
 	path as shortest(from: <SOURCE_UID>, to: <TARGET_UID>, numpaths: 2) {
  	~origins
    ~assembledFrom
    ~processedFrom
    company
 	}
 	path(func: uid(path)) {
    name
    number
    assembledFrom {
      name: number
    }
    processedFrom {
      name: number
    }
    origins {
      name: number
    }
    company {
      name
    }
 	}
}

One solution would be to fetch the entire tree for a specific node as a base. From what I’ve gathered this should be possible with the recurse query. But I’m not getting it to work. I’m either just getting a single node as a response (QUERY #1) or an error recurse queries require that all predicates are specified in one level (QUERY #2). The documentation isn’t of much help here unfortunately. It looks like you’ve added support for it from this thread, maybe I’m not using it correctly? :slight_smile:

QUERY #1:

{
  tree(func: eq(number, "3429d692")) @recurse(depth: 12992203, loop: true) {
    name: number
    company
    processedFrom
    assembledFrom
    origins
  }
}

QUERY 2:

{
  tree(func: eq(number, "3429d692")) @recurse(depth: 12992203, loop: true) {
    name: number
    company {
      name 
    }
    processedFrom {
      number 
    }
    assembledFrom {
      number 
    }
    origins {
      number 
    }
  }
}