reactive_graph_dynamic_graph_impl/object/entity/mutation/
export.rs1use crate::field::to_field_value;
2use async_graphql::dynamic::Field;
3use async_graphql::dynamic::FieldFuture;
4use async_graphql::dynamic::FieldValue;
5use async_graphql::dynamic::TypeRef;
6use reactive_graph_reactive_model_impl::ReactiveEntity;
7
8pub fn entity_export_field() -> Field {
9 Field::new("export", TypeRef::named_nn_list_nn("JSON"), move |ctx| {
10 FieldFuture::new(async move {
11 Ok(Some(FieldValue::list(
12 ctx.parent_value
13 .try_downcast_ref::<Vec<ReactiveEntity>>()?
14 .iter()
15 .filter_map(|reactive_entity| serde_json::to_value(reactive_entity).ok())
16 .filter_map(to_field_value),
17 )))
18 })
19 })
20}