Hi,
Really like Dgraph so far, most things are working great. There’s one thing that I can’t seem to figure out, not sure if it’s schema related or the way I create object.
My probem put very simply:
example, three objects I’d like to work with, they have:
objectTitle
objectDescription
two of these objects have the same title and description and when I query with the uid of one of those it only shows me the uid. Whereas when I query with the third unique object uid I can find all related information.
all object have a unique dgraph uid. when I query with another field (e.g. createdBy) I can find all three objects and the related data without any issues.
[UPDATE] When searching by objectTitle I can find both of those objects with the related data.
{
(func: eq(objectTitle,“this is the object title”)
createdBy
uid
objectTitle
objectDescription
}
}
So it seems like searching by UID is not the right way to do it, looking forward to some more insights on this
{
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
}
{
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
}
}
}
Oh wow , this made me completely rethink how I’m structured things. Somehow missed the part that nodes can have types and didn’t realize I can set the schema like that (post.Description)!
Thank you for your help Michel and perhaps also Newton. I’ll try to adapt my json mutations to this “paradigm”
Your paradigm is so intrinsic to your mental process that you are hardly aware of its existence, until you try to communicate with someone with a different paradigm.
There are several ways you can use Dgraph. This is a pattern that correlated with what we have in the graphoverflow example. The only difference is the “type” that it uses a indexed and unique predicate and not by empty predicates. That we can locate via “has( )”
Note that copying and pasting directly from the browser (Especially from discuss) may occur of copying characters that are not recognized by Dgraph. Just make sure.
Got it, I must have done something wrong or perhaps it’s because i’m running a version that is couple months old. when I was trying it I tried expand(all) like that and also adding the user when I was working on that, but in the end just decided to go with has(user), could that be problematic later on?
On a positive note, seems like I’ve got things sorted out much better now! No conflict and retrieving, both individual objects , objects related to a user, creating new objects is going well
appreciate your help, going to look into updating existing objects next