diff --git a/async-graphql-tide/Cargo.toml b/async-graphql-tide/Cargo.toml index 5e286ccb..177cde37 100644 --- a/async-graphql-tide/Cargo.toml +++ b/async-graphql-tide/Cargo.toml @@ -15,6 +15,7 @@ categories = ["network-programming", "asynchronous"] [dependencies] async-graphql = { path = "..", version = "1.9.18" } tide = "0.8" +http-types = "1.2.0" [dev-dependencies] async-std = "1.5.0" diff --git a/async-graphql-tide/src/lib.rs b/async-graphql-tide/src/lib.rs index 7ea2226c..15675bfb 100644 --- a/async-graphql-tide/src/lib.rs +++ b/async-graphql-tide/src/lib.rs @@ -4,7 +4,7 @@ #![allow(clippy::type_complexity)] #![allow(clippy::needless_doctest_main)] -use async_graphql::http::{GQLRequest, GQLResponse}; +use async_graphql::http::GQLResponse; use async_graphql::{ IntoQueryBuilder, IntoQueryBuilderOpts, ObjectType, QueryBuilder, Schema, SubscriptionType, }; @@ -61,7 +61,7 @@ where /// Similar to graphql, but you can set the options `IntoQueryBuilderOpts`. pub async fn graphql_opts( - mut req: Request, + req: Request, schema: Schema, query_builder_configuration: F, opts: IntoQueryBuilderOpts, @@ -73,12 +73,11 @@ where TideState: Send + Sync + 'static, F: Fn(QueryBuilder) -> QueryBuilder, { - let gql_request: GQLRequest = req - .body_json() - .await - .map_err(|e| tide::Error::new(StatusCode::BadRequest, e))?; + let content_type = req + .header(&http_types::headers::CONTENT_TYPE) + .and_then(|values| values.first().map(|value| value.to_string())); - let mut query_builder = gql_request + let mut query_builder = (content_type, req) .into_query_builder_opts(&opts) .await .map_err(|e| tide::Error::new(StatusCode::BadRequest, e))?;