-
Notifications
You must be signed in to change notification settings - Fork 94
/
Copy pathclient.rs
37 lines (30 loc) · 1.13 KB
/
client.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
use crate::Result;
use houston as config;
use rover_client::blocking::StudioClient;
/// the Apollo graph registry's production API endpoint
const STUDIO_PROD_API_ENDPOINT: &str = "https://graphql.api.apollographql.com/api/graphql";
/// the version of Rover currently set in `Cargo.toml`
const ROVER_VERSION: &str = env!("CARGO_PKG_VERSION");
pub struct StudioClientConfig {
uri: String,
config: config::Config,
version: String,
}
impl StudioClientConfig {
pub fn new(override_endpoint: Option<String>, config: config::Config) -> StudioClientConfig {
let version = if cfg!(debug_assertions) {
format!("{} (dev)", ROVER_VERSION)
} else {
ROVER_VERSION.to_string()
};
StudioClientConfig {
uri: override_endpoint.unwrap_or_else(|| STUDIO_PROD_API_ENDPOINT.to_string()),
config,
version,
}
}
pub fn get_client(&self, profile_name: &str) -> Result<StudioClient> {
let credential = config::Profile::get_credential(profile_name, &self.config)?;
Ok(StudioClient::new(credential, &self.uri, &self.version))
}
}