I have a bunch of nodes, and in the client I have a value called “status” which is derived from whether or not the nodes have certain predicates. It’s possible the nodes don’t have preceding stage predicates.
Now let’s say status is “closed” if a node has stage3, “active” if has stage2, and “ready” when it has stage1. Is there a way to query this data and sort by status like this?
Obviously I could just go in and manually set the ‘status’ value for each node, but I’m curious if there’s a way to achieve it using query variables.
CLOSED as closed(func: Type(Node)) @filter(has(stage3))
ACTIVE as active(func: Type(Node)) @filter(has(stage2) AND NOT uid(CLOSED))
READY as ready(func: Type(Node)) @filter(has(stage1) AND NOT (uid(CLOSED) OR uid(ACTIVE)))
Hey ppp225, I like that for its simplicity and was playing around with something similar. My question though is how to then order all of the nodes by that status? So from ready to closed or vice versa?
But I think you’re asking, how to create a derived/temporary string value, (and then use it to filter things). I don’t think it’s possible currently, as I was trying to do something similar. You could maybe use math variables to hack around. Or just handle this in the backend, as I have done.