Formatting

This commit is contained in:
Christoph Herzog 2019-11-15 21:53:15 +01:00
parent 50605ee73e
commit 5d270b7dea
15 changed files with 51 additions and 40 deletions

View file

@ -42,7 +42,10 @@ enum OverrideDocEnum {
#[test]
fn test_derived_enum() {
// Ensure that rename works.
assert_eq!(<SomeEnum as GraphQLType<DefaultScalarValue>>::name(&()), Some("Some"));
assert_eq!(
<SomeEnum as GraphQLType<DefaultScalarValue>>::name(&()),
Some("Some")
);
// Ensure validity of meta info.
let mut registry: juniper::Registry = juniper::Registry::new(FnvHashMap::default());

View file

@ -93,7 +93,10 @@ struct WithLifetime<'a> {
#[test]
fn test_derived_input_object() {
assert_eq!(<Input as GraphQLType<DefaultScalarValue>>::name(&()), Some("MyInput"));
assert_eq!(
<Input as GraphQLType<DefaultScalarValue>>::name(&()),
Some("MyInput")
);
// Validate meta info.
let mut registry: juniper::Registry = juniper::Registry::new(FnvHashMap::default());

View file

@ -170,7 +170,10 @@ fn test_doc_comment_override() {
#[test]
fn test_derived_object() {
assert_eq!(<Obj as GraphQLType<DefaultScalarValue>>::name(&()), Some("MyObj"));
assert_eq!(
<Obj as GraphQLType<DefaultScalarValue>>::name(&()),
Some("MyObj")
);
// Verify meta info.
let mut registry: juniper::Registry = juniper::Registry::new(FnvHashMap::default());

View file

@ -31,7 +31,10 @@ impl User2 {
#[test]
fn test_scalar_value_simple() {
assert_eq!(<UserId as GraphQLType<DefaultScalarValue>>::name(&()), Some("UserId"));
assert_eq!(
<UserId as GraphQLType<DefaultScalarValue>>::name(&()),
Some("UserId")
);
let mut registry: juniper::Registry = juniper::Registry::new(FnvHashMap::default());
let meta = UserId::meta(&(), &mut registry);
@ -49,7 +52,10 @@ fn test_scalar_value_simple() {
#[test]
fn test_scalar_value_custom() {
assert_eq!(<CustomUserId as GraphQLType<DefaultScalarValue>>::name(&()), Some("MyUserId"));
assert_eq!(
<CustomUserId as GraphQLType<DefaultScalarValue>>::name(&()),
Some("MyUserId")
);
let mut registry: juniper::Registry = juniper::Registry::new(FnvHashMap::default());
let meta = CustomUserId::meta(&(), &mut registry);

View file

@ -36,8 +36,8 @@ where
) -> BoxFuture<'a, ExecutionResult<S>> {
if let Some(selection_set) = selection_set {
Box::pin(async move {
let value =
resolve_selection_set_into_async(self, info, selection_set, executor).await;
let value =
resolve_selection_set_into_async(self, info, selection_set, executor).await;
Ok(value)
})
} else {

View file

@ -332,11 +332,12 @@ where
) -> ExecutionResult<S> {
if let Some(selection_set) = selection_set {
let mut result = Object::with_capacity(selection_set.len());
let out = if resolve_selection_set_into(self, info, selection_set, executor, &mut result) {
Value::Object(result)
} else {
Value::null()
};
let out =
if resolve_selection_set_into(self, info, selection_set, executor, &mut result) {
Value::Object(result)
} else {
Value::null()
};
Ok(out)
} else {
panic!("resolve() must be implemented by non-object output types");

View file

@ -1,8 +1,8 @@
use crate::{
ast::{FromInputValue, InputValue, Selection, ToInputValue},
executor::ExecutionResult,
schema::meta::MetaType,
value::{ScalarValue, Value},
executor::ExecutionResult,
};
use crate::{
@ -196,9 +196,9 @@ where
for o in iter {
match executor.resolve(info, &o) {
Ok(value) if stop_on_null && value.is_null() => { return Ok(value) },
Ok(value) => { result.push(value) },
Err(e) => { return Err(e) },
Ok(value) if stop_on_null && value.is_null() => return Ok(value),
Ok(value) => result.push(value),
Err(e) => return Err(e),
}
}

View file

@ -5,7 +5,7 @@ use crate::{
executor::{ExecutionResult, Executor, Registry},
schema::meta::MetaType,
types::base::{Arguments, GraphQLType},
value::{ScalarValue},
value::ScalarValue,
};
impl<S, T, CtxT> GraphQLType<S> for Box<T>

View file

@ -3,7 +3,7 @@ use std::{char, convert::From, marker::PhantomData, ops::Deref, u32};
use crate::{
ast::{InputValue, Selection, ToInputValue},
executor::{Executor, Registry, ExecutionResult},
executor::{ExecutionResult, Executor, Registry},
parser::{LexerError, ParseError, ScalarToken, Token},
schema::meta::MetaType,
types::base::GraphQLType,

View file

@ -41,17 +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

@ -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 generics = item.generics.clone();
let (impl_generics, _, where_clause) = generics.split_for_impl();
@ -139,7 +141,10 @@ 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

View file

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

View file

@ -118,8 +118,7 @@ use std::{error::Error, fmt, io::Read};
use serde_json::error::Error as SerdeError;
use juniper::{
http, serde::Deserialize, DefaultScalarValue, GraphQLType, InputValue, RootNode,
ScalarValue,
http, serde::Deserialize, DefaultScalarValue, GraphQLType, InputValue, RootNode, ScalarValue,
};
#[derive(serde_derive::Deserialize)]

View file

@ -57,8 +57,7 @@ use rocket::{
use juniper::{http, InputValue};
use juniper::{
serde::Deserialize, DefaultScalarValue, FieldError, GraphQLType, RootNode, ScalarRefValue,
ScalarValue,
serde::Deserialize, DefaultScalarValue, FieldError, GraphQLType, RootNode, ScalarValue,
};
#[derive(Debug, serde_derive::Deserialize, PartialEq)]
@ -85,7 +84,6 @@ where
impl<S> GraphQLBatchRequest<S>
where
S: ScalarValue,
for<'b> &'b S: ScalarRefValue<'b>,
{
pub fn execute<'a, CtxT, QueryT, MutationT>(
&'a self,
@ -161,7 +159,6 @@ pub fn playground_source(graphql_endpoint_url: &str) -> content::Html<String> {
impl<S> GraphQLRequest<S>
where
S: ScalarValue,
for<'b> &'b S: ScalarRefValue<'b>,
{
/// Execute an incoming GraphQL query
pub fn execute<CtxT, QueryT, MutationT>(