Add new `state` parameter to `FromRequest` usage
@@ -2,9 +2,8 @@ use std::{io::ErrorKind, marker::PhantomData};
use async_graphql::{futures_util::TryStreamExt, http::MultipartOptions, ParseRequestError};
use axum::{
- extract::{BodyStream, FromRequest, RequestParts},
- http,
- http::Method,
+ extract::{BodyStream, FromRequest},
+ http::{self, Method, Request},
response::IntoResponse,
BoxError,
};
@@ -61,18 +60,19 @@ pub mod rejection {
}
#[async_trait::async_trait]
-impl<B, R> FromRequest<B> for GraphQLRequest<R>
+impl<S, B, R> FromRequest<S, B> for GraphQLRequest<R>
where
B: http_body::Body + Unpin + Send + Sync + 'static,
B::Data: Into<Bytes>,
B::Error: Into<BoxError>,
+ S: Send + Sync,
R: IntoResponse + From<ParseRequestError>,
{
type Rejection = R;
- async fn from_request(req: &mut RequestParts<B>) -> Result<Self, Self::Rejection> {
+ async fn from_request(req: Request<B>, state: &S) -> Result<Self, Self::Rejection> {
Ok(GraphQLRequest(
- GraphQLBatchRequest::<R>::from_request(req)
+ GraphQLBatchRequest::<R>::from_request(req, state)
.await?
.0
.into_single()?,
@@ -96,16 +96,17 @@ impl<R> GraphQLBatchRequest<R> {
}
#[async_trait::async_trait]
-impl<B, R> FromRequest<B> for GraphQLBatchRequest<R>
+impl<S, B, R> FromRequest<S, B> for GraphQLBatchRequest<R>
where
B: http_body::Body + Unpin + Send + Sync + 'static,
B::Data: Into<Bytes>,
B::Error: Into<BoxError>,
+ S: Send + Sync,
R: IntoResponse + From<ParseRequestError>,
{
type Rejection = R;
- async fn from_request(req: &mut RequestParts<B>) -> Result<Self, Self::Rejection> {
+ async fn from_request(req: Request<B>, state: &S) -> Result<Self, Self::Rejection> {
if let (&Method::GET, uri) = (req.method(), req.uri()) {
let res = async_graphql::http::parse_query_string(uri.query().unwrap_or_default())
.map_err(|err| {
@@ -121,7 +122,7 @@ where
.get(http::header::CONTENT_TYPE)
.and_then(|value| value.to_str().ok())
.map(ToString::to_string);
- let body_stream = BodyStream::from_request(req)
+ let body_stream = BodyStream::from_request(req, state)
.await
.map_err(|_| {
ParseRequestError::Io(std::io::Error::new(
