Skip to content

Commit 563270d

Browse files
committed
Fix 'juniper_rocket_async' crate up to latest upstream changes
1 parent 5b4f6fc commit 563270d

File tree

2 files changed

+18
-27
lines changed

2 files changed

+18
-27
lines changed

juniper_rocket_async/examples/rocket_server.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ fn post_graphql_handler(
3232
request.execute_sync(&schema, &context)
3333
}
3434

35-
fn main() {
35+
#[rocket::main]
36+
async fn main() {
3637
rocket::ignite()
3738
.manage(Database::new())
3839
.manage(Schema::new(
@@ -45,5 +46,6 @@ fn main() {
4546
rocket::routes![graphiql, get_graphql_handler, post_graphql_handler],
4647
)
4748
.launch()
49+
.await
4850
.expect("server to launch");
4951
}

juniper_rocket_async/src/lib.rs

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -325,25 +325,15 @@ where
325325
}
326326
}
327327

328-
use rocket::futures::future::BoxFuture;
329-
330-
impl<'r> Responder<'r> for GraphQLResponse {
331-
fn respond_to<'a, 'x>(self, _req: &'r Request<'a>) -> BoxFuture<'x, response::Result<'r>>
332-
where
333-
'a: 'x,
334-
'r: 'x,
335-
Self: 'x,
336-
{
328+
impl<'r, 'o: 'r> Responder<'r, 'o> for GraphQLResponse {
329+
fn respond_to(self, _req: &'r Request<'_>) -> response::Result<'o> {
337330
let GraphQLResponse(status, body) = self;
338331

339-
Box::pin(async move {
340-
Ok(Response::build()
341-
.header(ContentType::new("application", "json"))
342-
.status(status)
343-
.sized_body(Cursor::new(body))
344-
.await
345-
.finalize())
346-
})
332+
Response::build()
333+
.header(ContentType::new("application", "json"))
334+
.status(status)
335+
.sized_body(body.len(), Cursor::new(body))
336+
.ok()
347337
}
348338
}
349339

@@ -528,10 +518,10 @@ mod tests {
528518
}
529519
}
530520

531-
#[test]
532-
fn test_rocket_integration() {
521+
#[tokio::test]
522+
async fn test_rocket_integration() {
533523
let rocket = make_rocket();
534-
let client = Client::new(rocket).expect("valid rocket");
524+
let client = Client::new(rocket).await.expect("valid rocket");
535525
let integration = TestRocketIntegration { client };
536526

537527
http_tests::run_http_test_suite(&integration);
@@ -551,7 +541,7 @@ mod tests {
551541

552542
let rocket = make_rocket_without_routes()
553543
.mount("/", routes![post_graphql_assert_operation_name_handler]);
554-
let client = Client::new(rocket).expect("valid rocket");
544+
let client = Client::new(rocket).await.expect("valid rocket");
555545

556546
let resp = client
557547
.post("/")
@@ -583,14 +573,13 @@ mod tests {
583573
.expect("No content type header from handler")
584574
.to_string();
585575
let body = response
586-
.body()
587-
.expect("No body returned from GraphQL handler")
588-
.into_string()
589-
.await;
576+
.body_string()
577+
.await
578+
.expect("No body returned from GraphQL handler");
590579

591580
http_tests::TestResponse {
592581
status_code,
593-
body,
582+
body: Some(body),
594583
content_type,
595584
}
596585
}

0 commit comments

Comments
 (0)