Skip to main content

kyma_graph/
provider.rs

1//! The provider abstraction every graph kind implements. G1a ships only
2//! `SchemaGraphProvider`; later phases add `StoredGraphProvider` behind the
3//! same trait.
4
5use async_trait::async_trait;
6
7use crate::types::{
8    Direction, EdgeExpansion, GraphNode, GraphPayload, GraphSchema, GraphStats, SearchHits,
9};
10
11#[async_trait]
12pub trait GraphProvider: Send + Sync {
13    /// Capped sample of the whole graph: stats + nodes + edges.
14    async fn overview(&self, realm: Option<&str>, limit: usize) -> anyhow::Result<GraphPayload>;
15    /// A single node by id, or `None` if absent.
16    async fn node(&self, id: &str) -> anyhow::Result<Option<GraphNode>>;
17    /// Edges touching `ids` (respecting `dir`), plus the node ids newly reached.
18    async fn neighbors(
19        &self,
20        ids: &[String],
21        dir: Direction,
22        only_internal: bool,
23        limit: usize,
24    ) -> anyhow::Result<EdgeExpansion>;
25    /// BFS from `id` up to `depth` hops (both directions); returns the subgraph.
26    async fn subgraph(&self, id: &str, depth: usize) -> anyhow::Result<GraphPayload>;
27    /// Nodes whose name matches `text` (case-insensitive), optionally filtered
28    /// by `labels` / `realm`.
29    async fn search(
30        &self,
31        text: &str,
32        labels: &[String],
33        realm: Option<&str>,
34        limit: usize,
35        offset: usize,
36    ) -> anyhow::Result<SearchHits>;
37    /// Node and relationship counts, optionally scoped to a single realm.
38    async fn stats(&self, realm: Option<&str>) -> anyhow::Result<GraphStats>;
39    /// Structural summary: known node kinds, edge types, and property keys per kind.
40    async fn schema(&self) -> anyhow::Result<GraphSchema>;
41}