Moved from GitHub dgraph/4023
Posted by Charrette:
A typical output of the following command
{
get(func: uid(0x1)) {
uid
expand(_all_) {
uid
}
}
}
is:
"data": {
"get": [
{
"uid": "0x1",
"friend": [
{
"uid": "0x2",
"friend|my-facet": "foo"
},
{
"uid": "0x3",
"friend|my-facet": "bar"
}
],
"colleague": [
{
"uid": "0x4",
"colleague|my-facet": "foo"
}
]
}
]
}
This kind of json structure is ok when you know in advance the types you’re getting, then you can unmarshal the result in a struct such as:
type Data struct {
Get []struct {
UID string `json:"uid"`
Friend []map[string]string `json:"friend"`
Colleague []map[string]string `json:"colleague"`
} `json:"get"`
}
But the struggle begins when you have dynamic edges and you don’t know all the existing edges type in your database in advance. In that case you’d prefer have a map of edges for instance.
Taking advantage of github.com/Jeffail/gabs
I built my own helper to deal with it more dynamically.
I was wondering if this is something we could implement directly in dgo, and I’d be glad to open a PR if so