Recurse from Seeded Nodes to Those With Type "Resource"

I am trying to write a recurse query having one-or-more seed nodes. This query below executes correctly and returns nested JSON (see snippet below).

My goal is to return a flattened set of Resource nodes only. This has defied my capability with DQL! Any advice would be greatly appreciated.

Here’s the current query:

{
   v(func:eq(centric.XID, "Skill/TE0046")) @recurse(depth:10, loop:true) {
      skill-inference
      Skill
      Organization
      Project
      ProjectRole
      Endorsement
      Resource
      uid
      dgraph.type
  }
}

Here’s are the results of query above: Please notice that all of the Resources are in the results, but they are interspersed with other types from the recursion.

{"data":{"v":[{"skill-inference":[{"skill-inference":[{"uid":"0x4dfbdc44","dgraph.type":["Resource"]},{"uid":"0x4dfbdc76","dgraph.type":["Resource"]},{"uid":"0x4dfd62de","dgraph.type":["Resource"]},{"uid":"0x4dfd6318","dgraph.type":["Resource"]},{"uid":"0x4dfee99f","dgraph.type":["Resource"]},{"uid":"0x4e00705f","dgraph.type":["Resource"]},{"uid":"0x4e01f6f5","dgraph.type":["Resource"]},{"uid":"0x4e08116c","dgraph.type":["Resource"]},{"uid":"0x4e0ca527","dgraph.type":["Resource"]},{"uid":"0x4e12bfea","dgraph.type":["Resource"]},{"uid":"0x4e14464a","dgraph.type":["Resource"]},{"uid":"0x4e144683","dgraph.type":["Resource"]},{"uid":"0x4e1753b9","dgraph.type":["Resource"]},{"uid":"0x4e1753c4","dgraph.type":["Resource"]},{"uid":"0x4e18da74","dgraph.type":["Resource"]},{"uid":"0x4e1a602e","dgraph.type":["Skill"]},{"uid":"0x4e220200","dgraph.type":["Resource"]},{"uid":"0x4e2388a2","dgraph.type":["Resource"]},{"uid":"0x4e2695cc","dgraph.type":["Resource"]},{"uid":"0x4e29a2ed","dgraph.type":["Resource"]},{"uid":"0x4e29a31a","dgraph.type":["Resource"]}],"uid":"0x4e037ce3","dgraph.type":["Skill"]},{"skill-inference":[{"uid":"0x4dfa55f3","dgraph.type":["Resource"]},{"uid":"0x4dfbdc30","dgraph.type":["Resource"]},{"uid":"0x4dfbdc44","dgraph.type":["Resource"]},{"uid":"0x4dfbdc5c","dgraph.type":["Resource"]},{"uid":"0x4dfbdc76","dgraph.type":["Resource"]},{"uid":"0x4dfd62de","dgraph.type":["Resource"]},{"uid":"0x4dfd6318","dgraph.type":["Resource"]},{"uid":"0x4dfee99f","dgraph.type":["Resource"]},{"uid":"0x4e00704f","dgraph.type":["Resource"]},{"uid":"0x4e00705f","dgraph.type":["Resource"]},{"uid":"0x4e01f6bf","dgraph.type":["Resource"]},{"uid":"0x4e01f6ce","dgraph.type":["Resource"]},{"uid":"0x4e01f6f5","dgraph.type":["Resource"]},{"uid":"0x4e037d87","dgraph.type":["Resource"]},{"uid":"0x4e050433","dgraph.type":["Resource"]},{"uid":"0x4e08116c","dgraph.type":["Resource"]},{"uid":"0x4e081184","dgraph.type":["Resource"]},{"uid":"0x4e0ca527","dgraph.type":["Resource"]},{"uid":"0x4e0ca550","dgraph.type":["Resource"]},{"uid":"0x4e0fb296","dgraph.type":["Resource"]},{"uid":"0x4e0fb2a9","dgraph.type":["Resource"]},{"uid":"0x4e12bfea","dgraph.type":["Resource"]},{"uid":"0x4e14464a","dgraph.type":["Resource"]},{"uid":"0x4e144671","dgraph.type":["Resource"]},{"uid":"0x4e144683","dgraph.type":["Resource"]},{"uid":"0x4e175378","dgraph.type":["Resource"]},{"uid":"0x4e1753b9","dgraph.type":["Resource"]},{"uid":"0x4e1753c4","dgraph.type":["Resource"]},{"uid":"0x4e18da74","dgraph.type":["Resource"]},{"uid":"0x4e1a602e","dgraph.type":["Skill"]},{"uid":"0x4e1a60fe","dgraph.type":["Resource"]},{"uid":"0x4e1be78c","dgraph.type":["Resource"]},{"uid":"0x4e2201e5","dgraph.type":["Resource"]},{"uid":"0x4e220200","dgraph.type":["Resource"]},{"uid":"0x4e220219","dgraph.type":["Resource"]},{"uid":"0x4e2388a2","dgraph.type":["Resource"]},{"uid":"0x4e250f0e","dgraph.type":["Resource"]},{"uid":"0x4e2695cc","dgraph.type":["Resource"]},{"uid":"0x4e29a2ed","dgraph.type":["Resource"]},{"uid":"0x4e29a31a","dgraph.type":["Resource"]}],"uid":"0x4e050374","dgraph.type":["Skill"]},{"skill-inference":[{"uid":"0x4dfbdc44","dgraph.type":["Resource"]},{"uid":"0x4dfbdc76","dgraph.type":["Resource"]},{"uid":"0x4dfd62de","dgraph.type":["Resource"]},{"uid":"0x4dfd6318","dgraph.type":["Resource"]},{"uid":"0x4dfee99f","dgraph.type":["Resource"]},{"uid":"0x4e01f6ce","dgraph.type":["Resource"]},{"uid":"0x4e037d99","dgraph.type":["Resource"]},{"uid":"0x4e037dab","dgraph.type":["Resource"]},{"uid":"0x4e050433","dgraph.type":["Resource"]},{"uid":"0x4e08116c","dgraph.type":["Resource"]},{"uid":"0x4e0fb296","dgraph.type":["Resource"]},{"uid":"0x4e0fb2a9","dgraph.type":["Resource"]},{"uid":"0x4e12bfea","dgraph.type":["Resource"]},{"uid":"0x4e14464a","dgraph.type":["Resource"]},{"uid":"0x4e144671","dgraph.type":["Resource"]},{"uid":"0x4e144683","dgraph.type":["Resource"]},{"uid":"0x4e175378","dgraph.type":["Resource"]},{"uid":"0x4e1753c4","dgraph.type":["Resource"]},{"uid":"0x4e18da74","dgraph.type":["Resource"]},{"uid":"0x4e1a602e","dgraph.type":["Skill"]},{"uid":"0x4e1a60fe","dgraph.type":["Resource"]},{"uid":"0x4e2201e5","dgraph.type":["Resource"]},{"uid":"0x4e220200","dgraph.type":["Resource"]},{"uid":"0x4e2388a2","dgraph.type":["Resource"]},{"uid":"0x4e2695b0","dgraph.type":["Resource"]},{"uid":"0x4e2695cc","dgraph.type":["Resource"]},{"uid":"0x4e29a2ed","dgraph.type":["Resource"]},{"uid":"0x4e29a31a","dgraph.type":["Resource"]}],"uid":"0x4e11387e","dgraph.type":["Skill"]},{"skill-inference":[{"uid":"0x4dfa55f3","dgraph.type":["Resource"]},{"uid":"0x4dfbdc30","dgraph.type":["Resource"]},{"uid":"0x4dfbdc44","dgraph.type":["Resource"]},{"uid":"0x4dfbdc5c","dgraph.type":["Resource"]},{"uid":"0x4dfbdc76","dgraph.type":["Resource"]},{"uid":"0x4dfd62de","dgraph.type":["Resource"]},{"uid":"0x4dfd6318","dgraph.type":["Resource"]},{"uid":"0x4dfee99f","dgraph.type":["Resource"]},{"uid":"0x4e00704f","dgraph.type":["Resource"]},{"uid":"0x4e00705f","dgraph.type":["Resource"]},{"uid":"0x4e01f6ce","dgraph.type":["Resource"]},{"uid":"0x4e01f6f5","dgraph.type":["Resource"]},{"uid":"0x4e037d87","dgraph.type":["Resource"]},{"uid":"0x4e037d99","dgraph.type":["Resource"]},{"uid":"0x4e050433","dgraph.type":["Resource"]},{"uid":"0x4e08116c","dgraph.type":["Resource"]},{"uid":"0x4e0ca527","dgraph.type":["Resource"]},{"uid":"0x4e0ca550","dgraph.type":["Resource"]},{"uid":"0x4e0fb296","dgraph.type":["Resource"]},{"uid":"0x4e0fb2a9","dgraph.type":["Resource"]},{"uid":"0x4e12bfea","dgraph.type":["Resource"]},{"uid":"0x4e14464a","dgraph.type":["Resource"]},{"uid":"0x4e144671","dgraph.type":["Resource"]},{"uid":"0x4e144683","dgraph.type":["Resource"]},{"uid":"0x4e175378","dgraph.type":["Resource"]},{"uid":"0x4e17537f","dgraph.type":["Resource"]},{"uid":"0x4e1753b9","dgraph.type":["Resource"]},{"uid":"0x4e1753c4","dgraph.type":["Resource"]},{"uid":"0x4e18da74","dgraph.type":["Resource"]},{"uid":"0x4e1a602e","dgraph.type":["Skill"]},{"uid":"0x4e1a60fe","dgraph.type":["Resource"]},{"uid":"0x4e2201e5","dgraph.type":["Resource"]},{"uid":"0x4e220200","dgraph.type":["Resource"]},{"uid":"0x4e220219","dgraph.type":["Resource"]},{"uid":"0x4e2388a2","dgraph.type":["Resource"]},{"uid":"0x4e250f0e","dgraph.type":["Resource"]},{"uid":"0x4e2695b0","dgraph.type":["Resource"]},{"uid":"0x4e2695cc","dgraph.type":["Resource"]},{"uid":"0x4e29a2ed","dgraph.type":["Resource"]},{"uid":"0x4e29a31a","dgraph.type":["Resource"]}],"uid":"0x4e22015d","dgraph.type":["Skill"]}],"uid":"0x4e1a602e","dgraph.type":["Skill"]}]},"extensions":{"server_latency":{"parsing_ns":103177,"processing_ns":5228261,"encoding_ns":222904,"assign_timestamp_ns":988360,"total_ns":6672896},"txn":{"start_ts":30411143,"hash":"2364b23ab0c52f7b164ef4120e5af157cc9bd11e670fcafdc30b33fc6c001c5f"},"metrics":{"num_uids":{"":1,"Endorsement":49,"Organization":49,"Project":49,"ProjectRole":49,"Resource":49,"Skill":49,"_total":442,"dgraph.type":49,"skill-inference":49,"uid":49}}}}

Here was my modified query attempt, but returns no results:

{
	g1 as var(func:uid("0x4e1a602e")) @recurse(depth:20, loop:true) {
      skill-inference
      Skill
      Organization
      Project
      ProjectRole
      Endorsement
      Resource
      uid
      dgraph.type
  }
  
  result(func:uid(g1)) @filter(has(Resource)) {
      uid
      dgraph.type
      Name
  }
}

Shouldn’t that be Type? do you have a predicate called Resource? Change it to

@filter(Type(Resource))

Thanks @MichelDiz. I made that change. Unfortunately the graph still returns no results even after that change. Other suggestions? Anything else I can provide that would make the situation clearer?

Updated code after the recommended change above. Returns no results.

{
	g1 as var(func:uid("0x4e1a602e")) @recurse(depth:20, loop:true) {
      skill-inference
      Skill
      Organization
      Project
      ProjectRole
      Endorsement
      Resource
      uid
      dgraph.type
  }
  
  result(func:uid(g1)) @filter(Type(Resource)) {
      uid
      dgraph.type
      Name
  }
}

Update: Removing @filter(Type(Resource)) will return the single node used to seed the original g1 query, defined by uid("0x4e1a602e").

can you move the variable to the body of the query?

	var(func:uid("0x4e1a602e")) @recurse(depth:20, loop:true) {
      skill-inference
      Skill
      Organization
      Project
      ProjectRole
      Endorsement
      Resource
     g1 as  uid
      dgraph.type
  }

Thanks @MichelDiz! That did the trick. I am a little confused on why the original syntax would not work, but will study up on it.

The other one will grab any uid in the root. As you are using recurse, you must use the body to grab the nested uids.

Thanks, that explanation was helpful, @MichelDiz.