How can i get a speical node with its all accessible nodes

I want to get a node with its all accessible nodes,so i use @recurse .like c i will get (BEF) ,like j
i will get(h) There are to problems
1.with the result of recurse there has no edges showed in graph
2.If I want to find multiple nodes at once, there is no way to distinguish results of ‘c’ and 'j’
I have tried recurse with ~ but maybe dgraph don’t support it
I wonder if there any better way to solve this problem or i should update my schema

#SCHEMA
{
    set {
        _:A  <guid_to> _:g1 .
        _:g1 <guid_to> _:B .
        _:B <guid_to> _:g1 .
        _:g1 <guid_to> _:C .
        _:B  <guid_to> _:E .
        _:E <guid_to> _:B .
        _:B  <guid_to> _:g2 .
      	_:C  <guid_to> _:g1 .
        _:g2 <guid_to> _:F .
        _:g3 <guid_to> _:H .
        _:H <guid_to> _:g3 .
        _:H <guid_to> _:J .
        _:J <guid_to> _:H .

        _:A <name> "a" .
        _:B <name> "b" .
        _:C <name> "c" .
        _:D <name> "d" .
        _:E <name> "e" .
        _:F <name> "f" .
     	  _:G <name> "g" .
        _:H <name> "h" .
        _:J <name> "j" .
        _:g1 <name> "g1" .
       	_:g1 <gtype> "g1" .
        _:g2 <name> "g2" .
      	_:g2 <gtype> "g2" .
    }
}


#QUERY
{
  node (func: eq(name, ["c","j"])) @recurse{
     gt as  guid_to
    }
  
  exclude (func:has(gtype)){
    en as name
  }
	result (func: uid(gt)) @filter(NOT uid(en)){
    name
  }
  
}

WechatIMG12

somebody can help me :blush:

Hey @luke,
I’m working on it.

You can run this to get two connected components. You can ignore the nodes with predicate gtype while processing the resulting nodes.

{
  node(func:eq(name, ["c","j"])) @recurse {
    uid
    guid_to{
    }
  }
}

image

2 Likes

you are cool! it helps me a lot.Thanks

1 Like

Hey @luke,

This can be another approach where you can get rid of the nodes having gtype predicate by running the following query:

{
  node(func:eq(name, ["c", "j"])) @recurse {
    u as guid_to {
    }
  }
  
  test(func: uid(u)) @filter(NOT has(gtype)) {
    uid
    name
  }
}

But this will not have connected components because if we exclude some nodes then we break the component. If you want the result for “c”, you can query only for “c” and if you don’t want to distinguish the results then may be you can query for a list of nodes.

2 Likes

Thanks @ahsan
I take this approach to solve my problem
when i want to distinguish a list like [“c”,“j”,“k” ] i use for to make multiple queries

{
  node (func: eq(name,["c","j"])) @recurse {
     gt as t.guid_to
    uid
  }
  result (func: uid(gt)) @filter(NOT has(gtype)){
    uid
   name
  }
}
1 Like