reactive_graph_dynamic_graph_impl/field/
entity.rs

1use crate::type_ref::TYPE_REF_ID;
2use async_graphql::ID;
3use async_graphql::dynamic::Field;
4use async_graphql::dynamic::FieldFuture;
5use async_graphql::dynamic::FieldValue;
6use reactive_graph_dynamic_graph_api::INTERFACE_ENTITY_FIELD_ID;
7use reactive_graph_reactive_model_impl::ReactiveEntity;
8
9pub fn entity_id_field() -> Field {
10    Field::new(INTERFACE_ENTITY_FIELD_ID, TYPE_REF_ID.clone(), |ctx| {
11        FieldFuture::new(async move {
12            let reactive_entity = ctx.parent_value.try_downcast_ref::<ReactiveEntity>()?;
13            Ok(Some(FieldValue::value(ID(reactive_entity.id.to_string()))))
14        })
15    })
16    .description("The unique identifier of the entity instance.")
17}