After a Mutate Transaction any relevant events will be dispatched followed by any events that have been queued. This is useful for responding to specific changes either from GraphQL Paper or custom events that might have been queued in a custom operation or by the Mutate Transaction itself using the
Listening to Events
Events are available via the
events property on the
Paper instance which follow the
To listen for an event use
events.addEventListener on a
Paper instance, for example to listen for the
removeEventListener is also available to stop listening for an event for a particular listener.
EventTarget for Node.js
If using a Node.js version 14 and higher
EventTarget should be supported, otherwise install the
Then include it early on in a top-level file before using GraphQL Paper
The following events are provided by default from GraphQL Paper when a document is created, removed, or modified.
When a document is created from a transaction a
create event is dispatched with the following properties:
changes property lists the changes per key, for example if
changedPropertyOnDocument changed on the document the
changes property would look:
Dispatching Custom Events
Any instance of
Event that is added either via
queueEvent operation or in a custom operation and pushed to the
eventQueue array will be dispatched after the transaction is complete and after the library events have been dispatched first.