graphql icon indicating copy to clipboard operation
graphql copied to clipboard

Add ability to subscribe to events via the OGM

Open kozak-codes opened this issue 1 year ago • 1 comments

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.

kozak-codes avatar Dec 17 '23 00:12 kozak-codes

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.

jbhurruth avatar May 02 '24 14:05 jbhurruth