mentorenwahl/frontend/src/graphql/mod.rs

29 lines
764 B
Rust
Raw Normal View History

2022-11-04 20:23:36 +00:00
use lazy_static::lazy_static;
use std::path::Path;
2022-11-05 20:27:49 +00:00
pub mod mutations;
2022-11-04 20:23:36 +00:00
pub mod queries;
lazy_static! {
pub static ref URL: String =
Path::new(&web_sys::window().unwrap().location().origin().unwrap())
.join("graphql")
.to_str()
.unwrap()
.to_string();
}
2022-11-12 21:50:06 +00:00
pub fn client(token: Option<&String>) -> Result<reqwest::Client, reqwest::Error> {
if let Some(x) = token {
let mut headers = reqwest::header::HeaderMap::new();
headers.insert(
"Authorization",
reqwest::header::HeaderValue::from_str(&format!("Bearer {}", x)).unwrap(),
);
reqwest::Client::builder().default_headers(headers).build()
} else {
Ok(reqwest::Client::new())
}
}