diff --git a/examples b/examples index ad5a2531..f9116e90 160000 --- a/examples +++ b/examples @@ -1 +1 @@ -Subproject commit ad5a253197dff977eadd7afb6626036776a162b7 +Subproject commit f9116e9029f6d57cea22c139c3e5fd952b774979 diff --git a/integrations/actix-web/Cargo.toml b/integrations/actix-web/Cargo.toml index 2cf8cf58..609ae633 100644 --- a/integrations/actix-web/Cargo.toml +++ b/integrations/actix-web/Cargo.toml @@ -14,9 +14,9 @@ categories = ["network-programming", "asynchronous"] [dependencies] async-graphql = { path = "../..", version = "3.0.13" } actix = "0.12.0" -actix-http = "3.0.0-beta.12" -actix-web = { version = "4.0.0-beta.11", default-features = false } -actix-web-actors = "4.0.0-beta.7" +actix-http = "3.0.0-beta.15" +actix-web = { version = "4.0.0-beta.14", default-features = false } +actix-web-actors = "4.0.0-beta.8" async-channel = "1.6.1" futures-util = { version = "0.3.17", default-features = false } serde_json = "1.0.64" diff --git a/integrations/actix-web/src/request.rs b/integrations/actix-web/src/request.rs index de5978e5..ecab4455 100644 --- a/integrations/actix-web/src/request.rs +++ b/integrations/actix-web/src/request.rs @@ -1,3 +1,4 @@ +use actix_http::body::BoxBody; use std::future::Future; use std::io::{self, ErrorKind}; use std::pin::Pin; @@ -153,6 +154,8 @@ impl From for GraphQLResponse { } impl Responder for GraphQLResponse { + type Body = BoxBody; + fn respond_to(self, _req: &HttpRequest) -> HttpResponse { let mut res = HttpResponse::build(StatusCode::OK); res.content_type("application/json"); diff --git a/integrations/actix-web/src/subscription.rs b/integrations/actix-web/src/subscription.rs index aae627c5..0d5748d8 100644 --- a/integrations/actix-web/src/subscription.rs +++ b/integrations/actix-web/src/subscription.rs @@ -114,7 +114,9 @@ where continuation: Vec::new(), }; - actix_web_actors::ws::start_with_protocols(actor, &ALL_WEBSOCKET_PROTOCOLS, request, stream) + actix_web_actors::ws::WsResponseBuilder::new(actor, request, stream) + .protocols(&ALL_WEBSOCKET_PROTOCOLS) + .start() } } diff --git a/integrations/actix-web/tests/graphql.rs b/integrations/actix-web/tests/graphql.rs index 4868cdbf..820d80ed 100644 --- a/integrations/actix-web/tests/graphql.rs +++ b/integrations/actix-web/tests/graphql.rs @@ -1,5 +1,5 @@ use actix_http::Method; -use actix_web::dev::{AnyBody, Service}; +use actix_web::dev::Service; use actix_web::{guard, test, web, web::Data, App}; use serde_json::json; @@ -21,12 +21,12 @@ async fn test_playground() { let req = test::TestRequest::with_uri("/").to_request(); let response = srv.call(req).await.unwrap(); assert!(response.status().is_success()); - let body = response.response().body(); - if let AnyBody::Bytes(bytes) = body { - assert!(std::str::from_utf8(&bytes).unwrap().contains("graphql")); - } else { - panic!("response body must be Bytes {:?}", body); - } + let body = response.into_body(); + assert!( + std::str::from_utf8(&actix_web::body::to_bytes(body).await.unwrap()) + .unwrap() + .contains("graphql") + ); } #[actix_rt::test] @@ -55,10 +55,10 @@ async fn test_add() { .await .unwrap(); assert!(response.status().is_success()); - let body = response.response().body(); + let body = response.into_body(); assert_eq!( - body, - &AnyBody::Bytes(json!({"data": {"add": 30}}).to_string().into_bytes().into()) + actix_web::body::to_bytes(body).await.unwrap(), + json!({"data": {"add": 30}}).to_string().into_bytes() ); } @@ -89,15 +89,12 @@ async fn test_hello() { .await .unwrap(); assert!(response.status().is_success()); - let body = response.response().body(); + let body = response.into_body(); assert_eq!( - body, - &AnyBody::Bytes( - json!({"data": {"hello": "Hello, world!"}}) - .to_string() - .into_bytes() - .into() - ) + actix_web::body::to_bytes(body).await.unwrap(), + json!({"data": {"hello": "Hello, world!"}}) + .to_string() + .into_bytes() ); } @@ -129,15 +126,12 @@ async fn test_hello_header() { .await .unwrap(); assert!(response.status().is_success()); - let body = response.response().body(); + let body = response.into_body(); assert_eq!( - body, - &AnyBody::Bytes( - json!({"data": {"hello": "Hello, Foo!"}}) - .to_string() - .into_bytes() - .into() - ) + actix_web::body::to_bytes(body).await.unwrap(), + json!({"data": {"hello": "Hello, Foo!"}}) + .to_string() + .into_bytes() ); } @@ -168,15 +162,10 @@ async fn test_count() { .await .unwrap(); assert!(response.status().is_success()); - let body = response.response().body(); + let body = response.into_body(); assert_eq!( - body, - &AnyBody::Bytes( - json!({"data": {"count": 0}}) - .to_string() - .into_bytes() - .into() - ) + actix_web::body::to_bytes(body).await.unwrap(), + json!({"data": {"count": 0}}).to_string().into_bytes() ); let response = srv @@ -189,15 +178,10 @@ async fn test_count() { .await .unwrap(); assert!(response.status().is_success()); - let body = response.response().body(); + let body = response.into_body(); assert_eq!( - body, - &AnyBody::Bytes( - json!({"data": {"addCount": 10}}) - .to_string() - .into_bytes() - .into() - ) + actix_web::body::to_bytes(body).await.unwrap(), + json!({"data": {"addCount": 10}}).to_string().into_bytes(), ); let response = srv @@ -210,15 +194,12 @@ async fn test_count() { .await .unwrap(); assert!(response.status().is_success()); - let body = response.response().body(); + let body = response.into_body(); assert_eq!( - body, - &AnyBody::Bytes( - json!({"data": {"subtractCount": 8}}) - .to_string() - .into_bytes() - .into() - ) + actix_web::body::to_bytes(body).await.unwrap(), + json!({"data": {"subtractCount": 8}}) + .to_string() + .into_bytes() ); let response = srv @@ -231,14 +212,11 @@ async fn test_count() { .await .unwrap(); assert!(response.status().is_success()); - let body = response.response().body(); + let body = response.into_body(); assert_eq!( - body, - &AnyBody::Bytes( - json!({"data": {"subtractCount": 6}}) - .to_string() - .into_bytes() - .into() - ) + actix_web::body::to_bytes(body).await.unwrap(), + json!({"data": {"subtractCount": 6}}) + .to_string() + .into_bytes() ); }