Here follows an example with sample dataset
{
G as var(func: type(User), first:1) {
F as friend
F2 as ~friend
}
result(func: uid(G)) {
name
requestsLeft : friend @filter(NOT uid(F2)) {
name
}
accepted : ~friend @filter(uid(F)) {
name
}
allFriends :friend {
name
}
}
}
Result
{
"data": {
"result": [
{
"name": "User 3",
"requestsLeft": [
{
"name": "User 2"
}
],
"accepted": [
{
"name": "User 4"
},
{
"name": "User 1"
}
],
"allFriends": [
{
"name": "User 4"
},
{
"name": "User 1"
},
{
"name": "User 2"
}
]
}
]
}
}
Second query
{
G as var(func: eq(name, "User 7")) {
F as friend
F2 as ~friend
}
result(func: uid(G)) {
name
requestsWaitingToBeAccepted : friend @filter(NOT uid(F2)) {
name
}
requestingMeFriendShip : ~friend @filter(NOT uid(F)) {
name
}
accepted : ~friend @filter(uid(F)) {
name
}
allFriends :friend {
name
}
}
}
Result
{
"data": {
"result": [
{
"name": "User 7",
"requestsWaitingToBeAccepted": [
{
"name": "User 5"
},
{
"name": "User 1"
}
],
"requestingMeFriendShip": [
{
"name": "User 8"
},
{
"name": "User 9"
}
],
"accepted": [
{
"name": "User 6"
}
],
"allFriends": [
{
"name": "User 5"
},
{
"name": "User 6"
},
{
"name": "User 1"
}
]
}
]
}
}
Sample
{
"set": [
{
"uid": "_:User1",
"dgraph.type": "User",
"name": "User 1",
"friend": [
{
"uid": "_:User2"
},
{
"uid": "_:User3"
},
{
"uid": "_:User4"
}
]
},
{
"uid": "_:User2",
"dgraph.type": "User",
"name": "User 2",
"friend": [
{
"uid": "_:User1"
}
]
},
{
"uid": "_:User3",
"dgraph.type": "User",
"name": "User 3",
"friend": [
{
"uid": "_:User1"
},
{
"uid": "_:User2"
},
{
"uid": "_:User4"
}
]
},
{
"uid": "_:User4",
"dgraph.type": "User",
"name": "User 4",
"friend": [
{
"uid": "_:User1"
},
{
"uid": "_:User3"
},
{
"uid": "_:User5"
}
]
},
{
"uid": "_:User5",
"dgraph.type": "User",
"name": "User 5",
"friend": [
{
"uid": "_:User1"
}
]
},
{
"uid": "_:User6",
"dgraph.type": "User",
"name": "User 6",
"friend": [
{
"uid": "_:User1"
},
{
"uid": "_:User5"
},
{
"uid": "_:User7"
}
]
},
{
"uid": "_:User7",
"dgraph.type": "User",
"name": "User 7",
"friend": [
{
"uid": "_:User1"
},
{
"uid": "_:User5"
},
{
"uid": "_:User6"
}
]
},
{
"uid": "_:User8",
"dgraph.type": "User",
"name": "User 8",
"friend": [
{
"uid": "_:User7"
}
]
},
{
"uid": "_:User9",
"dgraph.type": "User",
"name": "User 9",
"friend": [
{
"uid": "_:User7"
}
]
}
]
}