Based on what you described, I took the liberty of creating this to discuss with you. Any doubts about what I have created feel free to ask.
Schema
name: string @index(exact, fulltext) @count .
age: int @index(int) .
likes: uid @reverse @count .
answer: uid @reverse @count .
post.title: uid @reverse .
post.Description: uid @reverse .
owner.post: uid @reverse .
title: string @index(exact, fulltext) .
body: string @index(exact, fulltext) .
Mutation
{
set{
_:Author <name> "Lucas De Niro" .
_:Author <type.user> " " . #Giving to node a type
_:Author <age> "31" .
_:Post <type.post> "" . #Giving to node a type
_:Post <likes> <ox1> . #example of a user with UID ox2 giving a automatic like to that post
_:Post <answer> <ox15> . #example of an answer
_:Post <post.title> _:Title . #Normal relationship | But you need to @Reverse in case you go searching for the title or the content of the description.
_:Post <post.Description> _:Description . #Normal relationship
_:Author <owner.post> _:Post . #Relationship in @reverse | Author is Post's parent
_:Title <title> "This is a title" .
_:Title <type.title> "" . #Giving to node a type
_:Description <body> "This is a very large description." .
_:Description <type.desc> "" . #Giving to node a type
}
Queries
{
Users(func: has(type.user)){
expand(_all_) {
expand(_all_) {
expand(_all_)
}
}
}
}
{
search(func: has(type.title)) @filter(eq(title, "this is the object title”")) {
~post.title : postFound {
likes { uid name }
answer { uid #or expand for more
}
post.Description {
body #or expand for more if needed
}
post.title { title #or expand for more
}
}
}
}
Other way (using “expand” to ““debug”” the querie)
{
search(func: has(type.title)) # @filter(eq(title, "This is a title"))
{
uid
expand(_all_)
}
}
Best Way
{
var(func: has(type.title)) @filter(eq(title, "This is a title")) {
uid
~post.title {
PostFound as uid }
}
MyPost(func: uid(PostFound)) {
uid
likes { uid name }
totalLikes : count(likes)
answer { uid #or expand for more
}
totalAnswers : count(answer)
post.Description {
body #or expand for more if needed
}
post.title { title #or expand for more
}
}
}