How to link nodes of same type together?

I have big table (>100mi rows) with 2 columns, each row represents 1 connection between same data types.

person | friend

userId1 | userId2
userId1 | userId3
userId1 | userId4
userId2 | userId4

I tested this data in neo4j (loaded it with command):

LOAD CSV WITH HEADERS FROM 'file:///out-edges.csv' AS row
MERGE (f:Person {hash: row.Friend})
MERGE (p:Person {hash: row.Person})
MERGE (p)<-[:FRIEND]-(f)

And after queried whole graph with:

MATCH (p:Person)<-[:FRIEND*1..15]-(f:Person)
RETURN p, f

In dgraph i can’t understand how to make recursive connection using this table.
I tried to create mutation like:
{"hash": ..., friend:{"hash": ...}}

And after query it with:

query {
  q(func: has(friend) {
    hash
    friend {
      hash
    }
  }
}

But it doesn’t work like i expected. Dgraph returns a lot of edges but not connected between recursively. Just 1 edge per table’s row.
Could you help me to understand how to implement the same task on dgraph? Thanks.

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) .
    }
  }
}

Thanks for your reply.
As i understand person and friend fields in your request should be uid type. But what should i do, if id’s wasn’t created by dgraph? This hashes is uint64 from another db.

I have added in the example what you should do. You have to pick one.

#If the value in the userId is any value
1 Like