I want to understand how does query processing happen once the query has been parsed and we have identified main and nested functions and their types. [Query parsing and function identification happens in parseFunction
here]
Let’s discuss this with examples. Suppose my query looks like:
nameVar as var(func: eq(name, "Lucas Lee")){}
q(func: eq(name, "Jane Doe") ){
name
uid
friend @filter( uid(nameVar) ){
name
uid
memberOf {
uid
Party
}
}
}
This is broken into three top level functions (2 eq
and 1 uid
) viz.
1.
{
"Attr": "name",
"Lang": "",
"Name": "eq",
"Args": [
{
"Value": "Lucas Lee",
"IsValueVar": false,
"IsGraphQLVar": false,
"IsUIDVar": false
}
],
"UID": null,
"NeedsVar": null,
"IsCount": false,
"IsValueVar": false,
"IsLenVar": false,
"IsUIDVar": false
}
2.
{
"Attr": "name",
"Lang": "",
"Name": "eq",
"Args": [
{
"Value": "Jane Doe",
"IsValueVar": false,
"IsGraphQLVar": false,
"IsUIDVar": false
}
],
"UID": null,
"NeedsVar": null,
"IsCount": false,
"IsValueVar": false,
"IsLenVar": false,
"IsUIDVar": false
}
3.
{
"Attr": "",
"Lang": "",
"Name": "uid",
"Args": null,
"UID": null,
"NeedsVar": [
{
"Name": "nameVar",
"Typ": 1
}
],
"IsCount": false,
"IsValueVar": false,
"IsLenVar": false,
"IsUIDVar": false
}
None of the above has any nested functions and these independent functions are evaluated separately and combined via some mechanism. Can you suggest if that is a correct understanding and also point me where does this happen in code?
Now let’s look at an example with nested functions:
var(func: uid(0x0)){
nameVar as math(5190001) #decimal representation of uid - 0x4f3171
}
q(func: eq(name, "Jane Doe") ){
name
uid
friend @filter( uid_in(memberOf, val(nameVar) )){
name
uid
memberOf {
uid
Party
}
}
}
This gives following three functions:
1.
{
"Attr": "",
"Lang": "",
"Name": "uid",
"Args": null,
"UID": null,
"NeedsVar": null,
"IsCount": false,
"IsValueVar": false,
"IsLenVar": false,
"IsUIDVar": false
}
2.
{
"Attr": "name",
"Lang": "",
"Name": "eq",
"Args": [
{
"Value": "Jane Doe",
"IsValueVar": false,
"IsGraphQLVar": false,
"IsUIDVar": false
}
],
"UID": null,
"NeedsVar": null,
"IsCount": false,
"IsValueVar": false,
"IsLenVar": false,
"IsUIDVar": false
}
3.
{
"Attr": "memberOf",
"Lang": "",
"Name": "uid_in",
"Args": [
{
"Value": "nameVar",
"IsValueVar": true,
"IsGraphQLVar": false,
"IsUIDVar": false
}
],
"UID": null,
"NeedsVar": [
{
"Name": "nameVar",
"Typ": 2
}
],
"IsCount": false,
"IsValueVar": false,
"IsLenVar": false,
"IsUIDVar": false
}
In the above functions 1 & 2
are as expected but function 3
has a field NeedsVar
which captures the variable required inside the nested function. What is the order of evaluation in this case and where can I see it in code? Essentially how does NeedsVar govern evaluation?