Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fuel-gql-client support for "https://" #266

Merged
merged 2 commits into from
Apr 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions fuel-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ name = "fuel-gql-cli"
path = "src/main.rs"

[dependencies]
anyhow = "1.0"
chrono = { version = "0.4", features = ["serde"] }
clap = { version = "3.1", features = ["derive"] }
cynic = { version = "0.14", features = ["surf"] }
Expand Down
14 changes: 11 additions & 3 deletions fuel-client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use std::{
pub mod schema;
pub mod types;

use anyhow::anyhow;
use schema::{
balance::BalanceArgs,
block::BlockByIdArgs,
Expand All @@ -28,10 +29,17 @@ pub struct FuelClient {
}

impl FromStr for FuelClient {
type Err = net::AddrParseError;
type Err = anyhow::Error;

fn from_str(str: &str) -> Result<Self, Self::Err> {
str.parse().map(|s: net::SocketAddr| s.into())
// lightweight url verification
if !str.contains("/graphql") {
Err(anyhow!("Url is missing /graphql path".to_string()))
} else {
Ok(Self {
url: surf::Url::parse(str)?,
})
}
}
}

Expand All @@ -50,7 +58,7 @@ where
}

impl FuelClient {
pub fn new(url: impl AsRef<str>) -> Result<Self, net::AddrParseError> {
pub fn new(url: impl AsRef<str>) -> Result<Self, anyhow::Error> {
Self::from_str(url.as_ref())
}

Expand Down