Current
Currently @cascade
directive does not take any parameters. This means that, for a node, all its children in the sub-graph must be present for it to be part of the response. The directive is implied at all levels from the level it has been declared.
This is too strict for use-cases where @cascade
needs to be done only on some field/children and not all.
The proposal is to introduce parameterized cascade(param1, param2, ...)
.
Proposal
The proposed new behavior will be as follows:
- When
@cascade(param1, param2)
is at any level, then the node is part of the response if theparam1
andparam2
are present. It is filtered otherwise. - All the lower levels will have an implied
@cascade
(without the params), so the lower levels will be stricter where each of the field must be present for the lower level nodes to be part of the response. - If any of the lower level also have
@cascade(param3, param4)
, then it overrides the implied@cascade
.
In other words, @cascade
or @cascade(param1, param2)
at any level is applied to that level. All lower levels implicitly have the @cascade
unless it is overridden by @cascade(param3, param4)
.
e.g. Here is a simple graph.
{
set {
_:alice1 <name> "Alice 1" .
_:alice1 <age> "23" .
_:alice2 <name> "Alice 2" .
_:alice3 <name> "Alice 3" .
_:alice3 <age> "32" .
_:bob <name> "Bob" .
_:chris <name> "Chris" .
_:dave <name> "Dave" .
_:alice1 <friend> _:bob (close=true) .
_:alice1 <friend> _:dave .
_:alice2 <friend> _:chris (close=false) .
_:bob <friend> _:chris .
}
}
Example 1
Query 1 : parameterized @cascade(name)
at root. Implied @cascade
at lower level 2 and 3.
{
q(func: anyoftext(name, "Alice")) @cascade(name) { # parameterized cascade
name
age
friend { # implied `@cascade`
name
age
friend { # implied `@cascade`
name
age
}
}
}
}
Response Query 1
"data": {
"q": [
{
"name": "Alice 1",
"age": "23"
},
{
"name": "Alice 2"
},
{
"name": "Alice 3",
"age": "32"
}
]
}
Example 2
Query 2: @cascade(age)
at root and @cascade(name)
at lower level 2 (this overrides the implied @cascade
), and implied @cascade
at level 3.
{
q(func: anyoftext(name, "Alice")) @cascade(age) { # parameterized cascade
name
age
friend @cascade(name) { # parameterized cascade
name
age
friend { # implied @cascade
name
age
}
}
}
}
Response Query 2
"data": {
"q": [
{
"name": "Alice 1",
"age": "23",
"friend": [
{
"name": "Dave"
},
{
"name": "Bob"
}
]
},
{
"name": "Alice 3",
"age": "32"
}
]
}
Example 3
Query 3: Root level have parameterized @cascade(friend)
on a UID node instead of Value predicate.
{
q(func: anyoftext(name, "Alice")) @cascade(friend) { #paremeterize on UID node
name
age
friend { # implied @cascade here.
name
friend { # implied @cascade here.
name
}
}
}
}
Response 3:
"data": {
"q": [
{
"name": "Alice 1",
"age": "23",
"friend": [
{
"name": "Bob",
"friend": [
{
"name": "Chris"
}
]
}
]
}
]
}