Skip to main content

fraiseql_core/cache/
relay_cache.rs

1//! `RelayDatabaseAdapter` impl for `CachedDatabaseAdapter`.
2//!
3//! Relay pagination results are not cached — all calls are forwarded
4//! directly to the underlying adapter.
5
6use super::adapter::CachedDatabaseAdapter;
7use crate::{
8    backend::{DatabaseAdapter, RelayDatabaseAdapter},
9    error::Result,
10};
11
12impl<A: RelayDatabaseAdapter + DatabaseAdapter> RelayDatabaseAdapter for CachedDatabaseAdapter<A> {
13    async fn execute_relay_page(
14        &self,
15        view: &str,
16        cursor_column: &str,
17        after: Option<crate::backend::traits::CursorValue>,
18        before: Option<crate::backend::traits::CursorValue>,
19        limit: u32,
20        forward: bool,
21        where_clause: Option<&crate::backend::where_clause::WhereClause>,
22        order_by: Option<&[crate::compiler::aggregation::OrderByClause]>,
23        include_total_count: bool,
24    ) -> Result<crate::backend::traits::RelayPageResult> {
25        // Relay pagination results are not cached — always delegate to the underlying adapter
26        self.adapter
27            .execute_relay_page(
28                view,
29                cursor_column,
30                after,
31                before,
32                limit,
33                forward,
34                where_clause,
35                order_by,
36                include_total_count,
37            )
38            .await
39    }
40
41    #[allow(clippy::too_many_arguments)] // Reason: relay pagination requires all cursor/filter/sort/count arguments plus session vars; no natural grouping
42    async fn execute_relay_page_with_session(
43        &self,
44        view: &str,
45        cursor_column: &str,
46        after: Option<crate::backend::traits::CursorValue>,
47        before: Option<crate::backend::traits::CursorValue>,
48        limit: u32,
49        forward: bool,
50        where_clause: Option<&crate::backend::where_clause::WhereClause>,
51        order_by: Option<&[crate::compiler::aggregation::OrderByClause]>,
52        include_total_count: bool,
53        session_vars: &[(&str, &str)],
54        routing: crate::backend::types::ReadRouting,
55    ) -> Result<crate::backend::traits::RelayPageResult> {
56        // Relay results are not cached; forward with session affinity so RLS
57        // pagination sees the configured session variables (#329).
58        self.adapter
59            .execute_relay_page_with_session(
60                view,
61                cursor_column,
62                after,
63                before,
64                limit,
65                forward,
66                where_clause,
67                order_by,
68                include_total_count,
69                session_vars,
70                routing,
71            )
72            .await
73    }
74}