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.
- Create a new Dgraph graph
- Connect your graph to the Ratel web client
- Add data using mutations
- Query the graph using DQL
- Update the graph schema to support more advanced queries
Run Dgraph and connect the Ratel web UI
The recommended way to get started with Dgraph for local development is by using the official Dgraph Docker image. In this section we’ll create a new graph, then we’ll connect our new graph to Ratel, the web-based UI for Dgraph.1
Run Dgraph with Docker
The This will create a local Dgraph instance and expose the ports necessary to connect to Dgraph via HTTP and gRPC. Specifically:
dgraph/standalone
Docker image has everything needed to run Dgraph locally.Ensure you have Docker installed, then run the following command to start a local Dgraph instance:docker run
- initiates a new Docker container--rm
- automatically removes the container when it exits, helping with cleanup-it
- uses interactive mode to show output of the container-p 8080:8080
- maps port 8080 from the host machine to port 8080 in the Docker container to allow Dgraph HTTP connections-p 9080:9080
- maps port 9080 from the host machine to port 9080 in the Docker container to allow Dgraph gRPC connectionsdgraph/standalone:latest
- specifies the Docker image to use, this is the official Dgraph image with latest tag
2
Connect Ratel
Ratel is a web-based UI dashboard for interacting with Dgraph using Dgraph’s query language,DQLNavigate to the hosted version of Ratel at 
Now select Connect to verify the connection and then select Continue to access the Ratel console.
Now we’re ready to add data to our graph.
https://ratel.hypermode.com
and enter http://localhost:8080
for the “Dgraph Conn String”.
This will allow Ratel to connect to our local Dgraph instance and execute DQL queries.
You can also run Ratel locally by running the
dgraph/ratel
container with the following command:
Add data to the graph with a mutation
Graph databases like Dgraph use a data model called the property graph, which consists of nodes, relationships that connect nodes, and key-value pair properties that describe nodes and relationships. With Dgraph, we use triples to describe each piece of our graph, which when combined together make up our property graph. Triples are composed of a subject, predicate, and object.
1
Add mutation in Ratel
The create, update, and delete operations in Dgraph are called mutations.In the Ratel Console page, select the Mutate tab, then paste the
following mutation:The preceding DQL mutation uses
N-Quad RDF format to define the triples that
make up the property graph we want to create.
2
View mutation results
Select Run to execute the mutation. In the JSON tab we can see the result of
this mutation.Dgraph displays the universal identifiers (UID) of the
nodes that were created.
Query the graph
1
Query for all movies
In the Console page, select the Query tab and run this query:This query searches for all
Movie
nodes as the start of the traversal using
the type(Movie)
function to define the starting point of our query traversal,
then finds any genres, directors, and characters connected to each movie.2
View results in JSON and graph visualization
In Ratel’s JSON tab we can view the results of this query as JSON:In the response panel, Select Graph to view a graph visualization of the
results of our query:

Update the graph schema and query using an index
The previous query used thetype()
function to find the starting point of our
graph traversal. We can use more complex functions to filter by string
comparison operator, and others, however to use these function we must first
update the graph schema to create an index on the predicates we want to use in
these functions.
The function documentation specifies which kind of
index is needed for each function.
We’ll use Ratel to alter the schema to add indexes on some of the data so
queries can use term matching, filtering, and sorting.
1
Create an index for movie title
In Ratel’s Schema page, select Predicates. Here we can see all the
predicates used in the graph. A predicate is
Dgraph’s internal representation of a node, property, or relationship.Select the 
Movie.title
predicate. Ratel displays details about the predicate
type and indexes.Change the type to string then select index and select term for the
Movie.title
predicate, then select Update to apply the index.
2
Create an index for movie release date
Next, we’ll create an index for the 
Movie.release_date
predicate.Select the Movie.release_date
predicate. Change the type to dateTime.
Select index and choose year for the index tokenizer. Click Update
to apply the index on the release-date
predicate.
3
Query using indexes
Now let’s find all movies with the term “Star” in their title and released
before 1979.In the Console page select the Query tab and run this query:We can see the JSON result in the JSON tab:And also view the graph visualization of the result in the Graph tab:
Try changing the release date and the search terms conditions to see Dgraph
search and filtering in action.

Reverse relationship query
1
Add reverse relationship
In the previous queries we traversed from the movie node to its connected genre
node, but what if we want to find all movies connected to a genre node? In order
to traverse from a genre node to a movie node we need to explicitly define the

Movie.genre
predicate as a reverse relationship.To define a reverse relationship for the Movie.genre
predicate we’ll return to
the Schema page in Ratel, select the Movie.genre
predicate and toggle the
reverse checkbox. Then select Update to apply this schema change.
2
Query using the reverse relationship
In a DQL query the Note that we can also alias the field name to “movies” in our result JSON using
the syntax
~
operator is used to specify a reverse relationship. To
traverse from a genre node to a movie node we use the syntax ~Movie.genre
.In this query we find all movies connected to the “Sci-Fi” genre:movies: ~Movie.genre
.Where to go from here
- Learn more about using DQL to query your graph.
- Go to Clients to see how to communicate with Dgraph from your app.
- Learn how to build intelligent applications using Dgraph and Modus such as natural language search.
Need help
- Join the Hypermode Discord server for questions, issues, feature requests, and discussions.