Skip to content

Migrate to 2018 edition and away from skeptic #236

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 7 commits into from
May 15, 2019
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
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ before_script:
- if [ "$TRAVIS_RUST_VERSION" = "beta" ]; then (sudo apt-get update) fi
- if [ "$TRAVIS_RUST_VERSION" = "beta" ]; then (sudo apt-get install -y nodejs) fi
- if [ "$TRAVIS_RUST_VERSION" = "beta" ]; then (npm i -g prettier) fi
- if [ "$TRAVIS_RUST_VERSION" = "stable" ]; then (rustup component add rustfmt-preview clippy-preview) fi
- if [ "$TRAVIS_RUST_VERSION" = "stable" ]; then (rustup component add rustfmt clippy) fi
- if [ "$TRAVIS_RUST_VERSION" = "stable" ]; then (rustup target add wasm32-unknown-unknown) fi
- if [ "$TRAVIS_RUST_VERSION" = "stable" ]; then (cargo install -f wasm-bindgen-cli) fi
script:
- if [ "$TRAVIS_RUST_VERSION" = "stable" ]; then (cargo fmt --all -- --check) fi
- if [ "$TRAVIS_RUST_VERSION" = "stable" ]; then (cargo clippy -- -D warnings) fi
- if [ "$TRAVIS_RUST_VERSION" = "beta" ]; then (prettier --debug-check -l './**/*.json' './**/*.graphql') fi
- cargo test --all
# - cargo build --manifest-path=./examples/github/Cargo.toml
# - cargo build --manifest-path=./examples/web/Cargo.toml
- cargo build --manifest-path=./examples/github/Cargo.toml
- cargo build --manifest-path=./examples/web/Cargo.toml
- if [ "$TRAVIS_RUST_VERSION" = "stable" ]; then (xvfb-run cargo test --manifest-path=./graphql_client_web/Cargo.toml --target wasm32-unknown-unknown) fi
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## Unreleased

This release sees the switch to the Rust 2018 edition and is only compatible with Rust 1.31.0 and later.
This release sees the switch to the Rust 2018 edition - it is
only compatible with Rust 1.31.0 and later.

## 0.7.1

Expand Down
31 changes: 9 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,8 @@ A typed GraphQL client library for Rust.

- We now have everything we need to derive Rust types for our query. This is achieved through a procedural macro, as in the following snippet:

```rust,skt-empty-main
extern crate serde;
#[macro_use]
extern crate serde_derive;
#[macro_use]
extern crate graphql_client;
```rust
use graphql_client::GraphQLQuery;

// The paths are relative to the directory where your `Cargo.toml` is located.
// Both json and the GraphQL schema language are supported as sources for the schema
Expand All @@ -60,12 +56,7 @@ A typed GraphQL client library for Rust.

* We now need to create the complete payload that we are going to send to the server. For convenience, the [GraphQLQuery trait](https://docs.rs/graphql_client/latest/graphql_client/trait.GraphQLQuery.html), is implemented for the struct under derive, so a complete query body can be created this way:

```rust,skt-empty-main
extern crate failure;
#[macro_use]
extern crate graphql_client;
extern crate reqwest;

```rust
use graphql_client::{GraphQLQuery, Response};

#[derive(GraphQLQuery)]
Expand Down Expand Up @@ -95,9 +86,8 @@ A typed GraphQL client library for Rust.

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:

```rust,skt-empty-main
#[macro_use]
extern crate graphql_client;
```rust
use graphql_client::GraphQLQuery;

#[derive(GraphQLQuery)]
#[graphql(
Expand All @@ -117,9 +107,8 @@ The generated code will reference the scalar types as defined in the server sche
The generated code has support for [`@deprecated`](http://facebook.github.io/graphql/June2018/#sec-Field-Deprecation)
field annotations. You can configure how deprecations are handled via the `deprecated` argument in the `GraphQLQuery` derive:

```rust,skt-empty-main
#[macro_use]
extern crate graphql_client;
```rust
use graphql_client::GraphQLQuery;

#[derive(GraphQLQuery)]
#[graphql(
Expand All @@ -145,15 +134,13 @@ You can write multiple operations in one query document (one `.graphql` file). Y

Note that the struct and the operation in the GraphQL file *must* have the same name. We enforce this to make the generated code more predictable.

```rust,skt-empty-main
#[macro_use]
extern crate graphql_client;
```rust
use graphql_client::GraphQLQuery;

#[derive(GraphQLQuery)]
#[graphql(
schema_path = "tests/unions/union_schema.graphql",
query_path = "tests/unions/union_query.graphql",
selected_operation = "SearchQuery"
)]
pub struct UnionQuery;
```
Expand Down
9 changes: 0 additions & 9 deletions examples/example_module/Cargo.toml

This file was deleted.

3 changes: 0 additions & 3 deletions examples/example_module/src/custom_scalars.rs

This file was deleted.

17 changes: 0 additions & 17 deletions examples/example_module/src/lib.rs

This file was deleted.

1 change: 1 addition & 0 deletions examples/github/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
name = "graphql_query_github_example"
version = "0.1.0"
authors = ["Tom Houlé <tom@tomhoule.com>"]
edition = "2018"

[dependencies]
failure = "*"
Expand Down
23 changes: 5 additions & 18 deletions examples/github/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,8 @@
extern crate dotenv;
extern crate envy;
#[macro_use]
extern crate failure;
extern crate graphql_client;
#[macro_use]
extern crate log;
extern crate env_logger;
extern crate reqwest;
extern crate serde;
extern crate serde_json;
#[macro_use]
extern crate serde_derive;
extern crate structopt;
#[macro_use]
extern crate prettytable;

use failure::*;
use graphql_client::*;
use log::*;
use prettytable::*;
use serde::*;
use structopt::StructOpt;

type URI = String;
Expand Down Expand Up @@ -51,7 +38,7 @@ fn main() -> Result<(), failure::Error> {
dotenv::dotenv().ok();
env_logger::init();

let config: Env = envy::from_env()?;
let config: Env = envy::from_env().context("while reading from environment")?;

let args = Command::from_args();

Expand Down
4 changes: 2 additions & 2 deletions examples/web/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ lto = "thin"
crate-type = ["cdylib"]

[dependencies]
graphql_client = { path = "../../graphql_client" }
graphql_client_web = { path = "../../graphql_client_web" }
wasm-bindgen = "0.2.12"
serde = "1.0.67"
serde_derive = "1.0.67"
serde = { version = "1.0.67", features = ["derive"] }
serde_json = "1.0.22"
lazy_static = "1.0.1"
js-sys = "0.3.6"
Expand Down
4 changes: 1 addition & 3 deletions examples/web/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
use futures::Future;
use graphql_client_web::*;
use lazy_static::*;
use std::cell::RefCell;
use std::sync::Mutex;

use wasm_bindgen::prelude::*;
use wasm_bindgen_futures::future_to_promise;

use graphql_client_web::*;

#[derive(GraphQLQuery)]
#[graphql(
schema_path = "schema.json",
Expand Down
11 changes: 4 additions & 7 deletions graphql_client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,10 @@ edition = "2018"

[dependencies]
failure = "0.1"
graphql_query_derive = {path = "../graphql_query_derive", version = "0.7.1" }
serde = "^1.0.78"
serde_derive = "1.0"
graphql_query_derive = { path = "../graphql_query_derive", version = "0.7.1" }
serde = { version = "^1.0.78", features = ["derive"] }
serde_json = "1.0"

[build-dependencies]
skeptic = "0.13.4"
doc-comment = "0.3.1"

[dev-dependencies]
skeptic = "0.13.4"
reqwest = "*"
6 changes: 0 additions & 6 deletions graphql_client/build.rs

This file was deleted.

43 changes: 19 additions & 24 deletions graphql_client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@
//!
//! The main interface to this library is the custom derive that generates modules from a GraphQL query and schema. See the docs for the [`GraphQLQuery`] trait for a full example.

#![deny(warnings)]
#![deny(missing_docs)]
#![deny(rust_2018_idioms)]
#![deny(warnings)]

use serde;
#[allow(unused_imports)]
#[macro_use]
extern crate serde_derive;
pub use graphql_query_derive;
extern crate graphql_query_derive;

#[doc(hidden)]
pub use graphql_query_derive::*;

use serde::*;

#[cfg(test)]
use serde_json::json;
Expand All @@ -19,21 +24,17 @@ pub use graphql_query_derive::*;
use std::collections::HashMap;
use std::fmt::{self, Display};

doc_comment::doctest!("../../README.md");

/// A convenience trait that can be used to build a GraphQL request body.
///
/// This will be implemented for you by codegen in the normal case. It is implemented on the struct you place the derive on.
///
/// Example:
///
/// ```
/// extern crate failure;
/// #[macro_use]
/// extern crate graphql_client;
/// #[macro_use]
/// extern crate serde_derive;
/// #[macro_use]
/// extern crate serde_json;
/// extern crate serde;
/// use graphql_client::*;
/// use serde_json::json;
///
/// #[derive(GraphQLQuery)]
/// #[graphql(
Expand Down Expand Up @@ -127,12 +128,9 @@ impl Display for PathFragment {
///
///
/// ```
/// # extern crate failure;
/// # #[macro_use]
/// # extern crate serde_json;
/// # extern crate graphql_client;
/// # #[macro_use]
/// # extern crate serde_derive;
/// # use serde_json::json;
/// # use serde::Deserialize;
/// # use graphql_client::GraphQLQuery;
/// #
/// # #[derive(Debug, Deserialize, PartialEq)]
/// # struct ResponseData {
Expand Down Expand Up @@ -236,12 +234,9 @@ impl Display for Error {
/// [Spec](https://github.com/facebook/graphql/blob/master/spec/Section%207%20--%20Response.md)
///
/// ```
/// # extern crate failure;
/// # #[macro_use]
/// # extern crate serde_json;
/// # extern crate graphql_client;
/// # #[macro_use]
/// # extern crate serde_derive;
/// # use serde_json::json;
/// # use serde::Deserialize;
/// # use graphql_client::GraphQLQuery;
/// #
/// # #[derive(Debug, Deserialize, PartialEq)]
/// # struct User {
Expand Down
9 changes: 2 additions & 7 deletions graphql_client/tests/alias.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
#[macro_use]
extern crate graphql_client;

#[macro_use]
extern crate serde_derive;
#[macro_use]
extern crate serde_json;
use graphql_client::*;
use serde_json::*;

#[derive(GraphQLQuery)]
#[graphql(
Expand Down
9 changes: 2 additions & 7 deletions graphql_client/tests/custom_scalars.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
#[macro_use]
extern crate graphql_client;
extern crate serde;
#[macro_use]
extern crate serde_derive;
#[macro_use]
extern crate serde_json;
use graphql_client::*;
use serde_json::json;

use std::net::Ipv4Addr;

Expand Down
6 changes: 1 addition & 5 deletions graphql_client/tests/deprecation.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
#[macro_use]
extern crate graphql_client;
extern crate serde;
#[macro_use]
extern crate serde_derive;
use graphql_client::*;

#[derive(GraphQLQuery)]
#[graphql(
Expand Down
9 changes: 2 additions & 7 deletions graphql_client/tests/fragments.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
#[macro_use]
extern crate graphql_client;
extern crate serde;
#[macro_use]
extern crate serde_derive;
#[macro_use]
extern crate serde_json;
use graphql_client::*;
use serde_json::json;

#[derive(GraphQLQuery)]
#[graphql(
Expand Down
7 changes: 1 addition & 6 deletions graphql_client/tests/input_object_variables.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
#[macro_use]
extern crate graphql_client;
#[macro_use]
extern crate serde_derive;
extern crate serde;
extern crate serde_json;
use graphql_client::*;

#[derive(GraphQLQuery)]
#[graphql(
Expand Down
7 changes: 1 addition & 6 deletions graphql_client/tests/interfaces.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
#[macro_use]
extern crate graphql_client;
#[macro_use]
extern crate serde_derive;
extern crate serde;
extern crate serde_json;
use graphql_client::*;

const RESPONSE: &'static str = include_str!("interfaces/interface_response.json");

Expand Down
7 changes: 1 addition & 6 deletions graphql_client/tests/introspection.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
#[macro_use]
extern crate graphql_client;
#[macro_use]
extern crate serde_derive;
extern crate serde;
extern crate serde_json;
use graphql_client::*;

#[derive(GraphQLQuery)]
#[graphql(
Expand Down
Loading