Add GET request support for async-graphql-actix-web
This commit is contained in:
parent
96f7d38c8a
commit
e7eb9cca7f
@ -17,6 +17,7 @@ use async_graphql::{
|
|||||||
use futures::channel::mpsc;
|
use futures::channel::mpsc;
|
||||||
use futures::future::Ready;
|
use futures::future::Ready;
|
||||||
use futures::{Future, SinkExt, StreamExt, TryFutureExt};
|
use futures::{Future, SinkExt, StreamExt, TryFutureExt};
|
||||||
|
use http::Method;
|
||||||
use std::convert::Infallible;
|
use std::convert::Infallible;
|
||||||
use std::pin::Pin;
|
use std::pin::Pin;
|
||||||
pub use subscription::WSSubscription;
|
pub use subscription::WSSubscription;
|
||||||
@ -41,6 +42,19 @@ impl FromRequest for GQLRequest {
|
|||||||
|
|
||||||
fn from_request(req: &HttpRequest, payload: &mut Payload<PayloadStream>) -> Self::Future {
|
fn from_request(req: &HttpRequest, payload: &mut Payload<PayloadStream>) -> Self::Future {
|
||||||
let config = req.app_data::<Self::Config>().cloned().unwrap_or_default();
|
let config = req.app_data::<Self::Config>().cloned().unwrap_or_default();
|
||||||
|
|
||||||
|
if req.method() == Method::GET {
|
||||||
|
let res = web::Query::<async_graphql::http::GQLRequest>::from_query(req.query_string());
|
||||||
|
Box::pin(async move {
|
||||||
|
let gql_request = res?;
|
||||||
|
gql_request
|
||||||
|
.into_inner()
|
||||||
|
.into_query_builder_opts(&config)
|
||||||
|
.map_ok(GQLRequest)
|
||||||
|
.map_err(actix_web::error::ErrorBadRequest)
|
||||||
|
.await
|
||||||
|
})
|
||||||
|
} else {
|
||||||
let content_type = req
|
let content_type = req
|
||||||
.headers()
|
.headers()
|
||||||
.get(http::header::CONTENT_TYPE)
|
.get(http::header::CONTENT_TYPE)
|
||||||
@ -73,6 +87,7 @@ impl FromRequest for GQLRequest {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Responder for GraphQL response
|
/// Responder for GraphQL response
|
||||||
pub struct GQLResponse(async_graphql::Result<QueryResponse>);
|
pub struct GQLResponse(async_graphql::Result<QueryResponse>);
|
||||||
|
Loading…
Reference in New Issue
Block a user