Dynamic query

Hi,

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?

Many thx

A gloriously simple solution is to call a different @Repository method for each case, depending whether your themeId is null.

Otherwise, you could write your own function. See some docs on this here: https://docs.spring.io/spring-data/neo4j/docs/5.0.0.RELEASE/reference/html/#repositories.single-repository-behavior.