reactive_graph_dynamic_graph_impl/field/
relation.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_RELATION_FIELD_ID;
7use reactive_graph_dynamic_graph_api::INTERFACE_RELATION_FIELD_INSTANCE_ID;
8use reactive_graph_reactive_model_api::ReactiveInstance;
9use reactive_graph_reactive_model_impl::ReactiveRelation;
10
11/// Creates a field with the relation instance id.
12/// `{outbound_id}--[{fully_qualified_relation_type_namespace}__{instance_id}]-->{inbound_id}`
13pub fn relation_id_field() -> Field {
14    Field::new(INTERFACE_RELATION_FIELD_ID, TYPE_REF_ID.clone(), |ctx| {
15        FieldFuture::new(async move {
16            let reactive_relation = ctx.parent_value.try_downcast_ref::<ReactiveRelation>()?;
17            Ok(Some(FieldValue::value(ID(reactive_relation.id().to_string()))))
18        })
19    })
20}
21
22pub fn relation_instance_id_field() -> Field {
23    Field::new(INTERFACE_RELATION_FIELD_INSTANCE_ID, TYPE_REF_ID.clone(), |ctx| {
24        FieldFuture::new(async move {
25            let reactive_relation = ctx.parent_value.try_downcast_ref::<ReactiveRelation>()?;
26            Ok(Some(FieldValue::value(ID(reactive_relation.instance_id().to_string()))))
27        })
28    })
29}