Remove async_closure feature usage
This commit is contained in:
parent
639c29e91e
commit
5d3ed9ac72
9 changed files with 74 additions and 108 deletions
|
@ -2,8 +2,6 @@
|
|||
//! This example demonstrates async/await usage with warp.
|
||||
//! NOTE: this uses tokio 0.1 , not the alpha tokio 0.2.
|
||||
|
||||
#![feature(async_closure)]
|
||||
|
||||
use juniper::{EmptyMutation, RootNode, FieldError};
|
||||
use warp::{http::Response, Filter};
|
||||
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
#![feature(async_closure)]
|
||||
|
||||
use juniper::{graphql_value, RootNode, Value};
|
||||
|
||||
#[derive(juniper::GraphQLEnum)]
|
||||
|
|
|
@ -91,7 +91,6 @@ Juniper has not reached 1.0 yet, thus some API instability should be expected.
|
|||
|
||||
#![doc(html_root_url = "https://docs.rs/juniper/0.13.1")]
|
||||
#![warn(missing_docs)]
|
||||
#![cfg_attr(feature = "async", feature(async_closure))]
|
||||
|
||||
#[doc(hidden)]
|
||||
pub extern crate serde;
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
#![feature(async_closure)]
|
||||
|
||||
use juniper::{
|
||||
object, DefaultScalarValue, ExecutionError, FieldError, GraphQLEnum, Value, Variables,
|
||||
};
|
||||
|
|
|
@ -59,7 +59,7 @@ pub fn build_derive_object(ast: syn::DeriveInput, is_internal: bool) -> TokenStr
|
|||
description: field_attrs.description,
|
||||
deprecation: field_attrs.deprecation,
|
||||
resolver_code,
|
||||
resolver_code_async: None,
|
||||
is_async: false,
|
||||
})
|
||||
}
|
||||
});
|
||||
|
|
|
@ -197,29 +197,10 @@ pub fn build_object(args: TokenStream, body: TokenStream, is_internal: bool) ->
|
|||
}
|
||||
|
||||
let body = &method.block;
|
||||
let return_ty = &method.sig.output;
|
||||
|
||||
let (resolver_code, resolver_code_async) = if is_async {
|
||||
(
|
||||
quote!(),
|
||||
Some(quote!(
|
||||
(async move || #return_ty {
|
||||
#( #resolve_parts )*
|
||||
#body
|
||||
})()
|
||||
)),
|
||||
)
|
||||
} else {
|
||||
(
|
||||
quote!(
|
||||
(|| #return_ty {
|
||||
#( #resolve_parts )*
|
||||
#body
|
||||
})()
|
||||
),
|
||||
None,
|
||||
)
|
||||
};
|
||||
let resolver_code = quote!(
|
||||
#( #resolve_parts )*
|
||||
#body
|
||||
);
|
||||
|
||||
let ident = &method.sig.ident;
|
||||
let name = attrs
|
||||
|
@ -233,7 +214,7 @@ pub fn build_object(args: TokenStream, body: TokenStream, is_internal: bool) ->
|
|||
description: attrs.description,
|
||||
deprecation: attrs.deprecation,
|
||||
resolver_code,
|
||||
resolver_code_async,
|
||||
is_async,
|
||||
});
|
||||
}
|
||||
_ => {
|
||||
|
|
|
@ -592,14 +592,7 @@ pub struct GraphQLTypeDefinitionField {
|
|||
pub deprecation: Option<DeprecationAttr>,
|
||||
pub args: Vec<GraphQLTypeDefinitionFieldArg>,
|
||||
pub resolver_code: proc_macro2::TokenStream,
|
||||
pub resolver_code_async: Option<proc_macro2::TokenStream>,
|
||||
}
|
||||
|
||||
impl GraphQLTypeDefinitionField {
|
||||
#[inline]
|
||||
fn is_async(&self) -> bool {
|
||||
self.resolver_code_async.is_some()
|
||||
}
|
||||
pub is_async: bool,
|
||||
}
|
||||
|
||||
/// Definition of a graphql type based on information extracted
|
||||
|
@ -633,7 +626,7 @@ pub struct GraphQLTypeDefiniton {
|
|||
|
||||
impl GraphQLTypeDefiniton {
|
||||
fn has_async_field(&self) -> bool {
|
||||
self.fields.iter().any(|field| field.is_async())
|
||||
self.fields.iter().any(|field| field.is_async)
|
||||
}
|
||||
|
||||
pub fn into_tokens(self, juniper_crate_name: &str) -> proc_macro2::TokenStream {
|
||||
|
@ -706,7 +699,7 @@ impl GraphQLTypeDefiniton {
|
|||
let name = &field.name;
|
||||
let code = &field.resolver_code;
|
||||
|
||||
if field.is_async() {
|
||||
if field.is_async {
|
||||
// TODO: better error message with field/type name.
|
||||
quote!(
|
||||
#name => {
|
||||
|
@ -714,9 +707,10 @@ impl GraphQLTypeDefiniton {
|
|||
},
|
||||
)
|
||||
} else {
|
||||
let _type = &field._type;
|
||||
quote!(
|
||||
#name => {
|
||||
let res = { #code };
|
||||
let res: #_type = { #code };
|
||||
#juniper_crate_name::IntoResolvable::into(
|
||||
res,
|
||||
executor.context()
|
||||
|
@ -805,74 +799,74 @@ impl GraphQLTypeDefiniton {
|
|||
#[cfg(feature = "async")]
|
||||
let resolve_field_async = {
|
||||
let resolve_matches_async = self.fields.iter().map(|field| {
|
||||
let name = &field.name;
|
||||
let name = &field.name;
|
||||
let _type = &field._type;
|
||||
let code = &field.resolver_code;
|
||||
|
||||
if let Some(code) = field.resolver_code_async.as_ref() {
|
||||
quote!(
|
||||
#name => {
|
||||
let f = async move {
|
||||
let res = { #code }.await;
|
||||
if field.is_async {
|
||||
quote!(
|
||||
#name => {
|
||||
let f = async move {
|
||||
let res: #_type = async move { #code }.await;
|
||||
|
||||
let inner_res = #juniper_crate_name::IntoResolvable::into(
|
||||
res,
|
||||
executor.context()
|
||||
);
|
||||
match inner_res {
|
||||
Ok(Some((ctx, r))) => {
|
||||
let subexec = executor
|
||||
.replaced_context(ctx);
|
||||
subexec.resolve_with_ctx_async(&(), &r)
|
||||
.await
|
||||
},
|
||||
Ok(None) => Ok(#juniper_crate_name::Value::null()),
|
||||
Err(e) => Err(e),
|
||||
}
|
||||
};
|
||||
future::FutureExt::boxed(f)
|
||||
},
|
||||
)
|
||||
} else {
|
||||
let code = &field.resolver_code;
|
||||
|
||||
let inner = if !self.no_async {
|
||||
quote!(
|
||||
let f = async move {
|
||||
match res2 {
|
||||
Ok(Some((ctx, r))) => {
|
||||
let sub = executor.replaced_context(ctx);
|
||||
sub.resolve_with_ctx_async(&(), &r).await
|
||||
},
|
||||
Ok(None) => Ok(#juniper_crate_name::Value::null()),
|
||||
Err(e) => Err(e),
|
||||
}
|
||||
};
|
||||
future::FutureExt::boxed(f)
|
||||
)
|
||||
} else {
|
||||
quote!(
|
||||
let v = match res2 {
|
||||
Ok(Some((ctx, r))) => executor.replaced_context(ctx).resolve_with_ctx(&(), &r),
|
||||
Ok(None) => Ok(#juniper_crate_name::Value::null()),
|
||||
Err(e) => Err(e),
|
||||
};
|
||||
future::FutureExt::boxed(future::ready(v))
|
||||
)
|
||||
let inner_res = #juniper_crate_name::IntoResolvable::into(
|
||||
res,
|
||||
executor.context()
|
||||
);
|
||||
match inner_res {
|
||||
Ok(Some((ctx, r))) => {
|
||||
let subexec = executor
|
||||
.replaced_context(ctx);
|
||||
subexec.resolve_with_ctx_async(&(), &r)
|
||||
.await
|
||||
},
|
||||
Ok(None) => Ok(#juniper_crate_name::Value::null()),
|
||||
Err(e) => Err(e),
|
||||
}
|
||||
};
|
||||
future::FutureExt::boxed(f)
|
||||
},
|
||||
)
|
||||
} else {
|
||||
let inner = if !self.no_async {
|
||||
quote!(
|
||||
let f = async move {
|
||||
match res2 {
|
||||
Ok(Some((ctx, r))) => {
|
||||
let sub = executor.replaced_context(ctx);
|
||||
sub.resolve_with_ctx_async(&(), &r).await
|
||||
},
|
||||
Ok(None) => Ok(#juniper_crate_name::Value::null()),
|
||||
Err(e) => Err(e),
|
||||
}
|
||||
};
|
||||
future::FutureExt::boxed(f)
|
||||
)
|
||||
} else {
|
||||
quote!(
|
||||
let v = match res2 {
|
||||
Ok(Some((ctx, r))) => executor.replaced_context(ctx).resolve_with_ctx(&(), &r),
|
||||
Ok(None) => Ok(#juniper_crate_name::Value::null()),
|
||||
Err(e) => Err(e),
|
||||
};
|
||||
future::FutureExt::boxed(future::ready(v))
|
||||
)
|
||||
};
|
||||
|
||||
quote!(
|
||||
#name => {
|
||||
let res = { #code };
|
||||
let res2 = #juniper_crate_name::IntoResolvable::into(
|
||||
res,
|
||||
executor.context()
|
||||
);
|
||||
#inner
|
||||
},
|
||||
)
|
||||
}
|
||||
});
|
||||
quote!(
|
||||
#name => {
|
||||
let res: #_type = { #code };
|
||||
let res2 = #juniper_crate_name::IntoResolvable::into(
|
||||
res,
|
||||
executor.context()
|
||||
);
|
||||
#inner
|
||||
},
|
||||
)
|
||||
}
|
||||
});
|
||||
|
||||
let mut where_async = where_clause.cloned().unwrap_or_else(|| parse_quote!(where));;
|
||||
let mut where_async = where_clause.cloned().unwrap_or_else(|| parse_quote!(where));
|
||||
|
||||
where_async
|
||||
.predicates
|
||||
|
|
|
@ -38,7 +38,6 @@ 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_closure))]
|
||||
|
||||
use std::{error::Error, io::Cursor};
|
||||
|
||||
|
|
|
@ -39,7 +39,6 @@ Check the LICENSE file for details.
|
|||
#![deny(missing_docs)]
|
||||
#![deny(warnings)]
|
||||
#![doc(html_root_url = "https://docs.rs/juniper_warp/0.2.0")]
|
||||
#![cfg_attr(feature = "async", feature(async_closure))]
|
||||
|
||||
use futures::{future::poll_fn, Future};
|
||||
use serde::Deserialize;
|
||||
|
|
Loading…
Reference in a new issue