MATCH (a)-[r]->(b) WITH head(labels(a)) AS l, head(labels(b)) AS l2, type(r) AS rel_type, count(*) as count WITH collect({from:l,to:l2,type:rel_type, count:count}) as rels, apoc.coll.toSet(collect(l2)+collect(l)) as nodes WITH apoc.map.fromPairs([name in nodes | [name, apoc.create.vNode([name],{name:name})]]) as nodes, rels UNWIND rels as r CALL apoc.create.vRelationship(nodes[r.from],r.type,{count:r.count},nodes[r.to]) yield rel RETURN rel,nodes[r.from],nodes[r.to];