I want convert this to a tree in way that it clones Engine node and its children as 2 diff engine nodes one under Train and one under car as it has 2 incoming links
If I understood correctly, you can try this:
Get the id of your Engine node. I recreated your scenario and in my case id = 13.
MATCH (a) where id(a) = 13
CALL apoc.path.spanningTree(a,{maxLevel:2}) YIELD path
return path
Your data model shows one Engine node is connected to both Train and Car nodes. If you need two separate Engines then you should have:
(Train-[]- (Engine {type: "train"})
(Car)-[]-(Engine {type: "car"})
I was able to find apoc.convert.toTree() this solves my issue i get 2 copies of engines
MATCH p=(n:Part {partNumber:"100", revision: "A"})-[:HAS_BOM_PROPERTY|WITH_PART*]->(m) WITH COLLECT(p) AS ps CALL apoc.convert.toTree(ps) yield value RETURN value;
however i need to get rid the intermediate yellow nodes now.