Hey everyone … I am new to dgraph, and having some trouble with trying to flatten a set.
Basically, I am trying to get a list of all the unique nodes in a query. With a set of bordering nodes, I want to know everything that is within n
steps.
Here is a sample set:
{
set {
_:a <name> "NodeA" .
_:b <name> "NodeB" .
_:c <name> "NodeC" .
_:d <name> "NodeD" .
_:e <name> "NodeE" .
_:f <name> "NodeF" .
_:g <name> "NodeG" .
_:h <name> "NodeH" .
_:a <borders> _:b .
_:b <borders> _:a .
_:b <borders> _:c .
_:b <borders> _:d .
_:d <borders> _:b .
_:d <borders> _:c .
_:d <borders> _:e .
_:c <borders> _:b .
_:c <borders> _:d .
_:c <borders> _:e .
_:c <borders> _:f .
_:c <borders> _:g .
_:g <borders> _:h .
_:g <borders> _:f .
_:g <borders> _:c .
_:f <borders> _:h .
_:f <borders> _:g .
_:f <borders> _:c .
_:f <borders> _:d .
_:f <borders> _:e .
_:h <borders> _:g .
_:h <borders> _:f .
_:h <borders> _:f .
_:h <borders> _:e .
_:e <borders> _:h .
_:e <borders> _:f .
_:e <borders> _:c .
_:e <borders> _:d .
_:d <borders> _:e .
_:d <borders> _:c .
_:d <borders> _:b .
}
}
The query that I built is:
{
me(func: eq(name, "NodeA"))@recurse(depth: 4, loop: true) @normalize {
n: name
borders {
n: name
}
}
}
Results:
{
"data": {
"me": [
{
"n": [
"NodeA",
"NodeB",
"NodeC",
"NodeF"
]
},
{
"n": [
"NodeA",
"NodeB",
"NodeC",
"NodeG"
]
},
{
"n": [
"NodeA",
"NodeB",
"NodeC",
"NodeE"
]
},
{
"n": [
"NodeA",
"NodeB",
"NodeC",
"NodeB"
]
},
{
"n": [
"NodeA",
"NodeB",
"NodeC",
"NodeD"
]
},
{
"n": [
"NodeA",
"NodeB",
"NodeD",
"NodeC"
]
},
{
"n": [
"NodeA",
"NodeB",
"NodeD",
"NodeE"
]
},
{
"n": [
"NodeA",
"NodeB",
"NodeD",
"NodeB"
]
}
]
},
...
}
Really, what I am hoping to get is:
{
...
{
"n": [
"NodeA",
"NodeB",
"NodeC",
"NodeD",
"NodeE",
"NodeF",
"NodeG"
]
}
...
}
So, it would appear I am going at this the wrong way. Given my set above, how can I traverse n
levels and get a single list of unique nodes?