reactive_graph_dynamic_graph_impl/object/relation/mutation/
export.rs

1use 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::ReactiveRelation;
7
8pub fn relation_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<ReactiveRelation>>()?
14                    .iter()
15                    .filter_map(|reactive_relation| serde_json::to_value(reactive_relation).ok())
16                    .filter_map(to_field_value),
17            )))
18        })
19    })
20}