async-graphql-tide: use into_query_builder_opts to make QueryBuilder

This commit is contained in:
vkill 2020-04-26 22:56:27 +08:00
parent daa6ca7f20
commit 6c217666d9
2 changed files with 7 additions and 7 deletions

View File

@ -15,6 +15,7 @@ categories = ["network-programming", "asynchronous"]
[dependencies] [dependencies]
async-graphql = { path = "..", version = "1.9.18" } async-graphql = { path = "..", version = "1.9.18" }
tide = "0.8" tide = "0.8"
http-types = "1.2.0"
[dev-dependencies] [dev-dependencies]
async-std = "1.5.0" async-std = "1.5.0"

View File

@ -4,7 +4,7 @@
#![allow(clippy::type_complexity)] #![allow(clippy::type_complexity)]
#![allow(clippy::needless_doctest_main)] #![allow(clippy::needless_doctest_main)]
use async_graphql::http::{GQLRequest, GQLResponse}; use async_graphql::http::GQLResponse;
use async_graphql::{ use async_graphql::{
IntoQueryBuilder, IntoQueryBuilderOpts, ObjectType, QueryBuilder, Schema, SubscriptionType, IntoQueryBuilder, IntoQueryBuilderOpts, ObjectType, QueryBuilder, Schema, SubscriptionType,
}; };
@ -61,7 +61,7 @@ where
/// Similar to graphql, but you can set the options `IntoQueryBuilderOpts`. /// Similar to graphql, but you can set the options `IntoQueryBuilderOpts`.
pub async fn graphql_opts<Query, Mutation, Subscription, TideState, F>( pub async fn graphql_opts<Query, Mutation, Subscription, TideState, F>(
mut req: Request<TideState>, req: Request<TideState>,
schema: Schema<Query, Mutation, Subscription>, schema: Schema<Query, Mutation, Subscription>,
query_builder_configuration: F, query_builder_configuration: F,
opts: IntoQueryBuilderOpts, opts: IntoQueryBuilderOpts,
@ -73,12 +73,11 @@ where
TideState: Send + Sync + 'static, TideState: Send + Sync + 'static,
F: Fn(QueryBuilder) -> QueryBuilder, F: Fn(QueryBuilder) -> QueryBuilder,
{ {
let gql_request: GQLRequest = req let content_type = req
.body_json() .header(&http_types::headers::CONTENT_TYPE)
.await .and_then(|values| values.first().map(|value| value.to_string()));
.map_err(|e| tide::Error::new(StatusCode::BadRequest, e))?;
let mut query_builder = gql_request let mut query_builder = (content_type, req)
.into_query_builder_opts(&opts) .into_query_builder_opts(&opts)
.await .await
.map_err(|e| tide::Error::new(StatusCode::BadRequest, e))?; .map_err(|e| tide::Error::new(StatusCode::BadRequest, e))?;