DQL and GraphQL queries¶
Embedded 0.2.1 runs the same DQL executor and GraphQL layer as the standalone servers, but with single-node semantics: no Raft, zero, worker, ACL, or namespaces. Instances are isolated by handle, and graph data lives in the instance's posting partition.
For complete movies, TODO, and orders walkthroughs, see Embedded tutorials.
Schema: optional for scalars, required for relationships/indexes¶
Basic scalar predicates are auto-derived by mutations, Dgraph-style:
name becomes a scalar string predicate and has(name) works without any
schema. But declare schema when you need:
- UID/relationship predicates (
friend: [uid]); otherwise the engine may infer a scalar and reject the UID value. - Reverse edges (
@reverse) for~friendtraversal. - Indexes for
eq,term,hash,int, and similar root functions. - Type definitions for schema-aware expansion/cascade and GraphQL-derived
schemas. The
type(Person)root itself matchesdatastreamdb.typeedges.
name: string @index(exact, term) .
age: int @index(int) .
friend: [uid] @reverse .
type Person {
name
age
friend
}
Apply it once per instance (it is persisted for fjall directories):
db.dql_alter(r#"
name: string @index(exact, term) .
age: int @index(int) .
friend: [uid] @reverse .
type Person {
name
age
friend
}
"#)?;
db.dqlAlter(`
name: string @index(exact, term) .
age: int @index(int) .
friend: [uid] @reverse .
type Person {
name
age
friend
}
`)
db.dql_alter("""
name: string @index(exact, term) .
age: int @index(int) .
friend: [uid] @reverse .
type Person {
name
age
friend
}
""")
C uses the envelope:
{"op":"dql_alter","schema":"name: string @index(exact) . friend: [uid] @reverse . type Person { name\nfriend }"}
Relationship data¶
let assigned = db.dql_mutate(r#"{
set {
_:ada <name> "Ada" .
_:ada <age> "36"^^<xs:int> .
_:bob <name> "Bob" .
_:bob <age> "25"^^<xs:int> .
_:ada <friend> _:bob .
_:ada <datastreamdb.type> "Person" .
_:bob <datastreamdb.type> "Person" .
}
}"#)?;
dql_mutate returns blank-node assignments (_:ada -> uid). GraphQL mutations
use the same engine and do not need a separate DQL mutation.
Deleting data¶
Delete blocks take UIDs, so query them first:
Delete one relationship edge:
Delete every value of a property:
Or delete one exact scalar value:
Pass these to dql_mutate / dqlMutate / dql_mutate like any other
mutation. The reverse edge is removed with the forward edge.
Facets are replaced when the edge is set again; omitted facets are dropped.
Setting the edge with no facet map clears all facets. Deleting the edge removes
its facets. S * * is not applied in 0.2.1 — delete predicates individually.
See deletes for the full rules.
Relationship traversal¶
const result = JSON.parse(db.dqlQuery(`
{ people(func: eq(name, "Ada")) { name friend { name } } }
`))
Reverse edges work with ~friend when the predicate has @reverse:
Recursive queries¶
@recurse walks a predicate repeatedly. Put every predicate in one block;
nested child blocks are rejected.
depthcounts levels including the root:depth: 1returns only the root,depth: 2adds direct friends, and so on.loop: false(the default) deduplicates edges, so a cycle is traversed once and expansion stops when no new edge remains.loop: trueallows revisiting edges and requiresdepth > 0. Use it when repeated paths in a cyclic graph matter.- Omit
depth(or set0) withloop: falsefor unbounded expansion. The engine stops at the 1,000,000-edge query budget. $depthand$loopvariables parse, but embedded 0.2.1 does not expose query variables; use literals. Standalone accepts them in the variables header.
The friend predicate must be declared as [uid] (and @reverse if you need
~friend).
Nested pattern filters¶
This is a pattern query: the root selects candidates, @filter constrains the
root, and the nested friend block applies a second filter to related nodes.
@normalize, @cascade, @ignorereflex, and @groupby are also available.
@ignorereflex is a block-level directive: put it on the query block, not on a
predicate. See the DQL directives table for the
full list.
Other useful roots and filters:
{ q(func: has(friend)) { name } }
{ q(func: uid(0x2, 0x3)) { name friend { name } } }
{ q(func: eq(age, 36)) @filter(has(friend)) { name } }
{ q(func: has(name), orderasc: name, first: 10) { name } }
GraphQL schema and queries¶
db.setGraphqlSchema(`
type Post {
id: ID!
title: String @search(by: [term])
numLikes: Int @search
author: Author @hasInverse(field: posts)
}
type Author {
id: ID!
name: String @id @search(by: [hash])
posts: [Post]
}
`)
Mutation and relationship query:
mutation {
addPost(input: [{title: "Hello", numLikes: 42, author: {name: "Ann"}}]) {
post { id title numLikes author { name } }
numUids
}
}
GraphQL subscriptions¶
Subscriptions are poll-based. The embedded handle captures an initial response, then returns a changed response when the query result changes:
const id = db.graphqlSubscribe(`
subscription {
queryPost(filter: {title: {anyofterms: "Hello"}}) {
title
numLikes
}
}
`)
let event = JSON.parse(db.graphqlNext(id, 0)) // initial: changed=true
db.graphql('mutation { addPost(input: [{title: "Hello again"}]) { numUids } }')
event = JSON.parse(db.graphqlNext(id, 1000)) // changed=true after the mutation
db.graphqlUnsubscribe(id)
graphqlNext(id, wait_ms) blocks up to wait_ms, polling at the subscription
interval. It returns {changed, closed, response?}; closed becomes true when
the subscription is cancelled or the GraphQL schema is replaced.
In Rust, use the Subscription handle directly:
let sub = db.graphql_subscribe(query, json!({}), &headers, Duration::from_millis(100))?;
assert!(matches!(sub.next()?, SubscriptionEvent::Changed(_)));
let changed = sub.next_timeout(Duration::from_secs(2))?;
sub.close();
Supported types¶
The schema reference has a declaration and query example for every type and index tokenizer.
DQL predicate types¶
| Type | Meaning | Index tokenizers |
|---|---|---|
string |
UTF-8 text | exact, term, fulltext, trigram, hash |
int |
64-bit signed integer | int |
float |
64-bit floating point | float |
bool |
Boolean | bool |
datetime |
RFC3339 date/time; use this for calendar dates | year, month, day, hour |
geo |
GeoJSON geometry: Point, LineString, Polygon, MultiPolygon | geo |
uid |
Relationship to another node | Not indexable; supports @reverse |
password |
Hashed password | Not indexable |
bigfloat |
Arbitrary-precision decimal | No dedicated index tokenizer |
binary |
Raw bytes | Schema-supported; not exposed in GraphQL |
float32vector |
Float vector | Vector indexes are not supported in embedded 0.2.1 |
default |
Untyped/auto-derived scalar | Depends on the derived type |
There is no separate date type: use datetime with an RFC3339 value such
as "2026-11-25T00:00:00Z".
Spatial types¶
DQL uses geo and stores GeoJSON geometries. GraphQL exposes them as:
| GraphQL type | Geometry |
|---|---|
Point |
Point |
PointList |
Line string / point list |
Polygon |
Polygon |
MultiPolygon |
Multi-polygon |
GraphQL type mapping¶
| GraphQL type | DQL type |
|---|---|
ID |
uid |
String |
string |
Int / Int64 |
int |
Float |
float |
Boolean |
bool |
DateTime |
datetime |
Point, PointList, Polygon, MultiPolygon |
geo |
[T] |
list predicate |
| Object type | uid relationship, usually with @hasInverse |
Other data¶
| Item | Embedded graph support |
|---|---|
| Relationships | uid predicates, lists, @reverse, @hasInverse in GraphQL SDL |
| DQL values | RDF literals in mutations; JSON output from queries |
| GraphQL values | GraphQL scalar/object/list types from the user SDL |
| Raw KV values | UTF-8 strings in bindings; arbitrary bytes in Rust |
| Binary graph values | Not exposed in the 0.2.1 GraphQL/DQL envelope |
Errors¶
- Rust:
Result<_, CoreError>(Query,Schema,Posting,GraphQl). - Node: thrown
Error. - Python:
RuntimeError. - C: non-zero status +
datastreamdb_last_error().
GraphQL execution errors are returned inside the GraphQL response
(response.errors), not as transport errors.
0.2.1 boundaries¶
- Single-node only; no Raft/zero/worker, ACL, or namespaces.
- DQL alters are additive/updating; drop operations are not exposed.
- DQL upserts/conditional mutations and query variables are not exposed yet.
- GraphQL subscriptions are poll-based; no WebSocket transport.
@auth,@customHTTP/lambda resolvers, remote schemas, and vector indexes are not supported in embedded mode.