Update Poem integration to v0.4.5

This commit is contained in:
Sunli 2021-09-01 08:15:27 +08:00
parent 408ee53382
commit b0bcf34926
6 changed files with 24 additions and 9 deletions

@ -1 +1 @@
Subproject commit 19a426191a60334c7c7375188d87d68a2647c7bf
Subproject commit f9eb27f12d4ee9d6cd1c810ab9858aa178a567b1

View File

@ -1,7 +1,15 @@
[package]
name = "async-graphql-axum"
version = "2.9.12"
authors = ["sunli <scott_s829@163.com>"]
edition = "2018"
description = "async-graphql for axum"
license = "MIT/Apache-2.0"
documentation = "https://docs.rs/async-graphql-poem/"
homepage = "https://github.com/async-graphql/async-graphql"
repository = "https://github.com/async-graphql/async-graphql"
keywords = ["futures", "async", "graphql", "poem"]
categories = ["network-programming", "asynchronous"]
[dependencies]
async-graphql = { path = "../..", version = "=2.9.12" }

View File

@ -15,7 +15,7 @@ categories = ["network-programming", "asynchronous"]
[dependencies]
async-graphql = { path = "../..", version = "=2.9.12" }
poem = { version = "0.3.6", features = ["websocket"] }
poem = { version = "0.4.5", features = ["websocket"] }
futures-util = { version = "0.3.13", default-features = false }
serde_json = "1.0.66"
tokio-util = { version = "0.6.7", features = ["compat"] }

View File

@ -12,7 +12,7 @@ use tokio_util::compat::TokioAsyncReadCompatExt;
/// # Example
///
/// ```
/// use poem::{handler, route, EndpointExt};
/// use poem::{handler, RouteMethod, route, EndpointExt};
/// use poem::web::{Json, Data};
/// use poem::middleware::AddData;
/// use async_graphql_poem::GraphQLRequest;
@ -29,17 +29,20 @@ use tokio_util::compat::TokioAsyncReadCompatExt;
///
/// type MySchema = Schema<Query, EmptyMutation, EmptySubscription>;
///
/// #[handler(method = "get")]
/// #[handler]
/// async fn index(req: GraphQLRequest, schema: Data<&MySchema>) -> Json<async_graphql::Response> {
/// Json(schema.execute(req.0).await)
/// }
///
/// let app = route().at("/", index.with(AddData::new(Schema::new(Query, EmptyMutation, EmptySubscription))));
/// let schema = Schema::new(Query, EmptyMutation, EmptySubscription);
/// let app = route().at("/", RouteMethod::new().post(index.with(AddData::new(schema))));
/// ```
pub struct GraphQLRequest(pub async_graphql::Request);
#[async_trait]
impl<'a> FromRequest<'a> for GraphQLRequest {
type Error = Error;
async fn from_request(req: &'a Request, body: &mut RequestBody) -> Result<Self> {
Ok(GraphQLRequest(
GraphQLBatchRequest::from_request(req, body)
@ -56,6 +59,8 @@ pub struct GraphQLBatchRequest(pub async_graphql::BatchRequest);
#[async_trait]
impl<'a> FromRequest<'a> for GraphQLBatchRequest {
type Error = Error;
async fn from_request(req: &'a Request, body: &mut RequestBody) -> Result<Self> {
if req.method() == Method::GET {
let req = Query::from_request(req, body)

View File

@ -9,7 +9,7 @@ use crate::GraphQLBatchRequest;
/// # Example
///
/// ```
/// use poem::route;
/// use poem::{route, RouteMethod};
/// use async_graphql_poem::GraphQL;
/// use async_graphql::{EmptyMutation, EmptySubscription, Object, Schema};
///
@ -24,7 +24,8 @@ use crate::GraphQLBatchRequest;
///
/// type MySchema = Schema<Query, EmptyMutation, EmptySubscription>;
///
/// let app = route().at("/", GraphQL::new(Schema::new(Query, EmptyMutation, EmptySubscription)));
/// let schema = Schema::new(Query, EmptyMutation, EmptySubscription);
/// let app = route().at("/", RouteMethod::new().post(GraphQL::new(schema)));
/// ```
pub struct GraphQL<Query, Mutation, Subscription> {
schema: Schema<Query, Mutation, Subscription>,

View File

@ -12,7 +12,7 @@ use poem::{http, Endpoint, FromRequest, IntoResponse, Request, Response, Result}
/// # Example
///
/// ```
/// use poem::route;
/// use poem::{route, RouteMethod};
/// use async_graphql_poem::GraphQLSubscription;
/// use async_graphql::{EmptyMutation, Object, Schema, Subscription};
/// use futures_util::{Stream, stream};
@ -37,7 +37,8 @@ use poem::{http, Endpoint, FromRequest, IntoResponse, Request, Response, Result}
///
/// type MySchema = Schema<Query, EmptyMutation, Subscription>;
///
/// let app = route().at("/ws", GraphQLSubscription::new(Schema::new(Query, EmptyMutation, Subscription)));
/// let schema = Schema::new(Query, EmptyMutation, Subscription);
/// let app = route().at("/ws", RouteMethod::new().get(GraphQLSubscription::new(schema)));
/// ```
pub struct GraphQLSubscription<Query, Mutation, Subscription, F> {
schema: Schema<Query, Mutation, Subscription>,