Subscription Examples
🚨 This feature is currently under development! For more information or to express interest in using this feature, please contact us at
dev@momentum.se
.
Understanding Subscriptions
In GraphQL, the subscription type is used to implement real-time functionality. Clients can subscribe to specific events and receive the associated data as it becomes available.
When opening a subscription your account including a session token gets registered for changes for 12 hours
(time is subject for change). This means that a disconnection wont make your session miss messages. These messages will get notified after reconnecting within the 12 hour
window.
Session handle
Every subscription can listen for a individual session token. This token makes sure that the client can have multiple individual subscriptions opened against the same type, which listens and acknowledges each message individually.
Limitations
Each account is limited to 10
opened subscriptions. When trying to exceed that limit a message will be shown and stop any further subscriptions.
Examples of Subscriptions
Note: When using subscriptions, only
Id
andentityChangeLocalId
are available.Important: Always include
entityChangeLocalId
in every subscription call. This enables you to resume from the last known point in the event of a disconnection.
Subscribe to Changes in Any Contract
This subscription will notify you of any changes or additions to contracts, providing the contract's Id:
Subscribe to Changes in a Specific Contract
This subscription will notify you if a specific contract, identified by its Id, changes:
subscription testSubscribeOnContractByIdChange
{
contractById (id: "0e628534ef0143d6adfeeb631e3a4e3a") {
id
entityChangeLocalId
}
}
Handle missed data
To manage events that occur while disconnecting over a longer time period, we provide queries that return EntityChange
.
For example, if you are running a subscription on the entity Contract
and you disconnect with the last row returned having:
Id
: "a unique guid"
entityChangeLocalId
: 123
You can query for changes made after entityChangeLocalId
: 123, like this:
query GetContractChanges
{
contractChangesSync(lastEntityChangeLocalId: 123) {
nodes {
entityId
localId
}
}
}
After a successful change sync, it's possible to go back subscribing on new changes.