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.
- Running Dgraph using the
dgraph/standalone
docker image. - Running the following basic operations using Dgraph’s UI Ratel,
- Creating a node.
- Creating an edge between two nodes.
- Querying for the nodes.
Running Dgraph
Running thedgraph/standalone
docker image is the quickest way to get started
with Dgraph. This standalone image is meant for quickstart purposes only. It is
not recommended for production environments.
Ensure that Docker is installed and running
on your machine.
Now, it’s just a matter of running the following command, and you have Dgraph up
and running.
Nodes and relationships
The mental picture of the use case may be a graph with 2 nodes representing the 2 persons and an relationship representing the fact that “Ann” follows “Ben” :
Ann
and one holding the information about Ben
.
What we know is the name
and the age
of those persons.
We also know that Ann follows Jessica. This is also stored as a relationship
between the two nodes.
Using Ratel
Launch Ratel image

Mutations using Ratel
The create, update, and delete operations in Dgraph are called mutations. In Ratel console, select theMutate
tab and paste the following mutation into
the text area.
name
and age
with the
corresponding values.
It also creates a predicate ‘follows’ for that entity but the value isn’t a
literal (string, int, float, boolean).
So Dgraph also creates a second entity that’s the object of this predicate. This
second entity has itself some predicates (name
and age
).
Let’s execute this mutation. Click Run!

"uids"
field of the response correspond to the
two entities created for Ann and Ben.
Querying using the has function
Now, let’s run a query to visualize the graph which we just created. We’ll be using Dgraph’shas
function. The expression has(name)
returns all the
entities with a predicate name
associated with them.
Query
tab this time and type in the query. Then, click Run
on the
top right of the screen.


Understanding the query
people
. However, you could use any other name.
The func
parameter has to be associated with a built-in function of Dgraph.
Dgraph offers a variety of built-in functions. The has
function is one of
them. Check out the query language guide to know more
about other built-in functions in Dgraph.
The inner fields of the query are similar to the column names in a SQL select
statement or to a GraphQL query!
You can easily specify which predicates you want to get back.
has
function to find all entities with the age
predicate.
Flexible schema
Dgraph doesn’t enforce a structure or a schema. Instead, you can start entering your data immediately and add constraints as needed. Let’s look at this mutation.name
,
age
, and country
, the second one has name
, age
, and city
.
Schemas aren’t needed initially. Dgraph creates new predicates as they appear in
your mutations. This flexibility can be beneficial, but if you prefer to force
your mutations to follow a given schema there are options available that we’ll
explore in the next tutorial.
Wrapping up
In this tutorial, we learned the basics of Dgraph, including how to run the database, add new entities and predicates, and query them back. Check out our next tutorial of the getting started series here.Need help
- Please use discuss.hypermode.com for questions, feature requests, bugs, and discussions.