DQL Query Language
DQL (Dgraph Query Language) is the primary query language for OWLGraph. It supports graph traversals, filtering, aggregation, and OWLGraph’s ontology-aware extensions.
Basic Query
Section titled “Basic Query”{ q(func: type(Animal)) { name dgraph.type }}Root Functions
Section titled “Root Functions”| Function | Description |
|---|---|
type(X) | Nodes with type X (subsumption-aware) |
exactType(X) | Nodes with explicitly asserted type X |
eq(pred, val) | Equality match |
has(pred) | Nodes with the predicate |
allofterms(pred, "words") | Full-text term match |
anyofterms(pred, "words") | Any term match |
regexp(pred, /pattern/) | Regex match |
uid(0x1, 0x2) | Specific UIDs |
Filters
Section titled “Filters”{ q(func: type(Book)) @filter(eq(testament, "Old") AND has(reference)) { name reference }}Operators: AND, OR, NOT, eq, ge, le, gt, lt, has, type
Pagination and Ordering
Section titled “Pagination and Ordering”{ q(func: type(Person), first: 10, offset: 20, orderasc: name) { name }}Aggregation
Section titled “Aggregation”{ q(func: type(Prophecy)) { count(uid) min(val(publicationYear)) max(val(publicationYear)) }}Nested Traversals
Section titled “Nested Traversals”{ q(func: type(Prophecy)) { reference text hasTheme { name } fulfilledBy { reference inBook { name testament } } }}OWLGraph Extensions
Section titled “OWLGraph Extensions”Transitive Property Paths
Section titled “Transitive Property Paths”Follow a transitive property:
# Unbounded: follow until no more edges{ q(func: eq(name, "San Francisco")) { name locatedIn* { name } }}
# Bounded: maximum N hops{ q(func: eq(name, "San Francisco")) { name locatedIn*2 { name } }}Facet Queries for Inferred Edges
Section titled “Facet Queries for Inferred Edges”{ q(func: type(Dog)) { name dgraph.type @facets(owl.inferred) }}Variables
Section titled “Variables”{ var(func: type(Author)) { books as authorOf { themes as hasTheme } }
q(func: uid(themes), orderdesc: val(count)) { name appearances: val(count) }}Mutations in DQL
Section titled “Mutations in DQL”{ set { _:new <dgraph.type> "Dog" . _:new <name> "Rex" . }}For full DQL syntax, see the Dgraph DQL documentation.