I am trying to set up triggers in my db. Triggers for relationship creation, update and deletion. I have been able to set triggers for relationship creation properly.
CALL apoc.trigger.install(
'neo4j',
'POST_Created_Relationships',
'
UNWIND $createdRelationships AS r
WITH {
id: id(r),
type: type(r),
properties: properties(r),
startNodeId: id(startNode(r)),
endNodeId: id(endNode(r))
} AS relData
CALL apoc.load.jsonParams(
"http://192.168.1.122:9500/api/trigger/relationCreatedTrigger",
{method: "POST"},
apoc.convert.toJson(relData)
) YIELD value
RETURN value
',
{}
)
the above trigger statement hits the external api and provides the data of the created relationship.
for example, i created a relationship using this command
MATCH (p:Product) , (b:Brand) CREATE (p)-[rel:NEWRELN {additionalProp:"additionalpropvalue",anotherField:"anotherval"}]->(b);
here's the response from the trigger
'{"startNodeId":149,"id":40,"type":"NEWRELN","endNodeId":148,"properties":{"anotherField":"anotherval","additionalProp":"additionalpropvalue"}}': ''
this is not a proper response as all the data are present in key, but still i can extract the data.
i want to achieve the same for relationship updates (when any property of a relation is changed)
here's my trigger
CALL apoc.trigger.install(
'neo4j',
'POST_Updated_Relationships',
'
UNWIND $assignedRelationshipProperties AS r
CALL apoc.load.jsonParams("http://192.168.1.122:9500/api/trigger/relationUpdatedTrigger", {method: "POST"}, apoc.convert.toJson({data: r})) YIELD value
RETURN value
',
{}
)
after putting this trigger i just updated both the values of the relationship with this command
MATCH (p:Product)-[rel:NEWRELN]->(b:Brand) SET rel.additionalProp="updatedprop", rel.anotherField="updatedval";
this triggr is sending data in this format (ignore the slashes)
"{\"data\":{\"anotherField\":[{\"new\":\"updatedval\",\"old\":\"anotherval\",\"relationship\":{\"id\":\"40\",\"type\":\"relationship\",\"label\":\"NEWRELN\",\"start\":{\"id\":\"149\",\"type\":\"node\",\"labels\":": {
"\"Product\"": {
"\"Brand\"": {
"\"Product\"": {
"\"Brand\"": ""
}
}
}
}
here in this trigger response i am getting only one of the values of the field which i updated, no matter how many fields i am updating in this trigger's response i am only getting only one updated property. how can i get the entire data of this relationship, just like i am getting for the createdRelationship case.
i tried following the similar approach as of createdRelationships
WITH {
id: id(r),
type: type(r),
properties: properties(r),
startNodeId: id(startNode(r)),
endNodeId: id(endNode(r))
} AS relData
but this is not working as there is difference in the format how $createdRelationships is capturing the data and how $assignedRelationshipProperties is capturing the data.