Add GET request support for async-graphql-actix-web
@@ -17,6 +17,7 @@ use async_graphql::{
use futures::channel::mpsc;
use futures::future::Ready;
use futures::{Future, SinkExt, StreamExt, TryFutureExt};
+use http::Method;
use std::convert::Infallible;
use std::pin::Pin;
pub use subscription::WSSubscription;
@@ -41,6 +42,19 @@ impl FromRequest for GQLRequest {
fn from_request(req: &HttpRequest, payload: &mut Payload<PayloadStream>) -> Self::Future {
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
.headers()
.get(http::header::CONTENT_TYPE)
@@ -73,6 +87,7 @@ impl FromRequest for GQLRequest {
})
}
}
+}
/// Responder for GraphQL response
pub struct GQLResponse(async_graphql::Result<QueryResponse>);
