Skip to content

Commit fec8cdc

Browse files
authored
Merge pull request #35 from tomhoule/readme-update
Get the README in shape for initial release
2 parents 4e985d9 + 083867f commit fec8cdc

File tree

16 files changed

+101
-39
lines changed

16 files changed

+101
-39
lines changed

Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22
name = "graphql_client"
33
version = "0.0.1"
44
authors = ["Tom Houlé <tom@tomhoule.com>"]
5-
description = "A work-in-progress generic graphql client"
5+
description = "Typed GraphQL requests and responses"
66
repository = "https://github.com/tomhoule/graphql-client"
77
license = "Apache-2.0 OR MIT"
8+
keywords = ["graphql", "gql", "api", "web", "webassembly", "wasm"]
9+
categories = ["network-programming", "web-programming", "wasm"]
810

911
[dependencies]
1012
failure = "0.1"
@@ -20,6 +22,7 @@ serde_json = "1.0"
2022
[workspace]
2123
members = [
2224
".",
25+
"examples/example_module",
2326
"examples/github",
2427
"graphql_query_derive",
2528
"graphql_client_cli",

README.md

Lines changed: 52 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,77 @@
1-
NOTE: This is a WIP - I plan to write proper documentation and make a formal release soon.
1+
# graphql_client
22

3-
Derive Rust code to safely interact with queries written in the GraphQL query language.
3+
[![Build Status](https://travis-ci.org/tomhoule/graphql-client.svg?branch=master)](https://travis-ci.org/tomhoule/graphql-client)
4+
[![docs](https://docs.rs/graphql_client/badge.svg)](https://docs.rs/graphql_client/0.0.1/graphql_client/)
5+
[![crates.io](https://img.shields.io/crates/v/graphql_client.svg)](https://crates.io/crates/graphql_client)
46

5-
This library does not provide any networking, caching or other client functionality, it is just meant to make it easy to interact with a GraphQL query and the corresponding response in a strongly typed way. Building a client can be as simple as this:
7+
Derive Rust code to safely and ergonomically manipulate GraphQL queries.
8+
9+
This library does not provide any networking, caching or other client functionality yet, it is just meant to make it easy to interact with a GraphQL query and the corresponding response in a strongly typed way. Making a request can be as simple as this:
610

711
```rust
812
#[derive(GraphQLQuery)]
9-
#[gql(
10-
query = "/graphql/queries/my_query.graphql",
11-
schema = "/graphql/schema.graphql"
13+
#[graphql(
14+
// The paths are relative to the directory where your `Cargo.toml` is located.
15+
query_path = "src/graphql/queries/my_query.graphql",
16+
schema_path = "src/graphql/schema.json"
1217
)]
1318
struct MyQuery;
19+
```
1420

21+
```rust
1522
fn perform_my_query(variables: &my_query::Variables) -> Result<(), failure::Error> {
1623
let body = MyQuery::expand(variables);
1724
let client = reqwest::Client::new();
18-
let res: HttpResponse<graphql_client::Response<my_query::ResponseData>> = client.post("/graphql", body)?;
19-
println!("{:#?}", res.body);
25+
let mut res: HttpResponse<graphql_client::Response<my_query::ResponseData>> = client.post("/graphql").json(&body).send()?;
26+
println!("{:#?}", res.text());
27+
Ok(())
2028
}
2129
```
2230

31+
The GraphQL schema language (`.graphql`) and `schema.json` are both supported as sources for the schema.
32+
33+
`serde_derive` needs to be visible in the context of the `GraphQLQuery` derive (add it as an `extern crate`).
34+
2335
## Features
2436

25-
* Strongly typed query variables
26-
* Strongly typed response
37+
- Strongly typed query variables
38+
- Strongly typed responses
39+
- Works in the browser (WebAssembly)
40+
41+
Integration with different HTTP libraries is planned, although building one yourself is trivial (just send the constructed request payload as JSON with a POST request to a GraphQL endpoint, modulo authentication).
2742

28-
### Planned features
43+
There is an embryonic CLI for downloading schemas - the plan is to make it something similar to `apollo-codegen`.
2944

30-
* Strongly typed subscriptions
31-
* Query string minification (e.g. for embedding in a browser wasm app, and for minimizing payload size)
32-
* A command line interface in addition to the custom derive for generating code and downloading schemas
3345

34-
## What is generated?
46+
## What is generated?
3547

36-
* A module named after the struct under derive, which contains:
37-
* A `ResponseData` struct implementing `serde::Deserialize`
38-
* A `Variables` struct meant to contain the variables expected by the query
39-
* An impl for the `GraphQLQuery` trait for the struct under derive
48+
- A module named after the struct under derive, which contains:
49+
- A `ResponseData` struct implementing `serde::Deserialize`
50+
- A `Variables` struct meant to contain the variables expected by the query
51+
- An impl for the `GraphQLQuery` trait for the struct under derive
4052

41-
See the example generated module for a full example.
53+
See the [example generated module](https://www.tomhoule.com/docs/example_module/) for more details.
4254

4355
## Examples
4456

4557
See the examples directory in this project.
58+
59+
## Code of conduct
60+
61+
Anyone who interacts with this project in any space, including but not limited to
62+
this GitHub repository, must follow our [code of conduct](https://github.com/tomhoule/graphql-client/blob/master/CODE_OF_CONDUCT.md).
63+
64+
## License
65+
66+
Licensed under either of these:
67+
68+
* Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
69+
https://www.apache.org/licenses/LICENSE-2.0)
70+
* MIT license ([LICENSE-MIT](LICENSE-MIT) or
71+
https://opensource.org/licenses/MIT)
72+
73+
### Contributing
74+
75+
Unless you explicitly state otherwise, any contribution you intentionally submit
76+
for inclusion in the work, as defined in the Apache-2.0 license, shall be
77+
dual-licensed as above, without any additional terms or conditions.

examples/call_from_js/Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ name = "call_from_js"
33
version = "0.1.0"
44
authors = ["Tom Houlé <tom@tomhoule.com>"]
55

6+
[profile.release]
7+
lto = "thin"
8+
69
[lib]
710
crate-type = ["cdylib"]
811

@@ -15,4 +18,4 @@ serde_json = "1.0.22"
1518
lazy_static = "1.0.1"
1619

1720
[workspace]
18-
members = ["."]
21+
members = ["."]

examples/call_from_js/build.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
set -ex
22

3-
cargo +nightly build --target wasm32-unknown-unknown
3+
export CARGO_INCREMENTAL=0
4+
5+
cargo +nightly build --target wasm32-unknown-unknown --release
46

57
wasm-bindgen \
6-
../../target/wasm32-unknown-unknown/debug/call_from_js.wasm --out-dir .
8+
./target/wasm32-unknown-unknown/release/call_from_js.wasm --out-dir .
79

810
npm install
911
npm run serve

examples/call_from_js/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use wasm_bindgen::prelude::*;
1818
use graphql_client::*;
1919

2020
#[derive(GraphQLQuery)]
21-
#[gql(schema_path = "schema.json", query_path = "src/puppy_smiles.graphql")]
21+
#[graphql(schema_path = "schema.json", query_path = "src/puppy_smiles.graphql")]
2222
struct PuppySmiles;
2323

2424
#[wasm_bindgen]

examples/example_module/Cargo.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[package]
2+
name = "example_module"
3+
version = "0.1.0"
4+
authors = ["Tom Houlé <tom@tomhoule.com>"]
5+
6+
[dependencies]
7+
serde = "1.0.69"
8+
serde_derive = "1.0.69"
9+
graphql_client = { path = "../.."}

examples/example_module/src/lib.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
extern crate serde;
2+
#[macro_use]
3+
extern crate serde_derive;
4+
#[macro_use]
5+
extern crate graphql_client;
6+
7+
#[derive(GraphQLQuery)]
8+
#[graphql(
9+
schema_path = "../github/src/schema.graphql", query_path = "../github/src/query_1.graphql"
10+
)]
11+
pub struct ExampleModule;

examples/github/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use graphql_client::*;
1818
use structopt::StructOpt;
1919

2020
#[derive(GraphQLQuery)]
21-
#[gql(schema_path = "src/schema.graphql", query_path = "src/query_1.graphql")]
21+
#[graphql(schema_path = "src/schema.graphql", query_path = "src/query_1.graphql")]
2222
struct Query1;
2323

2424
#[derive(StructOpt)]

graphql_client_cli/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
https://developer.deutschebahn.com/free1bahnql/graphql
1+
# GraphQL client CLI
2+
3+
This is still a WIP, the main use for it now is to download the `schema.json` from a GraphQL endpoint, which you can also do with [apollo-codegen](https://github.com/apollographql/apollo-cli).

graphql_client_cli/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use std::path::PathBuf;
1313
use structopt::StructOpt;
1414

1515
#[derive(GraphQLQuery)]
16-
#[gql(
16+
#[graphql(
1717
schema_path = "src/introspection_schema.graphql", query_path = "src/introspection_query.graphql"
1818
)]
1919
struct IntrospectionQuery;

0 commit comments

Comments
 (0)