type User {
name
username
follows
}
name: string @index(hash) .
username: string @index(hash) .
follows: [uid] @reverse @count .
I want to query the user list, and the user of this list should contain the is_follow field, used to judge whether I have followed this user.
Suppose I make the following query:
{
users(func: has(username)) {
uid
name
username
is_follow: follows @filter(uid(0x4e25)){
uid
name
}
}
}
The 0x4e25 is the uid of the currently logged in user.
The is_follow field lets me know if the user is followed, but its value is user, and I want it to be a bool. What should I do?
I am scratching my head to figure out a way to get boolean result. But, as of now, I am able to come up with a simple trick which would give 0 or 1 result.
I use both, still at beginning stage of learning though & It might be possible to write the above query in GraphQL Filtering in Selection, will have to verify.
Do you mean that the node doesnât exist for the user which is not logged in? I am not getting exception for non-existent nodes. It would be very helpful if you could let me know how to reproduce this exception on a toy data.
Hi @pandalive, we appreciate your patience.
As for your first query regarding bool values. One way that I and @ahsan could figure out is to use math().
EDITED:
{
data(func: uid(0x3)) {
name
cnt as count(follows) @filter(uid(0x4))
result: math( cnt == 1 )
}
}
Meanwhile, you can look at the RFC around the improvement.
Also, you can look at the discussion related to custom variable blocks.
@ahsan Thanks, this is a feasible plan.
But even so, I still hope that when the query variable does not exist, dgraph will set it to 0x0 by default, which can save a lot of work for customers.
Cheers.