@id directive and mutations

Hello, I am new with Dgraph. Now I am trying to make it a part of ETL process and import some data in Dgraph database.
From the documentation I learnt that setting @id directive in my schema allows me to avoid duplicates on mutations:
https://dgraph.io/docs/graphql/schema/ids/

Dgraph requires a unique username when creating a new user. It generates the input type for addUser with username: String! , so you can’t make an add mutation without setting a username; and when processing the mutation, Dgraph will ensure that the username isn’t already set for another node of the User type.

So that one drew my special attention: “Dgraph will ensure that the username isn’t already set for another node of the User type”

So I created schema:

type Experiment {
  uuid: String! @id
  name: String
}

Then I run following mutation in Ratel:

{
	"set": {
  		"dgraph.type": "Experiment",
		"Experiment.name": "Dock",
		"Experiment.uuid": "1000"
	}
}

I do it twice by let’s say … by mistake,

and when I request for Experiment nodes, I have two!

      {
        "uid": "0x13881",
        "Experiment.name": "Dock",
        "Experiment.uuid": "1000"
      },
      {
        "uid": "0x13882",
        "Experiment.name": "Dock",
        "Experiment.uuid": "1000"
      }
    ]

Despite uuid is already set, ratel added two records!
Does that mean that Dgraph does not ensure that Experiment.uuid already exists?

You are mixing the concept of GraphQL with DQL/RDF. They are two different things. And no GraphQL feature will work in DQL out of the box. There’s no way to DQL/RDF check @id during a mutation.

The only way to guarantee this is by using a UID. Instead of @id in the DQL end.

1 Like

Check this out to help get you started with many of the same questions I and many others have about Dgraph, GraphQL, and DQL

1 Like