As I’m a DQL beginner, I’ve currently two “problems” which can be solved at application
level, but I’d like to learn if there are more elegant ways to do it directly in the
query. I tried several ways to accomplish it, but there seems to be some kind of
misunderstandings between dgraph and the component sitting in front of the keyboard…
Maybe someone can push me into the right direction. Here we go:
Problem 1:
I’ve a query which acts on a given root node (0x01 in this case) and retrieves
devices and sub nodes on that “level”. Maybe comparable to a tree like UI component,
where the user opens a node, and the next level appears.
{
q(func: uid(0x01)) {
device {
name
type
serial
}
node {
name
type
description
}
}
The response is
"q": [
{
"device": [
{
"name": "Device 1",
"type": "Device",
"serial": "A000001"
},
{
"name": "Device 2",
"type": "Device",
"serial": "A000002"
}
]
"node": [
{
"name": "Sub 1",
"type": "Container"
},
{
"name": "Sub 2",
"type": "Container"
}
]
}
]
}
Is it possible to get back the nodes and devices on one level like so:
"q": [
{
"objects": [
{
"name": "Device 1",
"type": "Device",
"serial": "A000001"
},
{
"name": "Device 2",
"type": "Device",
"serial": "A000002"
},
{
"name": "Sub 1",
"type": "Container"
},
{
"name": "Sub 2",
"type": "Container"
}
]
}
]
}
Problem 2:
Same problem like 1, but with recursion. I’d like to be follow the node edges and collect all node/device thingies into a flat list.