The syntax for creating a trigger on relationship property assignments

I really just want a 'hello world' example for how to make something work. I want to create a trigger on a relationship when new property is assigned to it that matches a specified key.

So this is a bit contrived, but let's say that whenever a property is added to a label with the property key of 'firstname', our trigger adds another property, lasname: 'Smith'.

I have tried some variations on this, but even when Neo4j accepts the trigger, it doesn't actually invoke the trigger's action. Here's what I have tried last:

CALL apoc.trigger.add('testRelProp','UNWIND apoc.trigger.propertiesByKey({assignedRelationshipProperties},'firstname') as prop  
WITH prop.relationship as r
SET r.lastname = "Smith"', 

I have to admit that I am guessing on prop.relationship because I haven't seen it defined anywhere for relationships.

I would be happy to see this run, or any example of the relationship-property-trigger.

Can't comment on using apoc.trigger. I don't think the writers of that project recommend it for mission-critical work. However, if you need a bulletproof solution, you can either:
A) Implement a plugin, aka "unmanaged extension". This is a JVM solution you can deploy in the /plugins folder to implement serious app work on the database machine, in the native/fast Neo4j verbatim. If you go this deep, you can also register a "transaction hook" whereby you can be guaranteed to make your changes in response to other changes.
B) Run a scheduled task executing Cypher against the DB, using your own infrastructure
outside of Neo4j.

The ideal scenario would be to work with continually improving community solutions (APOC).
At the moment, the documentation seems to be my issue. I find no example anywhere of a relationship firing a trigger upon property assignment to that relationship.

I’ll keep in mind the option of building my own unmanaged extension for these. I have coded in java in the past, but to be completely honest I would trust the community code over my own for something that runs inside Neo4j. If you’re offering to write a custom trigger, I can keep that in mind too, as my needs evolve. :slight_smile:

You're right, ideally APOC can do everything you need, and that's true especially if you only work with a single instance via the native browser. My comments are definitely biased toward my use of it for a backing store for an API truth state, where we may want to run scheduled tasks anyway, and we already support a plugin.

APOC can get you 98% of the way there – maybe others can chime in?