reactive_graph_dynamic_graph_impl/field/
reactive_instance.rs1use crate::object_type_name::object_type_name;
2use async_graphql::dynamic::FieldValue;
3use log::info;
4use reactive_graph_dynamic_graph_api::RootObjectType;
5use reactive_graph_graph::ComponentTypeId;
6use reactive_graph_reactive_model_api::ReactiveInstanceUnidentifiable;
7use std::sync::Arc;
8
9pub fn reactive_instance_component<'a, T: ReactiveInstanceUnidentifiable + 'static>(
10 reactive_instance: T,
11 ty: &ComponentTypeId,
12 root_object_type: RootObjectType,
13) -> FieldValue<'a> {
14 let type_name = match root_object_type {
15 RootObjectType::Interface => object_type_name(ty, root_object_type),
16 RootObjectType::Query => object_type_name(reactive_instance.namespaced_type(), root_object_type),
17 RootObjectType::Mutation => object_type_name(reactive_instance.namespaced_type(), root_object_type),
18 };
19 info!("{ty} {} {root_object_type} -> {type_name}", reactive_instance.namespace());
20 let boxed_reactive_instance = Arc::<Box<dyn ReactiveInstanceUnidentifiable>>::new(Box::new(reactive_instance));
31 FieldValue::owned_any(boxed_reactive_instance).with_type(type_name)
32}
33
34