Skip to main content

fraiseql_core/runtime/
embed_selection.rs

1//! What a transport asks to have embedded into the rows of a direct read.
2//!
3//! The REST `?select=posts(id,author(name)),posts.count` in engine terms: a tree of
4//! relationships to follow from the read's return type, the fields to take at each
5//! level, and the counts to take beside them. Nothing here says *how* a level is read —
6//! that is [`Executor::execute_query_composed`](crate::runtime::Executor::execute_query_composed)'s
7//! decision, and it composes every level into the parent's statement.
8
9/// A relationship to embed into each row of the level above it.
10#[derive(Debug, Clone, Default, PartialEq, Eq)]
11pub struct EmbedSelection {
12    /// The relationship's name on the parent type.
13    pub relationship: String,
14    /// The key the embedded value is written under — the relationship's name, or the
15    /// client's rename.
16    pub output_key:   String,
17    /// The target type's fields to return, in the order they were asked for.
18    pub fields:       Vec<String>,
19    /// The client's filter on the related rows, in the `{field: {op: value}}` shape a
20    /// `where` argument takes. Composed with the target's own security predicate the
21    /// way a filter on a flat read of the target is, so it can only narrow.
22    pub filter:       Option<serde_json::Value>,
23    /// The page each parent row gets of related rows. Capped by `max_page_size`, as any
24    /// read's page is.
25    pub limit:        Option<u32>,
26    /// Relationships to embed into each related row.
27    pub embeds:       Vec<EmbedSelection>,
28    /// Relationships to count for each related row.
29    pub counts:       Vec<CountSelection>,
30}
31
32/// A relationship whose related rows are counted, for each row of the level above it.
33#[derive(Debug, Clone, Default, PartialEq, Eq)]
34pub struct CountSelection {
35    /// The relationship's name on the parent type.
36    pub relationship: String,
37    /// The key the count is written under.
38    pub output_key:   String,
39    /// The client's filter on the counted rows — the same filter an embed of the same
40    /// relationship reads, so a list and its total cannot disagree (#1285).
41    pub filter:       Option<serde_json::Value>,
42}