Real-Time Collaboration API Example
GraphQL API for a collaborative document editor demonstrating multiple subscriptions, WebSocket configuration, trigger descriptions, and complexity hints for rate limiting.
This example demonstrates a real-time collaborative document editing API. It showcases multiple subscription types, detailed trigger descriptions, WebSocket server configuration, and complexity hints for managing high-frequency events.
API Overview
The Collaboration API enables:
- Document Editing - Real-time collaborative text editing
- Cursor Tracking - Live cursor positions for all participants
- Presence - User join/leave notifications
- Comments - Inline comments and discussions
Server Configuration
The API requires both HTTP and WebSocket endpoints:
{
"id": "api-collab-001",
"name": "Collaboration API",
"description": "Real-time collaborative document editing with presence, cursors, and comments.",
"version": "1.0.0",
"servers": [
{
"id": "production",
"url": "https://collab.example.com/graphql",
"wsUrl": "wss://collab.example.com/graphql",
"description": "Production environment with global CDN",
"healthCheckUrl": "https://collab.example.com/health",
"introspectionEnabled": false
},
{
"id": "regional-eu",
"url": "https://eu.collab.example.com/graphql",
"wsUrl": "wss://eu.collab.example.com/graphql",
"description": "European region for lower latency",
"introspectionEnabled": false
}
],
"tags": ["collaboration", "real-time", "documents"]
}
Subscriptions
The API provides four subscription types for different real-time events:
Complexity and Rate Limiting
Subscription complexity values help manage server resources:
Authentication
The API uses Bearer token authentication with WebSocket connection parameters:
{
"authSchemes": [
{
"id": "bearer",
"type": "bearer",
"description": "JWT token for user authentication. Pass as 'Authorization' header for HTTP or in connection_init payload for WebSocket.",
"bearerFormat": "JWT"
}
],
"defaultAuthRequirements": [
[{ "schemeId": "bearer" }]
]
}
For WebSocket connections, pass the token in the connection initialisation:
{
"type": "connection_init",
"payload": {
"Authorization": "Bearer eyJhbGciOiJIUzI1NiIs..."
}
}