reactive_graph_dynamic_graph_impl/field/entity/property/
property_field.rs

1use crate::field::to_field_value;
2use crate::field::to_type_ref;
3use async_graphql::dynamic::Field;
4use async_graphql::dynamic::FieldFuture;
5use reactive_graph_graph::PropertyInstanceGetter;
6use reactive_graph_graph::PropertyType;
7use reactive_graph_reactive_model_impl::ReactiveEntity;
8
9pub fn entity_property_field(property_type: &PropertyType) -> Field {
10    let property_type_inner = property_type.clone();
11    Field::new(&property_type.name, to_type_ref(&property_type.data_type), move |ctx| {
12        let property_type = property_type_inner.clone();
13        FieldFuture::new(async move {
14            let entity_instance = ctx.parent_value.try_downcast_ref::<ReactiveEntity>()?;
15            Ok(entity_instance.get(&property_type.name).and_then(to_field_value))
16        })
17    })
18    .description(&property_type.description)
19}