I Want to Do
Given a start Person, retrieve the last 10 Messages created by that user. For each Message,
return that Message, the original Post in its conversation (post), and the author of that Post (original Poster). If any of the Messages is a Post, then the original Post (post) will be the same Message, i.e. that Message will appear twice in that result.
I am unable to handle the second case where if the message itself is a post (instead of a comment in a post) then we return the message twice (thinking of it as a reply to its own post)
What I Did
query all($ID: string){
q(func: eq(fqid, $ID)) {
~hasCreator( orderdesc: creationDate, orderdesc: id, first:10){
id
content
creationDate
dgraph.type
replyOf{
id
hasCreator{
id
firstName
lastName
}
}
}
}
}
Relevant Schema
For a more visual representation of schema take a look at the specifications document (Pg. 62.)
type comment {
fqid
content
length
id
creationDate
hasCreator
isLocatedIn
replyOf
}
type forum{
fqid
id
title
creationDate
containerOf
hasMember
hasTag
hasModerator
}
type post{
fqid
locationIP
browserUsed
language
content
length
hasTag
id
hasCreator
isLocatedIn
}
type person{
fqid
id
firstName
lastName
gender
birthday
isLocatedIn
likes
workAt
email
language
studyAt
knows
}
fqid : string @index(hash) .
id : int .
name : string .
url : string .
hasType : uid @reverse .
locationIP : string .
content : string .
length : int .
creationDate : dateTime @index(day) .
hasCreator : [uid] @reverse .
replyOf : uid @reverse .
title : string @index(exact) .
containerOf : [uid] @reverse .
language : string .
firstName : string @index(hash) .
lastName : string @index(hash) .