I'm trying to build a rest api with Node.js which uses Neo4j-Bolt-Driver to connect to Neo4j-Db.
As the endpoints and the complexity of the graph grows, it is getting a lot harder to write and maintain a lot of long Cypher queries.
I'm having some difficulties to serve populated JSON objects which should contain some relations to the other nodes.
Below you see the query for a for GET /api/me endpoint.
MATCH (user:User) WHERE user.uuid = {userId}
OPTIONAL MATCH (user)-[:PROFILE_IMAGE]->(profileImage:Image)
OPTIONAL MATCH (user)-[:HEADER_IMAGE]->(headerImage:Image)
OPTIONAL MATCH (user)-[:OWNS]->(productToEmbed:Product)-[:TYPE]->(productType:ProductType)
WITH user, COLLECT(productToEmbed{.*, type: productType.name }) AS products
RETURN user{.*, products: products, profileImage: profileImage{.*}, headerImage: headerImage{.*}}
It gets even worse when the node which is connected to the user can have different labels. In that case; I should write a switch case expression in the cypher query to correctly populate related fields which doesn't feel right.
Any suggestions about this?
via mvltshn
No comments:
Post a Comment