diff --git a/examples/warp_async/Cargo.toml b/examples/warp_async/Cargo.toml index ae9b0d71..9285791f 100644 --- a/examples/warp_async/Cargo.toml +++ b/examples/warp_async/Cargo.toml @@ -1,20 +1,16 @@ [package] name = "warp_async" version = "0.1.0" -authors = ["Christoph Herzog "] edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +authors = ["Christoph Herzog "] [dependencies] -log = "0.4.8" +juniper = { git = "https://github.com/graphql-rust/juniper" } +juniper_warp = { git = "https://github.com/graphql-rust/juniper" } + env_logger = "0.6.2" -warp = "0.1.19" futures = { version = "0.3.1", features = ["compat"] } -reqwest = "0.9.19" +log = "0.4.8" +reqwest = { version = "0.10", features = ["rustls-tls"] } tokio = { version = "0.2", features = ["rt-core", "macros"] } - -juniper_codegen = { git = "https://github.com/graphql-rust/juniper", branch = "async-await", features = ["async"] } -juniper = { git = "https://github.com/graphql-rust/juniper", branch = "async-await", features = ["async"] } -juniper_warp = { git = "https://github.com/graphql-rust/juniper", branch = "async-await", features = ["async"] } - +warp = "0.2" diff --git a/examples/warp_async/src/main.rs b/examples/warp_async/src/main.rs index 7bc142c5..95a1671a 100644 --- a/examples/warp_async/src/main.rs +++ b/examples/warp_async/src/main.rs @@ -1,30 +1,29 @@ -//! //! This example demonstrates async/await usage with warp. -//! NOTE: this uses tokio 0.1 , not the alpha tokio 0.2. -use juniper::{EmptyMutation, EmptySubscription, RootNode, FieldError}; +use juniper::{ + graphql_object, EmptyMutation, EmptySubscription, FieldError, GraphQLEnum, RootNode, +}; use warp::{http::Response, Filter}; -#[derive(Clone)] -struct Context { - -} +#[derive(Clone, Copy, Debug)] +struct Context; impl juniper::Context for Context {} -#[derive(juniper::GraphQLEnum, Clone, Copy)] +#[derive(Clone, Copy, Debug, GraphQLEnum)] enum UserKind { Admin, User, Guest, } +#[derive(Clone, Debug)] struct User { id: i32, kind: UserKind, name: String, } -#[juniper::graphql_object(Context = Context)] +#[graphql_object(Context = Context)] impl User { fn id(&self) -> i32 { self.id @@ -43,45 +42,38 @@ impl User { } } +#[derive(Clone, Copy, Debug)] struct Query; -#[juniper::graphql_object(Context = Context)] +#[graphql_object(Context = Context)] impl Query { async fn users() -> Vec { - vec![ - User{ - id: 1, - kind: UserKind::Admin, - name: "user1".into(), - }, - ] + vec![User { + id: 1, + kind: UserKind::Admin, + name: "user1".into(), + }] } /// Fetch a URL and return the response body text. async fn request(url: String) -> Result { - use futures::{ compat::{Stream01CompatExt, Future01CompatExt}, stream::TryStreamExt}; - - let res = reqwest::r#async::Client::new() - .get(&url) - .send() - .compat() - .await?; - - let body_raw = res.into_body().compat().try_concat().await?; - let body = std::str::from_utf8(&body_raw).unwrap_or("invalid utf8"); - Ok(body.to_string()) + Ok(reqwest::get(&url).await?.text().await?) } } type Schema = RootNode<'static, Query, EmptyMutation, EmptySubscription>; fn schema() -> Schema { - Schema::new(Query, EmptyMutation::::new(), EmptySubscription::::new()) + Schema::new( + Query, + EmptyMutation::::new(), + EmptySubscription::::new(), + ) } #[tokio::main] async fn main() { - ::std::env::set_var("RUST_LOG", "warp_async"); + std::env::set_var("RUST_LOG", "warp_async"); env_logger::init(); let log = warp::log("warp_server"); @@ -96,13 +88,13 @@ async fn main() { log::info!("Listening on 127.0.0.1:8080"); - let state = warp::any().map(move || Context{} ); + let state = warp::any().map(|| Context); let graphql_filter = juniper_warp::make_graphql_filter(schema(), state.boxed()); warp::serve( warp::get() .and(warp::path("graphiql")) - .and(juniper_warp::graphiql_filter("/graphql")) + .and(juniper_warp::graphiql_filter("/graphql", None)) .or(homepage) .or(warp::path("graphql").and(graphql_filter)) .with(log), diff --git a/juniper_hyper/Cargo.toml b/juniper_hyper/Cargo.toml index a4867baf..46a3bdc6 100644 --- a/juniper_hyper/Cargo.toml +++ b/juniper_hyper/Cargo.toml @@ -14,11 +14,11 @@ url = "2" juniper = { version = "0.14.2", default-features = false, path = "../juniper"} tokio = "0.2" hyper = "0.13" -futures = { version = "0.3.1" } +futures = "0.3.1" [dev-dependencies] pretty_env_logger = "0.2" -reqwest = "0.9" +reqwest = { version = "0.10", features = ["blocking", "rustls-tls"] } [dev-dependencies.juniper] version = "0.14.2" diff --git a/juniper_hyper/src/lib.rs b/juniper_hyper/src/lib.rs index 3d1f5554..5d6d90a1 100644 --- a/juniper_hyper/src/lib.rs +++ b/juniper_hyper/src/lib.rs @@ -322,7 +322,7 @@ mod tests { tests::{model::Database, schema::Query}, EmptyMutation, EmptySubscription, RootNode, }; - use reqwest::{self, Response as ReqwestResponse}; + use reqwest::{self, blocking::Response as ReqwestResponse}; use std::{net::SocketAddr, sync::Arc, thread, time::Duration}; struct TestHyperIntegration { @@ -332,12 +332,12 @@ mod tests { impl http_tests::HttpIntegration for TestHyperIntegration { fn get(&self, url: &str) -> http_tests::TestResponse { let url = format!("http://127.0.0.1:{}/graphql{}", self.port, url); - make_test_response(reqwest::get(&url).expect(&format!("failed GET {}", url))) + make_test_response(reqwest::blocking::get(&url).expect(&format!("failed GET {}", url))) } fn post_json(&self, url: &str, body: &str) -> http_tests::TestResponse { let url = format!("http://127.0.0.1:{}/graphql{}", self.port, url); - let client = reqwest::Client::new(); + let client = reqwest::blocking::Client::new(); let res = client .post(&url) .header(reqwest::header::CONTENT_TYPE, "application/json") @@ -349,7 +349,7 @@ mod tests { fn post_graphql(&self, url: &str, body: &str) -> http_tests::TestResponse { let url = format!("http://127.0.0.1:{}/graphql{}", self.port, url); - let client = reqwest::Client::new(); + let client = reqwest::blocking::Client::new(); let res = client .post(&url) .header(reqwest::header::CONTENT_TYPE, "application/graphql") @@ -360,15 +360,15 @@ mod tests { } } - fn make_test_response(mut response: ReqwestResponse) -> http_tests::TestResponse { + fn make_test_response(response: ReqwestResponse) -> http_tests::TestResponse { let status_code = response.status().as_u16() as i32; - let body = response.text().unwrap(); let content_type_header = response.headers().get(reqwest::header::CONTENT_TYPE); let content_type = if let Some(ct) = content_type_header { format!("{}", ct.to_str().unwrap()) } else { String::default() }; + let body = response.text().unwrap(); http_tests::TestResponse { status_code,