title: query dependency chain of producers and requirements
body: <p>I'm setting up a graph structure with <i>transformers</i> that 'require' and 'produce' 1 or more Kafka topics. I can define the graph structure ok, but I'd like some help with a query.</p>
  
  <p>I'd like to query: <i>what chain of transformers and topics are required to create a certain topic</i>, for instance in the sample below, what transformers are required to produce Topic3. I'd expect </p>
  
  <pre><code>Ingest1-&gt;Topic7-&gt;T1-&gt;Topic1-&gt;T2-&gt;Topic3
  </code></pre>
  
  <p>The first answer below isn't quite correct, because it doesn't take into account the alternating directions of requires and produces.
  A correct query up to a certain depth would be something like</p>
  
  <pre><code>MATCH (topic:Topic{name:"topic-3"})
  &lt;-[:produces]- (tr1)  -[:requires]-&gt;(tp1) 
  &lt;-[:produces]- (tr2)  -[:requires]-&gt;(tp2) 
  &lt;-[:produces]- (tr3)  
  return [topic,tr1,tp1,tr2,tp2,tr3] as List
  </code></pre>
  
  <p>So it seems I'm looking for something that can repeat the paired produces/requires vertices.</p>
  
  <p>Here's some data that I'm playing with.</p>
  
  <pre><code>CREATE (DB1:Database {backbone: true, name:"postgres db 1"})
  CREATE (Ingest1:Ingest {backbone: true, name: "ingest-1"})
  
  CREATE (KV1:KV {name: "key-value store 1"})
  CREATE (KV2:KV {name: "key-value store 2"})
  CREATE (KV1)-[:requires]-&gt;(DB1)
  CREATE (KV2)-[:requires]-&gt;(DB1)
  CREATE (Topic1:Topic {name: "topic-1", partitions:100})
  CREATE (Topic2:Topic {name: "topic-2", partitions:100})
  CREATE (Topic3:Topic {name: "topic-3", partitions:100})
  CREATE (Topic4:Topic {name: "topic-4", partitions:100})
  CREATE (Topic5:Topic {name: "topic-5", partitions:100})
  CREATE (Topic6:Topic {name: "topic-6", partitions:100})
  CREATE (Topic7:Topic {name: "topic-7", partitions:100})
  CREATE (Topic8:Topic {name: "topic-8", partitions:100})
  CREATE (T2:Transformer {name: "T2"})
  CREATE (T1:Transformer {name: "T1"})
  CREATE (T3:Transformer {name: "T3"})
  CREATE (T4:Transformer {name: "T4"})
  CREATE (T5:Transformer {name: "T5"})
  CREATE (T6:Transformer {name: "T6"})
  CREATE (T7:Transformer {name: "T7"})
  CREATE (T8:Transformer {name: "T8"})
  CREATE (T9:Transformer {name: "T9"})
  CREATE (T4)-[:requires]-&gt;(Topic3)
  CREATE (T5)-[:requires]-&gt;(Topic3)
  CREATE (T2)-[:produces]-&gt;(Topic3)
  CREATE (T2)-[:produces]-&gt;(Topic4)
  CREATE (T2)-[:produces]-&gt;(KV1)
  CREATE (T2)-[:requires]-&gt;(Topic1)
  CREATE (T4)-[:produces]-&gt;(Topic5)
  
  CREATE (T2)-[:requires]-&gt;(Topic2)
  CREATE (T1)-[:produces]-&gt;(Topic1)
  CREATE (T1)-[:requires]-&gt;(Topic7)
  CREATE (T3)-[:produces]-&gt;(Topic2)
  CREATE (T3)-[:requires]-&gt;(Topic8)
  CREATE (Ingest1)-[:produces]-&gt;(Topic7)
  CREATE (Ingest1)-[:produces]-&gt;(Topic8);
  </code></pre>