reactive_graph_graphql_schema/mutation/instances/
flow_instance_definition.rs

1use async_graphql::*;
2use serde::Deserialize;
3use serde::Serialize;
4use uuid::Uuid;
5
6use reactive_graph_graph::EntityTypeId;
7use reactive_graph_graph::FlowInstance;
8
9use crate::mutation::GraphQLEntityInstanceDefinition;
10use crate::mutation::GraphQLRelationInstanceDefinition;
11
12/// Represents a flow with entity instances and relation instances.
13///
14/// The entity type of the flow and the entity types of each provided entity instance must exist.
15/// The relation types of each provided relation instance must exist.
16#[derive(Serialize, Deserialize, Clone, Debug, InputObject)]
17#[graphql(name = "FlowInstanceDefinition")]
18pub struct GraphQLFlowInstanceDefinition {
19    /// The id of the flow corresponds to the id of the wrapper entity instance
20    ///
21    /// This means the vector of entity instances must contain an instance with
22    /// the id of the flow.
23    pub id: Uuid,
24
25    /// The namespace the entity type belongs to.
26    pub namespace: String,
27
28    /// The name of the entity type.
29    pub type_name: String,
30
31    /// The name of the flow.
32    #[serde(default = "String::new")]
33    pub name: String,
34
35    /// Textual description of the flow.
36    #[serde(default = "String::new")]
37    pub description: String,
38
39    /// The entity instances which are contained in this flow.
40    ///
41    /// It can't have a default because the wrapper entity instance must be
42    /// present in the list of entities.
43    pub entity_instances: Vec<GraphQLEntityInstanceDefinition>,
44
45    /// The relation instances which are contained in this flow.
46    #[serde(default = "Vec::new")]
47    pub relation_instances: Vec<GraphQLRelationInstanceDefinition>,
48}
49
50impl From<GraphQLFlowInstanceDefinition> for FlowInstance {
51    fn from(flow: GraphQLFlowInstanceDefinition) -> Self {
52        let entity_instances = flow.entity_instances.iter().map(|entity_instance| entity_instance.clone().into()).collect();
53        let relation_instances = flow
54            .relation_instances
55            .iter()
56            .map(|relation_instance| relation_instance.clone().into())
57            .collect();
58        FlowInstance {
59            id: flow.id,
60            ty: EntityTypeId::new_from_type(flow.namespace, flow.type_name),
61            name: flow.name.clone(),
62            description: flow.description.clone(),
63            entity_instances,
64            relation_instances,
65        }
66    }
67}