We’re overhauling Dgraph’s docs to make them clearer and more approachable. If
you notice any issues during this transition or have suggestions, please
let us know.
<subject>
of a triple is always a node, and must be a numeric
UID. The <object>
of a triple may be another node or a literal value:
name
, and the object is
the literal value string: "Alice"
. The second triple specifies that Alice
knows Bob. The subject is again the UID of a node (the “alice” node), the
predicate is knows
, and the object of this triple is the UID of the other node
(the “bob” node). When the object is a UID, the triple represents a relationship
in Dgraph.
Each triple representation in RDF ends with a period.
Blank nodes in mutations
When creating nodes in Dgraph, you often let Dgraph assign the node UID by specifying a blank node starting with_:
. All
references to the same blank node, such as _:identifier123
, identify the same
node within a mutation. Dgraph creates a UID identifying each blank node.
Language for string values
Languages are written using@lang
. For example
Types
Dgraph understands standard RDF types specified in RDF using the^^
separator.
For example
Storage Type | Dgraph type |
---|---|
<xs:string> | string |
<xs:dateTime> | dateTime |
<xs:date> | datetime |
<xs:int> | int |
<xs:integer> | int |
<xs:boolean> | bool |
<xs:double> | float |
<xs:float> | float |
<geo:geojson> | geo |
<xs:password> | password |
<http://www.w3.org/2001/XMLSchema#string> | string |
<http://www.w3.org/2001/XMLSchema#dateTime> | dateTime |
<http://www.w3.org/2001/XMLSchema#date> | dateTime |
<http://www.w3.org/2001/XMLSchema#int> | int |
<http://www.w3.org/2001/XMLSchema#positiveInteger> | int |
<http://www.w3.org/2001/XMLSchema#integer> | int |
<http://www.w3.org/2001/XMLSchema#boolean> | bool |
<http://www.w3.org/2001/XMLSchema#double> | float |
<http://www.w3.org/2001/XMLSchema#float> | float |
Facets
Dgraph is more expressive than RDF in that it allows properties to be stored on every relation. These properties are called Facets in Dgraph, and dgraph allows an extension to RDF where facet values are included in any triple.Creating a list with facets
The following set operation uses a sequence of RDF statements with additional facet information:Dgraph can automatically generate a reverse relation. If the user wants to run
queries in that direction, they would define the reverse
relationship
N-quads format
While most RDF data uses only triples (with three parts) an optional fourth part is allowed. This fourth component in RDF is called a graph label, and in Dgraph it must be the UID of the namespace that the data should go into as described in Multi-tenancy.Processing RDF to comply with Dgraph syntax for subjects
While it’s valid RDF to specify subjects that are IRI strings, Dgraph requires a numeric UID or a blank node as the subject. If a string IRI is required, Dgraph support them via xid properties. When importing RDF from another source that does not use numeric UID subjects, it will be required to replace arbitrary subject IRIs with blank node IRIs. Typically this is done simply by prepending ”_:” to the start of the original IRI. So a triple such as:<http://abc.org/schema/foo#item1> <http://abc.org/hasRelation> "somevalue"^^xs:string
may be rewritten as
<_:http://abc.org/schema/foo#item1> <http://abc.org/hasRelation> "somevalue"^^xs:string
Dgraph will create a consistent UID for all references to the uniquely-named
blank node. To maintain this uniqueness over multiple data loads, use the
dgraph live utility with the xid option, or use specific
UIDs such as the hash of the IRI in the source RDF directly.