From 47e7003a7b9e6227b97059be4689ad26cb1f442e Mon Sep 17 00:00:00 2001 From: Graeme Coupar Date: Wed, 21 Aug 2019 13:16:19 +0100 Subject: [PATCH] Fix the rest of the rocket stuff --- juniper_rocket/Cargo.toml | 4 ++-- juniper_rocket/src/lib.rs | 42 +++++++++++++++++++++++---------------- 2 files changed, 27 insertions(+), 19 deletions(-) diff --git a/juniper_rocket/Cargo.toml b/juniper_rocket/Cargo.toml index e1bc0564..1d8feda5 100644 --- a/juniper_rocket/Cargo.toml +++ b/juniper_rocket/Cargo.toml @@ -12,7 +12,7 @@ repository = "https://github.com/graphql-rust/juniper" edition = "2018" [features] -async = [ "juniper/async", "futures03" ] +async = [ "juniper/async" ] [dependencies] serde = { version = "1.0.2" } @@ -20,7 +20,7 @@ serde_json = { version = "1.0.2" } serde_derive = { version = "1.0.2" } juniper = { version = "0.14.0", default-features = false, path = "../juniper"} -futures03 = { version = "0.3.0-alpha.18", optional = true, package = "futures-preview", features = ["compat"] } +futures03 = { version = "0.3.0-alpha.18", package = "futures-preview", features = ["compat"] } rocket = { git = "https://github.com/SergioBenitez/Rocket", branch = "async" } [dev-dependencies.juniper] diff --git a/juniper_rocket/src/lib.rs b/juniper_rocket/src/lib.rs index 9ebe0bbf..891a3723 100644 --- a/juniper_rocket/src/lib.rs +++ b/juniper_rocket/src/lib.rs @@ -38,12 +38,11 @@ Check the LICENSE file for details. #![doc(html_root_url = "https://docs.rs/juniper_rocket/0.2.0")] #![feature(decl_macro, proc_macro_hygiene)] - #![cfg_attr(feature = "async", feature(async_await, async_closure))] use std::{ error::Error, - io::{Cursor, Read}, + io::Cursor, }; use rocket::{ @@ -63,6 +62,9 @@ use juniper::{ ScalarValue, }; +#[cfg(feature = "async")] +use juniper::GraphQLTypeAsync; + #[cfg(feature = "async")] use futures03::future::{FutureExt, TryFutureExt}; @@ -71,7 +73,7 @@ use futures03::future::{FutureExt, TryFutureExt}; #[serde(bound = "InputValue: Deserialize<'de>")] enum GraphQLBatchRequest where - S: ScalarValue, + S: ScalarValue + Sync + Send, { Single(http::GraphQLRequest), Batch(Vec>), @@ -81,7 +83,7 @@ where #[serde(untagged)] enum GraphQLBatchResponse<'a, S = DefaultScalarValue> where - S: ScalarValue, + S: ScalarValue + Sync + Send, { Single(http::GraphQLResponse<'a, S>), Batch(Vec>), @@ -89,7 +91,7 @@ where impl GraphQLBatchRequest where - S: ScalarValue, + S: ScalarValue + Send + Sync, for<'b> &'b S: ScalarRefValue<'b>, { pub fn execute<'a, CtxT, QueryT, MutationT>( @@ -118,11 +120,14 @@ where pub async fn execute_async<'a, CtxT, QueryT, MutationT>( &'a self, root_node: &'a RootNode<'_, QueryT, MutationT, S>, - context: &CtxT, + context: &'a CtxT, ) -> GraphQLBatchResponse<'a, S> where - QueryT: GraphQLType, - MutationT: GraphQLType, + QueryT: GraphQLTypeAsync + Send + Sync, + QueryT::TypeInfo: Send + Sync, + MutationT: GraphQLTypeAsync + Send + Sync, + MutationT::TypeInfo: Send + Sync, + CtxT: Send + Sync, { match self { &GraphQLBatchRequest::Single(ref request) => { @@ -135,7 +140,7 @@ where .collect::>(); GraphQLBatchResponse::Batch(futures03::future::join_all(futures).await) - }, + } } } @@ -151,7 +156,7 @@ where impl<'a, S> GraphQLBatchResponse<'a, S> where - S: ScalarValue, + S: ScalarValue + Send + Sync, { fn is_ok(&self) -> bool { match self { @@ -171,7 +176,7 @@ where #[derive(Debug, PartialEq)] pub struct GraphQLRequest(GraphQLBatchRequest) where - S: ScalarValue; + S: ScalarValue + Send + Sync; /// Simple wrapper around the result of executing a GraphQL query pub struct GraphQLResponse(pub Status, pub String); @@ -190,7 +195,7 @@ pub fn playground_source(graphql_endpoint_url: &str) -> content::Html { impl GraphQLRequest where - S: ScalarValue, + S: ScalarValue + Sync + Send, for<'b> &'b S: ScalarRefValue<'b>, { /// Execute an incoming GraphQL query @@ -222,8 +227,11 @@ where context: &CtxT, ) -> GraphQLResponse where - QueryT: GraphQLType, - MutationT: GraphQLType, + QueryT: GraphQLTypeAsync + Send + Sync, + QueryT::TypeInfo: Send + Sync, + MutationT: GraphQLTypeAsync + Send + Sync, + MutationT::TypeInfo: Send + Sync, + CtxT: Send + Sync, { let response = self.0.execute_async(root_node, context).await; let status = if response.is_ok() { @@ -301,7 +309,7 @@ impl GraphQLResponse { impl<'f, S> FromForm<'f> for GraphQLRequest where - S: ScalarValue, + S: ScalarValue + Send + Sync, { type Error = String; @@ -372,7 +380,7 @@ where impl<'v, S> FromFormValue<'v> for GraphQLRequest where - S: ScalarValue, + S: ScalarValue + Send + Sync, { type Error = String; @@ -387,7 +395,7 @@ const BODY_LIMIT: u64 = 1024 * 100; impl FromDataSimple for GraphQLRequest where - S: ScalarValue, + S: ScalarValue + Send + Sync, { type Error = String;