reactive_graph_client/client/instances/relations/variables/
id_and_components.rs

1#[cynic::schema_for_derives(file = r#"../../schema/graphql/reactive-graph-schema.graphql"#, module = "crate::schema_graphql::schema")]
2pub mod variables {
3    use crate::schema_graphql::scalar::id::UUID;
4    use cynic::QueryVariables;
5    use reactive_graph_graph::ComponentTypeIds;
6    use reactive_graph_graph::NamespacedTypeIdContainer;
7    use reactive_graph_graph::RelationInstanceId;
8
9    #[derive(QueryVariables, Debug)]
10    pub struct RelationInstanceIdAndComponentsVariables {
11        /// The id of the outbound entity instance.
12        pub outbound_id: UUID,
13        /// The fully qualified namespace of the relation type.
14        #[cynic(rename = "type")]
15        pub _type: String,
16        /// The relation instance id.
17        pub instance_id: String,
18        /// The id of the inbound entity instance.
19        pub inbound_id: UUID,
20        /// The list of components.
21        pub components: Option<Vec<String>>,
22    }
23
24    impl RelationInstanceIdAndComponentsVariables {
25        pub fn new<TY: Into<ComponentTypeIds>>(id: &RelationInstanceId, component_tys: TY) -> Self {
26            let ty = id.ty.relation_type_id();
27            let component_tys = component_tys.into().into_fully_qualified_namespaces();
28            Self {
29                outbound_id: id.outbound_id.into(),
30                _type: ty.to_string(),
31                instance_id: id.ty.instance_id().to_string(),
32                inbound_id: id.inbound_id.into(),
33                components: Some(component_tys),
34            }
35        }
36
37        pub fn new_from_component_type<TY: Into<reactive_graph_graph::ComponentTypeId>>(id: &RelationInstanceId, component_ty: TY) -> Self {
38            Self::new(id, reactive_graph_graph::ComponentTypeIds::new().component(component_ty))
39        }
40    }
41}