I would like to create a node based on argument passed in func. In this createRelation func, one node is known "User" but other node might or might not exist. Depending on kind of relationship I want to create, I check if node of that type exist, if not create and then create a relationship. For e.g new node could be a book or a car .
def createRelationship(self, nodeName, value):
query = """
MATCH (u:User {username: {you}})
MERGE (b:nodeName {name: {value}})
ON CREATE SET b.name = {value}
CREATE UNIQUE (u) - [:OWNS] -> (b)
"""
return graph.cypher.execute(query, you=self.username, nodeName=nodeName, value=value)
I know node property can be used as the one passed in argument by declaring within {} but the same doesn't work for node
Looks like dynamic labels in CREATE (and very likely MERGE) statements aren't supported.
That said, I'm not sure if adding a label with the SET command is restricted in the same way. Though obviously that will be much less useful because your MERGE will be largely useless, I'd imagine you'd have lots of duplicates.