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    db::{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::db::traits::CursorValue>,
18        before: Option<crate::db::traits::CursorValue>,
19        limit: u32,
20        forward: bool,
21        where_clause: Option<&crate::db::where_clause::WhereClause>,
22        order_by: Option<&[crate::compiler::aggregation::OrderByClause]>,
23        include_total_count: bool,
24    ) -> Result<crate::db::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::db::traits::CursorValue>,
47        before: Option<crate::db::traits::CursorValue>,
48        limit: u32,
49        forward: bool,
50        where_clause: Option<&crate::db::where_clause::WhereClause>,
51        order_by: Option<&[crate::compiler::aggregation::OrderByClause]>,
52        include_total_count: bool,
53        session_vars: &[(&str, &str)],
54    ) -> Result<crate::db::traits::RelayPageResult> {
55        // Relay results are not cached; forward with session affinity so RLS
56        // pagination sees the configured session variables (#329).
57        self.adapter
58            .execute_relay_page_with_session(
59                view,
60                cursor_column,
61                after,
62                before,
63                limit,
64                forward,
65                where_clause,
66                order_by,
67                include_total_count,
68                session_vars,
69            )
70            .await
71    }
72}