reactive_graph_client/client/instances/relations/variables/
add_property.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::UUID;
4    use crate::schema_graphql::types::property_type::PropertyTypeDefinition;
5    use crate::schema_graphql::types::property_type::PropertyTypeDefinitions;
6    use cynic::QueryVariables;
7    use reactive_graph_graph::NamespacedTypeGetter;
8    use reactive_graph_graph::PropertyTypes;
9    use reactive_graph_graph::RelationInstanceId;
10
11    #[derive(QueryVariables, Debug)]
12    pub struct AddPropertiesVariables {
13        /// The id of the outbound entity instance.
14        pub outbound_id: UUID,
15        /// The fully qualified namespace of the relation type.
16        #[cynic(rename = "type")]
17        pub _type: String,
18        /// The instance id of the relation_instance_type_id.
19        pub instance_id: String,
20        /// The id of the inbound entity instance.
21        pub inbound_id: UUID,
22        /// The properties to add to the relation instance.
23        pub properties: Option<Vec<PropertyTypeDefinition>>,
24    }
25
26    impl AddPropertiesVariables {
27        pub fn new(id: &RelationInstanceId, property_types: PropertyTypes) -> Self {
28            let ty = id.ty.relation_type_id();
29            let property_types: PropertyTypeDefinitions = property_types.into();
30            Self {
31                outbound_id: id.outbound_id.into(),
32                _type: ty.namespace().to_string(),
33                instance_id: id.ty.instance_id().to_string(),
34                inbound_id: id.inbound_id.into(),
35                properties: Some(property_types.0),
36            }
37        }
38    }
39}