I’m trying to combine multiple queries into single query. In this query I’m returning a custom data structure that every field in this data structure is related to the result of one of those query variables. I am already done the query section but I don’t know how to return the result.
{
A as var(...) {} //Already wrote this query.
B as var(...) {} //Already wrote this query.
// I don't know how to return those results.
custom returned data structure {
fieldA = As
fieldB = Bs
}
}
I do not fully understand the purpose of the last block.
From what I understand of your example, it’s not possible to do this in Dgraph. Ideally you run the first two queries in the form of blocks. (No need for vars)
A “custom” block in Dgraph could only be done for the purpose of aggregation. In this case only mathematical operators could be used.
But it may be possible to support this custom usage. But you would have to make us understand this usage, how it would benefit others to spend time developing this feature.
Anyway, I recommend that you open a detailed issue in its usage according to the model described in the issues template.
Hi Michel,
I have multiple group of nodes. Instead of retrieving every group with single query. For the performance reason, I’m trying to do those multiple queries in single query. So what is the idiomatic way to return every group’s result as JSON object field’s value.
Is it ok to have multiple result blocks in root block, such as:
{
A as var(...) {} //Already wrote this query.
B as var(...) {} //Already wrote this query.
aResult(func: uid(A) ) {
uid
expand(_all_)
}
bResult(func: uid(B) ) {
uid
expand(_all_)
}
}
So, look. Since you wanna two “aResult and bResult” blocks
there is no need to use Var blocks. Then do the queries directly.
No need to do this whole round trip at all.
Yes you are absolutely right, But I have to traverse the graph to find the result. That is why I’m using var blocks. In my example, I just wanted to describe my situation in very simple example.
Than you, Michel, I got the idea.