Update async-graphql-tide::ResponseExt
This commit is contained in:
parent
18c3fa6005
commit
5cc0208765
@ -57,13 +57,7 @@ where
|
|||||||
TideState: Send + Sync + 'static,
|
TideState: Send + Sync + 'static,
|
||||||
F: Fn(QueryBuilder) -> QueryBuilder + Send,
|
F: Fn(QueryBuilder) -> QueryBuilder + Send,
|
||||||
{
|
{
|
||||||
let query_builder = req.body_graphql().await.status(StatusCode::BadRequest)?;
|
graphql_opts(req, schema, query_builder_configuration, Default::default()).await
|
||||||
let resp = GQLResponse(
|
|
||||||
query_builder_configuration(query_builder)
|
|
||||||
.execute(&schema)
|
|
||||||
.await,
|
|
||||||
);
|
|
||||||
Ok(Response::new(StatusCode::Ok).body_json(&resp)?)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Similar to graphql, but you can set the options `IntoQueryBuilderOpts`.
|
/// Similar to graphql, but you can set the options `IntoQueryBuilderOpts`.
|
||||||
@ -84,12 +78,13 @@ where
|
|||||||
.body_graphql_opts(opts)
|
.body_graphql_opts(opts)
|
||||||
.await
|
.await
|
||||||
.status(StatusCode::BadRequest)?;
|
.status(StatusCode::BadRequest)?;
|
||||||
let resp = GQLResponse(
|
Ok(Response::new(StatusCode::Ok)
|
||||||
query_builder_configuration(query_builder)
|
.body_graphql(
|
||||||
.execute(&schema)
|
query_builder_configuration(query_builder)
|
||||||
.await,
|
.execute(&schema)
|
||||||
);
|
.await,
|
||||||
Ok(Response::new(StatusCode::Ok).body_json(&resp)?)
|
)
|
||||||
|
.status(StatusCode::InternalServerError)?)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Tide request extension
|
/// Tide request extension
|
||||||
@ -123,12 +118,12 @@ impl<State: Send + Sync + 'static> RequestExt<State> for Request<State> {
|
|||||||
|
|
||||||
/// Tide response extension
|
/// Tide response extension
|
||||||
///
|
///
|
||||||
pub trait ResponseExt<State: Send + Sync + 'static>: Sized {
|
pub trait ResponseExt: Sized {
|
||||||
/// Set Body as the result of a GraphQL query.
|
/// Set Body as the result of a GraphQL query.
|
||||||
fn body_graphql(self, res: async_graphql::Result<QueryResponse>) -> serde_json::Result<Self>;
|
fn body_graphql(self, res: async_graphql::Result<QueryResponse>) -> serde_json::Result<Self>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<State: Send + Sync + 'static> ResponseExt<State> for Response {
|
impl ResponseExt for Response {
|
||||||
fn body_graphql(self, res: async_graphql::Result<QueryResponse>) -> serde_json::Result<Self> {
|
fn body_graphql(self, res: async_graphql::Result<QueryResponse>) -> serde_json::Result<Self> {
|
||||||
self.body_json(&GQLResponse(res))
|
self.body_json(&GQLResponse(res))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user