Skip to content

Commit eddbcd1

Browse files
authored
Merge pull request #351 from siedentop/bugfix/fix-regression-on-350
doctest: Fix regression after upgrade of reqwest to 0.10.
2 parents 9160417 + 5dc9f80 commit eddbcd1

File tree

4 files changed

+13
-15
lines changed

4 files changed

+13
-15
lines changed

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ A typed GraphQL client library for Rust.
5959
```rust
6060
use graphql_client::{GraphQLQuery, Response};
6161
use std::error::Error;
62+
use reqwest;
6263

6364
#[derive(GraphQLQuery)]
6465
#[graphql(
@@ -68,14 +69,14 @@ A typed GraphQL client library for Rust.
6869
)]
6970
pub struct UnionQuery;
7071

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

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

7677
let client = reqwest::Client::new();
77-
let mut res = client.post("/graphql").json(&request_body).send()?;
78-
let response_body: Response<union_query::ResponseData> = res.json()?;
78+
let mut res = client.post("/graphql").json(&request_body).send().await?;
79+
let response_body: Response<union_query::ResponseData> = res.json().await?;
7980
println!("{:#?}", response_body);
8081
Ok(())
8182
}

examples/github/examples/github.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,25 +51,21 @@ fn main() -> Result<(), anyhow::Error> {
5151
name: name.to_string(),
5252
});
5353

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

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

64+
res.error_for_status_ref()?;
65+
6266
let response_body: Response<repo_view::ResponseData> = res.json()?;
6367
info!("{:?}", response_body);
6468

65-
if let Some(errors) = response_body.errors {
66-
println!("there are errors:");
67-
68-
for error in &errors {
69-
println!("{:?}", error);
70-
}
71-
}
72-
7369
let response_data: repo_view::ResponseData = response_body.data.expect("missing response data");
7470

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

8278
let mut table = prettytable::Table::new();
83-
84-
table.add_row(row!(b => "issue", "comments"));
79+
table.set_format(*prettytable::format::consts::FORMAT_NO_LINESEP_WITH_TITLE);
80+
table.set_titles(row!(b => "issue", "comments"));
8581

8682
for issue in &response_data
8783
.repository

graphql_client/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ optional = true
4141
[dev-dependencies]
4242
# Note: If we bumpup wasm-bindge-test version, we should change CI setting.
4343
wasm-bindgen-test = "^0.3"
44+
reqwest = { version = "^0.10", features = ["json", "blocking"] }
4445

4546
[features]
4647
default = ["graphql_query_derive"]

graphql_client/src/web.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ impl Client {
7979
_query: Q,
8080
variables: Q::Variables,
8181
) -> Result<crate::Response<Q::ResponseData>, ClientError> {
82-
let window = web_sys::window().ok_or_else(|| ClientError::NoWindow)?;
82+
let window = web_sys::window().ok_or(ClientError::NoWindow)?;
8383
let body =
8484
serde_json::to_string(&Q::build_query(variables)).map_err(|_| ClientError::Body)?;
8585

0 commit comments

Comments
 (0)