Skip to content

Commit e344f1c

Browse files
committed
Merge branch 'async-await-resolve-some-todos' of https://github.com/instrumentisto/juniper into async-await-resolve-some-todos
# Conflicts: # juniper/src/macros/tests/args.rs [skip ci]
2 parents 09d9513 + e151026 commit e344f1c

File tree

14 files changed

+76
-58
lines changed

14 files changed

+76
-58
lines changed

examples/warp_async/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,3 @@ reqwest = "0.9.19"
1616
juniper_codegen = { git = "https://github.com/graphql-rust/juniper", branch = "async-await", features = ["async"] }
1717
juniper = { git = "https://github.com/graphql-rust/juniper", branch = "async-await", features = ["async"] }
1818
juniper_warp = { git = "https://github.com/graphql-rust/juniper", branch = "async-await", features = ["async"] }
19-

examples/warp_async/src/main.rs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@
22
//! This example demonstrates async/await usage with warp.
33
//! NOTE: this uses tokio 0.1 , not the alpha tokio 0.2.
44
5-
use juniper::{EmptyMutation, RootNode, FieldError};
5+
use juniper::{EmptyMutation, FieldError, RootNode};
66
use warp::{http::Response, Filter};
77

88
#[derive(Clone)]
9-
struct Context {
10-
11-
}
9+
struct Context {}
1210
impl juniper::Context for Context {}
1311

1412
#[derive(juniper::GraphQLEnum, Clone, Copy)]
@@ -43,23 +41,24 @@ impl User {
4341
}
4442
}
4543

46-
struct Query;
44+
struct Query;
4745

4846
#[juniper::object(Context = Context)]
4947
impl Query {
5048
async fn users() -> Vec<User> {
51-
vec![
52-
User{
53-
id: 1,
54-
kind: UserKind::Admin,
55-
name: "user1".into(),
56-
},
57-
]
49+
vec![User {
50+
id: 1,
51+
kind: UserKind::Admin,
52+
name: "user1".into(),
53+
}]
5854
}
5955

6056
/// Fetch a URL and return the response body text.
6157
async fn request(url: String) -> Result<String, FieldError> {
62-
use futures::{ compat::{Stream01CompatExt, Future01CompatExt}, stream::TryStreamExt};
58+
use futures::{
59+
compat::{Future01CompatExt, Stream01CompatExt},
60+
stream::TryStreamExt,
61+
};
6362

6463
let res = reqwest::r#async::Client::new()
6564
.get(&url)
@@ -95,7 +94,7 @@ fn main() {
9594

9695
log::info!("Listening on 127.0.0.1:8080");
9796

98-
let state = warp::any().map(move || Context{} );
97+
let state = warp::any().map(move || Context {});
9998
let graphql_filter = juniper_warp::make_graphql_filter_async(schema(), state.boxed());
10099

101100
warp::serve(
Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1 @@
11

2-
3-
4-

juniper/src/macros/common.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ macro_rules! __juniper_impl_trait {
77
}
88
) => {
99
impl<$($other,)*> $crate::$impl_trait<$crate::DefaultScalarValue> for $name {
10-
$($body)*
10+
$($body)+
1111
}
1212
};
1313
(
@@ -26,7 +26,7 @@ macro_rules! __juniper_impl_trait {
2626

2727
(
2828
impl< <$generic:tt $(: $bound: tt)*> $(, $other: tt)* > $impl_trait:tt for $name:ty {
29-
$($body:tt)*
29+
$($body:tt)+
3030
}
3131
) => {
3232
impl<$($other,)* $generic $(: $bound)*> $crate::$impl_trait<$generic> for $name
@@ -50,17 +50,17 @@ macro_rules! __juniper_impl_trait {
5050
$generic: $crate::ScalarValue,
5151
for<'__b> &'__b $generic: $crate::ScalarRefValue<'__b>,
5252
{
53-
$($body)*
53+
$($body)+
5454
}
5555
};
5656

5757
(
5858
impl<$scalar:ty $(, $other: tt )*> $impl_trait:tt for $name:ty {
59-
$($body:tt)*
59+
$($body:tt)+
6060
}
6161
) => {
6262
impl<$($other, )*> $crate::$impl_trait<$scalar> for $name {
63-
$($body)*
63+
$($body)+
6464
}
6565
};
6666
(

juniper/src/macros/tests/field.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,16 @@ impl Root {
9595
Ok(0)
9696
}
9797

98+
/*
99+
* FIXME: make this work again
98100
fn with_return() -> i32 {
99101
return 0;
100102
}
101103
102104
fn with_return_field_result() -> FieldResult<i32> {
103105
return Ok(0);
104106
}
107+
*/
105108
}
106109

107110
graphql_interface!(Interface: () |&self| {

juniper/src/macros/tests/union.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
use std::marker::PhantomData;
2+
3+
use crate::{
4+
ast::InputValue,
5+
schema::model::RootNode,
6+
types::scalars::EmptyMutation,
7+
value::{DefaultScalarValue, Object, Value},
8+
};
9+
110
/*
211
312
Syntax to validate:
@@ -35,6 +44,16 @@ enum WithGenerics<T> {
3544
enum DescriptionFirst {
3645
Concrete(Concrete),
3746
}
47+
enum ResolversFirst {
48+
Concrete(Concrete),
49+
}
50+
51+
enum CommasWithTrailing {
52+
Concrete(Concrete),
53+
}
54+
enum ResolversWithTrailingComma {
55+
Concrete(Concrete),
56+
}
3857

3958
struct Root;
4059

juniper/src/schema/schema.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,12 @@ where
9898
) -> ExecutionResult<S> {
9999
use futures::future::{ready, FutureExt};
100100
match field_name {
101-
"__schema" | "__type" => {
102-
let v = self.resolve_field(info, field_name, arguments, executor);
103-
Box::pin(ready(v))
101+
"__schema" | "__type" => self.resolve_field(info, field_name, arguments, executor),
102+
_ => {
103+
self.query_type
104+
.resolve_field_async(info, field_name, arguments, executor)
105+
.await
104106
}
105-
_ => self
106-
.query_type
107-
.resolve_field_async(info, field_name, arguments, executor),
108107
}
109108
}
110109
}

juniper/src/tests/introspection_tests.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,8 @@ fn test_introspection_possible_types() {
234234
assert_eq!(possible_types, vec!["Human", "Droid"].into_iter().collect());
235235
}
236236

237+
/*
238+
* FIXME: make this work again
237239
#[test]
238240
fn test_builtin_introspection_query() {
239241
let database = Database::new();
@@ -256,3 +258,4 @@ fn test_builtin_introspection_query_without_descriptions() {
256258
257259
assert_eq!(result, (expected, vec![]));
258260
}
261+
*/

juniper/src/types/async_await.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
use crate::{
22
ast::{Directive, FromInputValue, InputValue, Selection},
3-
value::{Object, ScalarRefValue, ScalarValue, Value},
4-
};
5-
6-
use crate::{
73
executor::{ExecutionResult, Executor},
84
parser::Spanning,
5+
value::{Object, ScalarRefValue, ScalarValue, Value},
6+
BoxFuture,
97
};
108

11-
use crate::BoxFuture;
12-
139
use super::base::{is_excluded, merge_key_into, Arguments, GraphQLType};
1410

1511
#[async_trait::async_trait]

juniper_codegen/src/impl_object.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,15 @@ pub fn build_object(args: TokenStream, body: TokenStream, is_internal: bool) ->
4141
}
4242
}
4343

44-
45-
let name =
46-
if let Some(name) = impl_attrs.name.as_ref(){
44+
let name = if let Some(name) = impl_attrs.name.as_ref() {
4745
name.to_string()
48-
}
49-
else {
46+
} else {
5047
if let Some(ident) = util::name_of_type(&*_impl.self_ty) {
5148
ident.to_string()
5249
} else {
53-
panic!("Could not determine a name for the object type: specify one with #[juniper::object(name = \"SomeName\")");
54-
}
55-
};
50+
panic!("Could not determine a name for the object type: specify one with #[juniper::object(name = \"SomeName\")");
51+
}
52+
};
5653

5754
let target_type = *_impl.self_ty.clone();
5855

juniper_codegen/src/impl_union.rs

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ impl syn::parse::Parse for ResolveBody {
3939
body.parse::<syn::token::Match>()?;
4040
body.parse::<syn::token::SelfValue>()?;
4141

42-
let match_body;
42+
let match_body;
4343
syn::braced!( match_body in body );
4444

4545
let mut variants = Vec::new();
@@ -67,7 +67,6 @@ pub fn impl_union(
6767
attrs: TokenStream,
6868
body: TokenStream,
6969
) -> Result<TokenStream, MacroError> {
70-
7170
// We are re-using the object attributes since they are almost the same.
7271
let attrs = syn::parse::<util::ObjectAttributes>(attrs)?;
7372

@@ -76,7 +75,8 @@ pub fn impl_union(
7675
if item.items.len() != 1 {
7776
return Err(MacroError::new(
7877
item.span(),
79-
"Invalid impl body: expected one method with signature: fn resolve(&self) { ... }".to_string(),
78+
"Invalid impl body: expected one method with signature: fn resolve(&self) { ... }"
79+
.to_string(),
8080
));
8181
}
8282

@@ -92,7 +92,7 @@ pub fn impl_union(
9292
"Expected a path ending in a simple type identifier".to_string(),
9393
)
9494
})?;
95-
let name = attrs.name.unwrap_or_else(|| ty_ident.to_string());
95+
let name = attrs.name.unwrap_or_else(|| ty_ident.to_string());
9696

9797
let juniper = util::juniper_path(is_internal);
9898

@@ -130,7 +130,9 @@ pub fn impl_union(
130130
.scalar
131131
.as_ref()
132132
.map(|s| quote!( #s ))
133-
.unwrap_or_else(|| { quote! { #juniper::DefaultScalarValue } });
133+
.unwrap_or_else(|| {
134+
quote! { #juniper::DefaultScalarValue }
135+
});
134136

135137
let mut generics = item.generics.clone();
136138
if attrs.scalar.is_some() {
@@ -139,10 +141,12 @@ pub fn impl_union(
139141
// compatible with ScalarValueRef.
140142
// This is done to prevent the user from having to specify this
141143
// manually.
142-
let where_clause = generics.where_clause.get_or_insert(syn::parse_quote!(where));
143-
where_clause.predicates.push(
144-
syn::parse_quote!(for<'__b> &'__b #scalar: #juniper::ScalarRefValue<'__b>),
145-
);
144+
let where_clause = generics
145+
.where_clause
146+
.get_or_insert(syn::parse_quote!(where));
147+
where_clause
148+
.predicates
149+
.push(syn::parse_quote!(for<'__b> &'__b #scalar: #juniper::ScalarRefValue<'__b>));
146150
}
147151

148152
let (impl_generics, _, where_clause) = generics.split_for_impl();
@@ -151,10 +155,13 @@ pub fn impl_union(
151155
Some(value) => quote!( .description( #value ) ),
152156
None => quote!(),
153157
};
154-
let context = attrs.context.map(|c| quote!{ #c } ).unwrap_or_else(|| quote!{ () });
158+
let context = attrs
159+
.context
160+
.map(|c| quote! { #c })
161+
.unwrap_or_else(|| quote! { () });
155162

156163
let output = quote! {
157-
impl #impl_generics #juniper::GraphQLType<#scalar> for #ty #where_clause
164+
impl #impl_generics #juniper::GraphQLType<#scalar> for #ty #where_clause
158165
{
159166
type Context = #context;
160167
type TypeInfo = ();

juniper_codegen/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,4 +389,3 @@ pub fn union_internal(attrs: TokenStream, body: TokenStream) -> TokenStream {
389389
};
390390
output
391391
}
392-

juniper_rocket/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ async = [ "juniper/async" ]
1818
serde = { version = "1.0.2" }
1919
serde_json = { version = "1.0.2" }
2020
serde_derive = { version = "1.0.2" }
21-
juniper = { version = "0.14.0", default-features = false, path = "../juniper"}
21+
juniper = { version = "0.14.1", default-features = false, path = "../juniper"}
2222

2323
futures03 = { version = "=0.3.0-alpha.19", package = "futures-preview", features = ["compat"] }
2424
rocket = { git = "https://github.com/SergioBenitez/Rocket", branch = "async" }
2525
tokio = "=0.2.0-alpha.6"
2626

2727
[dev-dependencies.juniper]
28-
version = "0.14.0"
28+
version = "0.14.1"
2929
features = ["expose-test-schema", "serde_json"]
3030
path = "../juniper"

juniper_warp/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ async = [ "juniper/async", "futures03" ]
1313

1414
[dependencies]
1515
warp = "0.1.8"
16-
juniper = { version = "0.14.0", path = "../juniper", default-features = false }
16+
juniper = { version = "0.14.1", path = "../juniper", default-features = false }
1717
serde_json = "1.0.24"
1818
serde_derive = "1.0.75"
1919
failure = "0.1.2"

0 commit comments

Comments
 (0)