reactive_graph_dynamic_graph_impl/object/flow/mutation/
delete.rs1use async_graphql::ID;
2use async_graphql::dynamic::Field;
3use async_graphql::dynamic::FieldFuture;
4use async_graphql::dynamic::FieldValue;
5use async_graphql::dynamic::TypeRef;
6use log::trace;
7use reactive_graph_reactive_model_impl::ReactiveFlow;
8use reactive_graph_reactive_service_api::ReactiveFlowManager;
9use std::sync::Arc;
10
11pub fn get_flow_delete_field() -> Field {
12 Field::new("delete", TypeRef::named_nn_list_nn(TypeRef::ID), move |ctx| {
13 FieldFuture::new(async move {
14 let flow_instance_manager = ctx.data::<Arc<dyn ReactiveFlowManager + Send + Sync>>()?;
15 let mut ids = Vec::new();
16 for flow_instance in ctx.parent_value.try_downcast_ref::<Vec<ReactiveFlow>>()? {
17 trace!("Deleting flow instance {flow_instance}");
18 let id = flow_instance.id;
19 flow_instance_manager.delete(id);
20 ids.push(id);
21 }
22 Ok(Some(FieldValue::list(ids.iter().map(|id| FieldValue::value(ID(id.to_string()))))))
23 })
24 })
25}