Fix bad merge [skip ci]
This commit is contained in:
parent
e344f1c06f
commit
778606c050
14 changed files with 55 additions and 74 deletions
|
@ -16,3 +16,4 @@ reqwest = "0.9.19"
|
||||||
juniper_codegen = { git = "https://github.com/graphql-rust/juniper", branch = "async-await", features = ["async"] }
|
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 = { 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"] }
|
juniper_warp = { git = "https://github.com/graphql-rust/juniper", branch = "async-await", features = ["async"] }
|
||||||
|
|
||||||
|
|
|
@ -2,11 +2,13 @@
|
||||||
//! This example demonstrates async/await usage with warp.
|
//! This example demonstrates async/await usage with warp.
|
||||||
//! NOTE: this uses tokio 0.1 , not the alpha tokio 0.2.
|
//! NOTE: this uses tokio 0.1 , not the alpha tokio 0.2.
|
||||||
|
|
||||||
use juniper::{EmptyMutation, FieldError, RootNode};
|
use juniper::{EmptyMutation, RootNode, FieldError};
|
||||||
use warp::{http::Response, Filter};
|
use warp::{http::Response, Filter};
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
struct Context {}
|
struct Context {
|
||||||
|
|
||||||
|
}
|
||||||
impl juniper::Context for Context {}
|
impl juniper::Context for Context {}
|
||||||
|
|
||||||
#[derive(juniper::GraphQLEnum, Clone, Copy)]
|
#[derive(juniper::GraphQLEnum, Clone, Copy)]
|
||||||
|
@ -46,19 +48,18 @@ struct Query;
|
||||||
#[juniper::object(Context = Context)]
|
#[juniper::object(Context = Context)]
|
||||||
impl Query {
|
impl Query {
|
||||||
async fn users() -> Vec<User> {
|
async fn users() -> Vec<User> {
|
||||||
vec![User {
|
vec![
|
||||||
|
User{
|
||||||
id: 1,
|
id: 1,
|
||||||
kind: UserKind::Admin,
|
kind: UserKind::Admin,
|
||||||
name: "user1".into(),
|
name: "user1".into(),
|
||||||
}]
|
},
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Fetch a URL and return the response body text.
|
/// Fetch a URL and return the response body text.
|
||||||
async fn request(url: String) -> Result<String, FieldError> {
|
async fn request(url: String) -> Result<String, FieldError> {
|
||||||
use futures::{
|
use futures::{ compat::{Stream01CompatExt, Future01CompatExt}, stream::TryStreamExt};
|
||||||
compat::{Future01CompatExt, Stream01CompatExt},
|
|
||||||
stream::TryStreamExt,
|
|
||||||
};
|
|
||||||
|
|
||||||
let res = reqwest::r#async::Client::new()
|
let res = reqwest::r#async::Client::new()
|
||||||
.get(&url)
|
.get(&url)
|
||||||
|
|
|
@ -1 +1,4 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -151,7 +151,6 @@ mod executor_tests;
|
||||||
pub use crate::util::to_camel_case;
|
pub use crate::util::to_camel_case;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
executor::{execute_validated_query, execute_validated_query_async},
|
|
||||||
introspection::{INTROSPECTION_QUERY, INTROSPECTION_QUERY_WITHOUT_DESCRIPTIONS},
|
introspection::{INTROSPECTION_QUERY, INTROSPECTION_QUERY_WITHOUT_DESCRIPTIONS},
|
||||||
parser::{parse_document_source, ParseError, Spanning},
|
parser::{parse_document_source, ParseError, Spanning},
|
||||||
validation::{validate_input_values, visit_all_rules, ValidatorContext},
|
validation::{validate_input_values, visit_all_rules, ValidatorContext},
|
||||||
|
@ -228,7 +227,7 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
execute_validated_query(document, operation_name, root_node, variables, context)
|
executor::execute_validated_query(document, operation_name, root_node, variables, context)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Execute a query in a provided schema
|
/// Execute a query in a provided schema
|
||||||
|
@ -268,7 +267,7 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
execute_validated_query_async(document, operation_name, root_node, variables, context)
|
executor::execute_validated_query_async(document, operation_name, root_node, variables, context)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ macro_rules! __juniper_impl_trait {
|
||||||
}
|
}
|
||||||
) => {
|
) => {
|
||||||
impl<$($other,)*> $crate::$impl_trait<$crate::DefaultScalarValue> for $name {
|
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 {
|
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
|
impl<$($other,)* $generic $(: $bound)*> $crate::$impl_trait<$generic> for $name
|
||||||
|
@ -50,17 +50,17 @@ macro_rules! __juniper_impl_trait {
|
||||||
$generic: $crate::ScalarValue,
|
$generic: $crate::ScalarValue,
|
||||||
for<'__b> &'__b $generic: $crate::ScalarRefValue<'__b>,
|
for<'__b> &'__b $generic: $crate::ScalarRefValue<'__b>,
|
||||||
{
|
{
|
||||||
$($body)+
|
$($body)*
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
(
|
(
|
||||||
impl<$scalar:ty $(, $other: tt )*> $impl_trait:tt for $name:ty {
|
impl<$scalar:ty $(, $other: tt )*> $impl_trait:tt for $name:ty {
|
||||||
$($body:tt)+
|
$($body:tt)*
|
||||||
}
|
}
|
||||||
) => {
|
) => {
|
||||||
impl<$($other, )*> $crate::$impl_trait<$scalar> for $name {
|
impl<$($other, )*> $crate::$impl_trait<$scalar> for $name {
|
||||||
$($body)+
|
$($body)*
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
(
|
(
|
||||||
|
|
|
@ -95,8 +95,6 @@ impl Root {
|
||||||
Ok(0)
|
Ok(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* FIXME: make this work again
|
|
||||||
fn with_return() -> i32 {
|
fn with_return() -> i32 {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -104,7 +102,6 @@ impl Root {
|
||||||
fn with_return_field_result() -> FieldResult<i32> {
|
fn with_return_field_result() -> FieldResult<i32> {
|
||||||
return Ok(0);
|
return Ok(0);
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
graphql_interface!(Interface: () |&self| {
|
graphql_interface!(Interface: () |&self| {
|
||||||
|
|
|
@ -1,12 +1,3 @@
|
||||||
use std::marker::PhantomData;
|
|
||||||
|
|
||||||
use crate::{
|
|
||||||
ast::InputValue,
|
|
||||||
schema::model::RootNode,
|
|
||||||
types::scalars::EmptyMutation,
|
|
||||||
value::{DefaultScalarValue, Object, Value},
|
|
||||||
};
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
||||||
Syntax to validate:
|
Syntax to validate:
|
||||||
|
@ -44,16 +35,6 @@ enum WithGenerics<T> {
|
||||||
enum DescriptionFirst {
|
enum DescriptionFirst {
|
||||||
Concrete(Concrete),
|
Concrete(Concrete),
|
||||||
}
|
}
|
||||||
enum ResolversFirst {
|
|
||||||
Concrete(Concrete),
|
|
||||||
}
|
|
||||||
|
|
||||||
enum CommasWithTrailing {
|
|
||||||
Concrete(Concrete),
|
|
||||||
}
|
|
||||||
enum ResolversWithTrailingComma {
|
|
||||||
Concrete(Concrete),
|
|
||||||
}
|
|
||||||
|
|
||||||
struct Root;
|
struct Root;
|
||||||
|
|
||||||
|
|
|
@ -98,12 +98,13 @@ where
|
||||||
) -> ExecutionResult<S> {
|
) -> ExecutionResult<S> {
|
||||||
use futures::future::{ready, FutureExt};
|
use futures::future::{ready, FutureExt};
|
||||||
match field_name {
|
match field_name {
|
||||||
"__schema" | "__type" => self.resolve_field(info, field_name, arguments, executor),
|
"__schema" | "__type" => {
|
||||||
_ => {
|
let v = self.resolve_field(info, field_name, arguments, executor);
|
||||||
self.query_type
|
Box::pin(ready(v))
|
||||||
.resolve_field_async(info, field_name, arguments, executor)
|
|
||||||
.await
|
|
||||||
}
|
}
|
||||||
|
_ => self
|
||||||
|
.query_type
|
||||||
|
.resolve_field_async(info, field_name, arguments, executor),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -234,8 +234,6 @@ fn test_introspection_possible_types() {
|
||||||
assert_eq!(possible_types, vec!["Human", "Droid"].into_iter().collect());
|
assert_eq!(possible_types, vec!["Human", "Droid"].into_iter().collect());
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* FIXME: make this work again
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_builtin_introspection_query() {
|
fn test_builtin_introspection_query() {
|
||||||
let database = Database::new();
|
let database = Database::new();
|
||||||
|
@ -258,4 +256,3 @@ fn test_builtin_introspection_query_without_descriptions() {
|
||||||
|
|
||||||
assert_eq!(result, (expected, vec![]));
|
assert_eq!(result, (expected, vec![]));
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
|
@ -1,11 +1,15 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
ast::{Directive, FromInputValue, InputValue, Selection},
|
ast::{Directive, FromInputValue, InputValue, Selection},
|
||||||
|
value::{Object, ScalarRefValue, ScalarValue, Value},
|
||||||
|
};
|
||||||
|
|
||||||
|
use crate::{
|
||||||
executor::{ExecutionResult, Executor},
|
executor::{ExecutionResult, Executor},
|
||||||
parser::Spanning,
|
parser::Spanning,
|
||||||
value::{Object, ScalarRefValue, ScalarValue, Value},
|
|
||||||
BoxFuture,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use crate::BoxFuture;
|
||||||
|
|
||||||
use super::base::{is_excluded, merge_key_into, Arguments, GraphQLType};
|
use super::base::{is_excluded, merge_key_into, Arguments, GraphQLType};
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
#[async_trait::async_trait]
|
||||||
|
|
|
@ -41,9 +41,11 @@ 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()
|
name.to_string()
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
if let Some(ident) = util::name_of_type(&*_impl.self_ty) {
|
if let Some(ident) = util::name_of_type(&*_impl.self_ty) {
|
||||||
ident.to_string()
|
ident.to_string()
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -67,6 +67,7 @@ pub fn impl_union(
|
||||||
attrs: TokenStream,
|
attrs: TokenStream,
|
||||||
body: TokenStream,
|
body: TokenStream,
|
||||||
) -> Result<TokenStream, MacroError> {
|
) -> Result<TokenStream, MacroError> {
|
||||||
|
|
||||||
// We are re-using the object attributes since they are almost the same.
|
// We are re-using the object attributes since they are almost the same.
|
||||||
let attrs = syn::parse::<util::ObjectAttributes>(attrs)?;
|
let attrs = syn::parse::<util::ObjectAttributes>(attrs)?;
|
||||||
|
|
||||||
|
@ -75,8 +76,7 @@ pub fn impl_union(
|
||||||
if item.items.len() != 1 {
|
if item.items.len() != 1 {
|
||||||
return Err(MacroError::new(
|
return Err(MacroError::new(
|
||||||
item.span(),
|
item.span(),
|
||||||
"Invalid impl body: expected one method with signature: fn resolve(&self) { ... }"
|
"Invalid impl body: expected one method with signature: fn resolve(&self) { ... }".to_string(),
|
||||||
.to_string(),
|
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -130,9 +130,7 @@ pub fn impl_union(
|
||||||
.scalar
|
.scalar
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map(|s| quote!( #s ))
|
.map(|s| quote!( #s ))
|
||||||
.unwrap_or_else(|| {
|
.unwrap_or_else(|| { quote! { #juniper::DefaultScalarValue } });
|
||||||
quote! { #juniper::DefaultScalarValue }
|
|
||||||
});
|
|
||||||
|
|
||||||
let mut generics = item.generics.clone();
|
let mut generics = item.generics.clone();
|
||||||
if attrs.scalar.is_some() {
|
if attrs.scalar.is_some() {
|
||||||
|
@ -141,12 +139,10 @@ pub fn impl_union(
|
||||||
// compatible with ScalarValueRef.
|
// compatible with ScalarValueRef.
|
||||||
// This is done to prevent the user from having to specify this
|
// This is done to prevent the user from having to specify this
|
||||||
// manually.
|
// manually.
|
||||||
let where_clause = generics
|
let where_clause = generics.where_clause.get_or_insert(syn::parse_quote!(where));
|
||||||
.where_clause
|
where_clause.predicates.push(
|
||||||
.get_or_insert(syn::parse_quote!(where));
|
syn::parse_quote!(for<'__b> &'__b #scalar: #juniper::ScalarRefValue<'__b>),
|
||||||
where_clause
|
);
|
||||||
.predicates
|
|
||||||
.push(syn::parse_quote!(for<'__b> &'__b #scalar: #juniper::ScalarRefValue<'__b>));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let (impl_generics, _, where_clause) = generics.split_for_impl();
|
let (impl_generics, _, where_clause) = generics.split_for_impl();
|
||||||
|
@ -155,10 +151,7 @@ pub fn impl_union(
|
||||||
Some(value) => quote!( .description( #value ) ),
|
Some(value) => quote!( .description( #value ) ),
|
||||||
None => quote!(),
|
None => quote!(),
|
||||||
};
|
};
|
||||||
let context = attrs
|
let context = attrs.context.map(|c| quote!{ #c } ).unwrap_or_else(|| quote!{ () });
|
||||||
.context
|
|
||||||
.map(|c| quote! { #c })
|
|
||||||
.unwrap_or_else(|| quote! { () });
|
|
||||||
|
|
||||||
let output = quote! {
|
let output = quote! {
|
||||||
impl #impl_generics #juniper::GraphQLType<#scalar> for #ty #where_clause
|
impl #impl_generics #juniper::GraphQLType<#scalar> for #ty #where_clause
|
||||||
|
|
|
@ -389,3 +389,4 @@ pub fn union_internal(attrs: TokenStream, body: TokenStream) -> TokenStream {
|
||||||
};
|
};
|
||||||
output
|
output
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -41,7 +41,6 @@ Check the LICENSE file for details.
|
||||||
#![doc(html_root_url = "https://docs.rs/juniper_warp/0.2.0")]
|
#![doc(html_root_url = "https://docs.rs/juniper_warp/0.2.0")]
|
||||||
|
|
||||||
use futures::{future::poll_fn, Future};
|
use futures::{future::poll_fn, Future};
|
||||||
use juniper::{DefaultScalarValue, InputValue, ScalarRefValue, ScalarValue};
|
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use warp::{filters::BoxedFilter, Filter};
|
use warp::{filters::BoxedFilter, Filter};
|
||||||
|
@ -49,6 +48,8 @@ use warp::{filters::BoxedFilter, Filter};
|
||||||
#[cfg(feature = "async")]
|
#[cfg(feature = "async")]
|
||||||
use futures03::future::{FutureExt, TryFutureExt};
|
use futures03::future::{FutureExt, TryFutureExt};
|
||||||
|
|
||||||
|
use juniper::{DefaultScalarValue, InputValue, ScalarRefValue, ScalarValue};
|
||||||
|
|
||||||
#[derive(Debug, serde_derive::Deserialize, PartialEq)]
|
#[derive(Debug, serde_derive::Deserialize, PartialEq)]
|
||||||
#[serde(untagged)]
|
#[serde(untagged)]
|
||||||
#[serde(bound = "InputValue<S>: Deserialize<'de>")]
|
#[serde(bound = "InputValue<S>: Deserialize<'de>")]
|
||||||
|
|
Loading…
Reference in a new issue