Skip to main content

edgequake_sdk/resources/
graph.rs

1//! Graph resource.
2
3use crate::client::EdgeQuakeClient;
4use crate::error::Result;
5use crate::types::graph::*;
6
7pub struct GraphResource<'a> {
8    pub(crate) client: &'a EdgeQuakeClient,
9}
10
11impl<'a> GraphResource<'a> {
12    /// `GET /api/v1/graph` — full graph.
13    pub async fn get(&self) -> Result<GraphResponse> {
14        self.client.get("/api/v1/graph").await
15    }
16
17    /// `GET /api/v1/graph/nodes/search?q=…`
18    pub async fn search(&self, query: &str) -> Result<SearchNodesResponse> {
19        self.client
20            .get(&format!(
21                "/api/v1/graph/nodes/search?q={}",
22                urlencoding::encode(query)
23            ))
24            .await
25    }
26
27    /// `GET /api/v1/graph/nodes/{node_id}` — Get a single node by ID.
28    pub async fn get_node(&self, node_id: &str) -> Result<serde_json::Value> {
29        self.client
30            .get(&format!(
31                "/api/v1/graph/nodes/{}",
32                urlencoding::encode(node_id)
33            ))
34            .await
35    }
36
37    /// `GET /api/v1/graph/labels/search?q=…` — Search labels.
38    pub async fn search_labels(&self, query: &str) -> Result<Vec<serde_json::Value>> {
39        self.client
40            .get(&format!(
41                "/api/v1/graph/labels/search?q={}",
42                urlencoding::encode(query)
43            ))
44            .await
45    }
46
47    /// `GET /api/v1/graph/labels/popular` — Get popular labels.
48    pub async fn popular_labels(&self) -> Result<Vec<serde_json::Value>> {
49        self.client.get("/api/v1/graph/labels/popular").await
50    }
51}