Triples - Mutations

A mutation that adds triples is done with the set keyword.

  set {
    # triples in here

The input language is triples in the W3C standard RDF N-Quad format.

Each triple has the form

<subject> <predicate> <object> .

Meaning that the graph node identified by subject is linked to object with directed edge predicate. Each triple ends with a period. The subject of a triple is always a node in the graph, while the object may be a node or a value (a literal).

For example, the triple

<0x01> <name> "Alice" .
<0x01> <dgraph.type> "Person" .

Represents that graph node with ID 0x01 has a name with string value "Alice". While triple

<0x01> <friend> <0x02> .

Represents that graph node with ID 0x01 is linked with the friend edge to node 0x02.

Dgraph creates a unique 64 bit identifier for every blank node in the mutation - the node’s UID. A mutation can include a blank node as an identifier for the subject or object, or a known UID from a previous mutation.

This is a companion discussion topic for the original entry at

Is it possible to refer to field of another node by uid when using triples?

For example:
_:node1 <Person.father_name> {refer to another Person by uid and return their}

I don’t want to directly refer to another node because I’d like this referred data not to be affected if the referred object is deleted later.

You can use an upsert mutation (docs) to do this with a query variable and val().

upsert {
  query {
    var(func: uid(0x123)) {
      fn as
  mutation {
    set {
      <_:node1> <Person.father_name> val(fn) .
1 Like