Failed to invoke procedure `apoc.do.case`: Caused by: org.neo4j.exceptions.SyntaxException

Hi everyone,

I have a problem with apoc.do.case but I do not understand where this come from.

I use apoc.do.case inside an apoc.trigger in this way:

CALL apoc.trigger.add('Trigger','UNWIND $createdNodes AS node
CALL apoc.do.case(
[
node:Mutation, reactkg.criticalEffect(node.name),
node:Sequence and reactkg.unassignedSequence(node.accession), reactkg.sequenceAlerts(5,6, node.accession),
],
"RETURN *", {node:node}) YIELD value
RETURN value', {phase:'afterAsync'});

What I would like this trigger to do is that when new nodes are added from a csv, the trigger checks both the label of the new node and some conditions with a custom procedure. If both conditions are verified then another procedure is called which creates other nodes with label 'Alert'.

However an error comes up only when a node with label Sequence is loaded from the csv:

Failed to invoke procedure `apoc.do.case`: Caused by: org.neo4j.exceptions.SyntaxException: Query cannot conclude with WITH (must be a RETURN clause, an update clause, a unit subquery call, or a procedure call with no YIELD) (line 1, column 2 (offset: 1)) " WITH $ `node` as `node`"

The creation of the node Sequence is done by this query:

MATCH (v:Variant {pangoLineage: '"+csvLine[8]+"'})
MATCH mutations = (m:Mutation) where m.name in "+csvLine[5]+"
MATCH (l:Lab {name: '"+csvLine[7]+"'})
MATCH (p:Patient {cf: '"+csvLine[6]+"'})
MERGE (l)<-[:SEQUENCED_AT]-(s:Sequence {accession: '"+csvLine[2]+"', collectionDate: '"+csvLine[3]+"', isolate: '"+csvLine[4]+"', mutations: "+csvLine[5]+", host: '"+csvLine[6]+"'})-[:BELONGS_TO]->(v)
MERGE (p)<-[:AFFECTED]-(s)
FOREACH (n IN nodes(mutations) | MERGE (s)<-[:FOUND_IN]-(m))

Can someone please explain why this might happen?

Thanks in advance,

Alessia

As a note, I thought the queries in your case statement had to be strings. As such, should the syntax be:

CALL apoc.trigger.add('Trigger',
'
 UNWIND $createdNodes AS node
 CALL apoc.do.case(
  [
    node:Mutation, "reactkg.criticalEffect(node.name)",
    node:Sequence and reactkg.unassignedSequence(node.accession), "reactkg.sequenceAlerts(5,6, node.accession)"
  ], 
  "RETURN *", 
  {node:node}) YIELD value 
  RETURN value
', 
 {phase:'afterAsync'});

Hi,

thank you for the suggestion but unfortunately those procedures already return strings themselves. In fact the creation of the node Alert related to the creation of a new node of label Mutation works fine, since the procedure:

reactkg.criticalEffect(node.name)

returns this string which creates the correct node Alert.

"CREATE (a:Alert{ description: 'New mutation with critical effect has been added', dateTime:datetime()})"

The procedure

reactkg.sequenceAlerts(5,6, node.accession)

does a very similar thing by returning strings of query of type CREATE.

However when adding nodes of type Sequence the log show the error

Failed to invoke procedure `apoc.do.case`: Caused by: org.neo4j.exceptions.SyntaxException: Query cannot conclude with WITH (must be a RETURN clause, an update clause, a unit subquery call, or a procedure call with no YIELD) (line 1, column 2 (offset: 1)) " WITH $ `node` as `node`"

Therefore I am not sure if this depends from a conflict of locks between the query that creates the node Sequence (shown in the original message) and the activation of the trigger or if it was because of a wrong syntax of the trigger.

Do you have any idea of what can it be? Thanks in advance!