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
90
91
92
93
94
95
96
//! The resolved request locale, carried to the engine (#1512).
//!
//! A transport resolves the locale once per request ([`LocaleConfig::resolve`]) and runs the
//! request's engine calls inside [`with_request_locale`]. The engine reads it with
//! [`request_locale`], which every read path uses for the `fraiseql.locale` session setting
//! and the result-cache key.
//!
//! It is a task-local, like [`crate::runtime::dispatched_at`]'s depth, and for the same
//! reason: a client controls neither. A transport whose engine calls cross a task boundary
//! (`/ws` after the upgrade, an async-operation worker) carries the resolved value across and
//! scopes it again on the far side.
//!
//! [`LocaleConfig::resolve`]: crate::schema::LocaleConfig::resolve
use Future;
use crateCompiledSchema;
task_local!
/// Run `future` as the work of a request whose locale resolved to `locale`.
pub async
/// The fallback chain a localized field is read through in the current request (#1513): the
/// request locale's chain from `[locale]`. `None` when the schema declares no locale.
/// A localized field's stored value read through `chain` (#1513).
///
/// The first locale whose label is a JSON string, `null` when none is. A string is its own
/// label (a label SQL already resolved, or a stored plain string, which SQL reads the same
/// way), so applying this twice changes nothing. Any other value is `null`.
///
/// The in-process twin of `fraiseql_db::projection_generator::localized_text_expr`, for
/// values that never pass through that SQL (a mutation's returned entity, a composed read
/// projected in Rust). Both skip a non-string label, so they agree; a parity test runs both
/// over one corpus on PostgreSQL.
/// The locale the current request was scoped in by its transport, unchecked.
///
/// `None` outside any scope. For a consumer with no schema at hand (the result cache's key);
/// anything that reaches SQL uses [`request_locale`], which checks it against `allowed`.
/// Run `f` in `locale`, when there is one.
///
/// The synchronous twin of [`with_request_locale`], for work done outside the request's own
/// task (a subscription event served on the bridge's task, in the locale captured when it
/// subscribed).
/// The locale the current request runs in, when `schema` declares `[locale]`: the scoped
/// value if it is one of `allowed`, otherwise `default`. `None` when the schema declares no
/// locale.
///
/// A scoped value outside `allowed` cannot come from a transport (they scope what
/// `LocaleConfig::resolve` returns), so it is treated as absent rather than trusted: only a
/// configured tag ever reaches SQL. An engine call made outside any scope (an embedder, a
/// background job) runs in `default`.