Subscriptions Overview
The GraphQL API supports real-time subscriptions for live data updates using cursor-based streaming.
Basic Subscription Patternβ
subscription WatchAtoms(
$cursor: [atoms_stream_cursor_input]!
$batchSize: Int!
) {
atoms_stream(
cursor: $cursor
batch_size: $batchSize
) {
term_id
label
created_at
}
}
Variablesβ
{
"cursor": [{
"initial_value": { "created_at": "2024-01-01T00:00:00Z" },
"ordering": "ASC"
}],
"batchSize": 10
}
Cursor Configurationβ
- initial_value: Starting point for the stream
- ordering: Sort direction (ASC or DESC)
- batch_size: Number of items per batch
When to Use Subscriptionsβ
Use subscriptions when:
- Building real-time dashboards
- Monitoring live protocol activity
- Creating notification systems
- Data changes frequently
Use polling when:
- Data updates infrequently
- Real-time updates aren't critical
- Minimizing server connections
Best Practicesβ
- Store last cursor to resume after disconnection
- Use batch_size to control data flow (10-50)
- Filter subscriptions with where clauses
- Handle reconnections gracefully