Regarding MERGE (item1)-[h:VERB]->(item2)
and MERGE (item1)-[h:ERROR_MSG]->(error)
,
afaik the type relationship cannot be parameterized.
You can use the equivalent apoc.merge.relationship
but in this case you cannot use a subquery structure like your because of WHERE item2 IS NOT NULL
which, unlike MERGE, block the query in the first subquery if item2 is not null.
However with this structure you can use the apoc.do.case(condition, firstQuery, secondQuery, {}) procedure, where firstQuery
will be executed when item2 IS NOT NULL
, otherwise the secondQuery
.
So you can create this file filename.cypher
:
CALL apoc.do.when($item2 IS NOT NULL,
"CALL apoc.merge.relationship(item1, type1, {}, {}, item2) YIELD rel RETURN 1",
"MERGE (error:Error) WITH error, item1, item2, type2 CALL apoc.merge.relationship(item1, type2, {}, {}, error) YIELD rel RETURN 1",
{item1: $item1, item2: $item2, type1: $type1, type2: $type2});
and then execute:
match (organization:Organization)
with organization, null as store // this is an example to be changed
// pass your query....
// ... here is the code
call apoc.cypher.runFile("filename.cypher",
{parameters: {item1: organization, item2: store, type1: "HAS", type2: "HAS_NO_ORGANIZATION"}})
// in parameters I pass the parameters $item1, $item2, $type1 and $type2 present in filename.cypher
yield result, row
return result, row