And I want to sort devices by owner’s name, but in result, I want to get all devices.
So I sort devices
var(func: type(Device)) {
owner {
ownerName as name
}
x as min(val(ownerName))
}
withOwner(func: type(Device)), orderasc: val(x), orderasc: number) {
uuid
number
owner {
uuid
name
}
}
Result contains only devices with owners.
But how can I get all devices?
I can get only devices without owners
withoutOwner as var(func: type(Device), orderasc: number) @filter(not has(owner))
Is it possible to combine sorted withOwner and withoutOwner in one result?
Also looks like this has been asked earlier as well without a solution. Going back to the issue here, I think we require all the values to be present on which you want to sort otherwise they get filtered out.
Yes, I realized. That is because the uids in the variables are sorted as per their order (ascending order with respect to each uid) and not by the order we specify.
I thought to add a dummy owner to which devices without an owner belonged, but this solution is really ugly.
I also can’t append the query answers inside the app-logic because of a large number of devices and pagination.
Maybe there are some other solutions?
Hey @poketulhu
Added some notes on sort queries here. For your specific case, we do not yet support adding nodes that point to nodes on which you want to sort.