Dgraph DQL Tour

Basic

Facets : Edge attributes

Dgraph supports facets — key value pairs on edges — as an extension to RDF triples. That is, facets add properties to edges, rather than to nodes. For example, a friend edge between two nodes may have a boolean property of close friendship. Facets can also be used as weights for edges.

More details about Facets you can find in our Docs: https://dgraph.io/docs/query-language/#facets-edge-attributes

Reading all the documentation about Facets you will have examples of:

  • Facets on scalar predicates
  • Alias with facets
  • Facets on UID predicates
  • Filtering on facets
  • Sorting using facets
  • Assigning Facet values to a variable
  • Facets and Variable Propagation
  • Facets and Aggregation

For JSON mutation with Facets see: https://dgraph.io/docs/mutations/#facets

Run this mutation on you terminal, before running the query:

Add multiple attributes to a third single node

Sometimes you need two Edges with distinct predicates pointing to the same node. This feature can be used to “explain the relationship” of nodes.

Let’s say you have a existing Node that’s your target his UID is “0x0f43”. So you need to setup your RDF like this.

_:MyNode <predicate1> <0x0f43> ( foo=bar, and=1 ) .
_:MyNode <predicate2> <0x0f43> ( bar=bar, and=2 ) .
_:MyNode <predicate3> <0x0f43> ( bar=bar, and=3 ) .

more examples:

If you do the same mutation above but using the same predicates instead of unique one. You will override the Edge attribute. Line by line. So you must to use distinct predicates.

2.17 Facets : Edge attributes