Does dgraph have a if-else function?
If author is same as original author, return false for knows flag.
How to achieve this requirement?
Does dgraph have a if-else function?
If author is same as original author, return false for knows flag.
How to achieve this requirement?
case when?
foreach?
while?
No, dgraph doesnāt have a direct if-else. But there is a different approach to achieve what you want. You would want to read about Query Variables, Value Variables and probably Math on value variables. If you could ask a more specific question then Iād be able to help you write the query. In your question, I am not sure about what is āoriginal authorā, is it a known string? What is āknows flagā?
@ahsan
the relationship like this:
I need to calculateļ¼
Given a Message, retrieve the (1-hop) Comments that reply to it.
In addition, return a boolean flag knows indicating
if the author of the reply knows the author of the original message.
**If author is same as original author, return false for knows flag.**
What should I do to get a knows flagļ¼
I replicated your model by this mutation:
{
set{
_:p1 <name> "person1" .
_:p1 <knows> _:p2 .
_:p2 <name> "person2" .
_:p2 <knows> _:p1 .
_:c1 <text> "comment1" .
_:c1 <hasCreator> _:p2 .
_:m1 <text> "message1" .
_:m1 <hasCreator> _:p1 .
_:m1 <replyOf> _:c1 .
}
}
and what you want can be achieved by this query:
{
var(func: eq(text, "message1")){
u as uid
hasCreator{n as name}
replyOf {
text
hasCreator {
knows
}
}
}
f(func: uid(u)){
replyOf {
hasCreator {
c as count(knows) @filter(eq(name, val(n)))
knows: math(c == 1)
}
}
}
}
By āGiven a messageā, I assume that the text of the message is given. It can be the uid, or any other field as well. You can use whatever identifier you like.
The response is like this:
"data": {
"f": [
{
"replyOf": [
{
"hasCreator": [
{
"count(knows)": 1,
"knows": true
}
]
}
]
}
]
}