Ask a Question

Advanced Queries with DQL

You can now embed DQL queries inside your GraphQL schema, which is recommended for most use cases. The rest of this document covers how to connect to your Dgraph Cloud backend with existing Dgraph clients.

In addition to GraphQL support, Dgraph Cloud also supports running advanced queries using Dgraph Query Language (DQL) (previously named GraphQL+-). DQL is based on GraphQL, but adds and removes features to better support graph database operations. Advanced users can use DQL to send queries and mutations to Dgraph Cloud’s HTTP or gRPC endpoints using the Dgraph client libraries. To learn more about the Dgraph client libraries, see the client library documentation. To learn more about DQL, see DQL Fundamentals..

If you are getting started with Dgraph Cloud, you should probably start out by using Dgraph’s GraphQL API instead. Dgraph’s GraphQL API lets you quickly use Dgraph Cloud before moving on to the advanced features available using DQL.

Note Dgraph Cloud’s schema modes let you configure whether and how schema changes are allowed. To alter your schema using the /alter HTTP and GRPC endpoints, you’ll need to use Flexible Mode.


The APIs documented here all require an API token for access. To learn how to create an API token, please see Authentication.


You can query your backend with DQL using your cluster’s /query endpoint. As an example, if your GraphQL endpoint is, then the admin endpoint for the schema is

You can also access the /mutate and /commit endpoints.

For example, let’s say you have the following GraphQL schema:

type Person {
 name: String! @search(by: [fulltext])
 age: Int
 country: String

Here is an example of a cURL command with the /mutate endpoint:

curl -H "Content-Type: application/rdf" -H "x-auth-token: <api-key>" -X POST "<graphql-endpoint>/mutate?commitNow=true" -d $'
 set {
    _:x <> "John" .
    _:x <Person.age> "30" .
    _:x <> "US" .

Here is an example of a cURL command with the /query endpoint:

curl -H "Content-Type: application/dql" -H "x-auth-token: <api-key>" -XPOST "<graphql-endpoint>/query" -d '{
   queryPerson(func: type(Person))  {


Dgraph Cloud is compatible with most existing Dgraph clients. You can use the helper methods from each library to connect to your backend, passing in a Dgraph Cloud endpoint and an API token.

Here is an example which uses the pydgraph client to make gRPC requests.

import pydgraph

client_stub = pydgraph.DgraphClientStub.from_slash_endpoint("", "<api-key>")
client = pydgraph.DgraphClient(client_stub)

Here is an example of a mutation using the pydgraph client:

mut = {
  "": "John Doe",
  "Person.age": "32",
  "": "US"

txn = client.txn()
  res = txn.mutate(set_obj=mut)

Here is an example of a query using the pydgraph client:

query = """
   queryPerson(func: type(Person))  {
txn = client.txn()
  res = txn.query(query)
  ppl = json.loads(res.json)

Connecting from Dgraph Clients

Below are snippets to connect to your Dgraph Cloud backend from various Dgraph clients.


import pydgraph

client_stub = pydgraph.DgraphClientStub.from_slash_endpoint("", "<api-key>")
client = pydgraph.DgraphClient(client_stub)


const dgraph = require("dgraph-js");

const clientStub = dgraph.clientStubFromSlashGraphQLEndpoint(
const dgraphClient = new dgraph.DgraphClient(clientStub);


// This example uses dgo
conn, err := dgo.DialSlashEndpoint("", "<api-key>")
if err != nil {
defer conn.Close()
dgraphClient := dgo.NewDgraphClient(api.NewDgraphClient(conn))


// This example uses dgraph4j
DgraphStub stub = DgraphClient.clientStubFromSlashEndpoint("", "<api-key>");
DgraphClient dgraphClient = new DgraphClient(stub);

C# / .NET

var client = new DgraphClient(SlashChannel.Create("", "<api-key>"));

Visualizing your Graph with Ratel

You can use Ratel to visualize your Dgraph Cloud backend with DQL. You can host Ratel yourself, or you can use Ratel online at Dgraph Play.

To configure Ratel:

  1. Click the Dgraph logo in the top left to bring up the connection screen (by default, it has the caption:
  2. Enter your backend’s host in the Dgraph Server URL field. This is obtained by removing /graphql from the end of your /graphql endpoint URL. For example, if your /graphql endpoint is, then the host for Ratel is
  3. Click the Connect button. You should see a green check mark next to the word Connected.
  4. Click on the Extra Settings tab, and then enter your API token into the API Key field. To create a new API token, see Authentication.
  5. Click on the Continue button.

You can now run queries and mutations using Ratel, and see visualizations of your data.

Ratel has certain limitations; it doesn’t support backups, modifying ACL or attempting to remove nodes from the cluster.

Switching Schema Modes

If you want to use DQL as your primary mode of interaction with the Dgraph Cloud backend (instead of primarily using the GraphQL API), you can switch your backend to flexible mode. To learn more, see Schema Modes.