Skip to content

Commit add0e23

Browse files
Remove hyper for juniper_axum dependencies (#1219)
Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Kai Ren <[email protected]>
1 parent 4ef8cf7 commit add0e23

File tree

3 files changed

+21
-13
lines changed

3 files changed

+21
-13
lines changed

juniper_axum/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ bytes = "1.2"
3939
[dev-dependencies]
4040
anyhow = "1.0"
4141
axum = { version = "0.6", features = ["macros"] }
42-
hyper = "0.14"
4342
juniper = { version = "0.16.0-dev", path = "../juniper", features = ["expose-test-schema"] }
4443
tokio = { version = "1.20", features = ["macros", "rt-multi-thread", "time"] }
4544
tokio-stream = "0.1"
4645
tokio-tungstenite = "0.20"
46+
tower-service = "0.3"
4747
tracing = "0.1"
4848
tracing-subscriber = "0.3"
4949
urlencoding = "2.1"

juniper_axum/src/extract.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -280,14 +280,17 @@ mod juniper_request_tests {
280280
}
281281

282282
/// Converts the provided [`HttpBody`] into a [`String`].
283-
async fn display_body<B>(body: B) -> String
283+
async fn display_body<B>(mut body: B) -> String
284284
where
285-
B: HttpBody<Data = Bytes>,
285+
B: HttpBody<Data = Bytes> + Unpin,
286286
B::Error: fmt::Display,
287287
{
288-
let bytes = hyper::body::to_bytes(body)
289-
.await
290-
.unwrap_or_else(|e| panic!("failed to represent `Body` as `Bytes`: {e}"));
291-
String::from_utf8(bytes.into()).unwrap_or_else(|e| panic!("not UTF-8 body: {e}"))
288+
let mut body_bytes = vec![];
289+
while let Some(bytes) = body.data().await {
290+
body_bytes.extend(
291+
bytes.unwrap_or_else(|e| panic!("failed to represent `Body` as `Bytes`: {e}")),
292+
);
293+
}
294+
String::from_utf8(body_bytes).unwrap_or_else(|e| panic!("not UTF-8 body: {e}"))
292295
}
293296
}

juniper_axum/tests/http_test_suite.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
use std::sync::Arc;
22

33
use axum::{
4+
body::{Body, HttpBody as _},
45
http::Request,
56
response::Response,
67
routing::{get, post},
78
Extension, Router,
89
};
9-
use hyper::{service::Service, Body};
1010
use juniper::{
1111
http::tests::{run_http_test_suite, HttpIntegration, TestResponse},
1212
tests::fixtures::starwars::schema::{Database, Query},
1313
EmptyMutation, EmptySubscription, RootNode,
1414
};
1515
use juniper_axum::{extract::JuniperRequest, response::JuniperResponse};
16+
use tower_service::Service as _;
1617

1718
type Schema = RootNode<'static, Query, EmptyMutation<Database>, EmptySubscription<Database>>;
1819

@@ -89,15 +90,19 @@ async fn into_test_response(resp: Response) -> TestResponse {
8990
.headers()
9091
.get("content-type")
9192
.map(|header| {
92-
String::from_utf8(header.as_bytes().into())
93+
header
94+
.to_str()
9395
.unwrap_or_else(|e| panic!("not UTF-8 header: {e}"))
96+
.to_owned()
9497
})
9598
.unwrap_or_default();
9699

97-
let body = hyper::body::to_bytes(resp.into_body())
98-
.await
99-
.unwrap_or_else(|e| panic!("failed to represent `Body` as `Bytes`: {e}"));
100-
let body = String::from_utf8(body.into()).unwrap_or_else(|e| panic!("not UTF-8 body: {e}"));
100+
let mut body = resp.into_body();
101+
let mut body_bytes = vec![];
102+
while let Some(bytes) = body.data().await {
103+
body_bytes.extend(bytes.unwrap());
104+
}
105+
let body = String::from_utf8(body_bytes).unwrap_or_else(|e| panic!("not UTF-8 body: {e}"));
101106

102107
TestResponse {
103108
status_code,

0 commit comments

Comments
 (0)