Skip to content

Commit

Permalink
fix: optionally allow empty subscriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
Theodus committed May 10, 2024
1 parent d335994 commit c0c81f4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
9 changes: 6 additions & 3 deletions gateway-framework/src/subscriptions/subgraph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub struct Client {
impl Client {
pub async fn create(
subgraph_client: subgraph_client::Client,
allow_empty: bool,
) -> watch::Receiver<HashMap<Address, Subscription>> {
let (tx, mut rx) = watch::channel(Default::default());
let mut client = Client {
Expand All @@ -39,9 +40,11 @@ impl Client {
}
});

rx.wait_for(|subscriptions| !subscriptions.is_empty())
.await
.unwrap();
if !allow_empty {
rx.wait_for(|subscriptions| !subscriptions.is_empty())
.await
.unwrap();
}
rx
}

Expand Down
3 changes: 3 additions & 0 deletions graph-gateway/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,9 @@ pub struct Subscriptions {
/// e.g. If 0.01 USDC (6 decimals) is required per query per minute, then this should be set to
/// 10000.
pub rate_per_query: u128,
/// Allow startup with no active subscriptions.
#[serde(default)]
pub allow_empty: bool,
}

#[serde_as]
Expand Down
1 change: 1 addition & 0 deletions graph-gateway/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,7 @@ async fn init_auth_service(
)
.with_auth_token(subscriptions.ticket.clone())
.build(),
subscriptions.allow_empty,
)
.await
}
Expand Down

0 comments on commit c0c81f4

Please sign in to comment.