How to get longest path from node to node? and how to list leaf nodes only for recurse query?

Hi there,
Could you help to provide some usage examples for following needs? Thanks

  1. Using recurse query, find all nodes from a ROOT node, but only return a list of leaf nodes.
  2. Find the longest path from node to node. For example, P1 to P4. We are sure the paths from P1 to P4 are limited

schema:

name: string @index(exact) .
to: [uid] .
{
  set {
    <0x11> <name> "P1" .
    <0x12> <name> "P2" .
    <0x13> <name> "P3" .
    <0x14> <name> "P4" .
    <0x15> <name> "P5" .
    <0x16> <name> "P6" .

    <0x11> <to> <0x12> .
    <0x11> <to> <0x13> .
    <0x12> <to> <0x14> .
    <0x13> <to> <0x15> .
    <0x15> <to> <0x14> .
    <0x15> <to> <0x16> .
  }
}

image

Recurse Query

{
  fo(func: eq(name, "P1")) @recurse(loop: false) {
    name
    to
  }
}

Result what we want, only return leaf nodes:

{
  "data": {
    "fo": [
      {
        "name": "P4"
     },
      {
        "name": "P6"
     },
  ]
  }

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.