reactive_graph_client/client/json_schema/instances/
flows.rs

1#[cynic::schema_for_derives(file = r#"../../schema/graphql/reactive-graph-schema.graphql"#, module = "crate::schema_graphql::schema")]
2pub mod queries {
3    use cynic::Operation;
4    use cynic::QueryFragment;
5    use serde_json::Value;
6
7    #[derive(QueryFragment, Debug)]
8    #[cynic(graphql_type = "Query")]
9    pub struct JsonSchemaFlowInstances {
10        pub json_schema: JsonSchema,
11    }
12
13    #[derive(QueryFragment, Debug)]
14    #[cynic(graphql_type = "JsonSchema")]
15    pub struct JsonSchema {
16        pub instances: JsonSchemaInstanceSystem,
17    }
18
19    #[derive(QueryFragment, Debug)]
20    #[cynic(graphql_type = "JsonSchemaInstanceSystem")]
21    pub struct JsonSchemaInstanceSystem {
22        pub flows: Value,
23    }
24
25    pub fn get_json_schema_for_flow_instances() -> Operation<JsonSchemaFlowInstances, ()> {
26        use cynic::QueryBuilder;
27        JsonSchemaFlowInstances::build(())
28    }
29
30    #[cfg(all(test, feature = "integration-tests"))]
31    mod tests {
32        use reactive_graph_runtime_impl::RuntimeBuilder;
33        use std::sync::Arc;
34
35        use crate::ReactiveGraphClient;
36        use reactive_graph_runtime_api::Runtime;
37
38        #[tokio::test(flavor = "multi_thread")]
39        async fn test_get_json_schema_for_flow_instances() {
40            RuntimeBuilder::new()
41                .ignore_config_files()
42                .instance_name("test_get_json_schema_for_flow_instances")
43                .pick_free_port()
44                .disable_all_plugins(true)
45                .init()
46                .await
47                .post_init()
48                .await
49                .spawn()
50                .await
51                .with_runtime(|runtime: Arc<dyn Runtime + Send + Sync>| async move {
52                    let client = ReactiveGraphClient::new_from_runtime(runtime.clone()).expect("Failed to get client from runtime");
53                    let json_schema = client
54                        .json_schema()
55                        .instances()
56                        .flows()
57                        .await
58                        .expect("Failed to get JSON Schema for flow instances");
59                    let json_schema = json_schema.expect("No JSON Schema for flow instances was returned");
60                    let json_schema = serde_json::to_string_pretty(&json_schema).expect("Failed to serialize JSON Schema for flow instances");
61                    println!("{}", json_schema);
62                })
63                .await
64                .stop()
65                .await
66                .pre_shutdown()
67                .await
68                .shutdown()
69                .await;
70        }
71    }
72}