Try this.
{
U1 as var(func: eq(name, "Product 1"))
var(func: type(Order)) @cascade {
products @filter(uid(U1))
also_bought: products @filter(NOT uid(U1)) {
G as uid
}
}
also_bought(func: uid(G)) {
name
}
}
Modified dataset
{
"set": [
{
"uid": "_:0x21",
"dgraph.type": "Product",
"name": "Product 1"
},
{
"uid": "_:0x22",
"dgraph.type": "Product",
"name": "Product 2"
},
{
"uid": "_:0x23",
"dgraph.type": "Product",
"name": "Product 3"
},
{
"uid": "_:0x24",
"dgraph.type": "Product",
"name": "Product 4"
},
{
"uid": "_:0x25",
"dgraph.type": "Product",
"name": "Product 5"
},
{
"dgraph.type": "Order",
"products": [
{
"uid": "_:0x21"
},
{
"uid": "_:0x22"
}
]
},
{
"dgraph.type": "Order",
"products": [
{
"uid": "_:0x21"
},
{
"uid": "_:0x23"
}
]
},
{
"dgraph.type": "Order",
"products": [
{
"uid": "_:0x23"
},
{
"uid": "_:0x24"
}
]
},
{
"dgraph.type": "Order",
"products": [
{
"uid": "_:0x21"
},
{
"uid": "_:0x22"
},
{
"uid": "_:0x23"
}
]
}
]
}