Skip to content

Commit 2144ad0

Browse files
nWackytheduke
authored andcommitted
Remove async-trait [skip ci]
1 parent a5580a9 commit 2144ad0

File tree

9 files changed

+79
-93
lines changed

9 files changed

+79
-93
lines changed

juniper/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ default = [
3535
[dependencies]
3636
juniper_codegen = { version = "0.14.1", path = "../juniper_codegen" }
3737

38-
async-trait = "0.1.16"
3938
chrono = { version = "0.4.0", optional = true }
4039
fnv = "1.0.3"
4140
futures = { version = "=0.3.1", optional = true }

juniper/src/macros/scalar.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -423,16 +423,12 @@ macro_rules! graphql_scalar {
423423
)
424424
{
425425

426-
fn resolve_async<'a, 'async_trait>(
426+
fn resolve_async<'a>(
427427
&'a self,
428428
info: &'a Self::TypeInfo,
429-
selection_set: Option<&'a [$crate::Selection<'a, $crate::__juniper_insert_generic!($($scalar)+)>]>,
430-
executor: &'a $crate::Executor<'a, Self::Context, $crate::__juniper_insert_generic!($($scalar)+)>,
431-
) -> $crate::BoxFuture<'async_trait, $crate::Value<$crate::__juniper_insert_generic!($($scalar)+)>>
432-
where
433-
'a: 'async_trait,
434-
Self: 'async_trait,
435-
{
429+
selection_set: Option<&'a [$crate::Selection<$crate::__juniper_insert_generic!($($scalar)+)>]>,
430+
executor: &'a $crate::Executor<Self::Context, $crate::__juniper_insert_generic!($($scalar)+)>,
431+
) -> $crate::BoxFuture<'a, $crate::Value<$crate::__juniper_insert_generic!($($scalar)+)>> {
436432
use $crate::GraphQLType;
437433
use futures::future;
438434
let v = self.resolve(info, selection_set, executor);

juniper/src/schema/schema.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ where
7777
}
7878

7979
#[cfg(feature = "async")]
80-
#[async_trait::async_trait]
8180
impl<'a, CtxT, S, QueryT, MutationT> crate::GraphQLTypeAsync<S>
8281
for RootNode<'a, QueryT, MutationT, S>
8382
where
@@ -86,25 +85,25 @@ where
8685
QueryT::TypeInfo: Send + Sync,
8786
MutationT: crate::GraphQLTypeAsync<S, Context = CtxT>,
8887
MutationT::TypeInfo: Send + Sync,
89-
CtxT: Send + Sync + 'a,
90-
for<'c> &'c S: ScalarRefValue<'c>,
88+
CtxT: Send + Sync,
89+
for<'b> &'b S: ScalarRefValue<'b>,
9190
{
92-
async fn resolve_field_async<'b>(
91+
fn resolve_field_async<'b>(
9392
&'b self,
94-
info: &'b <Self as crate::GraphQLType<S>>::TypeInfo,
93+
info: &'b Self::TypeInfo,
9594
field_name: &'b str,
96-
arguments: &'b Arguments<'b, S>,
97-
executor: &'b Executor<'b, <Self as crate::GraphQLType<S>>::Context, S>,
98-
) -> ExecutionResult<S> {
95+
arguments: &'b Arguments<S>,
96+
executor: &'b Executor<Self::Context, S>,
97+
) -> crate::BoxFuture<'b, ExecutionResult<S>> {
9998
use futures::future::{ready, FutureExt};
10099
match field_name {
101100
"__schema" | "__type" => {
102-
self.resolve_field(info, field_name, arguments, executor)
101+
let v = self.resolve_field(info, field_name, arguments, executor);
102+
Box::pin(ready(v))
103103
}
104104
_ => self
105105
.query_type
106-
.resolve_field_async(info, field_name, arguments, executor)
107-
.await
106+
.resolve_field_async(info, field_name, arguments, executor),
108107
}
109108
}
110109
}

juniper/src/types/async_await.rs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,46 +12,48 @@ use crate::BoxFuture;
1212

1313
use super::base::{is_excluded, merge_key_into, Arguments, GraphQLType};
1414

15-
#[async_trait::async_trait]
1615
pub trait GraphQLTypeAsync<S>: GraphQLType<S> + Send + Sync
1716
where
1817
Self::Context: Send + Sync,
1918
Self::TypeInfo: Send + Sync,
2019
S: ScalarValue + Send + Sync,
2120
for<'b> &'b S: ScalarRefValue<'b>,
2221
{
23-
async fn resolve_field_async<'a>(
22+
fn resolve_field_async<'a>(
2423
&'a self,
2524
info: &'a Self::TypeInfo,
2625
field_name: &'a str,
27-
arguments: &'a Arguments<'a, S>,
28-
executor: &'a Executor<'a, Self::Context, S>,
29-
) -> ExecutionResult<S> {
26+
arguments: &'a Arguments<S>,
27+
executor: &'a Executor<Self::Context, S>,
28+
) -> BoxFuture<'a, ExecutionResult<S>> {
3029
panic!("resolve_field must be implemented by object types");
3130
}
3231

33-
async fn resolve_async<'a>(
32+
fn resolve_async<'a>(
3433
&'a self,
3534
info: &'a Self::TypeInfo,
36-
selection_set: Option<&'a [Selection<'a, S>]>,
37-
executor: &'a Executor<'a, Self::Context, S>,
38-
) -> Value<S> {
35+
selection_set: Option<&'a [Selection<S>]>,
36+
executor: &'a Executor<Self::Context, S>,
37+
) -> BoxFuture<'a, Value<S>> {
3938
if let Some(selection_set) = selection_set {
40-
resolve_selection_set_into_async(self, info, selection_set, executor).await
39+
resolve_selection_set_into_async(self, info, selection_set, executor)
4140
} else {
4241
panic!("resolve() must be implemented by non-object output types");
4342
}
4443
}
4544

46-
async fn resolve_into_type_async<'a>(
45+
fn resolve_into_type_async<'a>(
4746
&'a self,
4847
info: &'a Self::TypeInfo,
4948
type_name: &str,
5049
selection_set: Option<&'a [Selection<'a, S>]>,
5150
executor: &'a Executor<'a, Self::Context, S>,
52-
) -> ExecutionResult<S> {
51+
) -> BoxFuture<'a, ExecutionResult<S>> {
5352
if Self::name(info).unwrap() == type_name {
54-
Ok(self.resolve_async(info, selection_set, executor).await)
53+
Box::pin(async move {
54+
let res = self.resolve_async(info, selection_set, executor).await;
55+
Ok(res)
56+
})
5557
} else {
5658
panic!("resolve_into_type_async must be implemented by unions and interfaces");
5759
}

juniper/src/types/containers.rs

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,6 @@ where
257257
}
258258

259259
#[cfg(feature = "async")]
260-
#[async_trait::async_trait]
261260
impl<S, T, CtxT> crate::GraphQLTypeAsync<S> for Vec<T>
262261
where
263262
T: crate::GraphQLTypeAsync<S, Context = CtxT>,
@@ -266,18 +265,18 @@ where
266265
CtxT: Send + Sync,
267266
for<'b> &'b S: ScalarRefValue<'b>,
268267
{
269-
async fn resolve_async<'a>(
268+
fn resolve_async<'a>(
270269
&'a self,
271-
info: &'a <Self as crate::GraphQLType<S>>::TypeInfo,
272-
selection_set: Option<&'a [Selection<'a, S>]>,
273-
executor: &'a Executor<'a, <Self as crate::GraphQLType<S>>::Context, S>,
274-
) -> Value<S> {
275-
resolve_into_list_async(executor, info, self.iter()).await
270+
info: &'a Self::TypeInfo,
271+
selection_set: Option<&'a [Selection<S>]>,
272+
executor: &'a Executor<Self::Context, S>,
273+
) -> crate::BoxFuture<'a, Value<S>> {
274+
let f = resolve_into_list_async(executor, info, self.iter());
275+
Box::pin(f)
276276
}
277277
}
278278

279279
#[cfg(feature = "async")]
280-
#[async_trait::async_trait]
281280
impl<S, T, CtxT> crate::GraphQLTypeAsync<S> for &[T]
282281
where
283282
T: crate::GraphQLTypeAsync<S, Context = CtxT>,
@@ -286,18 +285,18 @@ where
286285
CtxT: Send + Sync,
287286
for<'b> &'b S: ScalarRefValue<'b>,
288287
{
289-
async fn resolve_async<'a>(
288+
fn resolve_async<'a>(
290289
&'a self,
291-
info: &'a <Self as crate::GraphQLType<S>>::TypeInfo,
292-
selection_set: Option<&'a [Selection<'a, S>]>,
293-
executor: &'a Executor<'a, <Self as crate::GraphQLType<S>>::Context, S>,
294-
) -> Value<S> {
295-
resolve_into_list_async(executor, info, self.iter()).await
290+
info: &'a Self::TypeInfo,
291+
selection_set: Option<&'a [Selection<S>]>,
292+
executor: &'a Executor<Self::Context, S>,
293+
) -> crate::BoxFuture<'a, Value<S>> {
294+
let f = resolve_into_list_async(executor, info, self.iter());
295+
Box::pin(f)
296296
}
297297
}
298298

299299
#[cfg(feature = "async")]
300-
#[async_trait::async_trait]
301300
impl<S, T, CtxT> crate::GraphQLTypeAsync<S> for Option<T>
302301
where
303302
T: crate::GraphQLTypeAsync<S, Context = CtxT>,
@@ -306,15 +305,18 @@ where
306305
CtxT: Send + Sync,
307306
for<'b> &'b S: ScalarRefValue<'b>,
308307
{
309-
async fn resolve_async<'a>(
308+
fn resolve_async<'a>(
310309
&'a self,
311-
info: &'a <Self as crate::GraphQLType<S>>::TypeInfo,
312-
selection_set: Option<&'a [Selection<'a, S>]>,
313-
executor: &'a Executor<'a, <Self as crate::GraphQLType<S>>::Context, S>,
314-
) -> Value<S> {
315-
match *self {
316-
Some(ref obj) => executor.resolve_into_value_async(info, obj).await,
317-
None => Value::null(),
318-
}
310+
info: &'a Self::TypeInfo,
311+
selection_set: Option<&'a [Selection<S>]>,
312+
executor: &'a Executor<Self::Context, S>,
313+
) -> crate::BoxFuture<'a, Value<S>> {
314+
let f = async move {
315+
match *self {
316+
Some(ref obj) => executor.resolve_into_value_async(info, obj).await,
317+
None => Value::null(),
318+
}
319+
};
320+
Box::pin(f)
319321
}
320322
}

juniper/src/types/pointers.rs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,6 @@ where
137137
}
138138

139139
#[cfg(feature = "async")]
140-
#[async_trait::async_trait]
141140
impl<'e, S, T> crate::GraphQLTypeAsync<S> for &'e T
142141
where
143142
S: ScalarValue + Send + Sync,
@@ -146,24 +145,23 @@ where
146145
T::Context: Send + Sync,
147146
for<'c> &'c S: ScalarRefValue<'c>,
148147
{
149-
async fn resolve_field_async<'b>(
148+
fn resolve_field_async<'b>(
150149
&'b self,
151-
info: &'b <Self as crate::GraphQLType<S>>::TypeInfo,
150+
info: &'b Self::TypeInfo,
152151
field_name: &'b str,
153-
arguments: &'b Arguments<'b, S>,
154-
executor: &'b Executor<'b, <Self as crate::GraphQLType<S>>::Context, S>,
155-
) -> ExecutionResult<S> {
152+
arguments: &'b Arguments<S>,
153+
executor: &'b Executor<Self::Context, S>,
154+
) -> crate::BoxFuture<'b, ExecutionResult<S>> {
156155
crate::GraphQLTypeAsync::resolve_field_async(&**self, info, field_name, arguments, executor)
157-
.await
158156
}
159157

160-
async fn resolve_async<'a>(
158+
fn resolve_async<'a>(
161159
&'a self,
162-
info: &'a <Self as crate::GraphQLType<S>>::TypeInfo,
163-
selection_set: Option<&'a [Selection<'a, S>]>,
164-
executor: &'a Executor<'a, <Self as crate::GraphQLType<S>>::Context, S>,
165-
) -> Value<S> {
166-
crate::GraphQLTypeAsync::resolve_async(&**self, info, selection_set, executor).await
160+
info: &'a Self::TypeInfo,
161+
selection_set: Option<&'a [Selection<S>]>,
162+
executor: &'a Executor<Self::Context, S>,
163+
) -> crate::BoxFuture<'a, Value<S>> {
164+
crate::GraphQLTypeAsync::resolve_async(&**self, info, selection_set, executor)
167165
}
168166
}
169167

juniper/src/types/scalars.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -197,19 +197,19 @@ where
197197
}
198198

199199
#[cfg(feature = "async")]
200-
#[async_trait::async_trait]
201200
impl<'e, S> crate::GraphQLTypeAsync<S> for &'e str
202201
where
203202
S: ScalarValue + Send + Sync,
204203
for<'b> &'b S: ScalarRefValue<'b>,
205204
{
206-
async fn resolve_async<'a>(
205+
fn resolve_async<'a>(
207206
&'a self,
208-
info: &'a <Self as crate::GraphQLType<S>>::TypeInfo,
209-
selection_set: Option<&'a [Selection<'a, S>]>,
210-
executor: &'a Executor<'a, <Self as crate::GraphQLType<S>>::Context, S>,
211-
) -> crate::Value<S> {
212-
self.resolve(info, selection_set, executor)
207+
info: &'a Self::TypeInfo,
208+
selection_set: Option<&'a [Selection<S>]>,
209+
executor: &'a Executor<Self::Context, S>,
210+
) -> crate::BoxFuture<'a, crate::Value<S>> {
211+
use futures::future;
212+
future::FutureExt::boxed(future::ready(self.resolve(info, selection_set, executor)))
213213
}
214214
}
215215

juniper_codegen/src/derive_enum.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -213,16 +213,12 @@ pub fn impl_enum(ast: &syn::DeriveInput, is_internal: bool) -> TokenStream {
213213
__S: #juniper_path::ScalarValue + Send + Sync,
214214
for<'__b> &'__b __S: #juniper_path::ScalarRefValue<'__b>
215215
{
216-
fn resolve_async<'a, 'async_trait>(
216+
fn resolve_async<'a>(
217217
&'a self,
218218
info: &'a Self::TypeInfo,
219219
selection_set: Option<&'a [#juniper_path::Selection<__S>]>,
220220
executor: &'a #juniper_path::Executor<Self::Context, __S>,
221-
) -> #juniper_path::BoxFuture<'async_trait, #juniper_path::Value<__S>>
222-
where
223-
'a: 'async_trait,
224-
Self: 'async_trait
225-
{
221+
) -> #juniper_path::BoxFuture<'a, #juniper_path::Value<__S>> {
226222
use #juniper_path::GraphQLType;
227223
use futures::future;
228224
let v = self.resolve(info, selection_set, executor);

juniper_codegen/src/util.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -932,27 +932,21 @@ impl GraphQLTypeDefiniton {
932932
impl#impl_generics #juniper_crate_name::GraphQLTypeAsync<#scalar> for #ty #type_generics_tokens
933933
#where_async
934934
{
935-
fn resolve_field_async<'b, 'async_trait>(
935+
fn resolve_field_async<'b>(
936936
&'b self,
937937
info: &'b Self::TypeInfo,
938938
field: &'b str,
939939
args: &'b #juniper_crate_name::Arguments<#scalar>,
940940
executor: &'b #juniper_crate_name::Executor<Self::Context, #scalar>,
941-
) -> #juniper_crate_name::BoxFuture<'async_trait, #juniper_crate_name::ExecutionResult<#scalar>>
942-
where
943-
#scalar: Send + Sync,
944-
'b: 'async_trait,
945-
Self: 'async_trait,
941+
) -> #juniper_crate_name::BoxFuture<'b, #juniper_crate_name::ExecutionResult<#scalar>>
942+
where #scalar: Send + Sync,
946943
{
947944
use futures::future;
948945
use #juniper_crate_name::GraphQLType;
949946
match field {
950947
#( #resolve_matches_async )*
951948
_ => {
952-
panic!("Field {} not found on type {:?}",
953-
field,
954-
<Self as #juniper_crate_name::GraphQLType<#scalar>>::name(info)
955-
);
949+
panic!("Field {} not found on type {}", field, "Mutation");
956950
}
957951
}
958952
}

0 commit comments

Comments
 (0)