call {
match path = (n:A{Name:"xyz"})<-[e:BelongsTo]-(p:B)<-[:BelongsTo]-(ps:C)-[r:CanAccess]->(k)
return n as Identity, e as edge, r.Effect as Effect, r.Action as Action, k as ResourceId, path, p
union
match path = (n:A{Name:"xyz"})-[e:Uses]->(p:D)<-[:BelongsTo]-(:D)<-[:BelongsTo]-(:C)-[r:CanAccess]->(k)
return n as Identity, e as edge, r.Effect as Effect, r.Action as Action, k as ResourceId, path, p
union
match path = (n:A{Name:"xyz"})-[e:BelongsTo]->(:E)-[:Uses]->(p:D)<-[:BelongsTo]-(:D)<-[:BelongsTo]-(ps:C)-[r:CanAccess]->(k)
return n as Identity, r.Effect as Effect, r.Action as Action, k as ResourceId, path, p, e as edge
union
match path = (n:A{Name:"xyz"})-[e:BelongsTo]->(:E)<-[:BelongsTo]-(p:E)<-[:BelongsTo]-(:C)-[r:CanAccess]->(k)
return n as Identity, r.Effect as Effect, r.Action as Action, k as ResourceId, path, p, e as edge
union
match path = (k:F)-[e:BelongsTo]-(p:G)-[:BelongsTo]-(:G)-[r:isAttachedTo]->(n:A{Name:"xyz"})
return n as Identity, r.Effect as Effect, r.Action as Action, k as ResourceId, path, p, e as edge
}
with collect(distinct Effect) as EffectList, Identity, Action, ResourceId, collect(path) as paths, collect(p) as policies, edge
where size(EffectList) = 1 and EffectList[0] = "Allow"
with EffectList, Identity, Action, ResourceId, paths, policies, edge
unwind policies as p
return apoc.create.vRelationship(p, 'MyEdge', {Effect:"Allow"}, ResourceId) as relations, Identity,edge
Basically for eg in the first match I want to skip "C" node in the path and directly connect B->k