Skip to content

DQL guide

DQL (the graph query language) over HTTP: schema in POST /alter, reads in POST /query, writes in POST /mutate. This page covers the core; the full language follows the upstream semantics, and anything in Limitations is not implemented.

Schema

curl -XPOST localhost:8080/alter -d '
name: string @index(exact, trigram) .
age: int .
friend: [uid] .
datastreamdb.type: [string] @index(exact) .
'

Types group predicates for @filter(type(...)):

curl -XPOST localhost:8080/alter -d '
type Person {
  name
  age
  friend
}'

(Type fields go one per line.)

Mutations (RDF)

curl -XPOST 'localhost:8080/mutate?commitNow=true' \
  -H 'content-type: application/rdf' -d '
_:ada <name> "Ada" .
_:ada <age> "36"^^<xs:int> .
_:ada <datastreamdb.type> "Person" .
_:ada <friend> _:grace .
_:grace <name> "Grace" .
_:grace <datastreamdb.type> "Person" .
'

Blanks (_:ada) come back mapped to uids in data.uids. Without commitNow, commit later with the returned start_ts:

curl 'localhost:8080/commit?startTs=123'

Mutations (JSON)

curl -XPOST 'localhost:8080/mutate?commitNow=true' \
  -H 'content-type: application/json' -d '
{"uid": "_:alan", "name": "Alan", "age": 41, "datastreamdb.type": "Person"}'

Queries

curl -XPOST localhost:8080/query -d '{
  ada(func: eq(name, "Ada")) {
    uid name age
    friend { uid name }
  }
}'

Root functions include uid(...), has(pred), eq/le/ge/gt/lt, between, allofterms/anyofterms, regexp, type(...), uid_in, and geo functions. Filters, facets, pagination (first:/offset:), ordering (orderasc:/orderdesc:), and @cascade follow upstream semantics.

Directives

All six DQL directives are implemented in both standalone and embedded mode:

Directive Support Notes
@filter Yes Functions and boolean operators; nested filters.
@normalize Yes Flattens the response to aliased predicates.
@cascade Yes Bare or @cascade(pred, ...); checks nested paths.
@recurse Yes depth and loop; one level of predicates.
@ignorereflex Yes Block-level; removes a node that is its own ancestor.
@groupby Yes count, min, max, sum, avg; aliases.
{ q(func: has(name)) @cascade { name age } }
{ q(func: eq(name, "A")) @ignorereflex { name friend { name } } }
{ q(func: has(age)) @groupby(age) { count(uid) } }

@ignorereflex applies to the query block. Putting it on a predicate (friend @ignorereflex) is rejected. Recursive traversal uses @recurse(depth: N, loop: false) with every predicate in one block; depth includes the root, and loop: true allows cycles and requires a positive depth. See recursive queries for the edge budget and variable rules.

Variables cross blocks with var():

{
  var(func: has(age)) { a as age }
  old(func: gt(age, 30)) @filter(uid(a)) { name }
}

Upserts

cond guards a mutation on the request's query vars (eq/gt/lt/ge/le(len(v), n), AND-joined). It shines over gRPC, where one Request carries both query and mutations: the query runs first, its var() counts feed the guard, and failing mutations are skipped without writing.

Note: POST /mutate carries no query, so every len(v) reads 0 there — @if(eq(len(v),0)) always passes and @if(gt(len(v),0)) always fails over plain HTTP. Real upserts need the gRPC query+mutations form.

Deletes

Deletes ride in delete blocks (bare bodies are always sets):

curl -XPOST 'localhost:8080/mutate?commitNow=true' \
  -H 'content-type: application/rdf' -d '{
    delete { <0x2> <age> * . }
  }'

The delete block takes UIDs or blank nodes, not query functions. Find the UIDs first:

{ q(func: eq(name, "Ada")) { uid friend { uid } } }

Delete one relationship

Delete the specific edge by naming both endpoints:

{
  delete {
    <0x2> <friend> <0x3> .
  }
}

The reverse edge (~friend) is removed with it. Deleting one item from a list predicate removes only that edge.

Delete all values of a predicate

S P * removes every value of that predicate on the node, including its index entries:

{
  delete {
    <0x2> <age> * .
  }
}

For a scalar, naming the exact value also works:

{
  delete {
    <0x2> <age> "30"^^<xs:int> .
  }
}

For a language-tagged value, include the tag: <0x2> <name@es> * ..

Delete every predicate on a node

Dgraph's S * * wildcard is not applied in 0.2.1. The mutation is accepted but leaves the data in place, even on typed nodes. Delete predicates individually with S P *, or drop the predicate server-side with alter.

{ delete { <0x2> <name> * . <0x2> <age> * . <0x2> <friend> * . } }

There is no node-delete operation. Removing all of a node's predicates leaves an empty node; the UID is not reused.

Facets

Facets have no separate delete form. The facet map on an edge is replaced when the edge is set again:

{ set { <0x2> <friend> <0x3> (role="Trinity", billing=2) . } }

Omitted facets are removed — setting the same edge with only role drops billing. Setting the edge with no facet map clears all facets while keeping the edge. Deleting the edge removes the facets with it.

Drop a whole predicate, with all its data, via alter instead:

curl -XPOST localhost:8080/alter -d '{"drop_attr": "age"}'

{"drop_all": true} wipes everything (guardians only under ACL).