Clone Subgraph and link nodes back to original node with apoc clone

Hello all,
i need to clone a subgraph and link the individual nodes of the cloned subgraph back to the original nodes.
Example
(n1:A)-[r:demorel]->(n2:B)
(n1)-[r:demorel]->(n3:C)
(n2)-[r:demorel]->(n4:D)
(n2)-[r:demorel]->(n5:E)

now clone this subgraph to (can be done with apoc...)
(n11:A1)-[r:demorel]->(n21:B1)
(n11)-[r:demorel]->(n31:C1)
(n21)-[r:demorel]->(n41:D1)
(n21)-[r:demorel]->(n51:E1)

and create rels
(n11)-[r:original]->(n1)
(n21)-[r:original]->(n2)
(n31)-[r:original]->(n3)
(n41)-[r:original]->(n4)
(n51)-[r:original]->(n5)

or like so

regards
Thomas

It looks like the apoc.refactor.cloneNodes procedure returns the 'id' of the node being cloned as 'input' and the cloned node as 'output'. As such, you could search for the node corresponding to 'input' using its given 'id' and create a relationships between the matched node and the 'output' node.

Here is an example showing how to do it:

create (f:Foo{name:'Foo'}),(b:Bar{name:'Bar'})
with f, b
CALL apoc.refactor.cloneNodes([f,b])
YIELD input, output, error
match(x where id(x)=input)
create(x)-[:HAS_CLONE]->(output)
return id(x), x, id(output), output

Screen Shot 2023-07-16 at 12.40.18 PM

Screen Shot 2023-07-16 at 12.43.32 PM