How do I pass parameters when calling apoc.cypher.runFile

While calling through the following query in neo4jBrowser
call apoc.cypher.runFile("toolQuery.cyp",{parameters: {transitionType: 'SERVICEDESK'}})

There were no response no record and no changes exist. But without parameter , its working as expected.

Note: - toolQuery.cyp has contain my cypher query details. here is the parameter query am passing MATCH p=(n)-[r:$transitionType]->(m).
kindly go through is there any mistake i did.

Hello @mr.gsk0509 and welcome to the Neo4j community :slight_smile:

You can't set a relationship type or a label from a parameter :confused:

Regards,
Cobra

1 Like

Thank you. Is there any another way of achieve this?

What are you trying to achieve with your Cypher file? :slight_smile:

Dynamic relationship data will change from my frontend. so, I have to pass the parameter in this cypher query.But this below syntax didn't work in neo browser ,

call apoc.cypher.runFile("toolQuery.cyp",{parameters: {transitionType: 'xxx'}})

transitionType would be xxx, yyy or zzz ..

You want to create relationships?

No. Node,labels and relationships are already created in neo4j db.

Only need to call apoc.cypher.runFile("toolQuery.cyp",{parameters: {transitionType: 'xxx'}})
with following param of either xxx, yyy or zzz.
dynamically cypher query should accept the either of this value.
MATCH p=(n)-[r:$transitionType]->(m)

Try:

MATCH p=(n)-[r]->(m) WHERE type(r) = $transitionType

Tried its working cobra. Thank you very much.

While you can't use parameters as labels directly, you can use CALL apoc.create.addLabels( [node,id,ids,nodes], ['Label',…​]) to apply labels based on an array of values, and those array of values can come from parameters.

Example - this won't work:

MATCH (n) where id(n) = 3
SET n:$LabelParameter
RETURN n

This should work:

CALL apoc.create.addLabels([3], [$LabelParameter]);
1 Like