Mutation should fail but instead creates fake UIDs

Version: v21.12.0

I am executing a mutation through Ratel:

{
  "set": [
    {
      "User.name": "Test User",
      "User.website": "test.com",
      "User.games": [
        {
          "Game.id": "0x851ff2e"
        }
      ]
    }
  ]
}

dgraphs response

{
  "data": {
    "code": "Success",
    "message": "Done",
    "queries": null,
    "uids": {
      "dg.2413928439.103": "0x9a4e4fc",
      "dg.2413928439.104": "0x9a4e4fb"
    }
  },
......
......

This should fail since the entry already exists. Instead, Dgraph is returning a successful JSON with two UIDs created.

First of all, I don’t understand what are those two UIDs. Also, those UIDs don’t exist in the database after the call.

Can someone help me understand what is happening?

Every time you submit a mutation without declaring the UID key with an existing UID. Dgraph will create new uids. So new entities every time you run the same mutation.

The correct mutation would be

{
  "set": [
    {
      "uid": "0x1",
      "User.name": "Test User",
      "User.website": "test.com",
      "User.games": [
        {
          "uid": "0x851ff2e",
          "Game.id": "0x851ff2e" #Not sure why you did like this
        }
      ]
    }
  ]
}

They do, you are not querying correctly. Dgraph will never fail to record a successful mutation.

Thanks @MichelDiz. Yea it seems that Game.id is wrong but still this doesn’t explain why the new node is being created.

Also, The above mutation is not working either. I found a solution that I need to pass the dgraph.type.
But, if I don’t pass it, it still creates a UID but that UID doesn’t exist anywhere!!!

It is wrong.

The explantion is that every mutation, every entity needs a existing UID.

It works. dgraph.type is part of the Type System. But if you query the exact predicates with the exact UID. You gonna see the data there. But yes, you need dgraph.type and also define that entity type in the schema.
See https://dgraph.io/docs/query-language/type-system/#sidebar