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]
This commit is contained in:
nWacky 2019-11-06 11:46:21 +03:00
commit e344f1c06f
No known key found for this signature in database
GPG key ID: 22EF2C62F6F79FD0
14 changed files with 76 additions and 58 deletions

View file

@ -16,4 +16,3 @@ reqwest = "0.9.19"
juniper_codegen = { git = "https://github.com/graphql-rust/juniper", branch = "async-await", features = ["async"] }
juniper = { git = "https://github.com/graphql-rust/juniper", branch = "async-await", features = ["async"] }
juniper_warp = { git = "https://github.com/graphql-rust/juniper", branch = "async-await", features = ["async"] }

View file

@ -2,13 +2,11 @@
//! This example demonstrates async/await usage with warp.
//! NOTE: this uses tokio 0.1 , not the alpha tokio 0.2.
use juniper::{EmptyMutation, RootNode, FieldError};
use juniper::{EmptyMutation, FieldError, RootNode};
use warp::{http::Response, Filter};
#[derive(Clone)]
struct Context {
}
struct Context {}
impl juniper::Context for Context {}
#[derive(juniper::GraphQLEnum, Clone, Copy)]
@ -43,23 +41,24 @@ impl User {
}
}
struct Query;
struct Query;
#[juniper::object(Context = Context)]
impl Query {
async fn users() -> Vec<User> {
vec![
User{
id: 1,
kind: UserKind::Admin,
name: "user1".into(),
},
]
vec![User {
id: 1,
kind: UserKind::Admin,
name: "user1".into(),
}]
}
/// Fetch a URL and return the response body text.
async fn request(url: String) -> Result<String, FieldError> {
use futures::{ compat::{Stream01CompatExt, Future01CompatExt}, stream::TryStreamExt};
use futures::{
compat::{Future01CompatExt, Stream01CompatExt},
stream::TryStreamExt,
};
let res = reqwest::r#async::Client::new()
.get(&url)
@ -95,7 +94,7 @@ fn main() {
log::info!("Listening on 127.0.0.1:8080");
let state = warp::any().map(move || Context{} );
let state = warp::any().map(move || Context {});
let graphql_filter = juniper_warp::make_graphql_filter_async(schema(), state.boxed());
warp::serve(

View file

@ -7,7 +7,7 @@ macro_rules! __juniper_impl_trait {
}
) => {
impl<$($other,)*> $crate::$impl_trait<$crate::DefaultScalarValue> for $name {
$($body)*
$($body)+
}
};
(
@ -26,7 +26,7 @@ macro_rules! __juniper_impl_trait {
(
impl< <$generic:tt $(: $bound: tt)*> $(, $other: tt)* > $impl_trait:tt for $name:ty {
$($body:tt)*
$($body:tt)+
}
) => {
impl<$($other,)* $generic $(: $bound)*> $crate::$impl_trait<$generic> for $name
@ -50,17 +50,17 @@ macro_rules! __juniper_impl_trait {
$generic: $crate::ScalarValue,
for<'__b> &'__b $generic: $crate::ScalarRefValue<'__b>,
{
$($body)*
$($body)+
}
};
(
impl<$scalar:ty $(, $other: tt )*> $impl_trait:tt for $name:ty {
$($body:tt)*
$($body:tt)+
}
) => {
impl<$($other, )*> $crate::$impl_trait<$scalar> for $name {
$($body)*
$($body)+
}
};
(

View file

@ -95,6 +95,8 @@ impl Root {
Ok(0)
}
/*
* FIXME: make this work again
fn with_return() -> i32 {
return 0;
}
@ -102,6 +104,7 @@ impl Root {
fn with_return_field_result() -> FieldResult<i32> {
return Ok(0);
}
*/
}
graphql_interface!(Interface: () |&self| {

View file

@ -1,3 +1,12 @@
use std::marker::PhantomData;
use crate::{
ast::InputValue,
schema::model::RootNode,
types::scalars::EmptyMutation,
value::{DefaultScalarValue, Object, Value},
};
/*
Syntax to validate:
@ -35,6 +44,16 @@ enum WithGenerics<T> {
enum DescriptionFirst {
Concrete(Concrete),
}
enum ResolversFirst {
Concrete(Concrete),
}
enum CommasWithTrailing {
Concrete(Concrete),
}
enum ResolversWithTrailingComma {
Concrete(Concrete),
}
struct Root;

View file

@ -98,13 +98,12 @@ where
) -> ExecutionResult<S> {
use futures::future::{ready, FutureExt};
match field_name {
"__schema" | "__type" => {
let v = self.resolve_field(info, field_name, arguments, executor);
Box::pin(ready(v))
"__schema" | "__type" => self.resolve_field(info, field_name, arguments, executor),
_ => {
self.query_type
.resolve_field_async(info, field_name, arguments, executor)
.await
}
_ => self
.query_type
.resolve_field_async(info, field_name, arguments, executor),
}
}
}

View file

@ -234,6 +234,8 @@ fn test_introspection_possible_types() {
assert_eq!(possible_types, vec!["Human", "Droid"].into_iter().collect());
}
/*
* FIXME: make this work again
#[test]
fn test_builtin_introspection_query() {
let database = Database::new();
@ -256,3 +258,4 @@ fn test_builtin_introspection_query_without_descriptions() {
assert_eq!(result, (expected, vec![]));
}
*/

View file

@ -1,15 +1,11 @@
use crate::{
ast::{Directive, FromInputValue, InputValue, Selection},
value::{Object, ScalarRefValue, ScalarValue, Value},
};
use crate::{
executor::{ExecutionResult, Executor},
parser::Spanning,
value::{Object, ScalarRefValue, ScalarValue, Value},
BoxFuture,
};
use crate::BoxFuture;
use super::base::{is_excluded, merge_key_into, Arguments, GraphQLType};
#[async_trait::async_trait]

View file

@ -41,18 +41,15 @@ pub fn build_object(args: TokenStream, body: TokenStream, is_internal: bool) ->
}
}
let name =
if let Some(name) = impl_attrs.name.as_ref(){
let name = if let Some(name) = impl_attrs.name.as_ref() {
name.to_string()
}
else {
} else {
if let Some(ident) = util::name_of_type(&*_impl.self_ty) {
ident.to_string()
} else {
panic!("Could not determine a name for the object type: specify one with #[juniper::object(name = \"SomeName\")");
}
};
panic!("Could not determine a name for the object type: specify one with #[juniper::object(name = \"SomeName\")");
}
};
let target_type = *_impl.self_ty.clone();

View file

@ -39,7 +39,7 @@ impl syn::parse::Parse for ResolveBody {
body.parse::<syn::token::Match>()?;
body.parse::<syn::token::SelfValue>()?;
let match_body;
let match_body;
syn::braced!( match_body in body );
let mut variants = Vec::new();
@ -67,7 +67,6 @@ pub fn impl_union(
attrs: TokenStream,
body: TokenStream,
) -> Result<TokenStream, MacroError> {
// We are re-using the object attributes since they are almost the same.
let attrs = syn::parse::<util::ObjectAttributes>(attrs)?;
@ -76,7 +75,8 @@ pub fn impl_union(
if item.items.len() != 1 {
return Err(MacroError::new(
item.span(),
"Invalid impl body: expected one method with signature: fn resolve(&self) { ... }".to_string(),
"Invalid impl body: expected one method with signature: fn resolve(&self) { ... }"
.to_string(),
));
}
@ -92,7 +92,7 @@ pub fn impl_union(
"Expected a path ending in a simple type identifier".to_string(),
)
})?;
let name = attrs.name.unwrap_or_else(|| ty_ident.to_string());
let name = attrs.name.unwrap_or_else(|| ty_ident.to_string());
let juniper = util::juniper_path(is_internal);
@ -130,7 +130,9 @@ pub fn impl_union(
.scalar
.as_ref()
.map(|s| quote!( #s ))
.unwrap_or_else(|| { quote! { #juniper::DefaultScalarValue } });
.unwrap_or_else(|| {
quote! { #juniper::DefaultScalarValue }
});
let mut generics = item.generics.clone();
if attrs.scalar.is_some() {
@ -139,10 +141,12 @@ pub fn impl_union(
// compatible with ScalarValueRef.
// This is done to prevent the user from having to specify this
// manually.
let where_clause = generics.where_clause.get_or_insert(syn::parse_quote!(where));
where_clause.predicates.push(
syn::parse_quote!(for<'__b> &'__b #scalar: #juniper::ScalarRefValue<'__b>),
);
let where_clause = generics
.where_clause
.get_or_insert(syn::parse_quote!(where));
where_clause
.predicates
.push(syn::parse_quote!(for<'__b> &'__b #scalar: #juniper::ScalarRefValue<'__b>));
}
let (impl_generics, _, where_clause) = generics.split_for_impl();
@ -151,10 +155,13 @@ pub fn impl_union(
Some(value) => quote!( .description( #value ) ),
None => quote!(),
};
let context = attrs.context.map(|c| quote!{ #c } ).unwrap_or_else(|| quote!{ () });
let context = attrs
.context
.map(|c| quote! { #c })
.unwrap_or_else(|| quote! { () });
let output = quote! {
impl #impl_generics #juniper::GraphQLType<#scalar> for #ty #where_clause
impl #impl_generics #juniper::GraphQLType<#scalar> for #ty #where_clause
{
type Context = #context;
type TypeInfo = ();

View file

@ -389,4 +389,3 @@ pub fn union_internal(attrs: TokenStream, body: TokenStream) -> TokenStream {
};
output
}

View file

@ -18,13 +18,13 @@ async = [ "juniper/async" ]
serde = { version = "1.0.2" }
serde_json = { version = "1.0.2" }
serde_derive = { version = "1.0.2" }
juniper = { version = "0.14.0", default-features = false, path = "../juniper"}
juniper = { version = "0.14.1", default-features = false, path = "../juniper"}
futures03 = { version = "=0.3.0-alpha.19", package = "futures-preview", features = ["compat"] }
rocket = { git = "https://github.com/SergioBenitez/Rocket", branch = "async" }
tokio = "=0.2.0-alpha.6"
[dev-dependencies.juniper]
version = "0.14.0"
version = "0.14.1"
features = ["expose-test-schema", "serde_json"]
path = "../juniper"

View file

@ -13,7 +13,7 @@ async = [ "juniper/async", "futures03" ]
[dependencies]
warp = "0.1.8"
juniper = { version = "0.14.0", path = "../juniper", default-features = false }
juniper = { version = "0.14.1", path = "../juniper", default-features = false }
serde_json = "1.0.24"
serde_derive = "1.0.75"
failure = "0.1.2"