diff --git a/juniper_axum/Cargo.toml b/juniper_axum/Cargo.toml index b7cd896e6..970708f1c 100644 --- a/juniper_axum/Cargo.toml +++ b/juniper_axum/Cargo.toml @@ -39,11 +39,11 @@ bytes = "1.2" [dev-dependencies] anyhow = "1.0" axum = { version = "0.6", features = ["macros"] } -hyper = "0.14" juniper = { version = "0.16.0-dev", path = "../juniper", features = ["expose-test-schema"] } tokio = { version = "1.20", features = ["macros", "rt-multi-thread", "time"] } tokio-stream = "0.1" tokio-tungstenite = "0.20" +tower-service = "0.3" tracing = "0.1" tracing-subscriber = "0.3" urlencoding = "2.1" diff --git a/juniper_axum/src/extract.rs b/juniper_axum/src/extract.rs index ef42f3841..2ce807c8d 100644 --- a/juniper_axum/src/extract.rs +++ b/juniper_axum/src/extract.rs @@ -280,14 +280,17 @@ mod juniper_request_tests { } /// Converts the provided [`HttpBody`] into a [`String`]. - async fn display_body(body: B) -> String + async fn display_body(mut body: B) -> String where - B: HttpBody, + B: HttpBody + Unpin, B::Error: fmt::Display, { - let bytes = hyper::body::to_bytes(body) - .await - .unwrap_or_else(|e| panic!("failed to represent `Body` as `Bytes`: {e}")); - String::from_utf8(bytes.into()).unwrap_or_else(|e| panic!("not UTF-8 body: {e}")) + let mut body_bytes = vec![]; + while let Some(bytes) = body.data().await { + body_bytes.extend( + bytes.unwrap_or_else(|e| panic!("failed to represent `Body` as `Bytes`: {e}")), + ); + } + String::from_utf8(body_bytes).unwrap_or_else(|e| panic!("not UTF-8 body: {e}")) } } diff --git a/juniper_axum/tests/http_test_suite.rs b/juniper_axum/tests/http_test_suite.rs index 2a93405c5..06571bcb1 100644 --- a/juniper_axum/tests/http_test_suite.rs +++ b/juniper_axum/tests/http_test_suite.rs @@ -1,18 +1,19 @@ use std::sync::Arc; use axum::{ + body::{Body, HttpBody as _}, http::Request, response::Response, routing::{get, post}, Extension, Router, }; -use hyper::{service::Service, Body}; use juniper::{ http::tests::{run_http_test_suite, HttpIntegration, TestResponse}, tests::fixtures::starwars::schema::{Database, Query}, EmptyMutation, EmptySubscription, RootNode, }; use juniper_axum::{extract::JuniperRequest, response::JuniperResponse}; +use tower_service::Service as _; type Schema = RootNode<'static, Query, EmptyMutation, EmptySubscription>; @@ -89,15 +90,19 @@ async fn into_test_response(resp: Response) -> TestResponse { .headers() .get("content-type") .map(|header| { - String::from_utf8(header.as_bytes().into()) + header + .to_str() .unwrap_or_else(|e| panic!("not UTF-8 header: {e}")) + .to_owned() }) .unwrap_or_default(); - let body = hyper::body::to_bytes(resp.into_body()) - .await - .unwrap_or_else(|e| panic!("failed to represent `Body` as `Bytes`: {e}")); - let body = String::from_utf8(body.into()).unwrap_or_else(|e| panic!("not UTF-8 body: {e}")); + let mut body = resp.into_body(); + let mut body_bytes = vec![]; + while let Some(bytes) = body.data().await { + body_bytes.extend(bytes.unwrap()); + } + let body = String::from_utf8(body_bytes).unwrap_or_else(|e| panic!("not UTF-8 body: {e}")); TestResponse { status_code,