-
Notifications
You must be signed in to change notification settings - Fork 94
/
Copy pathmod.rs
153 lines (134 loc) · 5.13 KB
/
mod.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#![warn(missing_docs)]
use std::io::stdin;
use anyhow::anyhow;
use apollo_federation_types::config::RouterVersion;
use camino::Utf8PathBuf;
use futures::StreamExt;
use houston::{Config, Profile};
use router::{install::InstallRouter, run::RunRouter, watchers::file::FileWatcher};
use rover_client::operations::config::who_am_i::WhoAmI;
use crate::{
command::Dev,
composition::pipeline::CompositionPipeline,
utils::{
client::StudioClientConfig,
effect::{
exec::{TokioCommand, TokioSpawn},
read_file::FsReadFile,
write_file::FsWriteFile,
},
},
RoverError, RoverOutput, RoverResult,
};
use self::router::{
binary::RouterLog,
config::{RouterAddress, RunRouterConfig},
};
mod router;
impl Dev {
/// Runs rover dev
pub async fn run(
&self,
override_install_path: Option<Utf8PathBuf>,
client_config: StudioClientConfig,
) -> RoverResult<RoverOutput> {
let elv2_license_accepter = self.opts.plugin_opts.elv2_license_accepter;
let skip_update = self.opts.plugin_opts.skip_update;
let read_file_impl = FsReadFile::default();
let write_file_impl = FsWriteFile::default();
let exec_command_impl = TokioCommand::default();
let router_address = RouterAddress::new(
self.opts.supergraph_opts.supergraph_address,
self.opts.supergraph_opts.supergraph_port,
);
let tmp_dir = tempfile::Builder::new().prefix("supergraph").tempdir()?;
let tmp_config_dir_path = Utf8PathBuf::try_from(tmp_dir.into_path())?;
let router_config_path = self.opts.supergraph_opts.router_config_path.clone();
let _config = RunRouterConfig::default()
.with_address(router_address)
.with_config(&read_file_impl, router_config_path.as_ref())
.await
.map_err(|err| RoverError::new(anyhow!("{}", err)))?;
let profile = &self.opts.plugin_opts.profile;
let graph_ref = &self.opts.supergraph_opts.graph_ref;
let supergraph_config_path = &self.opts.supergraph_opts.clone().supergraph_config_path;
let service = client_config.get_authenticated_client(profile)?.service()?;
let service = WhoAmI::new(service);
let composition_pipeline = CompositionPipeline::default()
.init(
&mut stdin(),
&client_config.get_authenticated_client(profile)?,
supergraph_config_path.clone(),
graph_ref.clone(),
)
.await?
.resolve_federation_version(
&client_config,
&client_config.get_authenticated_client(profile)?,
self.opts.supergraph_opts.federation_version.clone(),
)
.await?
.install_supergraph_binary(
client_config.clone(),
override_install_path.clone(),
elv2_license_accepter,
skip_update,
)
.await?;
let composition_success = composition_pipeline
.compose(&exec_command_impl, &read_file_impl, &write_file_impl, None)
.await?;
let supergraph_schema = composition_success.supergraph_sdl();
// TODO: figure out how to actually get this; maybe based on fed version? didn't see a cli
// opt
let router_version = RouterVersion::Latest;
let credential =
Profile::get_credential(&profile.profile_name, &Config::new(None::<&String>, None)?)?;
let composition_runner = composition_pipeline
.runner(
exec_command_impl,
read_file_impl.clone(),
write_file_impl.clone(),
profile,
&client_config,
self.opts.subgraph_opts.subgraph_polling_interval,
tmp_config_dir_path.clone(),
)
.await?;
let composition_messages = composition_runner.run();
let mut run_router = RunRouter::default()
.install::<InstallRouter>(
router_version,
client_config.clone(),
override_install_path,
elv2_license_accepter,
skip_update,
)
.await?
.load_config(&read_file_impl, router_address, router_config_path)
.await?
.load_remote_config(service, graph_ref.clone(), Some(credential))
.await
.run(
FsWriteFile::default(),
TokioSpawn::default(),
&tmp_config_dir_path,
client_config.clone(),
supergraph_schema,
)
.await?
.watch_for_changes(write_file_impl, composition_messages)
.await;
while let Some(router_log) = run_router.router_logs().next().await {
match router_log {
Ok(router_log) => {
eprintln!("{}", router_log);
}
Err(err) => {
tracing::error!("{:?}", err);
}
}
}
Ok(RoverOutput::EmptySuccess)
}
}