reactive_graph_dynamic_graph_impl/union/
relation.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_RELATIONS: &str = "AllRelations";
9pub const UNION_NAMESPACE_RELATIONS_SUFFIX: &str = "Relations";
10
11pub fn get_namespace_relations_union(schema: SchemaBuilder, context: &SchemaBuilderContext, namespace: &String) -> SchemaBuilder {
12 let type_name = format!("{}{}", namespace.to_case(Pascal), UNION_NAMESPACE_RELATIONS_SUFFIX);
13 let mut union = Union::new(type_name).description(format!("Any relation of the namespace {namespace}"));
14 for relation_ty in context.relation_type_manager.get_types_by_namespace(namespace) {
15 let dy_ty = DynamicGraphTypeDefinition::from(&relation_ty);
16 union = union.possible_type(dy_ty.to_string());
17 }
18 schema.register(union)
19}
20
21pub fn get_all_relations_union(schema: SchemaBuilder, context: &SchemaBuilderContext) -> SchemaBuilder {
22 if context.relation_type_manager.get_type_ids().is_empty() {
23 return schema;
24 }
25 let mut union = Union::new(UNION_ALL_RELATIONS).description("Any relation.");
26 for relation_ty in context.relation_type_manager.get_type_ids() {
27 let dy_ty = DynamicGraphTypeDefinition::from(&relation_ty);
28 union = union.possible_type(dy_ty.to_string());
29 }
30 schema.register(union)
31}