hive_console_sdk/supergraph_fetcher/
mod.rs1use tokio::sync::RwLock;
2use tokio::sync::TryLockError;
3
4use crate::circuit_breaker::CircuitBreakerError;
5use crate::supergraph_fetcher::async_fetcher::SupergraphFetcherAsyncState;
6use reqwest::header::HeaderValue;
7use reqwest::header::InvalidHeaderValue;
8
9pub mod async_fetcher;
10pub mod builder;
11pub mod sync_fetcher;
12
13pub const SUPERGRAPH_FETCHER_TARGET: &str = "console_sdk::supergraph";
14
15#[derive(Debug)]
16pub struct SupergraphFetcher<State> {
17 state: State,
18 etag: RwLock<Option<HeaderValue>>,
19}
20
21impl SupergraphFetcher<SupergraphFetcherAsyncState> {
23 pub fn builder() -> builder::SupergraphFetcherBuilder {
24 builder::SupergraphFetcherBuilder::default()
25 }
26}
27
28pub enum LockErrorType {
29 Read,
30 Write,
31}
32
33#[derive(Debug, thiserror::Error)]
34pub enum SupergraphFetcherError {
35 #[error("Creating HTTP Client failed: {0}")]
36 HTTPClientCreation(reqwest::Error),
37 #[error("Network error: {0}")]
38 Network(reqwest_middleware::Error),
39 #[error("Parsing response failed: {0}")]
40 ResponseParse(reqwest::Error),
41 #[error("Reading the etag record failed: {0:?}")]
42 ETagRead(TryLockError),
43 #[error("Updating the etag record failed: {0:?}")]
44 ETagWrite(TryLockError),
45 #[error("Invalid CDN key: {0}")]
46 InvalidKey(InvalidHeaderValue),
47 #[error("Missing configuration option: {0}")]
48 MissingConfigurationOption(String),
49 #[error("Request rejected by circuit breaker")]
50 RejectedByCircuitBreaker,
51 #[error("Creating circuit breaker failed: {0}")]
52 CircuitBreakerCreation(CircuitBreakerError),
53}