neo4j / graphql

A GraphQL to Cypher query execution layer for Neo4j and JavaScript GraphQL implementations.
https://neo4j.com/docs/graphql-manual/current/
Apache License 2.0
496 stars 148 forks source link

Add ability to subscribe to events via the OGM #4420

Open kozak-codes opened 8 months ago

kozak-codes commented 8 months ago

Is your feature request related to a problem? Please describe.

eg:

const Message = ogm.model('Message');
Message.on('created', {
  where: {},
}, (result) => {
  // do something with your new message
})

Describe the solution you'd like A clear and concise description of what you want to happen.

Describe alternatives you've considered A clear and concise description of any alternative solutions or features you've considered.

Additional context Add any other context or screenshots about the feature request here.

jbhurruth commented 4 months ago

You can achieve this by writing a custom subscription plugin and then routing the events to your handlers. I've found the only issue is that the execution context doesn't make it through to plugin unless you make some minor patches to the library. This doesn't matter if you don't have about your event handlers and the mutations thats caused them being scoped to the same transaction.