Hi boys, I’ve been using dgraph in the last two year in a big pet project that we’re about to launch live.
However, I’m struggling with some complex queries, I really think that the weak point of this amazing product is a decent IDE, ratel lacks some stuff, linting, formatting, autocompletes, making really hard to build queries.
Anyway, back to my question.
I have the following schema.
<id>: string @index(hash) @upsert .
<createdWhen>: datetime .
<dislikedBy>: uid @reverse .
<dislikedFeedback>: uid @reverse .
<likedBy>: uid @reverse .
<likedFeedback>: uid @reverse .
type <DislikeFeedbackGraphModel> {
id
createdWhen
dislikedBy
dislikedFeedback
}
type <LikeFeedbackGraphModel> {
id
createdWhen
likedBy
likedFeedback
}
type <FeedbackGraphModel> {
id
createdWhen
}
type <PersonGraphModel> {
id
createdWhen
}
So, think about facebook.
You have a feedback, a feedback can be liked / disliked by a person.
As I want some metadata of these actions (example, I liked two days ago, I disliked yesterday, and I liked again) I had to make the middle entity LikeGraphModel & DislikeGraphModel.
Now, in my UI, I just want to show only the last activity of this person on this feedback, meaning the Like.
So starting by a feedback, I need to grab all his like/dislikes, group by person (likedBy / dislikedBy), sort by createdWhen, and return the last one.
Is that even possible in DQL? I tried creating 3 vars, merging the stuff, but I could not succeed, unluckly. My current solution is just to grab all likes, dislikes, and do it in memory, but of course, I cannot keep this solution if we go big.