Skip to content

doctest: Fix regression after upgrade of reqwest to 0.10. #351

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

Merged
merged 3 commits into from
Nov 20, 2020
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
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ A typed GraphQL client library for Rust.
```rust
use graphql_client::{GraphQLQuery, Response};
use std::error::Error;
use reqwest;

#[derive(GraphQLQuery)]
#[graphql(
Expand All @@ -68,14 +69,14 @@ A typed GraphQL client library for Rust.
)]
pub struct UnionQuery;

fn perform_my_query(variables: union_query::Variables) -> Result<(), Box<dyn Error>> {
async fn perform_my_query(variables: union_query::Variables) -> Result<(), Box<dyn Error>> {

// this is the important line
let request_body = UnionQuery::build_query(variables);

let client = reqwest::Client::new();
let mut res = client.post("/graphql").json(&request_body).send()?;
let response_body: Response<union_query::ResponseData> = res.json()?;
let mut res = client.post("/graphql").json(&request_body).send().await?;
let response_body: Response<union_query::ResponseData> = res.json().await?;
println!("{:#?}", response_body);
Ok(())
}
Expand Down
18 changes: 7 additions & 11 deletions examples/github/examples/github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,25 +51,21 @@ fn main() -> Result<(), anyhow::Error> {
name: name.to_string(),
});

let client = reqwest::blocking::Client::new();
let client = reqwest::blocking::Client::builder()
.user_agent("graphql-rust/0.9.0")
.build()?;

let res = client
.post("https://api.github.com/graphql")
.bearer_auth(config.github_api_token)
.json(&q)
.send()?;

res.error_for_status_ref()?;

let response_body: Response<repo_view::ResponseData> = res.json()?;
info!("{:?}", response_body);

if let Some(errors) = response_body.errors {
println!("there are errors:");

for error in &errors {
println!("{:?}", error);
}
}

let response_data: repo_view::ResponseData = response_body.data.expect("missing response data");

let stars: Option<i64> = response_data
Expand All @@ -80,8 +76,8 @@ fn main() -> Result<(), anyhow::Error> {
println!("{}/{} - 🌟 {}", owner, name, stars.unwrap_or(0),);

let mut table = prettytable::Table::new();

table.add_row(row!(b => "issue", "comments"));
table.set_format(*prettytable::format::consts::FORMAT_NO_LINESEP_WITH_TITLE);
table.set_titles(row!(b => "issue", "comments"));

for issue in &response_data
.repository
Expand Down
1 change: 1 addition & 0 deletions graphql_client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ optional = true
[dev-dependencies]
# Note: If we bumpup wasm-bindge-test version, we should change CI setting.
wasm-bindgen-test = "^0.3"
reqwest = { version = "^0.10", features = ["json", "blocking"] }

[features]
default = ["graphql_query_derive"]
Expand Down
2 changes: 1 addition & 1 deletion graphql_client/src/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ impl Client {
_query: Q,
variables: Q::Variables,
) -> Result<crate::Response<Q::ResponseData>, ClientError> {
let window = web_sys::window().ok_or_else(|| ClientError::NoWindow)?;
let window = web_sys::window().ok_or(ClientError::NoWindow)?;
let body =
serde_json::to_string(&Q::build_query(variables)).map_err(|_| ClientError::Body)?;

Expand Down