The use case is building a query from url parameters that can achieve N level deep with predicates that reference other types. The number of types, levels, filters, etc. are given at runtime and a query to Dgraph is constructed, executed, and the data returned as a search result.
I’d like to be able to use expand(all) and include a filter to one/many predicates at the same level. The “repeated subgraph” error is given when trying this approach.
{
var(func: type("orderstest__type0")) {
T0 AS uid
}
var(func: type("orderstest__type1")) {
T1 AS uid
}
t as total(func: uid(T0,T1))
@filter(((eq(caseowner,"test@gmail.com") AND has(caseowner)))) {
count(uid)
}
query(func: uid(t), orderasc: createdat, first: 10, offset: 0) {
expand(_all_)
task @filter((eq(assignee,"test@gmail.com") AND has(assignee))) {
expand(_all_)
taskcomment @filter((eq(comments,"test comments") AND has(comments))) {
expand(_all_)
}
}
}
}
What you actually did
My workaround is retrieving all predicates for the given types while building the query.
{
var(func: type("orderstest__type0")) {
T0 AS uid
}
var(func: type("orderstest__type1")) {
T1 AS uid
}
t as total(func: uid(T0,T1))
@filter(((eq(caseowner,"test@gmail.com") AND has(caseowner)))) {
count(uid)
}
query(func: uid(t), orderasc: createdat, first: 10, offset: 0) {
caseowner
createdat
notes
priority
reservationnumber
space
status
task @filter((eq(assignee,"test@gmail.com") AND has(assignee))) {
assignee
space
testdatetime
title
taskcomment @filter((eq(comments,"test comments") AND has(comments))) {
expand(_all_)
}
}
}
}
Why that wasn’t great, with examples
This is not ideal because there are types with 100+ predicates, and queries to many types could yield an even higher number. This requires a call to cache/network to retrieve the predicates for each level. We need additional code to make sure we retrieve all the unique predicates except the ones we are filtering on. We also would ideally like to retrieve the data in this format from the “query” block.
If you use the DQL Types you won’t see and “repeated subgraph” error.
You can also try to create a “dummy type”. A type that you will only use for expanding purposes. That’s a “hacky way” of doing it, but works fine. Create a type with all possible predicates you have. And then use it on your query.
Awesome, this is exactly what we were looking for!
We are thinking of making the change now to use this new feature- has this been released yet or been planned for release? Still no rush on our end, we have a workaround, but this will let us build cleaner queries. Thanks!
This is planned for release in 20.11 which is just around the corner. It is present in master if you want to test out the feature.
Want to highlight the below query (without filters) wouldn’t work. But your specific use case where you expand nodes with some filters would work fine.