Skip to content

Commit cbacb1f

Browse files
committed
Get the README in shape for initial release
1 parent 4e985d9 commit cbacb1f

File tree

5 files changed

+57
-21
lines changed

5 files changed

+57
-21
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é <[email protected]>"]
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: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,57 @@
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+
![CI Status](https://img.shields.io/travis/tomhoule/graphql-client.svg)
4+
![docs](https://docs.rs/mio/badge.svg)
5+
![crates.io](https://img.shields.io/crates/d/graphql-client.svg)
6+
![license](https://img.shields.io/github/license/mashape/apistatus.svg)
7+
![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)
48

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:
9+
Derive Rust code to safely and ergonomically manipulate GraphQL queries.
10+
11+
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:
612

713
```rust
814
#[derive(GraphQLQuery)]
915
#[gql(
10-
query = "/graphql/queries/my_query.graphql",
11-
schema = "/graphql/schema.graphql"
16+
query_path = "src/graphql/queries/my_query.graphql",
17+
schema_path = "src/graphql/schema.json"
1218
)]
1319
struct MyQuery;
1420

1521
fn perform_my_query(variables: &my_query::Variables) -> Result<(), failure::Error> {
1622
let body = MyQuery::expand(variables);
1723
let client = reqwest::Client::new();
18-
let res: HttpResponse<graphql_client::Response<my_query::ResponseData>> = client.post("/graphql", body)?;
19-
println!("{:#?}", res.body);
24+
let mut res: HttpResponse<graphql_client::Response<my_query::ResponseData>> = client.post("/graphql").json(&body).send()?;
25+
println!("{:#?}", res.text());
26+
Ok(())
2027
}
2128
```
2229

30+
The paths in the `gql` attribute are relative to the directory where your `Cargo.toml` is located.
31+
32+
The GraphQL schema language and schema.json are both supported as sources for the schema.
33+
34+
`serde_derive` needs to be visible in the context of the `GraphQLQuery` derive (add it as an `extern crate`).
35+
2336
## Features
2437

25-
* Strongly typed query variables
26-
* Strongly typed response
38+
- Strongly typed query variables
39+
- Strongly typed responses
40+
- Works in the browser (WebAssembly)
41+
42+
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).
2743

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

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
3346

34-
## What is generated?
47+
## What is generated?
3548

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
49+
- A module named after the struct under derive, which contains:
50+
- A `ResponseData` struct implementing `serde::Deserialize`
51+
- A `Variables` struct meant to contain the variables expected by the query
52+
- An impl for the `GraphQLQuery` trait for the struct under derive
4053

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

4356
## Examples
4457

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é <[email protected]>"]
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: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
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+
#[gql(schema_path = "../github/src/schema.graphql", query_path = "../github/src/query_1.graphql")]
9+
pub struct ExampleModule;

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).

0 commit comments

Comments
 (0)