reactive_graph_dynamic_graph_impl/
union_manager_impl.rs1use crate::object_type_name::object_type_name;
2use async_graphql::dynamic::Union;
3use async_trait::async_trait;
4use log::trace;
5use reactive_graph_dynamic_graph_api::RootObjectType::Query;
6use reactive_graph_dynamic_graph_api::UNION_ALL_ENTITIES;
7use reactive_graph_dynamic_graph_api::UNION_ALL_FLOWS;
8use reactive_graph_dynamic_graph_api::UNION_ALL_RELATIONS;
9use reactive_graph_dynamic_graph_api::UnionManager;
10use reactive_graph_lifecycle::Lifecycle;
11use reactive_graph_type_system_api::EntityTypeManager;
12use reactive_graph_type_system_api::FlowTypeManager;
13use reactive_graph_type_system_api::RelationTypeManager;
14use springtime_di::Component;
15use springtime_di::component_alias;
16use std::sync::Arc;
17
18#[derive(Component)]
19pub struct UnionManagerImpl {
20 entity_type_manager: Arc<dyn EntityTypeManager + Send + Sync>,
21 relation_type_manager: Arc<dyn RelationTypeManager + Send + Sync>,
22 flow_type_manager: Arc<dyn FlowTypeManager + Send + Sync>,
23}
24
25impl UnionManagerImpl {}
26
27#[async_trait]
28#[component_alias]
29impl UnionManager for UnionManagerImpl {
30 fn get_unions(&self) -> Vec<Union> {
31 vec![self.all_entities(), self.all_relations(), self.all_flows()]
32 }
33
34 fn all_entities(&self) -> Union {
35 let mut union = Union::new(UNION_ALL_ENTITIES).description("Any entity.");
36 for ty in self.entity_type_manager.get_type_ids() {
37 let object_type_name = object_type_name(&ty, Query);
38 trace!("AllEntities += {object_type_name}");
39 union = union.possible_type(object_type_name);
40 }
41 union
42 }
43
44 fn all_relations(&self) -> Union {
45 let mut union = Union::new(UNION_ALL_RELATIONS).description("Any relation.");
46 for ty in self.relation_type_manager.get_type_ids() {
47 let object_type_name = object_type_name(&ty, Query);
48 trace!("AllRelations += {object_type_name}");
49 union = union.possible_type(object_type_name);
50 }
51 union
52 }
53
54 fn all_flows(&self) -> Union {
55 let mut union = Union::new(UNION_ALL_FLOWS).description("Any flow.");
56 for ty in self.flow_type_manager.get_type_ids() {
57 let object_type_name = object_type_name(&ty, Query);
58 trace!("AllFlows += {object_type_name}");
59 union = union.possible_type(object_type_name);
60 }
61 union
62 }
63
64 }
70
71#[async_trait]
72impl Lifecycle for UnionManagerImpl {}