Dgraph GraphQL Tour


Queries describe graphs

GraphQL query results are graphs; in fact, the query result is structured like the query.

The braces in a query like <edge name> { ... } 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 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 shown below.

Something to try: Query to get a list of Alice’s friends' pets, or Alice’s friends' friends.

In these examples, you’ll see that you formulate a query as a traversal through a graph, following edges to the desired data. The id’s in the JSON output allows for interpretation as a graph rather than a tree. Because the output is a graph rather than a tree, you will see some cycles (or repeated nodes) in the query for Alice’s friends' friends.

2.4 Queries describe graphs