Subscription events
|
This is the documentation of the GraphQL Library version 7. For the long-term support (LTS) version 5, refer to GraphQL Library version 5 LTS. |
This page covers a variety of subscription options offered by the Neo4j GraphQL Library.
CREATE
Subscriptions to CREATE events listen only to newly created nodes, not new relationships.
In this occasion, a new event is triggered for each new node, containing its properties.
This action is performed with the top-level subscription [type]Created, which contains the following fields:
-
event: the event triggering this subscription (in this case,CREATE). -
created<typename>: top-level properties of the newly created node, without relationships. -
timestamp: the timestamp in which the mutation was made. If a same query triggers multiple events, they should have the same timestamp.
As an example, consider the following type definitions:
type Movie @node {
title: String
genre: String
}
extend schema @subscription
A subscription to any newly created node of the Movie type should look like this:
subscription {
movieCreated {
createdMovie {
title
genre
}
event
timestamp
}
}
UPDATE
Subscriptions to UPDATE events listen only to node properties changes, not updates to other fields.
In this occasion, a new event is triggered for each mutation that modifies the node top-level properties.
This action is performed with the top-level subscription [type]Updated, which contains the following fields:
-
event: the event triggering this subscription (in this case,UPDATE). -
updated<typename>: top-level properties of the updated node, without relationships. -
previousState: the previous top-level properties of the node, before theUPDATEevent. -
timestamp: the timestamp in which the mutation was made. If a same query triggers multiple events, they should have the same timestamp.
As an example, consider the following type definitions:
type Movie @node {
title: String
genre: String
}
extend schema @subscription
A subscription to any node of the Movie type with its properties recently updated should look like this:
subscription MovieUpdated {
movieUpdated {
event
previousState {
title
genre
}
updatedMovie {
title
}
timestamp
}
}
DELETE
Subscriptions to DELETE events listen only to nodes being deleted, not deleted relationships.
This action is performed with the top-level subscription [type]Deleted, which contains the following fields:
-
event: the event triggering this subscription (in this case,DELETE). -
deleted<typename>: top-level properties of the deleted node, without relationships. -
timestamp: the timestamp in which the mutation was made. If a same query triggers multiple events, they should have the same timestamp.
As an example, consider the following type definitions:
type Movie @node {
title: String
genre: String
}
extend schema @subscription
A subscription to any deleted nodes of the Movie type should look like this:
subscription {
movieDeleted {
deletedMovie {
title
}
event
timestamp
}
}