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