reactive_graph_client/schema_graphql/instances/property_instance/
property_instance_definition.rs

1use reactive_graph_graph::PropertyInstances;
2use serde_json::Value;
3use typed_builder::TypedBuilder;
4
5#[derive(cynic::InputObject, Debug, TypedBuilder)]
6#[cynic(
7    schema_path = "../../schema/graphql/reactive-graph-schema.graphql",
8    schema_module = "crate::schema_graphql::schema"
9)]
10pub struct PropertyInstanceDefinition {
11    pub name: String,
12    pub value: Value,
13}
14
15impl From<(&String, &Value)> for PropertyInstanceDefinition {
16    fn from(entry: (&String, &Value)) -> Self {
17        PropertyInstanceDefinition {
18            name: entry.0.clone(),
19            value: entry.1.clone(),
20        }
21    }
22}
23
24pub struct PropertyInstanceDefinitions(pub Vec<PropertyInstanceDefinition>);
25
26impl PropertyInstanceDefinitions {
27    pub fn new() -> Self {
28        Self(Vec::new())
29    }
30}
31
32impl From<PropertyInstanceDefinitions> for Vec<PropertyInstanceDefinition> {
33    fn from(property_instances: PropertyInstanceDefinitions) -> Self {
34        property_instances.0.into_iter().collect()
35    }
36}
37
38impl From<PropertyInstances> for PropertyInstanceDefinitions {
39    fn from(property_instances: PropertyInstances) -> Self {
40        PropertyInstanceDefinitions(
41            property_instances
42                .iter()
43                .map(|p| PropertyInstanceDefinition {
44                    name: p.key().clone(),
45                    value: p.value().clone(),
46                })
47                .collect(),
48        )
49    }
50}
51
52impl Default for PropertyInstanceDefinitions {
53    fn default() -> Self {
54        Self::new()
55    }
56}