Remove async-trait
[skip ci]
This commit is contained in:
parent
a5580a939d
commit
2144ad0d7d
9 changed files with 79 additions and 93 deletions
|
@ -35,7 +35,6 @@ default = [
|
|||
[dependencies]
|
||||
juniper_codegen = { version = "0.14.1", path = "../juniper_codegen" }
|
||||
|
||||
async-trait = "0.1.16"
|
||||
chrono = { version = "0.4.0", optional = true }
|
||||
fnv = "1.0.3"
|
||||
futures = { version = "=0.3.1", optional = true }
|
||||
|
|
|
@ -423,16 +423,12 @@ macro_rules! graphql_scalar {
|
|||
)
|
||||
{
|
||||
|
||||
fn resolve_async<'a, 'async_trait>(
|
||||
fn resolve_async<'a>(
|
||||
&'a self,
|
||||
info: &'a Self::TypeInfo,
|
||||
selection_set: Option<&'a [$crate::Selection<'a, $crate::__juniper_insert_generic!($($scalar)+)>]>,
|
||||
executor: &'a $crate::Executor<'a, Self::Context, $crate::__juniper_insert_generic!($($scalar)+)>,
|
||||
) -> $crate::BoxFuture<'async_trait, $crate::Value<$crate::__juniper_insert_generic!($($scalar)+)>>
|
||||
where
|
||||
'a: 'async_trait,
|
||||
Self: 'async_trait,
|
||||
{
|
||||
selection_set: Option<&'a [$crate::Selection<$crate::__juniper_insert_generic!($($scalar)+)>]>,
|
||||
executor: &'a $crate::Executor<Self::Context, $crate::__juniper_insert_generic!($($scalar)+)>,
|
||||
) -> $crate::BoxFuture<'a, $crate::Value<$crate::__juniper_insert_generic!($($scalar)+)>> {
|
||||
use $crate::GraphQLType;
|
||||
use futures::future;
|
||||
let v = self.resolve(info, selection_set, executor);
|
||||
|
|
|
@ -77,7 +77,6 @@ where
|
|||
}
|
||||
|
||||
#[cfg(feature = "async")]
|
||||
#[async_trait::async_trait]
|
||||
impl<'a, CtxT, S, QueryT, MutationT> crate::GraphQLTypeAsync<S>
|
||||
for RootNode<'a, QueryT, MutationT, S>
|
||||
where
|
||||
|
@ -86,25 +85,25 @@ where
|
|||
QueryT::TypeInfo: Send + Sync,
|
||||
MutationT: crate::GraphQLTypeAsync<S, Context = CtxT>,
|
||||
MutationT::TypeInfo: Send + Sync,
|
||||
CtxT: Send + Sync + 'a,
|
||||
for<'c> &'c S: ScalarRefValue<'c>,
|
||||
CtxT: Send + Sync,
|
||||
for<'b> &'b S: ScalarRefValue<'b>,
|
||||
{
|
||||
async fn resolve_field_async<'b>(
|
||||
fn resolve_field_async<'b>(
|
||||
&'b self,
|
||||
info: &'b <Self as crate::GraphQLType<S>>::TypeInfo,
|
||||
info: &'b Self::TypeInfo,
|
||||
field_name: &'b str,
|
||||
arguments: &'b Arguments<'b, S>,
|
||||
executor: &'b Executor<'b, <Self as crate::GraphQLType<S>>::Context, S>,
|
||||
) -> ExecutionResult<S> {
|
||||
arguments: &'b Arguments<S>,
|
||||
executor: &'b Executor<Self::Context, S>,
|
||||
) -> crate::BoxFuture<'b, ExecutionResult<S>> {
|
||||
use futures::future::{ready, FutureExt};
|
||||
match field_name {
|
||||
"__schema" | "__type" => {
|
||||
self.resolve_field(info, field_name, arguments, executor)
|
||||
let v = self.resolve_field(info, field_name, arguments, executor);
|
||||
Box::pin(ready(v))
|
||||
}
|
||||
_ => self
|
||||
.query_type
|
||||
.resolve_field_async(info, field_name, arguments, executor)
|
||||
.await
|
||||
.resolve_field_async(info, field_name, arguments, executor),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,7 +12,6 @@ use crate::BoxFuture;
|
|||
|
||||
use super::base::{is_excluded, merge_key_into, Arguments, GraphQLType};
|
||||
|
||||
#[async_trait::async_trait]
|
||||
pub trait GraphQLTypeAsync<S>: GraphQLType<S> + Send + Sync
|
||||
where
|
||||
Self::Context: Send + Sync,
|
||||
|
@ -20,38 +19,41 @@ where
|
|||
S: ScalarValue + Send + Sync,
|
||||
for<'b> &'b S: ScalarRefValue<'b>,
|
||||
{
|
||||
async fn resolve_field_async<'a>(
|
||||
fn resolve_field_async<'a>(
|
||||
&'a self,
|
||||
info: &'a Self::TypeInfo,
|
||||
field_name: &'a str,
|
||||
arguments: &'a Arguments<'a, S>,
|
||||
executor: &'a Executor<'a, Self::Context, S>,
|
||||
) -> ExecutionResult<S> {
|
||||
arguments: &'a Arguments<S>,
|
||||
executor: &'a Executor<Self::Context, S>,
|
||||
) -> BoxFuture<'a, ExecutionResult<S>> {
|
||||
panic!("resolve_field must be implemented by object types");
|
||||
}
|
||||
|
||||
async fn resolve_async<'a>(
|
||||
fn resolve_async<'a>(
|
||||
&'a self,
|
||||
info: &'a Self::TypeInfo,
|
||||
selection_set: Option<&'a [Selection<'a, S>]>,
|
||||
executor: &'a Executor<'a, Self::Context, S>,
|
||||
) -> Value<S> {
|
||||
selection_set: Option<&'a [Selection<S>]>,
|
||||
executor: &'a Executor<Self::Context, S>,
|
||||
) -> BoxFuture<'a, Value<S>> {
|
||||
if let Some(selection_set) = selection_set {
|
||||
resolve_selection_set_into_async(self, info, selection_set, executor).await
|
||||
resolve_selection_set_into_async(self, info, selection_set, executor)
|
||||
} else {
|
||||
panic!("resolve() must be implemented by non-object output types");
|
||||
}
|
||||
}
|
||||
|
||||
async fn resolve_into_type_async<'a>(
|
||||
fn resolve_into_type_async<'a>(
|
||||
&'a self,
|
||||
info: &'a Self::TypeInfo,
|
||||
type_name: &str,
|
||||
selection_set: Option<&'a [Selection<'a, S>]>,
|
||||
executor: &'a Executor<'a, Self::Context, S>,
|
||||
) -> ExecutionResult<S> {
|
||||
) -> BoxFuture<'a, ExecutionResult<S>> {
|
||||
if Self::name(info).unwrap() == type_name {
|
||||
Ok(self.resolve_async(info, selection_set, executor).await)
|
||||
Box::pin(async move {
|
||||
let res = self.resolve_async(info, selection_set, executor).await;
|
||||
Ok(res)
|
||||
})
|
||||
} else {
|
||||
panic!("resolve_into_type_async must be implemented by unions and interfaces");
|
||||
}
|
||||
|
|
|
@ -257,7 +257,6 @@ where
|
|||
}
|
||||
|
||||
#[cfg(feature = "async")]
|
||||
#[async_trait::async_trait]
|
||||
impl<S, T, CtxT> crate::GraphQLTypeAsync<S> for Vec<T>
|
||||
where
|
||||
T: crate::GraphQLTypeAsync<S, Context = CtxT>,
|
||||
|
@ -266,18 +265,18 @@ where
|
|||
CtxT: Send + Sync,
|
||||
for<'b> &'b S: ScalarRefValue<'b>,
|
||||
{
|
||||
async fn resolve_async<'a>(
|
||||
fn resolve_async<'a>(
|
||||
&'a self,
|
||||
info: &'a <Self as crate::GraphQLType<S>>::TypeInfo,
|
||||
selection_set: Option<&'a [Selection<'a, S>]>,
|
||||
executor: &'a Executor<'a, <Self as crate::GraphQLType<S>>::Context, S>,
|
||||
) -> Value<S> {
|
||||
resolve_into_list_async(executor, info, self.iter()).await
|
||||
info: &'a Self::TypeInfo,
|
||||
selection_set: Option<&'a [Selection<S>]>,
|
||||
executor: &'a Executor<Self::Context, S>,
|
||||
) -> crate::BoxFuture<'a, Value<S>> {
|
||||
let f = resolve_into_list_async(executor, info, self.iter());
|
||||
Box::pin(f)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "async")]
|
||||
#[async_trait::async_trait]
|
||||
impl<S, T, CtxT> crate::GraphQLTypeAsync<S> for &[T]
|
||||
where
|
||||
T: crate::GraphQLTypeAsync<S, Context = CtxT>,
|
||||
|
@ -286,18 +285,18 @@ where
|
|||
CtxT: Send + Sync,
|
||||
for<'b> &'b S: ScalarRefValue<'b>,
|
||||
{
|
||||
async fn resolve_async<'a>(
|
||||
fn resolve_async<'a>(
|
||||
&'a self,
|
||||
info: &'a <Self as crate::GraphQLType<S>>::TypeInfo,
|
||||
selection_set: Option<&'a [Selection<'a, S>]>,
|
||||
executor: &'a Executor<'a, <Self as crate::GraphQLType<S>>::Context, S>,
|
||||
) -> Value<S> {
|
||||
resolve_into_list_async(executor, info, self.iter()).await
|
||||
info: &'a Self::TypeInfo,
|
||||
selection_set: Option<&'a [Selection<S>]>,
|
||||
executor: &'a Executor<Self::Context, S>,
|
||||
) -> crate::BoxFuture<'a, Value<S>> {
|
||||
let f = resolve_into_list_async(executor, info, self.iter());
|
||||
Box::pin(f)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "async")]
|
||||
#[async_trait::async_trait]
|
||||
impl<S, T, CtxT> crate::GraphQLTypeAsync<S> for Option<T>
|
||||
where
|
||||
T: crate::GraphQLTypeAsync<S, Context = CtxT>,
|
||||
|
@ -306,15 +305,18 @@ where
|
|||
CtxT: Send + Sync,
|
||||
for<'b> &'b S: ScalarRefValue<'b>,
|
||||
{
|
||||
async fn resolve_async<'a>(
|
||||
fn resolve_async<'a>(
|
||||
&'a self,
|
||||
info: &'a <Self as crate::GraphQLType<S>>::TypeInfo,
|
||||
selection_set: Option<&'a [Selection<'a, S>]>,
|
||||
executor: &'a Executor<'a, <Self as crate::GraphQLType<S>>::Context, S>,
|
||||
) -> Value<S> {
|
||||
match *self {
|
||||
Some(ref obj) => executor.resolve_into_value_async(info, obj).await,
|
||||
None => Value::null(),
|
||||
}
|
||||
info: &'a Self::TypeInfo,
|
||||
selection_set: Option<&'a [Selection<S>]>,
|
||||
executor: &'a Executor<Self::Context, S>,
|
||||
) -> crate::BoxFuture<'a, Value<S>> {
|
||||
let f = async move {
|
||||
match *self {
|
||||
Some(ref obj) => executor.resolve_into_value_async(info, obj).await,
|
||||
None => Value::null(),
|
||||
}
|
||||
};
|
||||
Box::pin(f)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -137,7 +137,6 @@ where
|
|||
}
|
||||
|
||||
#[cfg(feature = "async")]
|
||||
#[async_trait::async_trait]
|
||||
impl<'e, S, T> crate::GraphQLTypeAsync<S> for &'e T
|
||||
where
|
||||
S: ScalarValue + Send + Sync,
|
||||
|
@ -146,24 +145,23 @@ where
|
|||
T::Context: Send + Sync,
|
||||
for<'c> &'c S: ScalarRefValue<'c>,
|
||||
{
|
||||
async fn resolve_field_async<'b>(
|
||||
fn resolve_field_async<'b>(
|
||||
&'b self,
|
||||
info: &'b <Self as crate::GraphQLType<S>>::TypeInfo,
|
||||
info: &'b Self::TypeInfo,
|
||||
field_name: &'b str,
|
||||
arguments: &'b Arguments<'b, S>,
|
||||
executor: &'b Executor<'b, <Self as crate::GraphQLType<S>>::Context, S>,
|
||||
) -> ExecutionResult<S> {
|
||||
arguments: &'b Arguments<S>,
|
||||
executor: &'b Executor<Self::Context, S>,
|
||||
) -> crate::BoxFuture<'b, ExecutionResult<S>> {
|
||||
crate::GraphQLTypeAsync::resolve_field_async(&**self, info, field_name, arguments, executor)
|
||||
.await
|
||||
}
|
||||
|
||||
async fn resolve_async<'a>(
|
||||
fn resolve_async<'a>(
|
||||
&'a self,
|
||||
info: &'a <Self as crate::GraphQLType<S>>::TypeInfo,
|
||||
selection_set: Option<&'a [Selection<'a, S>]>,
|
||||
executor: &'a Executor<'a, <Self as crate::GraphQLType<S>>::Context, S>,
|
||||
) -> Value<S> {
|
||||
crate::GraphQLTypeAsync::resolve_async(&**self, info, selection_set, executor).await
|
||||
info: &'a Self::TypeInfo,
|
||||
selection_set: Option<&'a [Selection<S>]>,
|
||||
executor: &'a Executor<Self::Context, S>,
|
||||
) -> crate::BoxFuture<'a, Value<S>> {
|
||||
crate::GraphQLTypeAsync::resolve_async(&**self, info, selection_set, executor)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -197,19 +197,19 @@ where
|
|||
}
|
||||
|
||||
#[cfg(feature = "async")]
|
||||
#[async_trait::async_trait]
|
||||
impl<'e, S> crate::GraphQLTypeAsync<S> for &'e str
|
||||
where
|
||||
S: ScalarValue + Send + Sync,
|
||||
for<'b> &'b S: ScalarRefValue<'b>,
|
||||
{
|
||||
async fn resolve_async<'a>(
|
||||
fn resolve_async<'a>(
|
||||
&'a self,
|
||||
info: &'a <Self as crate::GraphQLType<S>>::TypeInfo,
|
||||
selection_set: Option<&'a [Selection<'a, S>]>,
|
||||
executor: &'a Executor<'a, <Self as crate::GraphQLType<S>>::Context, S>,
|
||||
) -> crate::Value<S> {
|
||||
self.resolve(info, selection_set, executor)
|
||||
info: &'a Self::TypeInfo,
|
||||
selection_set: Option<&'a [Selection<S>]>,
|
||||
executor: &'a Executor<Self::Context, S>,
|
||||
) -> crate::BoxFuture<'a, crate::Value<S>> {
|
||||
use futures::future;
|
||||
future::FutureExt::boxed(future::ready(self.resolve(info, selection_set, executor)))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -213,16 +213,12 @@ pub fn impl_enum(ast: &syn::DeriveInput, is_internal: bool) -> TokenStream {
|
|||
__S: #juniper_path::ScalarValue + Send + Sync,
|
||||
for<'__b> &'__b __S: #juniper_path::ScalarRefValue<'__b>
|
||||
{
|
||||
fn resolve_async<'a, 'async_trait>(
|
||||
fn resolve_async<'a>(
|
||||
&'a self,
|
||||
info: &'a Self::TypeInfo,
|
||||
selection_set: Option<&'a [#juniper_path::Selection<__S>]>,
|
||||
executor: &'a #juniper_path::Executor<Self::Context, __S>,
|
||||
) -> #juniper_path::BoxFuture<'async_trait, #juniper_path::Value<__S>>
|
||||
where
|
||||
'a: 'async_trait,
|
||||
Self: 'async_trait
|
||||
{
|
||||
) -> #juniper_path::BoxFuture<'a, #juniper_path::Value<__S>> {
|
||||
use #juniper_path::GraphQLType;
|
||||
use futures::future;
|
||||
let v = self.resolve(info, selection_set, executor);
|
||||
|
|
|
@ -932,27 +932,21 @@ impl GraphQLTypeDefiniton {
|
|||
impl#impl_generics #juniper_crate_name::GraphQLTypeAsync<#scalar> for #ty #type_generics_tokens
|
||||
#where_async
|
||||
{
|
||||
fn resolve_field_async<'b, 'async_trait>(
|
||||
fn resolve_field_async<'b>(
|
||||
&'b self,
|
||||
info: &'b Self::TypeInfo,
|
||||
field: &'b str,
|
||||
args: &'b #juniper_crate_name::Arguments<#scalar>,
|
||||
executor: &'b #juniper_crate_name::Executor<Self::Context, #scalar>,
|
||||
) -> #juniper_crate_name::BoxFuture<'async_trait, #juniper_crate_name::ExecutionResult<#scalar>>
|
||||
where
|
||||
#scalar: Send + Sync,
|
||||
'b: 'async_trait,
|
||||
Self: 'async_trait,
|
||||
) -> #juniper_crate_name::BoxFuture<'b, #juniper_crate_name::ExecutionResult<#scalar>>
|
||||
where #scalar: Send + Sync,
|
||||
{
|
||||
use futures::future;
|
||||
use #juniper_crate_name::GraphQLType;
|
||||
match field {
|
||||
#( #resolve_matches_async )*
|
||||
_ => {
|
||||
panic!("Field {} not found on type {:?}",
|
||||
field,
|
||||
<Self as #juniper_crate_name::GraphQLType<#scalar>>::name(info)
|
||||
);
|
||||
panic!("Field {} not found on type {}", field, "Mutation");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue