neo4j/cypher-builder

Help Required on complex queries !

MockingMagician opened this issue · 2 comments

Hello @neo4j-team-graphql

I have some questions on how to build complex queries. Let me show you this example:

MATCH (u:User)-[likes:REACTED_TO {reaction: 'like'}]->(posts:Post)
                  WHERE NOT (:User {id: $user_id})-[:VISITED]->(posts)
                OPTIONAL MATCH (posts)<-[dislikes:REACTED_TO {reaction: 'dislike'}]-(:User)
                WITH posts, COUNT(distinct likes) AS likeCount, count(distinct dislikes) as dislikeCount
                RETURN posts.id as post_id, likeCount, dislikeCount, (likeCount - dislikeCount) as diffLike
                ORDER BY diffLike DESC LIMIT 20;

To obtain it, I have to chain clause methods as Cypher.Match and Cypher.OptionalMatch, but I can perform it ?

Please, if you can upgrade your documentation with pore complex examples, it will be great !

Best regards :-)

Hi @MockingMagician

There is a small limitation at the moment with chaining top-level clauses (#90)

For the moment, you'll need to use Cypher.concat. Documentation on this is still lacking (already covered in #47 )

As a quick example of using it:

const match1=new Cypher.Match(...)
const match2=new Cypher.Match(...)

const query=Cypher.concat(match1,match2)
query.build()

I'll close this issue, if you have specific questions about a cypher query, feel free to open a Discussion

@angrykoala For me it would also be interesting to know how to create a where clause like "WHERE NOT (:User {id: $user_id})-[:VISITED]->(posts)". How can I make a predicate out of the pattern?

Edit: Never mind. I opened a new discussion #181