Run a mutation with a external id

I am trying to use a external id instead of default UID for a subject of a N-quad record.

According to the docs: External-ids:

I should use a_fixed_identifier as the subject of a N-quad record, so I try to mutate the database like this:

# <lianlian>: the fixed_identified that I want to use as a external id
# <type>: the predicate
# "product": a value object
curl -s -XPOST localhost:8080/mutate/25 -d '
{
  set {
    <lianlian> <type> "product" .
  }
}
'

However, I got a error response:

{
  "errors": [
    {
      "code": "ErrorInvalidRequest",
      "message": "strconv.ParseUint": parsing \"lianlian\": invalid syntax"
    }
  ],
  "data": null
}

Seems like Dgraph tried to parse the External ID as a integer which causes the error?

Is it a wrong usage of external id?

Yes.

In the documentation says:

As of version 0.8 Dgraph doesn’t natively support such external IDs as node identifiers. Instead, external IDs can be stored as properties of a node with an xid edge. For example, from the above, the predicate names are valid in Dgraph, but the node identified with <http://schema.org/Person> could be identified in Dgraph with a UID, say 0x123 , and an edge

Dgraph will never identify <lianlian> as BlankNode or something valid.
As you can see at Get started with Dgraph
In the RDF format used by Dgraph the Entity will always represent a standard Dgraph entity identification. Be it a BlankNode or a UID (eg: 0x1a35).

This part of the Get started with Dgraph documentation is teaching how to use this xid as part of the Node itself. Not as a RDF markup identifier.

In other words, it is transforming this
_: userA <http://schema.org/type> <http://schema.org/Person>.
into a node with UID ==> “0x123” or
<0x123> <xid> "http://schema.org/Person".

It transforms the <http://schema.org/Person> into a Dgraph Node
<0x123> <xid> "http://schema.org/Person".

I got it.

After reading this https://docs.dgraph.io/v1.0.7/mutations/#external-ids carefully, I found that: it is the Dgraph’s input language RDF supports this form of external id: <a_fixed_identifier> <predicate> literal/node, which I misunderstood it as the form of Dgraph that it supports.

Thanks a lot.

1 Like