1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
//! Axum route wiring for the realtime `WebSocket` endpoint.
//!
//! `realtime_router()` returns a standalone [`axum::Router`] that mounts
//! `/realtime/v1`. Merge it into the server's base router when the compiled
//! schema enables realtime:
//!
//! ```rust,ignore
//! if schema_config.realtime.as_ref().is_some_and(|r| r.enabled) {
//! let state = build_realtime_state(&schema_config, &validator);
//! app = app.merge(realtime_router(state));
//! }
//! ```
//!
//! # Schema config
//!
//! The `"realtime"` key in `schema.compiled.json` is deserialised into
//! [`RealtimeSchemaConfig`]. Only entities listed in [`RealtimeSchemaConfig::entities`]
//! will accept subscriptions — any subscribe request for an unlisted entity
//! returns `{ "type": "error", "message": "unknown entity: …" }`.
use ;
use Deserialize;
use ;
/// Configuration for the realtime subsystem, parsed from `schema.compiled.json`.
///
/// Embedded under the top-level `"realtime"` key:
///
/// ```json
/// {
/// "realtime": {
/// "enabled": true,
/// "entities": ["Post", "Comment"],
/// "max_connections_per_context": 25
/// }
/// }
/// ```
/// Build a router that mounts the realtime `WebSocket` endpoint at `/realtime/v1`.
///
/// Pass the returned router to [`axum::Router::merge`] when assembling the
/// server. The route is only mounted when `RealtimeSchemaConfig::enabled` is
/// `true` — callers are responsible for checking the flag before calling this
/// function.
///
/// # Example
///
/// ```rust,ignore
/// let realtime = realtime_router(state);
/// let app = base_router.merge(realtime);
/// ```