title: Neo4j Cypher traversal - find path by multiple relationship types
body: <p>I have a schema, where nodes are connected by 2 types of relationship - r:A and r:B. I'm trying to write a pattern, which will find every path from node N to node M. This can be simply done by following cypher query:</p>
  
  <pre><code>match path = (n)-[:A|:B*]-&gt;(m) return path;
  </code></pre>
  
  <p>Unfortunately this is not what I need exactly. I need to find every path from (n) to (m) where depth via relation r:A can be infinite, but along the way only limited number of r:B relations can be use. In happy day scenario the cypher query would look like this:</p>
  
  <pre><code>match path = (n)-[:A*|:B*0..3]-&gt;(m) return path;
  </code></pre>
  
  <p>However cypher does not allow this syntax. I can't solve this problem even with usage of another "helping" node on the way:</p>
  
  <pre><code>match path = (n)-[:A*]-&gt;()-[:B*0..3]-&gt;(m) return path;
  </code></pre>
  
  <p>This does not match my need also, because the nodes can be interconnected in any possible way. For example:</p>
  
  <pre><code>(n)-[r:A]-()-[r:A]-()-[r:A]-(m)
  (n)-[r:A]-(m)
  (n)-[r:A]-()-[r:B]-()-[r:A]-()-[r:B]-()-[r:A]-()-[r:A]-(m)
  </code></pre>
  
  <p>Is there a way how this can be achieved? If not in cypher, can it be done in gremlin / neo4j traversal api / embedded functions of spring data neo4j project?</p>
  
  <p>Thank's for the answers.</p>