reactive_graph_client/client/runtime/remotes/mutations/
add_remote.rs

1#[cynic::schema_for_derives(file = r#"../../schema/graphql/reactive-graph-runtime-schema.graphql"#, module = "crate::schema_runtime::schema")]
2pub mod mutations {
3    use crate::client::runtime::instance::variables::address::variables::InstanceAddressVariables;
4    use crate::client::runtime::instance::variables::address::variables::InstanceAddressVariablesFields;
5    use crate::schema_runtime::InstanceInfo;
6
7    #[derive(Debug, cynic::QueryFragment)]
8    #[cynic(graphql_type = "Mutation", variables = "InstanceAddressVariables")]
9    pub struct AddRemote {
10        pub remotes: AddRemoteMutationRemotes,
11    }
12
13    #[derive(Debug, cynic::QueryFragment)]
14    #[cynic(graphql_type = "MutationRemotes", variables = "InstanceAddressVariables")]
15    pub struct AddRemoteMutationRemotes {
16        #[arguments(address: $address)]
17        pub add: InstanceInfo,
18    }
19
20    pub fn add(vars: InstanceAddressVariables) -> cynic::Operation<AddRemote, InstanceAddressVariables> {
21        use cynic::MutationBuilder;
22        AddRemote::build(vars)
23    }
24}
25
26#[cfg(all(test, feature = "integration-tests"))]
27pub mod test {
28    use crate::ReactiveGraphClient;
29    use reactive_graph_runtime_api::Runtime;
30    use reactive_graph_runtime_impl::RuntimeBuilder;
31    use std::sync::Arc;
32    use std::time::Duration;
33    use tokio::time::sleep;
34
35    #[tokio::test(flavor = "multi_thread")]
36    async fn test_add_remote() {
37        RuntimeBuilder::new()
38            .ignore_config_files()
39            .disable_all_plugins(true)
40            .pick_free_port()
41            .init()
42            .await
43            .post_init()
44            .await
45            .spawn()
46            .await
47            .with_runtime(|runtime: Arc<dyn Runtime + Send + Sync>| async move {
48                sleep(Duration::from_millis(2000)).await;
49
50                let remotes_manager = runtime.get_remotes_manager();
51
52                // Get instance info from the runtime
53                let rt_address = runtime.address();
54
55                // Check that there are no remotes
56                assert_eq!(remotes_manager.get_all().len(), 0);
57
58                // Client: Connect to self and get all remotes
59                let client = ReactiveGraphClient::new(rt_address.clone()).expect("Cannot create client");
60                let remote = client.runtime().remotes().add(&rt_address).await.expect("Failed to add remote");
61
62                // Check that there is a new remote
63                assert_eq!(remotes_manager.get_all().len(), 1);
64                assert_eq!(rt_address, remote.address);
65            })
66            .await
67            .stop()
68            .await
69            .pre_shutdown()
70            .await
71            .shutdown()
72            .await;
73    }
74}