Dgraph DQL Tour

Basic

Queries describe graphs

Dgraph query results are graphs. In fact, the result structure matches the query structure.

The braces edge_name { ... } in the query signify nested blocks where the edges inside the block are matched against nodes found by following the edge that begins the block. We continue nesting the query as we follow edges from node to node.

While not strictly required, it’s a good style to indent the query.

Compare the JSON result to the structure of the query and note, for example, that the friend edge matched a number of nodes and each is represented in the JSON.

Something to try: How about Michael’s friends' pets, or Michael’s friends' friends.

The idea is to formulate the query as a traversal through the graph, following edges to the desired data. The uid’s in the JSON output allow interpretation as a graph rather than a tree. See, for example, the cycles in Michael’s friends' friends.

2.5 Queries describe graphs