You can also use Upsert Block. (There is a JSON version, which I believe it works only via HTTP/cURL):
upsert {
query {
q(func: eq(company_name, "Acme")) {
v as uid #Find the company
}
}
mutation {
set {
_:NewUser <name> "Example name" .
_:NewUser <dgraph.type> "Person" .
_:NewUser <works_for> uid(v) .
}
}
}
See https://dgraph.io/docs/mutations/upsert-block/#sidebar
You have to remove the “company_name” from your users to not confuse it.
Liveloader has some options to do automatic upserts. But you have to use a flag to record the XIDs and also keep tracking XIDs(XIDs are external identifiers, in the case of Dgraph, Blank nodes will be considered XIDs during the load).