I have a graph of different ids. My requirement is I want to add a new pair to the system. But I am not sure if both the pair exists or not. It could be that
u1 exists and u2 doesn’t
u1 doesn’t exist and u2 exists
u1 and u2 both exist
u1 and u2 both are not there.
So, can I do all of the operations in a single upsert block ?
type:
type IdNode {
idval: string
idtype: string
ts: int
conn: [IdNode]
}
idval: string @index(exact) .
data:
{
set {
_:uuid1 <idval> "uuid1" .
_:uuid1 <idval> "uuid" .
_:uuid1 <dgraph.type> "IdNode" .
_:uuid1 <ts> "12313223211" .
_:uuid1 <conn> _:gm1 .
_:gm1 <idval> "mygmail.com" .
_:gm1 <idtype> "gmail" .
_:gm1 <dgraph.type> "IdNode" .
_:gm1 <ts> "12313223213" .
_:uuid2 <idval> "uuid2" .
_:uuid2 <idtype> "uuid" .
_:uuid2 <dgraph.type> "IdNode" .
_:uuid2 <ts> "12313223212" .
_:uuid2 <conn> _:gm1 .
_:uuid3 <idval> "uuid3" .
_:uuid3 <idtype> "uuid" .
_:uuid3 <dgraph.type> "IdNode" .
_:uuid3 <ts> "12313223212" .
_:uuid3 <conn> _:uuid2 .
_:eid <idval> "eid" .
_:eid <idtype> "eid" .
_:eid <dgraph.type> "IdNode" .
_:eid <ts> "12313223212" .
_:eid <conn> _:uuid1 .
_:fb <idval> "fb.com" .
_:fb <idtype> "fb" .
_:fb <dgraph.type> "IdNode" .
_:fb <ts> "12313223212" .
_:fb <conn> _:uuid1 .
}
}
questions
- insert uuid9 and fb.com mapping. (in this case uuid9 doesn’t exist and fb.com is present)
- insert uuid9 and uuid10 mapping. (in this case both don’t exist, so the system should create two nodes and join them together)
- connect eid and mygmail.com. (in this case both exist and are not connected, so connect them)
- connect eid and uuid.(dont do anything, as they are already connected)
Can we do all of the above query in a single upsert block?