Quickstart
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.
This is a quick start guide to run DQL queries and mutations.
This guide helps you:
- Understand how JSON data is represented as a graph
- Query the graph using DQL
- Use indexes
Step 1: Run Dgraph
The easiest way to get Dgraph up and running is using the Dgraph on Hypermode.
- In the Hypermode console, click Launch new backend
- Select a region that meets your requirements
- Type a name for your graph instance
- Click Launch
- Click Ratel to access the UI that provides browser-based queries, mutations and visualizations.
Step 2: Run mutation
The create, update, and delete operations in Dgraph are called mutations.
Ratel makes it easier to run queries and mutations.
-
In the Console page, select Mutate tab.
-
Paste the following:
The input data is in JSON Format. Dgraph also supports RDF notation.
The sample JSON data is an array of two movies with some attributes. These are stored as Nodes in Dgraph.
The “Star Wars” movie has a
director
field which is an JSON object and astarring
field which is an array of JSON objects. Each object is also stored as a Node in Dgraph . Thedirector
andstarring
are stored as relations. -
Click Run to execute the mutation.
View the Dgraph response in the JSON tab:
Dgraph displays the universal identifiers (UID) of the nodes that were created.
Step 3: First query
-
In the Console page, select Query tab and run this query:
The query lists all movies that have a
release_date
and for each, it looks for thedirector
andstarring
relations and provides the name attribute of the related nodes if any. -
In the response panel, select Graph, to view a Graph output:
Step 4: Alter schema
Alter the schema to add indexes on some of the data so queries can use term matching, filtering, and sorting.
- In the Schema page, select Predicates. Dgraph creates and displays
the predicates
name
,release-date
,director
andstarring
. A predicate is Dgraph internal representation of a node attribute or a relation. - Select the
name
predicate. Ratel displays details about the predicate type and indexes. - Select index and select term for
name
predicate. - Click Update to apply the index.
Set the index for the release_date
:
- Select
release_date
predicate. - Change the type to dateTime
- Select index and choose year for the index type.
- Click Update to apply the index on the
release-date
predicate.
Step 5: Queries using indexes
Let’s get the movies having the term “Star” in their name and released before 1979.
In the Console page select Query tab and run this query:
Observe the JSON result and the graph result.
You can play with the release date and the search terms conditions to see Dgraph search and filtering in action.
In these five steps, you set up Dgraph, added some data, visualized it as a graph, added indexes and queried the data .
Where to go from here
- Take the Tour for a guided tour of how to write queries in Dgraph.
- A wider range of queries can also be found in the Query Language reference.
- Go to Clients to see how to communicate with Dgraph from your app.
Need help
- Please use discuss.dgraph.io for questions, issues, feature requests, and discussions.
Was this page helpful?