How to pass paramters correctly

neo4j 5.12, langchain Python
I need more details about passing paramters with '$'.
The code adds a label according to node_type.But it can‘t access the label, not only SET label, but also MATCH label is not work,such as MATCH (n: $type).
I want to know where exactly ’$var‘ works.Does it only work on value of key-value?
If not, how can I pass variables to the key?

QUERY = '''
MATCH (n:Node {node_type:$type})
SET n: $type 
'''
graph.query(QUERY, params={"type": "Gene"})

You can not set nor specify a label with a variable nor parameter. They have to specified with a literal value.

One other place variables and parameters can not be use is setting properties dynamically. As an example, the following not allowed:

Match(n)
Set n[$prop]=100

setting properties dynamically
How it works?Please give me a allowed code.

You can access a property in a map using dot notation or using brackets, i.e, map.prop or map[“prop”]. Using the brackets notation, you can access a map’s properties dynamically by specifying the property with a variable or parameter, i.e., map[var] or map[$parm].

What you can not do is use the bracket notation to set a property dynamically. You will receive an error if you try. The following statement is not allowed set map[var] because var is a variable.

The APOC library has routine you can leverage dynamically add/modify key values in a map.

As an example, you can use apoc.map.setEntry to set a key’s value in a map. This could be used to Set a node’s property dynamically.

With “name” as propertyToChange, “update” as newValue
Match(n{id: $id})
Set n = apoc.map.setEntry(properties(n), propertyToChange, newValue)