Skip to content

Commit 364bba1

Browse files
authored
Merge pull request #371 from graphql-rust/prepare-for-release
Prepare for release
2 parents de80139 + 2e573f9 commit 364bba1

File tree

36 files changed

+374
-542
lines changed

36 files changed

+374
-542
lines changed

.github/workflows/ci.yml

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ jobs:
2929
override: true
3030
- name: Execute cargo test
3131
run: cargo test --all --tests --examples
32-
wasm_test:
33-
name: Cargo test for wasm
32+
wasm_build:
33+
name: Cargo build for wasm
3434
runs-on: ubuntu-18.04
3535
steps:
3636
- name: Checkout sources
@@ -41,14 +41,10 @@ jobs:
4141
profile: minimal
4242
toolchain: stable
4343
override: true
44-
- name: Setup wasm-bindgen
44+
target: wasm32-unknown-unknown
45+
- name: Execute cargo build
4546
run: |
46-
rustup target add wasm32-unknown-unknown &&
47-
sudo apt update && sudo apt install -y firefox-geckodriver &&
48-
cargo install wasm-bindgen-cli
49-
- name: Execute cargo test
50-
run: |
51-
xvfb-run cargo test --manifest-path=./graphql_client/Cargo.toml --features="web" --target wasm32-unknown-unknown
47+
cargo build --manifest-path=./graphql_client/Cargo.toml --features="reqwest" --target wasm32-unknown-unknown
5248
lint:
5349
name: Rustfmt and Clippy
5450
runs-on: ubuntu-latest

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ Cargo.lock
55
.idea
66
scripts/*
77
!scripts/*.sh
8+
/.vscode

CHANGELOG.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,14 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
77

88
## Unreleased
99

10-
- [to be documnented] — A CLI and derive option to specify a module to import
11-
custom scalar from. Thanks @miterst! ([PR](https://github.com/graphql-rust/graphql-client/pull/354))
10+
- The `web` feature is dropped. You can now use a `reqwest::Client` instead of the custom HTTP client.
11+
- Allow specifying externally defined enums (thanks @jakmeier)
12+
- Make the derive feature optional (but enabled by default)
13+
- `--no-ssl` param in CLI (thanks @danielharbor!)
14+
- The shape of some generated response types changed to be flatter and more ergonomic.
15+
- Many dependencies were dropped
16+
— A CLI and derive option to specify a module to import custom scalar from.
17+
Thanks @miterst! ([PR](https://github.com/graphql-rust/graphql-client/pull/354))
1218

1319
## 0.9.0 - 2020-03-13
1420

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
[workspace]
2+
resolver = "2"
23
members = [
34
"graphql_client",
45
"graphql_client_cli",
56
"graphql_client_codegen",
6-
"graphql_client_web",
77
"graphql-introspection-query",
88
"graphql_query_derive",
99

README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
[![Github actions Status](https://github.com/graphql-rust/graphql-client/workflows/CI/badge.svg?branch=master&event=push)](https://github.com/graphql-rust/graphql-client/actions)
44
[![docs](https://docs.rs/graphql_client/badge.svg)](https://docs.rs/graphql_client/latest/graphql_client/)
55
[![crates.io](https://img.shields.io/crates/v/graphql_client.svg)](https://crates.io/crates/graphql_client)
6-
[![Join the chat](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/juniper-graphql/graphql-client)
76

87
A typed GraphQL client library for Rust.
98

@@ -19,7 +18,7 @@ A typed GraphQL client library for Rust.
1918
- Supports multiple operations per query document.
2019
- Supports setting GraphQL fields as deprecated and having the Rust compiler check
2120
their use.
22-
- [web client](./graphql_client_web) for boilerplate-free API calls from browsers.
21+
- Optional reqwest-based client for boilerplate-free API calls from browsers.
2322

2423
## Getting started
2524

@@ -84,6 +83,15 @@ A typed GraphQL client library for Rust.
8483

8584
[A complete example using the GitHub GraphQL API is available](https://github.com/graphql-rust/graphql-client/tree/master/examples/github), as well as sample [rustdoc output](https://www.tomhoule.com/docs/example_module/).
8685

86+
## Alternative workflow using the CLI
87+
88+
You can introspect GraphQL APIs and generate module from a command line interface to the library:
89+
90+
```bash
91+
$ cargo install graphql_client_cli
92+
$ graphql-client --help
93+
```
94+
8795
## Deriving specific traits on the response
8896

8997
The generated response types always derive `serde::Deserialize` but you may want to print them (`Debug`), compare them (`PartialEq`) or derive any other trait on it. You can achieve this with the `response_derives` option of the `graphql` attribute. Example:

examples/github/Cargo.toml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,10 @@ edition = "2018"
66

77
[dev-dependencies]
88
anyhow = "1.0"
9-
graphql_client = { path = "../../graphql_client" }
9+
graphql_client = { path = "../../graphql_client", features = ["reqwest-blocking"] }
1010
serde = "^1.0"
11-
reqwest = { version = "^0.10", features = ["json", "blocking"] }
11+
reqwest = { version = "^0.11", features = ["json", "blocking"] }
1212
prettytable-rs = "^0.7"
1313
structopt = "^0.3"
14-
dotenv = "^0.13"
15-
envy = "^0.3"
1614
log = "^0.4"
1715
env_logger = "^0.5"

examples/github/examples/github.rs

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
use ::reqwest::blocking::Client;
12
use anyhow::*;
2-
use graphql_client::*;
3+
use graphql_client::{reqwest::post_graphql_blocking as post_graphql, GraphQLQuery};
34
use log::*;
45
use prettytable::*;
5-
use serde::*;
66
use structopt::StructOpt;
77

8+
#[allow(clippy::upper_case_acronyms)]
89
type URI = String;
910

1011
#[derive(GraphQLQuery)]
@@ -22,11 +23,6 @@ struct Command {
2223
repo: String,
2324
}
2425

25-
#[derive(Deserialize, Debug)]
26-
struct Env {
27-
github_api_token: String,
28-
}
29-
3026
fn parse_repo_name(repo_name: &str) -> Result<(&str, &str), anyhow::Error> {
3127
let mut parts = repo_name.split('/');
3228
match (parts.next(), parts.next()) {
@@ -36,34 +32,36 @@ fn parse_repo_name(repo_name: &str) -> Result<(&str, &str), anyhow::Error> {
3632
}
3733

3834
fn main() -> Result<(), anyhow::Error> {
39-
dotenv::dotenv().ok();
4035
env_logger::init();
4136

42-
let config: Env = envy::from_env().context("while reading from environment")?;
37+
let github_api_token =
38+
std::env::var("GITHUB_API_TOKEN").expect("Missing GITHUB_API_TOKEN env var");
4339

4440
let args = Command::from_args();
4541

4642
let repo = args.repo;
4743
let (owner, name) = parse_repo_name(&repo).unwrap_or(("tomhoule", "graphql-client"));
4844

49-
let q = RepoView::build_query(repo_view::Variables {
45+
let variables = repo_view::Variables {
5046
owner: owner.to_string(),
5147
name: name.to_string(),
52-
});
48+
};
5349

54-
let client = reqwest::blocking::Client::builder()
50+
let client = Client::builder()
5551
.user_agent("graphql-rust/0.9.0")
52+
.default_headers(
53+
std::iter::once((
54+
reqwest::header::AUTHORIZATION,
55+
reqwest::header::HeaderValue::from_str(&format!("Bearer {}", github_api_token))
56+
.unwrap(),
57+
))
58+
.collect(),
59+
)
5660
.build()?;
5761

58-
let res = client
59-
.post("https://api.github.com/graphql")
60-
.bearer_auth(config.github_api_token)
61-
.json(&q)
62-
.send()?;
63-
64-
res.error_for_status_ref()?;
62+
let response_body =
63+
post_graphql::<RepoView, _>(&client, "https://api.github.com/graphql", variables).unwrap();
6564

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

6967
let response_data: repo_view::ResponseData = response_body.data.expect("missing response data");
@@ -79,16 +77,16 @@ fn main() -> Result<(), anyhow::Error> {
7977
table.set_format(*prettytable::format::consts::FORMAT_NO_LINESEP_WITH_TITLE);
8078
table.set_titles(row!(b => "issue", "comments"));
8179

82-
for issue in &response_data
80+
for issue in response_data
8381
.repository
8482
.expect("missing repository")
8583
.issues
8684
.nodes
8785
.expect("issue nodes is null")
86+
.iter()
87+
.flatten()
8888
{
89-
if let Some(issue) = issue {
90-
table.add_row(row!(issue.title, issue.comments.total_count));
91-
}
89+
table.add_row(row!(issue.title, issue.comments.total_count));
9290
}
9391

9492
table.printstd();

examples/hasura/Cargo.toml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,10 @@ edition = "2018"
66

77
[dev-dependencies]
88
anyhow = "1.0"
9-
graphql_client = { path = "../../graphql_client" }
10-
serde = "1.0"
11-
serde_derive = "1.0"
9+
graphql_client = { path = "../../graphql_client", features = ["reqwest-blocking"] }
10+
serde = { version = "1.0", features = ["derive"] }
1211
serde_json = "1.0"
13-
reqwest = { version = "^0.10", features = ["json", "blocking"] }
12+
reqwest = { version = "^0.11", features = ["json", "blocking"] }
1413
prettytable-rs = "0.7.0"
15-
dotenv = "0.13.0"
1614
log = "0.4.3"
1715
env_logger = "0.5.10"

examples/hasura/examples/hasura.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
use graphql_client::*;
1+
use ::reqwest::blocking::Client;
2+
use graphql_client::{reqwest::post_graphql_blocking as post_graphql, GraphQLQuery};
23
use log::*;
34
use prettytable::*;
45

@@ -16,27 +17,22 @@ struct UpsertIssue;
1617

1718
fn main() -> Result<(), anyhow::Error> {
1819
use upsert_issue::{IssuesUpdateColumn::*, *};
19-
dotenv::dotenv().ok();
2020
env_logger::init();
2121

22-
let q = UpsertIssue::build_query(Variables {
22+
let v = Variables {
2323
issues: vec![IssuesInsertInput {
2424
id: Some("001000000000000".to_string()),
2525
name: Some("Name".to_string()),
2626
status: Some("Draft".to_string()),
2727
salesforce_updated_at: Some("2019-06-11T08:14:28Z".to_string()),
2828
}],
2929
update_columns: vec![Name, Status, SalesforceUpdatedAt],
30-
});
30+
};
3131

32-
let client = reqwest::blocking::Client::new();
32+
let client = Client::new();
3333

34-
let res = client
35-
.post("https://localhost:8080/v1/graphql")
36-
.json(&q)
37-
.send()?;
38-
39-
let response_body: Response<ResponseData> = res.json()?;
34+
let response_body =
35+
post_graphql::<UpsertIssue, _>(&client, "https://localhost:8080/v1/graphql", v)?;
4036
info!("{:?}", response_body);
4137

4238
if let Some(errors) = response_body.errors {

examples/web/Cargo.toml

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,19 @@ version = "0.1.0"
44
authors = ["Tom Houlé <tom@tomhoule.com>"]
55
edition = "2018"
66

7-
# https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#profile-overrides
8-
#[profile.release]
9-
#lto = "thin"
7+
[lib]
8+
crate-type = ["cdylib", "rlib"]
109

11-
[dev-dependencies]
12-
graphql_client = { path = "../../graphql_client" }
13-
graphql_client_web = { path = "../../graphql_client_web" }
10+
[dependencies]
11+
graphql_client = { path = "../../graphql_client", features = ["reqwest"] }
1412
wasm-bindgen = "^0.2"
1513
serde = { version = "1.0.67", features = ["derive"] }
1614
lazy_static = "1.0.1"
1715
js-sys = "0.3.6"
18-
futures-util = "0.3.8"
1916
wasm-bindgen-futures = "0.4.18"
17+
reqwest = "0.11.3"
2018

21-
[dev-dependencies.web-sys]
19+
[dependencies.web-sys]
2220
version = "0.3.6"
2321
features = [
2422
"console",
@@ -29,8 +27,5 @@ features = [
2927
"HtmlBodyElement",
3028
"HtmlDocument",
3129
"HtmlElement",
30+
"Window",
3231
]
33-
34-
[[example]]
35-
name = "web"
36-
crate-type = ["cdylib"]

examples/web/examples/web.rs renamed to examples/web/src/lib.rs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use graphql_client::GraphQLQuery;
1+
use graphql_client::{reqwest::post_graphql, GraphQLQuery};
22
use lazy_static::*;
33
use std::cell::RefCell;
44
use std::sync::Mutex;
@@ -9,7 +9,7 @@ use wasm_bindgen_futures::future_to_promise;
99
#[derive(GraphQLQuery)]
1010
#[graphql(
1111
schema_path = "schema.json",
12-
query_path = "examples/puppy_smiles.graphql",
12+
query_path = "src/puppy_smiles.graphql",
1313
response_derives = "Debug"
1414
)]
1515
struct PuppySmiles;
@@ -23,20 +23,22 @@ lazy_static! {
2323
}
2424

2525
async fn load_more() -> Result<JsValue, JsValue> {
26-
let client = graphql_client::web::Client::new("https://www.graphqlhub.com/graphql");
26+
let url = "https://www.graphqlhub.com/graphql";
2727
let variables = puppy_smiles::Variables {
2828
after: LAST_ENTRY
2929
.lock()
3030
.ok()
3131
.and_then(|opt| opt.borrow().to_owned()),
3232
};
33-
let response = client.call(PuppySmiles, variables).await.map_err(|err| {
34-
log(&format!(
35-
"Could not fetch puppies. graphql_client_web error: {:?}",
36-
err
37-
));
38-
JsValue::NULL
39-
})?;
33+
34+
let client = reqwest::Client::new();
35+
36+
let response = post_graphql::<PuppySmiles, _>(&client, url, variables)
37+
.await
38+
.map_err(|err| {
39+
log(&format!("Could not fetch puppies. error: {:?}", err));
40+
JsValue::NULL
41+
})?;
4042
render_response(response);
4143
Ok(JsValue::NULL)
4244
}
@@ -72,14 +74,14 @@ fn add_load_more_button() {
7274
on_click.forget();
7375
}
7476

75-
fn render_response(response: graphql_client_web::Response<puppy_smiles::ResponseData>) {
77+
fn render_response(response: graphql_client::Response<puppy_smiles::ResponseData>) {
7678
use std::fmt::Write;
7779

7880
log(&format!("response body\n\n{:?}", response));
7981

8082
let parent = document().body().expect_throw("no body");
8183

82-
let json: graphql_client_web::Response<puppy_smiles::ResponseData> = response;
84+
let json: graphql_client::Response<puppy_smiles::ResponseData> = response;
8385
let response = document()
8486
.create_element("div")
8587
.expect_throw("could not create div");
@@ -98,22 +100,20 @@ fn render_response(response: graphql_client_web::Response<puppy_smiles::Response
98100
.map(|puppy| puppy.fullname_id.clone());
99101
LAST_ENTRY.lock().unwrap_throw().replace(new_cursor);
100102

101-
for puppy in &listings {
102-
if let Some(puppy) = puppy {
103-
write!(
104-
inner_html,
105-
r#"
103+
for puppy in listings.iter().flatten() {
104+
write!(
105+
inner_html,
106+
r#"
106107
<div class="card" style="width: 26rem;">
107108
<img class="img-thumbnail card-img-top" alt="{}" src="{}" />
108109
<div class="card-body">
109110
<h5 class="card-title">{}</h5>
110111
</div>
111112
</div>
112113
"#,
113-
puppy.title, puppy.url, puppy.title
114-
)
115-
.expect_throw("write to string");
116-
}
114+
puppy.title, puppy.url, puppy.title
115+
)
116+
.expect_throw("write to string");
117117
}
118118
response.set_inner_html(&format!(
119119
"<h2>response:</h2><div class=\"container\"><div class=\"row\">{}</div></div>",

0 commit comments

Comments
 (0)