Fix some clippy issues (#704)
This commit is contained in:
parent
3c79f6a2c5
commit
87883876bc
19 changed files with 73 additions and 75 deletions
|
@ -5,8 +5,8 @@ extern crate juniper;
|
||||||
use bencher::Bencher;
|
use bencher::Bencher;
|
||||||
|
|
||||||
use juniper::{
|
use juniper::{
|
||||||
execute_sync, tests::model::Database, DefaultScalarValue, EmptyMutation, EmptySubscription,
|
execute_sync, tests::fixtures::starwars::model::Database, DefaultScalarValue, EmptyMutation,
|
||||||
RootNode, Variables,
|
EmptySubscription, RootNode, Variables,
|
||||||
};
|
};
|
||||||
|
|
||||||
fn query_type_name(b: &mut Bencher) {
|
fn query_type_name(b: &mut Bencher) {
|
||||||
|
|
|
@ -595,7 +595,7 @@ where
|
||||||
|
|
||||||
/// Add an error to the execution engine at the current executor location
|
/// Add an error to the execution engine at the current executor location
|
||||||
pub fn push_error(&self, error: FieldError<S>) {
|
pub fn push_error(&self, error: FieldError<S>) {
|
||||||
self.push_error_at(error, self.location().clone());
|
self.push_error_at(error, *self.location());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Add an error to the execution engine at a specific location
|
/// Add an error to the execution engine at a specific location
|
||||||
|
|
|
@ -42,7 +42,7 @@ where
|
||||||
{
|
{
|
||||||
/// Returns the `operation_name` associated with this request.
|
/// Returns the `operation_name` associated with this request.
|
||||||
pub fn operation_name(&self) -> Option<&str> {
|
pub fn operation_name(&self) -> Option<&str> {
|
||||||
self.operation_name.as_ref().map(|oper_name| &**oper_name)
|
self.operation_name.as_deref()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn variables(&self) -> Variables<S> {
|
fn variables(&self) -> Variables<S> {
|
||||||
|
|
|
@ -42,7 +42,7 @@ where
|
||||||
fn from_input_value(v: &InputValue) -> Option<UtcDateTime> {
|
fn from_input_value(v: &InputValue) -> Option<UtcDateTime> {
|
||||||
v.as_string_value()
|
v.as_string_value()
|
||||||
.and_then(|s| (s.parse::<DateTime<Utc>>().ok()))
|
.and_then(|s| (s.parse::<DateTime<Utc>>().ok()))
|
||||||
.map(|d| UtcDateTime(d))
|
.map(UtcDateTime)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn from_str<'a>(value: ScalarToken<'a>) -> ParseScalarResult<'a, S> {
|
fn from_str<'a>(value: ScalarToken<'a>) -> ParseScalarResult<'a, S> {
|
||||||
|
|
|
@ -259,7 +259,7 @@ impl GraphQLParserTranslator {
|
||||||
.map(|x| GraphQLParserTranslator::translate_argument(&x))
|
.map(|x| GraphQLParserTranslator::translate_argument(&x))
|
||||||
.collect()
|
.collect()
|
||||||
})
|
})
|
||||||
.unwrap_or_else(|| Vec::new());
|
.unwrap_or_else(Vec::new);
|
||||||
|
|
||||||
ExternalField {
|
ExternalField {
|
||||||
position: Pos::default(),
|
position: Pos::default(),
|
||||||
|
|
|
@ -237,7 +237,7 @@ where
|
||||||
let sub_exec = executor.field_sub_executor(
|
let sub_exec = executor.field_sub_executor(
|
||||||
&response_name,
|
&response_name,
|
||||||
f.name.item,
|
f.name.item,
|
||||||
start_pos.clone(),
|
*start_pos,
|
||||||
f.selection_set.as_ref().map(|v| &v[..]),
|
f.selection_set.as_ref().map(|v| &v[..]),
|
||||||
);
|
);
|
||||||
let args = Arguments::new(
|
let args = Arguments::new(
|
||||||
|
@ -336,7 +336,7 @@ where
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
} else if let Err(e) = sub_result {
|
} else if let Err(e) = sub_result {
|
||||||
sub_exec.push_error_at(e, start_pos.clone());
|
sub_exec.push_error_at(e, *start_pos);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
async_values.push(AsyncValueFuture::InlineFragment2(async move {
|
async_values.push(AsyncValueFuture::InlineFragment2(async move {
|
||||||
|
|
|
@ -457,7 +457,7 @@ where
|
||||||
let sub_exec = executor.field_sub_executor(
|
let sub_exec = executor.field_sub_executor(
|
||||||
response_name,
|
response_name,
|
||||||
f.name.item,
|
f.name.item,
|
||||||
start_pos.clone(),
|
*start_pos,
|
||||||
f.selection_set.as_ref().map(|v| &v[..]),
|
f.selection_set.as_ref().map(|v| &v[..]),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -482,7 +482,7 @@ where
|
||||||
Ok(Value::Null) if meta_field.field_type.is_non_null() => return false,
|
Ok(Value::Null) if meta_field.field_type.is_non_null() => return false,
|
||||||
Ok(v) => merge_key_into(result, response_name, v),
|
Ok(v) => merge_key_into(result, response_name, v),
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
sub_exec.push_error_at(e, start_pos.clone());
|
sub_exec.push_error_at(e, *start_pos);
|
||||||
|
|
||||||
if meta_field.field_type.is_non_null() {
|
if meta_field.field_type.is_non_null() {
|
||||||
return false;
|
return false;
|
||||||
|
@ -540,7 +540,7 @@ where
|
||||||
merge_key_into(result, &k, v);
|
merge_key_into(result, &k, v);
|
||||||
}
|
}
|
||||||
} else if let Err(e) = sub_result {
|
} else if let Err(e) = sub_result {
|
||||||
sub_exec.push_error_at(e, start_pos.clone());
|
sub_exec.push_error_at(e, *start_pos);
|
||||||
}
|
}
|
||||||
} else if !resolve_selection_set_into(
|
} else if !resolve_selection_set_into(
|
||||||
instance,
|
instance,
|
||||||
|
|
|
@ -80,7 +80,7 @@ where
|
||||||
T: FromInputValue<S>,
|
T: FromInputValue<S>,
|
||||||
S: ScalarValue,
|
S: ScalarValue,
|
||||||
{
|
{
|
||||||
fn from_input_value<'a>(v: &'a InputValue<S>) -> Option<Option<T>> {
|
fn from_input_value(v: &InputValue<S>) -> Option<Option<T>> {
|
||||||
match v {
|
match v {
|
||||||
&InputValue::Null => Some(None),
|
&InputValue::Null => Some(None),
|
||||||
v => v.convert().map(Some),
|
v => v.convert().map(Some),
|
||||||
|
@ -163,7 +163,7 @@ where
|
||||||
T: FromInputValue<S>,
|
T: FromInputValue<S>,
|
||||||
S: ScalarValue,
|
S: ScalarValue,
|
||||||
{
|
{
|
||||||
fn from_input_value<'a>(v: &'a InputValue<S>) -> Option<Vec<T>>
|
fn from_input_value(v: &InputValue<S>) -> Option<Vec<T>>
|
||||||
where {
|
where {
|
||||||
match *v {
|
match *v {
|
||||||
InputValue::List(ref ls) => {
|
InputValue::List(ref ls) => {
|
||||||
|
|
|
@ -93,7 +93,7 @@ where
|
||||||
S: ScalarValue,
|
S: ScalarValue,
|
||||||
T: FromInputValue<S>,
|
T: FromInputValue<S>,
|
||||||
{
|
{
|
||||||
fn from_input_value<'a>(v: &'a InputValue<S>) -> Option<Box<T>> {
|
fn from_input_value(v: &InputValue<S>) -> Option<Box<T>> {
|
||||||
match <T as FromInputValue<S>>::from_input_value(v) {
|
match <T as FromInputValue<S>>::from_input_value(v) {
|
||||||
Some(v) => Some(Box::new(v)),
|
Some(v) => Some(Box::new(v)),
|
||||||
None => None,
|
None => None,
|
||||||
|
|
|
@ -293,7 +293,7 @@ where
|
||||||
let sub_exec = executor.field_sub_executor(
|
let sub_exec = executor.field_sub_executor(
|
||||||
response_name,
|
response_name,
|
||||||
f.name.item,
|
f.name.item,
|
||||||
start_pos.clone(),
|
*start_pos,
|
||||||
f.selection_set.as_ref().map(|x| &x[..]),
|
f.selection_set.as_ref().map(|x| &x[..]),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -319,7 +319,7 @@ where
|
||||||
}
|
}
|
||||||
Ok(v) => merge_key_into(&mut object, response_name, v),
|
Ok(v) => merge_key_into(&mut object, response_name, v),
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
sub_exec.push_error_at(e, start_pos.clone());
|
sub_exec.push_error_at(e, *start_pos);
|
||||||
|
|
||||||
if meta_field.field_type.is_non_null() {
|
if meta_field.field_type.is_non_null() {
|
||||||
return Value::Null;
|
return Value::Null;
|
||||||
|
@ -365,7 +365,7 @@ where
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(e) => sub_exec.push_error_at(e, start_pos.clone()),
|
Err(e) => sub_exec.push_error_at(e, *start_pos),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -393,7 +393,7 @@ where
|
||||||
merge_key_into(&mut object, &k, v);
|
merge_key_into(&mut object, &k, v);
|
||||||
}
|
}
|
||||||
} else if let Err(e) = sub_result {
|
} else if let Err(e) = sub_result {
|
||||||
sub_exec.push_error_at(e, start_pos.clone());
|
sub_exec.push_error_at(e, *start_pos);
|
||||||
}
|
}
|
||||||
} else if let Some(type_name) = meta_type.name() {
|
} else if let Some(type_name) = meta_type.name() {
|
||||||
let sub_result = instance
|
let sub_result = instance
|
||||||
|
@ -405,7 +405,7 @@ where
|
||||||
merge_key_into(&mut object, &k, v);
|
merge_key_into(&mut object, &k, v);
|
||||||
}
|
}
|
||||||
} else if let Err(e) = sub_result {
|
} else if let Err(e) = sub_result {
|
||||||
sub_exec.push_error_at(e, start_pos.clone());
|
sub_exec.push_error_at(e, *start_pos);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return Value::Null;
|
return Value::Null;
|
||||||
|
|
|
@ -103,10 +103,10 @@ pub fn impl_enum(ast: syn::DeriveInput, error: GraphQLScope) -> syn::Result<Toke
|
||||||
if fields.is_empty() {
|
if fields.is_empty() {
|
||||||
error.not_empty(ast_span);
|
error.not_empty(ast_span);
|
||||||
}
|
}
|
||||||
|
if let Some(duplicates) =
|
||||||
match crate::util::duplicate::Duplicate::find_by_key(&fields, |field| &field.name) {
|
crate::util::duplicate::Duplicate::find_by_key(&fields, |field| &field.name)
|
||||||
Some(duplicates) => error.duplicate(duplicates.iter()),
|
{
|
||||||
None => {}
|
error.duplicate(duplicates.iter())
|
||||||
}
|
}
|
||||||
|
|
||||||
if !attrs.interfaces.is_empty() {
|
if !attrs.interfaces.is_empty() {
|
||||||
|
|
|
@ -102,9 +102,10 @@ pub fn impl_input_object(ast: syn::DeriveInput, error: GraphQLScope) -> syn::Res
|
||||||
error.not_empty(ast_span);
|
error.not_empty(ast_span);
|
||||||
}
|
}
|
||||||
|
|
||||||
match crate::util::duplicate::Duplicate::find_by_key(&fields, |field| &field.name) {
|
if let Some(duplicates) =
|
||||||
Some(duplicates) => error.duplicate(duplicates.iter()),
|
crate::util::duplicate::Duplicate::find_by_key(&fields, |field| &field.name)
|
||||||
None => {}
|
{
|
||||||
|
error.duplicate(duplicates.iter())
|
||||||
}
|
}
|
||||||
|
|
||||||
if !attrs.interfaces.is_empty() {
|
if !attrs.interfaces.is_empty() {
|
||||||
|
|
|
@ -36,13 +36,7 @@ pub fn expand(attr_args: TokenStream, body: TokenStream) -> syn::Result<TokenStr
|
||||||
ast.attrs = ast
|
ast.attrs = ast
|
||||||
.attrs
|
.attrs
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.filter_map(|attr| {
|
.filter(|attr| !path_eq_single(&attr.path, "graphql_union"))
|
||||||
if path_eq_single(&attr.path, "graphql_union") {
|
|
||||||
None
|
|
||||||
} else {
|
|
||||||
Some(attr)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let meta = UnionMeta::from_attrs("graphql_union", &trait_attrs)?;
|
let meta = UnionMeta::from_attrs("graphql_union", &trait_attrs)?;
|
||||||
|
@ -130,13 +124,7 @@ fn parse_variant_from_trait_method(
|
||||||
// Remove repeated attributes from the method, to omit incorrect expansion.
|
// Remove repeated attributes from the method, to omit incorrect expansion.
|
||||||
method.attrs = mem::take(&mut method.attrs)
|
method.attrs = mem::take(&mut method.attrs)
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.filter_map(|attr| {
|
.filter(|attr| !path_eq_single(&attr.path, "graphql_union"))
|
||||||
if path_eq_single(&attr.path, "graphql_union") {
|
|
||||||
None
|
|
||||||
} else {
|
|
||||||
Some(attr)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let meta = UnionVariantMeta::from_attrs("graphql_union", &method_attrs)
|
let meta = UnionVariantMeta::from_attrs("graphql_union", &method_attrs)
|
||||||
|
@ -299,7 +287,7 @@ fn parse_trait_method_input_args(sig: &syn::Signature) -> Result<Option<syn::Typ
|
||||||
return Err(sig.inputs.span());
|
return Err(sig.inputs.span());
|
||||||
}
|
}
|
||||||
|
|
||||||
let second_arg_ty = match sig.inputs.iter().skip(1).next() {
|
let second_arg_ty = match sig.inputs.iter().nth(1) {
|
||||||
Some(syn::FnArg::Typed(arg)) => arg.ty.deref(),
|
Some(syn::FnArg::Typed(arg)) => arg.ty.deref(),
|
||||||
None => return Ok(None),
|
None => return Ok(None),
|
||||||
_ => return Err(sig.inputs.span()),
|
_ => return Err(sig.inputs.span()),
|
||||||
|
|
|
@ -696,7 +696,7 @@ fn emerge_union_variants_from_meta(
|
||||||
///
|
///
|
||||||
/// [1]: https://spec.graphql.org/June2018/#sec-Unions
|
/// [1]: https://spec.graphql.org/June2018/#sec-Unions
|
||||||
/// [2]: https://docs.rs/static_assertions/latest/static_assertions/macro.assert_type_ne_all.html
|
/// [2]: https://docs.rs/static_assertions/latest/static_assertions/macro.assert_type_ne_all.html
|
||||||
fn all_variants_different(variants: &Vec<UnionVariantDefinition>) -> bool {
|
fn all_variants_different(variants: &[UnionVariantDefinition]) -> bool {
|
||||||
let mut types: Vec<_> = variants.iter().map(|var| &var.ty).collect();
|
let mut types: Vec<_> = variants.iter().map(|var| &var.ty).collect();
|
||||||
types.dedup();
|
types.dedup();
|
||||||
types.len() == variants.len()
|
types.len() == variants.len()
|
||||||
|
|
|
@ -14,7 +14,7 @@ pub fn build_object(args: TokenStream, body: TokenStream, error: GraphQLScope) -
|
||||||
Ok(definition) => definition,
|
Ok(definition) => definition,
|
||||||
Err(err) => return err.to_compile_error(),
|
Err(err) => return err.to_compile_error(),
|
||||||
};
|
};
|
||||||
definition.into_tokens().into()
|
definition.into_tokens()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Generate code for the juniper::graphql_subscription macro.
|
/// Generate code for the juniper::graphql_subscription macro.
|
||||||
|
@ -27,7 +27,7 @@ pub fn build_subscription(
|
||||||
Ok(definition) => definition,
|
Ok(definition) => definition,
|
||||||
Err(err) => return err.to_compile_error(),
|
Err(err) => return err.to_compile_error(),
|
||||||
};
|
};
|
||||||
definition.into_subscription_tokens().into()
|
definition.into_subscription_tokens()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create(
|
fn create(
|
||||||
|
@ -172,9 +172,10 @@ fn create(
|
||||||
// Early abort after checking all fields
|
// Early abort after checking all fields
|
||||||
proc_macro_error::abort_if_dirty();
|
proc_macro_error::abort_if_dirty();
|
||||||
|
|
||||||
match crate::util::duplicate::Duplicate::find_by_key(&fields, |field| &field.name) {
|
if let Some(duplicates) =
|
||||||
Some(duplicates) => error.duplicate(duplicates.iter()),
|
crate::util::duplicate::Duplicate::find_by_key(&fields, |field| &field.name)
|
||||||
None => {}
|
{
|
||||||
|
error.duplicate(duplicates.iter())
|
||||||
}
|
}
|
||||||
|
|
||||||
if !_impl.attrs.is_internal && name.starts_with("__") {
|
if !_impl.attrs.is_internal && name.starts_with("__") {
|
||||||
|
|
|
@ -183,37 +183,45 @@ pub fn build_scalar(
|
||||||
let attrs = syn::parse2::<util::FieldAttributes>(attributes)?;
|
let attrs = syn::parse2::<util::FieldAttributes>(attributes)?;
|
||||||
let input = syn::parse2::<ScalarCodegenInput>(body)?;
|
let input = syn::parse2::<ScalarCodegenInput>(body)?;
|
||||||
|
|
||||||
let impl_for_type = input.impl_for_type.ok_or(error.custom_error(
|
let impl_for_type = input.impl_for_type.ok_or_else(|| {
|
||||||
body_span,
|
error.custom_error(
|
||||||
"unable to find target for implementation target for `GraphQLScalar`",
|
body_span,
|
||||||
))?;
|
"unable to find target for implementation target for `GraphQLScalar`",
|
||||||
|
)
|
||||||
|
})?;
|
||||||
let custom_data_type = input
|
let custom_data_type = input
|
||||||
.custom_data_type
|
.custom_data_type
|
||||||
.ok_or(error.custom_error(body_span, "unable to find custom scalar data type"))?;
|
.ok_or_else(|| error.custom_error(body_span, "unable to find custom scalar data type"))?;
|
||||||
let resolve_body = input
|
let resolve_body = input
|
||||||
.resolve_body
|
.resolve_body
|
||||||
.ok_or(error.custom_error(body_span, "unable to find body of `resolve` method"))?;
|
.ok_or_else(|| error.custom_error(body_span, "unable to find body of `resolve` method"))?;
|
||||||
let from_input_value_arg = input.from_input_value_arg.ok_or(error.custom_error(
|
let from_input_value_arg = input.from_input_value_arg.ok_or_else(|| {
|
||||||
body_span,
|
error.custom_error(
|
||||||
"unable to find argument for `from_input_value` method",
|
body_span,
|
||||||
))?;
|
"unable to find argument for `from_input_value` method",
|
||||||
let from_input_value_body = input.from_input_value_body.ok_or(error.custom_error(
|
)
|
||||||
body_span,
|
})?;
|
||||||
"unable to find body of `from_input_value` method",
|
let from_input_value_body = input.from_input_value_body.ok_or_else(|| {
|
||||||
))?;
|
error.custom_error(
|
||||||
let from_input_value_result = input.from_input_value_result.ok_or(error.custom_error(
|
body_span,
|
||||||
body_span,
|
"unable to find body of `from_input_value` method",
|
||||||
"unable to find return type of `from_input_value` method",
|
)
|
||||||
))?;
|
})?;
|
||||||
let from_str_arg = input
|
let from_input_value_result = input.from_input_value_result.ok_or_else(|| {
|
||||||
.from_str_arg
|
error.custom_error(
|
||||||
.ok_or(error.custom_error(body_span, "unable to find argument for `from_str` method"))?;
|
body_span,
|
||||||
|
"unable to find return type of `from_input_value` method",
|
||||||
|
)
|
||||||
|
})?;
|
||||||
|
let from_str_arg = input.from_str_arg.ok_or_else(|| {
|
||||||
|
error.custom_error(body_span, "unable to find argument for `from_str` method")
|
||||||
|
})?;
|
||||||
let from_str_body = input
|
let from_str_body = input
|
||||||
.from_str_body
|
.from_str_body
|
||||||
.ok_or(error.custom_error(body_span, "unable to find body of `from_str` method"))?;
|
.ok_or_else(|| error.custom_error(body_span, "unable to find body of `from_str` method"))?;
|
||||||
let from_str_result = input
|
let from_str_result = input.from_str_result.ok_or_else(|| {
|
||||||
.from_str_result
|
error.custom_error(body_span, "unable to find return type of `from_str` method")
|
||||||
.ok_or(error.custom_error(body_span, "unable to find return type of `from_str` method"))?;
|
})?;
|
||||||
|
|
||||||
let name = attrs
|
let name = attrs
|
||||||
.name
|
.name
|
||||||
|
|
|
@ -6,7 +6,7 @@ use proc_macro_error::{Diagnostic, Level};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
||||||
/// URL of the GraphQL specification (June 2018 Edition).
|
/// URL of the GraphQL specification (June 2018 Edition).
|
||||||
pub const SPEC_URL: &'static str = "https://spec.graphql.org/June2018/";
|
pub const SPEC_URL: &str = "https://spec.graphql.org/June2018/";
|
||||||
|
|
||||||
#[allow(unused_variables)]
|
#[allow(unused_variables)]
|
||||||
pub enum GraphQLScope {
|
pub enum GraphQLScope {
|
||||||
|
|
|
@ -600,7 +600,7 @@ impl FieldAttributes {
|
||||||
let doc_comment = get_doc_comment(&attrs);
|
let doc_comment = get_doc_comment(&attrs);
|
||||||
let deprecation = get_deprecated(&attrs);
|
let deprecation = get_deprecated(&attrs);
|
||||||
|
|
||||||
let attr_opt = attrs.into_iter().find(|attr| attr.path.is_ident("graphql"));
|
let attr_opt = attrs.iter().find(|attr| attr.path.is_ident("graphql"));
|
||||||
|
|
||||||
let mut output = match attr_opt {
|
let mut output = match attr_opt {
|
||||||
Some(attr) => attr.parse_args()?,
|
Some(attr) => attr.parse_args()?,
|
||||||
|
|
|
@ -257,7 +257,7 @@ where
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
if strict {
|
if strict {
|
||||||
return Err(format!("Prohibited extra field '{}'", key).to_owned());
|
return Err(format!("Prohibited extra field '{}'", key));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue