Newer
Older
pub use graphql_client::{reqwest::post_graphql, GraphQLQuery};
query_path = "res/indexer-queries.graphql"
)]
pub struct IdentityNameByPubkey;
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#[derive(GraphQLQuery)]
#[graphql(
schema_path = "res/indexer-schema.json",
query_path = "res/indexer-queries.graphql"
)]
pub struct IdentityPubkeyByName;
pub struct Indexer<'a> {
pub gql_client: reqwest::Client,
pub gql_url: &'a str,
}
impl<'a> Indexer<'a> {
pub async fn username_by_pubkey(&self, pubkey: &str) -> Result<Option<String>> {
Ok(post_graphql::<IdentityNameByPubkey, _>(
&self.gql_client,
self.gql_url,
identity_name_by_pubkey::Variables {
pubkey: pubkey.to_string(),
},
)
.await?
.data
.and_then(|data| data.identity.into_iter().next().map(|idty| idty.name)))
}
pub async fn pubkey_by_username(&self, username: &str) -> Result<Option<String>> {
Ok(post_graphql::<IdentityPubkeyByName, _>(
&self.gql_client,
self.gql_url,
identity_pubkey_by_name::Variables {
name: username.to_string(),
},
)
.await?
.data
.and_then(|data| data.identity_by_pk.map(|idty| idty.pubkey)))
}
}