Maybe something like this
upsert {
query {
q(func: type(out-edges)) {
P as person
F as friend
}
#If the value in the userId is a UID
qP as qPerson(func: uid(P))
qF as qFriend(func: uid(F))
#If the value in the userId is any value
qP as qPerson(func: eq(myID, val(P)))
qF as qFriend(func: eq(myID, val(F)))
}
mutation {
set {
uid(qP) <friend> uid(qF) .
}
}
}