@@ -71,14 +71,14 @@ where
71
71
S : ScalarValue ;
72
72
73
73
#[ async_trait]
74
- impl < S , State > FromRequest < State , Body > for JuniperRequest < S >
74
+ impl < S , State > FromRequest < State > for JuniperRequest < S >
75
75
where
76
76
S : ScalarValue ,
77
77
State : Sync ,
78
78
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 > ,
82
82
{
83
83
type Rejection = Response ;
84
84
96
96
. into_response ( )
97
97
} ) ?;
98
98
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) {
100
102
( & Method :: GET , _) => req
101
103
. extract_parts :: < Query < GetRequest > > ( )
102
104
. await
@@ -180,13 +182,8 @@ impl<S: ScalarValue> TryFrom<GetRequest> for GraphQLRequest<S> {
180
182
181
183
#[ cfg( test) ]
182
184
mod 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 _;
190
187
use juniper:: {
191
188
graphql_input_value,
192
189
http:: { GraphQLBatchRequest , GraphQLRequest } ,
@@ -279,18 +276,15 @@ mod juniper_request_tests {
279
276
}
280
277
}
281
278
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}" ) )
295
289
}
296
290
}
0 commit comments