reactive_graph_client/client/runtime/command/
api.rs1use std::sync::Arc;
2
3use cynic::http::ReqwestExt;
4use serde_json::Value;
5
6use crate::ReactiveGraphClient;
7use crate::ReactiveGraphClientExecutionError;
8use crate::client::runtime::command::mutations::execute_command::mutations::execute_command;
9
10pub struct Command {
11 client: Arc<ReactiveGraphClient>,
12}
13
14impl Command {
15 pub fn new(client: Arc<ReactiveGraphClient>) -> Self {
16 Self { client }
17 }
18
19 pub async fn execute(&self, name: String, args: Option<Value>) -> Result<Option<Value>, ReactiveGraphClientExecutionError> {
20 let value = self
21 .client
22 .client
23 .post(self.client.url_reactive_graph_runtime())
24 .run_graphql(execute_command(name, args))
25 .await
26 .map_err(ReactiveGraphClientExecutionError::FailedToSendRequest)?
27 .data
28 .and_then(|data| data.commands.execute)
29 .map(|property_instance| property_instance.value.0);
30 Ok(value)
31 }
32}