I want to execute a Cypher query that'll return every user in our graph, along with whether I follow them or not.
So I first tried a query like this:
START me=node(1), user=[all users] # index query omitted
MATCH (me) -[r?:follows]-> (user)
My intent with the return `r?` was thinking that the `?` operator would evaluate to true or false, like in CoffeeScript. ("Does r exist?") I realize now that's not the case.
Turns out that this was a syntax error; just returning `r` handles the optional case. But it does something I don't want: in cases that match, it returns the whole relationship JSON.
In this case, I just want to know whether the relationship exists or not. How can I do that?
I thought I'd try `r IS NULL` or `r ISNT NULL`, but those are also syntax errors. I guess `IS NULL` etc. is only accepted in the WHERE clause.
I then thought to try returning TYPE(r), so it'd be "follows" or <null> (hopefully). But this fails silently. (BUG)
Finally, I tried returning COUNT(r), which returns 1 or 0, and that works! So I've found a decent option.
But that does feel a bit hacky to me, so I thought I'd ask if there's a better/proper way of just returning true/false. Thanks!
Aseem