I would need to generate dynamic queries, to add some filters on conditions.
Let say that my app handle Books and Authors. Books concerns one or more Theme.
User can filter by Theme.
So a query could be :
MATCH (b:Book)-[w:WRITEN]-(a:Author) MATCH (b:Book)-[c:CONCERNS]-(t:Theme {id : '1234'}) return b, w, a, c, t
Sometimes book's theme is unknown so a Book is not associated with any Theme.
If user doesn't pick any filter, query would be :
MATCH (b:Book)-[w:WRITEN]-(a:Author) OPTIONAL MATCH (b:Book)-[c:CONCERNS]-(t:Theme) return b, w, a, c, t
In this case I can not go with @Query because of the optional filter and MATCH.
From what I saw, queryDSL is not supported (yet?)
Is there any way to generate query with conditions, like we can do with Criteria for relational DB?
For whatever it is worth a year later, but might help others, there is a way to do dynamic cypher with the help of the APOC library.
Consider this query:
@QUERY("CALL apoc.cypher.doIt({filterQuery}, {id: {id}}) " +
"YIELD value AS v_res RETURN x,y,z")
myQuery(String filterQuery, Long id);
So filterQuery is dynamically built in the code and you can also pass into it parameters like {id} in this example.
The other options it to move away from Spring Data and use the Java driver directly or use a custom Neo4j plugin.