When using the dgraph-http-js-client to perform mutation like this simple example:
try {
const person = {
'dgraph.type': 'Customer',
'uid': '_:michael',
'Customer.username': "Michael"
}
// Perform any number of queries and mutations
const response = await txn.mutate({ setJson: [
person
]
});
await txn.commit();
} catch (e) {
if (e === dgraph.ERR_ABORTED) {
} else {
throw e;
}
} finally {
await txn.discard();
}
Results: duplicate “Michael” nodes are created.
However, when using the online interface to do this:
mutation {
addCustomer(input: [{ username: "Michael"}]) {
customer {
username
}
}
}
The result is:
{
"errors": [
{
"message": "mutation addCustomer failed because Found multiple nodes with ID: 0xfffd8d6acce814d2",
"locations": [
{
"line": 2,
"column": 3
}
],
"path": [
"addCustomer"
]
}
],
"data": {
"addCustomer": null
},.....
Which is correct because “Michael” already exists.
The question is why the first method of mutate keeps creating the “Michael” nodes?
Many thanks in advance.