reactive_graph_dynamic_graph_impl/union/
flow.rs1use async_graphql::dynamic::*;
2use convert_case::Case::Pascal;
3use convert_case::Casing;
4
5use crate::object::types::DynamicGraphTypeDefinition;
6use reactive_graph_dynamic_graph_api::SchemaBuilderContext;
7
8pub const UNION_ALL_FLOWS: &str = "AllFlows";
9pub const UNION_NAMESPACE_FLOWS_SUFFIX: &str = "Flows";
10
11pub fn namespace_flows_union_type_name(namespace: &str) -> String {
12 format!("{}{}", namespace.to_case(Pascal), UNION_NAMESPACE_FLOWS_SUFFIX)
13}
14
15pub fn get_namespace_flows_union(schema: SchemaBuilder, context: &SchemaBuilderContext, namespace: &String) -> SchemaBuilder {
16 let type_name = namespace_flows_union_type_name(namespace);
17 let mut union = Union::new(type_name).description(format!("Any flow of the namespace {namespace}"));
18 for flow_tys in context.flow_type_manager.get_types_by_namespace(namespace) {
19 let dy_ty = DynamicGraphTypeDefinition::from(&flow_tys);
20 union = union.possible_type(dy_ty.to_string());
21 }
22 schema.register(union)
23}
24
25pub fn get_all_flows_union(schema: SchemaBuilder, context: &SchemaBuilderContext) -> SchemaBuilder {
26 if context.flow_type_manager.get_type_ids().is_empty() {
27 return schema;
28 }
29 let mut union = Union::new(UNION_ALL_FLOWS).description("Any flow.");
30 for flow_ty in context.flow_type_manager.get_type_ids() {
31 let dy_ty = DynamicGraphTypeDefinition::from(&flow_ty);
32 union = union.possible_type(dy_ty.to_string());
33 }
34 schema.register(union)
35}