Update to latest Rocket on master ()

The `async` branch has now landed on Rocket's `master`. The git
branch has been deleted.
This commit is contained in:
Christian Legnitto 2020-07-14 21:38:09 -10:00 committed by GitHub
parent 61a5a747f1
commit 3616e36ece
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 8 deletions
juniper_rocket_async

View file

@ -15,7 +15,7 @@ edition = "2018"
serde_json = { version = "1.0.2" } serde_json = { version = "1.0.2" }
juniper = { version = "0.14.2", default-features = false, path = "../juniper" } juniper = { version = "0.14.2", default-features = false, path = "../juniper" }
futures = { version = "0.3.1", features = ["compat"] } futures = { version = "0.3.1", features = ["compat"] }
rocket = { git = "https://github.com/SergioBenitez/Rocket", branch = "async", default-features = false } rocket = { git = "https://github.com/SergioBenitez/Rocket", branch = "master", default-features = false }
tokio = { version = "0.2", features = ["rt-core", "macros"] } tokio = { version = "0.2", features = ["rt-core", "macros"] }
[dev-dependencies.juniper] [dev-dependencies.juniper]

View file

@ -42,7 +42,7 @@ Check the LICENSE file for details.
use std::io::Cursor; use std::io::Cursor;
use rocket::{ use rocket::{
data::{FromDataFuture, FromDataSimple}, data::{self, FromData},
http::{ContentType, RawStr, Status}, http::{ContentType, RawStr, Status},
request::{FormItems, FromForm, FromFormValue}, request::{FormItems, FromForm, FromFormValue},
response::{self, content, Responder, Response}, response::{self, content, Responder, Response},
@ -288,13 +288,14 @@ where
const BODY_LIMIT: u64 = 1024 * 100; const BODY_LIMIT: u64 = 1024 * 100;
impl<S> FromDataSimple for GraphQLRequest<S> #[rocket::async_trait]
impl<S> FromData for GraphQLRequest<S>
where where
S: ScalarValue, S: ScalarValue,
{ {
type Error = String; type Error = String;
fn from_data(req: &Request, data: Data) -> FromDataFuture<'static, Self, Self::Error> { async fn from_data(req: &Request<'_>, data: Data) -> data::Outcome<Self, Self::Error> {
use tokio::io::AsyncReadExt as _; use tokio::io::AsyncReadExt as _;
let content_type = req let content_type = req
@ -303,7 +304,7 @@ where
let is_json = match content_type { let is_json = match content_type {
Some(("application", "json")) => true, Some(("application", "json")) => true,
Some(("application", "graphql")) => false, Some(("application", "graphql")) => false,
_ => return Box::pin(async move { Forward(data) }), _ => return Box::pin(async move { Forward(data) }).await,
}; };
Box::pin(async move { Box::pin(async move {
@ -322,6 +323,7 @@ where
GraphQLBatchRequest::Single(http::GraphQLRequest::new(body, None, None)) GraphQLBatchRequest::Single(http::GraphQLRequest::new(body, None, None))
})) }))
}) })
.await
} }
} }
@ -464,7 +466,7 @@ mod tests {
use rocket::{ use rocket::{
self, get, self, get,
http::ContentType, http::ContentType,
local::{Client, LocalResponse}, local::asynchronous::{Client, LocalResponse},
post, post,
request::Form, request::Form,
routes, Rocket, State, routes, Rocket, State,
@ -566,14 +568,14 @@ mod tests {
)) ))
} }
async fn make_test_response(mut response: LocalResponse<'_>) -> http_tests::TestResponse { async fn make_test_response(response: LocalResponse<'_>) -> http_tests::TestResponse {
let status_code = response.status().code as i32; let status_code = response.status().code as i32;
let content_type = response let content_type = response
.content_type() .content_type()
.expect("No content type header from handler") .expect("No content type header from handler")
.to_string(); .to_string();
let body = response let body = response
.body_string() .into_string()
.await .await
.expect("No body returned from GraphQL handler"); .expect("No body returned from GraphQL handler");