First off, I’m super new to DGraph and graphing databases in general, but so far it’s been great to play around with!
I’m having trouble figuring out how to do a query/aggregation for a set of data. Basically, what I want is to have a “component” that has weight that’s an int. I want to also allow for a component to “contain” other components. If it contains other component, then its weight is derived from the components that belong to it. This can go on and on down the tree. Ultimately, I want the top level component to have a derived weight that’s based on the weights of all the components associated with it—be it from components that have their own inherent weight, or from components that are made up of other components.
So far I have been able to come up with the following query, but it only works for one level deep.
{
component(func: uid(0x3)) {
name
component {
name
weight: w as weight
}
weight : sum(val(w))
}
}