Skip to main content

hanzo_client/apis/
graph_api.rs

1/*
2 * Hanzo Cloud API
3 *
4 * The Hanzo Cloud API as a customer calls it: every operation under /v1/ except the operator's admin product, relay routes, legacy spellings and capabilities still reached by flag. Tagged by product: the first path segment after /v1/.
5 *
6 * The version of the OpenAPI document: v1
7 * 
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17
18/// struct for typed errors of method [`graph_assert`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum GraphAssertError {
22    UnknownValue(serde_json::Value),
23}
24
25/// struct for typed errors of method [`graph_neighbors`]
26#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum GraphNeighborsError {
29    UnknownValue(serde_json::Value),
30}
31
32/// struct for typed errors of method [`graph_read`]
33#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum GraphReadError {
36    UnknownValue(serde_json::Value),
37}
38
39/// struct for typed errors of method [`graph_resolve`]
40#[derive(Debug, Clone, Serialize, Deserialize)]
41#[serde(untagged)]
42pub enum GraphResolveError {
43    UnknownValue(serde_json::Value),
44}
45
46/// struct for typed errors of method [`graph_search`]
47#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum GraphSearchError {
50    UnknownValue(serde_json::Value),
51}
52
53/// struct for typed errors of method [`graph_vocabulary`]
54#[derive(Debug, Clone, Serialize, Deserialize)]
55#[serde(untagged)]
56pub enum GraphVocabularyError {
57    UnknownValue(serde_json::Value),
58}
59
60/// struct for typed errors of method [`post_graph_graphql`]
61#[derive(Debug, Clone, Serialize, Deserialize)]
62#[serde(untagged)]
63pub enum PostGraphGraphqlError {
64    UnknownValue(serde_json::Value),
65}
66
67
68pub async fn graph_assert(configuration: &configuration::Configuration, graph_assert_in: models::GraphAssertIn) -> Result<models::GraphAssertOut, Error<GraphAssertError>> {
69    // add a prefix to parameters to efficiently prevent name collisions
70    let p_graph_assert_in = graph_assert_in;
71
72    let uri_str = format!("{}/v1/graph", configuration.base_path);
73    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
74
75    if let Some(ref user_agent) = configuration.user_agent {
76        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
77    }
78    if let Some(ref token) = configuration.bearer_access_token {
79        req_builder = req_builder.bearer_auth(token.to_owned());
80    };
81    req_builder = req_builder.json(&p_graph_assert_in);
82
83    let req = req_builder.build()?;
84    let resp = configuration.client.execute(req).await?;
85
86    let status = resp.status();
87    let content_type = resp
88        .headers()
89        .get("content-type")
90        .and_then(|v| v.to_str().ok())
91        .unwrap_or("application/octet-stream");
92    let content_type = super::ContentType::from(content_type);
93
94    if !status.is_client_error() && !status.is_server_error() {
95        let content = resp.text().await?;
96        match content_type {
97            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
98            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GraphAssertOut`"))),
99            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::GraphAssertOut`")))),
100        }
101    } else {
102        let content = resp.text().await?;
103        let entity: Option<GraphAssertError> = serde_json::from_str(&content).ok();
104        Err(Error::ResponseError(ResponseContent { status, content, entity }))
105    }
106}
107
108pub async fn graph_neighbors(configuration: &configuration::Configuration, graph_neighbors_in: models::GraphNeighborsIn) -> Result<models::GraphNeighborsOut, Error<GraphNeighborsError>> {
109    // add a prefix to parameters to efficiently prevent name collisions
110    let p_graph_neighbors_in = graph_neighbors_in;
111
112    let uri_str = format!("{}/v1/graph/neighbors", configuration.base_path);
113    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
114
115    if let Some(ref user_agent) = configuration.user_agent {
116        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
117    }
118    if let Some(ref token) = configuration.bearer_access_token {
119        req_builder = req_builder.bearer_auth(token.to_owned());
120    };
121    req_builder = req_builder.json(&p_graph_neighbors_in);
122
123    let req = req_builder.build()?;
124    let resp = configuration.client.execute(req).await?;
125
126    let status = resp.status();
127    let content_type = resp
128        .headers()
129        .get("content-type")
130        .and_then(|v| v.to_str().ok())
131        .unwrap_or("application/octet-stream");
132    let content_type = super::ContentType::from(content_type);
133
134    if !status.is_client_error() && !status.is_server_error() {
135        let content = resp.text().await?;
136        match content_type {
137            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
138            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GraphNeighborsOut`"))),
139            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::GraphNeighborsOut`")))),
140        }
141    } else {
142        let content = resp.text().await?;
143        let entity: Option<GraphNeighborsError> = serde_json::from_str(&content).ok();
144        Err(Error::ResponseError(ResponseContent { status, content, entity }))
145    }
146}
147
148pub async fn graph_read(configuration: &configuration::Configuration, entity: Option<&str>, relation: Option<&str>, value: Option<&str>, as_of: Option<&str>, limit: Option<i32>) -> Result<models::GraphReadOut, Error<GraphReadError>> {
149    // add a prefix to parameters to efficiently prevent name collisions
150    let p_entity = entity;
151    let p_relation = relation;
152    let p_value = value;
153    let p_as_of = as_of;
154    let p_limit = limit;
155
156    let uri_str = format!("{}/v1/graph", configuration.base_path);
157    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
158
159    if let Some(ref param_value) = p_entity {
160        req_builder = req_builder.query(&[("entity", &param_value.to_string())]);
161    }
162    if let Some(ref param_value) = p_relation {
163        req_builder = req_builder.query(&[("relation", &param_value.to_string())]);
164    }
165    if let Some(ref param_value) = p_value {
166        req_builder = req_builder.query(&[("value", &param_value.to_string())]);
167    }
168    if let Some(ref param_value) = p_as_of {
169        req_builder = req_builder.query(&[("as_of", &param_value.to_string())]);
170    }
171    if let Some(ref param_value) = p_limit {
172        req_builder = req_builder.query(&[("limit", &param_value.to_string())]);
173    }
174    if let Some(ref user_agent) = configuration.user_agent {
175        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
176    }
177    if let Some(ref token) = configuration.bearer_access_token {
178        req_builder = req_builder.bearer_auth(token.to_owned());
179    };
180
181    let req = req_builder.build()?;
182    let resp = configuration.client.execute(req).await?;
183
184    let status = resp.status();
185    let content_type = resp
186        .headers()
187        .get("content-type")
188        .and_then(|v| v.to_str().ok())
189        .unwrap_or("application/octet-stream");
190    let content_type = super::ContentType::from(content_type);
191
192    if !status.is_client_error() && !status.is_server_error() {
193        let content = resp.text().await?;
194        match content_type {
195            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
196            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GraphReadOut`"))),
197            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::GraphReadOut`")))),
198        }
199    } else {
200        let content = resp.text().await?;
201        let entity: Option<GraphReadError> = serde_json::from_str(&content).ok();
202        Err(Error::ResponseError(ResponseContent { status, content, entity }))
203    }
204}
205
206pub async fn graph_resolve(configuration: &configuration::Configuration, graph_resolve_in: models::GraphResolveIn) -> Result<models::GraphResolveOut, Error<GraphResolveError>> {
207    // add a prefix to parameters to efficiently prevent name collisions
208    let p_graph_resolve_in = graph_resolve_in;
209
210    let uri_str = format!("{}/v1/graph/resolve", configuration.base_path);
211    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
212
213    if let Some(ref user_agent) = configuration.user_agent {
214        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
215    }
216    if let Some(ref token) = configuration.bearer_access_token {
217        req_builder = req_builder.bearer_auth(token.to_owned());
218    };
219    req_builder = req_builder.json(&p_graph_resolve_in);
220
221    let req = req_builder.build()?;
222    let resp = configuration.client.execute(req).await?;
223
224    let status = resp.status();
225    let content_type = resp
226        .headers()
227        .get("content-type")
228        .and_then(|v| v.to_str().ok())
229        .unwrap_or("application/octet-stream");
230    let content_type = super::ContentType::from(content_type);
231
232    if !status.is_client_error() && !status.is_server_error() {
233        let content = resp.text().await?;
234        match content_type {
235            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
236            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GraphResolveOut`"))),
237            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::GraphResolveOut`")))),
238        }
239    } else {
240        let content = resp.text().await?;
241        let entity: Option<GraphResolveError> = serde_json::from_str(&content).ok();
242        Err(Error::ResponseError(ResponseContent { status, content, entity }))
243    }
244}
245
246/// Finds assertions by their text where read finds them by their keys.  It is the READ with one more term, not a second way to leave the store: same order, same ceiling, same tenancy, and searching composes with narrowing by relation and by instant because all of them are terms of one filter.  It resolves nothing. What matches is what was asserted, including claims that were later corrected — which is the honest answer to \"where is this mentioned\" and the reason the caller then asks resolve about what it found.
247pub async fn graph_search(configuration: &configuration::Configuration, q: Option<&str>, relation: Option<&str>, as_of: Option<&str>, limit: Option<i32>) -> Result<models::GraphReadOut, Error<GraphSearchError>> {
248    // add a prefix to parameters to efficiently prevent name collisions
249    let p_q = q;
250    let p_relation = relation;
251    let p_as_of = as_of;
252    let p_limit = limit;
253
254    let uri_str = format!("{}/v1/graph/search", configuration.base_path);
255    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
256
257    if let Some(ref param_value) = p_q {
258        req_builder = req_builder.query(&[("q", &param_value.to_string())]);
259    }
260    if let Some(ref param_value) = p_relation {
261        req_builder = req_builder.query(&[("relation", &param_value.to_string())]);
262    }
263    if let Some(ref param_value) = p_as_of {
264        req_builder = req_builder.query(&[("as_of", &param_value.to_string())]);
265    }
266    if let Some(ref param_value) = p_limit {
267        req_builder = req_builder.query(&[("limit", &param_value.to_string())]);
268    }
269    if let Some(ref user_agent) = configuration.user_agent {
270        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
271    }
272    if let Some(ref token) = configuration.bearer_access_token {
273        req_builder = req_builder.bearer_auth(token.to_owned());
274    };
275
276    let req = req_builder.build()?;
277    let resp = configuration.client.execute(req).await?;
278
279    let status = resp.status();
280    let content_type = resp
281        .headers()
282        .get("content-type")
283        .and_then(|v| v.to_str().ok())
284        .unwrap_or("application/octet-stream");
285    let content_type = super::ContentType::from(content_type);
286
287    if !status.is_client_error() && !status.is_server_error() {
288        let content = resp.text().await?;
289        match content_type {
290            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
291            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GraphReadOut`"))),
292            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::GraphReadOut`")))),
293        }
294    } else {
295        let content = resp.text().await?;
296        let entity: Option<GraphSearchError> = serde_json::from_str(&content).ok();
297        Err(Error::ResponseError(ResponseContent { status, content, entity }))
298    }
299}
300
301pub async fn graph_vocabulary(configuration: &configuration::Configuration, ) -> Result<models::GraphVocabularyOut, Error<GraphVocabularyError>> {
302
303    let uri_str = format!("{}/v1/graph/vocabulary", configuration.base_path);
304    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
305
306    if let Some(ref user_agent) = configuration.user_agent {
307        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
308    }
309    if let Some(ref token) = configuration.bearer_access_token {
310        req_builder = req_builder.bearer_auth(token.to_owned());
311    };
312
313    let req = req_builder.build()?;
314    let resp = configuration.client.execute(req).await?;
315
316    let status = resp.status();
317    let content_type = resp
318        .headers()
319        .get("content-type")
320        .and_then(|v| v.to_str().ok())
321        .unwrap_or("application/octet-stream");
322    let content_type = super::ContentType::from(content_type);
323
324    if !status.is_client_error() && !status.is_server_error() {
325        let content = resp.text().await?;
326        match content_type {
327            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
328            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GraphVocabularyOut`"))),
329            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::GraphVocabularyOut`")))),
330        }
331    } else {
332        let content = resp.text().await?;
333        let entity: Option<GraphVocabularyError> = serde_json::from_str(&content).ok();
334        Err(Error::ResponseError(ResponseContent { status, content, entity }))
335    }
336}
337
338/// Runs a GraphQL query against this organization's assertions.  It is the one endpoint here a caller can TRAVERSE: the REST ops each answer a single question, so composing them — the entities this one points at, and what each of those resolves to — costs a request per hop with the intermediate keys held by the caller. Here that is one query and the nesting is the answer's shape.  It adds no way to ask anything new. Every field runs the SAME operation the matching REST route runs, so the tenancy, the as-of bound, the traversal bounds and the conflict rule are the ones already in force; the schema is served by introspection.  A query that cannot run answers 200 with an `errors` list, which is the wire every GraphQL client parses.
339pub async fn post_graph_graphql(configuration: &configuration::Configuration, graph_qlin: Option<models::GraphQlin>) -> Result<models::GraphQlOut, Error<PostGraphGraphqlError>> {
340    // add a prefix to parameters to efficiently prevent name collisions
341    let p_graph_qlin = graph_qlin;
342
343    let uri_str = format!("{}/v1/graph/graphql", configuration.base_path);
344    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
345
346    if let Some(ref user_agent) = configuration.user_agent {
347        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
348    }
349    if let Some(ref token) = configuration.bearer_access_token {
350        req_builder = req_builder.bearer_auth(token.to_owned());
351    };
352    req_builder = req_builder.json(&p_graph_qlin);
353
354    let req = req_builder.build()?;
355    let resp = configuration.client.execute(req).await?;
356
357    let status = resp.status();
358    let content_type = resp
359        .headers()
360        .get("content-type")
361        .and_then(|v| v.to_str().ok())
362        .unwrap_or("application/octet-stream");
363    let content_type = super::ContentType::from(content_type);
364
365    if !status.is_client_error() && !status.is_server_error() {
366        let content = resp.text().await?;
367        match content_type {
368            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
369            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GraphQlOut`"))),
370            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::GraphQlOut`")))),
371        }
372    } else {
373        let content = resp.text().await?;
374        let entity: Option<PostGraphGraphqlError> = serde_json::from_str(&content).ok();
375        Err(Error::ResponseError(ResponseContent { status, content, entity }))
376    }
377}
378