Hello Community!
I wanted to reach out to introduce you Deku, the first DGraph Query Builder.
I’m planning to cut the first stable release end of this week, in mean time I wanted to gather some of your feedback on the overall API and if you like/dislike the concept.
Why?
The DGraph query language is awesome! it is really powerful, and you can achieve a lot with it.
However, as you start trying to add dynamicity (like any other declarative query language) you soon starts
fiddling with a lot strings concatenations and can quickly get messy.
Deku tries to simplify the construction of DGraph Queries and mutations with a fluent API.
Features
- Schema Builder (Types, Predicates, Indexes)
- Filtering - Connecting Filters (AND / OR)
- Nested Selection / Filters
- Functions
- Pagination
- Aggregation
- Sorting
- GroupBy
- Multiple Query Block
- Query Variables
- Values Variables
- Facets
- Mutations
Simple Query Example
query, variables, err := dql.
Query("bladerunner", dql.EqFn("item", "value")).
Fields(`
uid
name
initial_release_date
netflix_id
`).
Filter(dql.Eq{"field1": "value1"}).
ToDQL()
print(query)
Produces
query Bladerunner($0:string, $1:string) {
bladerunner(func: eq(item,$0)) @filter(eq(field1,$1)) {
uid
name
initial_release_date
netflix_id
}
}
Nested Query Example
The true power of Deku shows when you start getting serious
query, variables, err := dql.
Query("bladerunner", dql.EqFn("name@en", "Blade Runner")).
Fields(`
uid
name
initial_release_date
netflix_id
`).
Edge("authors", dql.Fields(`
uid
name
surname
age
`), dql.Eq{"age": 20}).
Edge("actors", dql.Fields(`
uid
surname
age
`), dql.Gt{"age": []int{18, 20, 30}}).
Edge("actors->rewards"), dql.Fields(`
uid
points
`), dql.Gt{"points": 3}).
ToDQL()
Produces
query Bladerunner($0:string, $1:int, $2:int, $3:int, $4:int, $5:int) {
bladerunner(func: eq(name@en,$0)) {
uid
name
initial_release_date
netflix_id
authors @filter(eq(age,$1)) {
uid
name
surname
age
}
actors @filter(gt(age,[$2,$3,$4])) {
uid
surname
age
rewards @filter(gt(points,$5)) {
uid
points
}
}
}
}
Don’t forget to check the repository for more information leave a star if you like it.
The documentation is working progress, until then refer to the Test Cases for more sofisticated queries
Regards!