1use std::collections::HashMap;
2#[cfg(not(target_arch = "wasm32"))]
3use std::convert::TryFrom;
4
5use serde::{Deserialize, Serialize};
6
7#[cfg(not(target_arch = "wasm32"))]
8use crate::GraphQLError;
9
10#[derive(Clone, Debug, Deserialize, Serialize)]
12pub struct ClientConfig {
13 pub endpoint: String,
15 pub timeout: Option<u64>,
17 pub headers: Option<HashMap<String, String>>,
19 pub proxy: Option<GQLProxy>,
21}
22
23#[derive(Clone, Debug, Deserialize, Serialize)]
25pub enum ProxyType {
26 Http,
27 Https,
28 All,
29}
30
31#[derive(Clone, Debug, Deserialize, Serialize)]
33pub struct ProxyAuth {
34 pub username: String,
35 pub password: String,
36}
37
38#[derive(Clone, Debug, Deserialize, Serialize)]
40pub struct GQLProxy {
41 pub schema: String,
43 pub type_: ProxyType,
45 pub auth: Option<ProxyAuth>,
47}
48
49#[cfg(not(target_arch = "wasm32"))]
50impl TryFrom<GQLProxy> for reqwest::Proxy {
51 type Error = GraphQLError;
52
53 fn try_from(gql_proxy: GQLProxy) -> Result<Self, Self::Error> {
54 let proxy = match gql_proxy.type_ {
55 ProxyType::Http => reqwest::Proxy::http(gql_proxy.schema),
56 ProxyType::Https => reqwest::Proxy::https(gql_proxy.schema),
57 ProxyType::All => reqwest::Proxy::all(gql_proxy.schema),
58 }
59 .map_err(|e| Self::Error::with_text(format!("{:?}", e)))?;
60 Ok(proxy)
61 }
62}