... this one was a cryptic one as the error message is sort of lost as where the problem is and I assume in a simpler query the returned value is interpreted by the browser in a different way from when you send it as part of a more complex query, but found out what was the problem:
apoc.cypher.run()
returns a list of maps and the merge needs a node.
To return a node to the next part of the query, you have to UNWIND
:
CALL apoc.cypher.run('MATCH (referee:`' + refData.label + '` {code: theCode}) RETURN referee', { theCode: refData.code })
YIELD value
UNWIND value.referee AS r
my section of the query now looks:
WITH A, l, linkData
CALL {
WITH A, l, linkData
UNWIND COALESCE(linkData.references, []) AS refData
CALL apoc.cypher.run('MATCH (referee:`' + refData.label + '` {code: theCode}) RETURN referee', { theCode: refData.code })
YIELD value
UNWIND value.referee AS r
MERGE (l)-[valu:value]->(r)
ON CREATE
SET valu.created = timestamp(),
valu.updated = timestamp()
ON MATCH
SET valu.updated = timestamp()
}