@@ -71,14 +71,14 @@ where
7171 S : ScalarValue ;
7272
7373#[ async_trait]
74- impl < S , State > FromRequest < State , Body > for JuniperRequest < S >
74+ impl < S , State > FromRequest < State > for JuniperRequest < S >
7575where
7676 S : ScalarValue ,
7777 State : Sync ,
7878 Query < GetRequest > : FromRequestParts < State > ,
79- Json < GraphQLBatchRequest < S > > : FromRequest < State , Body > ,
80- <Json < GraphQLBatchRequest < S > > as FromRequest < State , Body > >:: Rejection : fmt:: Display ,
81- String : FromRequest < State , Body > ,
79+ Json < GraphQLBatchRequest < S > > : FromRequest < State > ,
80+ <Json < GraphQLBatchRequest < S > > as FromRequest < State > >:: Rejection : fmt:: Display ,
81+ String : FromRequest < State > ,
8282{
8383 type Rejection = Response ;
8484
9696 . into_response ( )
9797 } ) ?;
9898
99- match ( req. method ( ) , content_type) {
99+ // TODO: Move into `match` expression directly once MSRV is bumped higher than 1.74.
100+ let method = req. method ( ) ;
101+ match ( method, content_type) {
100102 ( & Method :: GET , _) => req
101103 . extract_parts :: < Query < GetRequest > > ( )
102104 . await
@@ -180,13 +182,8 @@ impl<S: ScalarValue> TryFrom<GetRequest> for GraphQLRequest<S> {
180182
181183#[ cfg( test) ]
182184mod juniper_request_tests {
183- use std:: fmt;
184-
185- use axum:: {
186- body:: { Body , Bytes , HttpBody } ,
187- extract:: FromRequest as _,
188- http:: Request ,
189- } ;
185+ use axum:: { body:: Body , extract:: FromRequest as _, http:: Request } ;
186+ use futures:: TryStreamExt as _;
190187 use juniper:: {
191188 graphql_input_value,
192189 http:: { GraphQLBatchRequest , GraphQLRequest } ,
@@ -279,18 +276,15 @@ mod juniper_request_tests {
279276 }
280277 }
281278
282- /// Converts the provided [`HttpBody`] into a [`String`].
283- async fn display_body < B > ( mut body : B ) -> String
284- where
285- B : HttpBody < Data = Bytes > + Unpin ,
286- B :: Error : fmt:: Display ,
287- {
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}" ) )
279+ /// Converts the provided [`Body`] into a [`String`].
280+ async fn display_body ( body : Body ) -> String {
281+ String :: from_utf8 (
282+ body. into_data_stream ( )
283+ . map_ok ( |bytes| bytes. to_vec ( ) )
284+ . try_concat ( )
285+ . await
286+ . unwrap ( ) ,
287+ )
288+ . unwrap_or_else ( |e| panic ! ( "not UTF-8 body: {e}" ) )
295289 }
296290}
0 commit comments