-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
36 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,46 @@ | ||
use graphql_client::{GraphQLQuery, Response}; | ||
use std::error::Error; | ||
use ::reqwest; | ||
|
||
const HASURA_ACCOUNT: &str = "darunrs_near"; | ||
|
||
#[allow(clippy::upper_case_acronyms)] | ||
type URI = String; | ||
type Date = String; | ||
|
||
#[derive(GraphQLQuery)] | ||
#[graphql( | ||
schema_path = "graphql/darunrs_near/schema.json", | ||
query_path = "graphql/darunrs_near/get_bitmap_by_date.graphql", | ||
query_path = "graphql/darunrs_near/get_bitmaps.graphql", | ||
response_derives = "Debug", | ||
normalization = "rust" | ||
)] | ||
struct GetBitmapsByDateAndId; | ||
struct GetBitmaps; | ||
|
||
pub struct GraphqlClient { | ||
client: reqwest::Client, | ||
graphql_endpoint: URI, | ||
graphql_endpoint: String, | ||
} | ||
|
||
#[cfg(not(test))] | ||
pub use GraphqlClientImpl as GraphqlClient; | ||
#[cfg(test)] | ||
pub use MockGraphqlClientImpl as GraphqlClient; | ||
|
||
#[cfg_attr(test, mockall::automock)] | ||
impl GraphqlClientImpl { | ||
pub fn new (graphql_endpoint: URI) -> Self { | ||
impl GraphqlClient { | ||
pub fn new(graphql_endpoint: String) -> Self { | ||
Self { | ||
client: reqwest::Client::new(), | ||
graphql_endpoint, | ||
} | ||
} | ||
|
||
|
||
pub async fn get_bitmaps(&self, receiver_ids: String, block_date: String, limit: i64, offset: i64) -> Result<(), Box<dyn Error>> { | ||
let variables = get_bitmaps::Variables { | ||
receiver_ids: Some(receiver_ids), | ||
block_date: Some(block_date), | ||
limit: Some(limit), | ||
offset: Some(offset), | ||
}; | ||
let request_body = GetBitmaps::build_query(variables); | ||
let res = self.client.post(&self.graphql_endpoint).header("x-hasura-role", HASURA_ACCOUNT).json(&request_body).send().await?; | ||
let response_body: Response<get_bitmaps::ResponseData> = res.json().await?; | ||
println!("{:#?}", response_body); | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ mod blockstreamer { | |
} | ||
|
||
pub use blockstreamer::*; | ||
pub mod graphql; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters