Skip to content

Commit 80c1290

Browse files
committed
fixes
1 parent a183415 commit 80c1290

26 files changed

+352
-252
lines changed

src/ast/collect_fields.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ fn does_fragment_condition_match<'a>(
4747
return interface_type.is_implemented_by(current_selection_set_type)
4848
}
4949
TypeDefinition::Union(union_type) => {
50-
return union_type.has_sub_type(&current_selection_set_type.name())
50+
return union_type.has_sub_type(current_selection_set_type.name())
5151
}
5252
_ => return false,
5353
}
@@ -70,14 +70,14 @@ fn collect_fields_inner<'a>(
7070
) {
7171
selection_set.items.iter().for_each(|item| match item {
7272
Selection::Field(f) => {
73-
let existing = result_arr.entry(f.name.clone()).or_insert(vec![]);
73+
let existing = result_arr.entry(f.name.clone()).or_default();
7474
existing.push(f.clone());
7575
}
7676
Selection::InlineFragment(f) => {
7777
if does_fragment_condition_match(&f.type_condition, parent_type, context) {
7878
collect_fields_inner(
7979
&f.selection_set,
80-
&parent_type,
80+
parent_type,
8181
known_fragments,
8282
context,
8383
result_arr,
@@ -86,22 +86,21 @@ fn collect_fields_inner<'a>(
8686
}
8787
}
8888
Selection::FragmentSpread(f) => {
89-
if visited_fragments_names
89+
if !visited_fragments_names
9090
.iter()
91-
.find(|name| f.fragment_name.eq(*name))
92-
.is_none()
91+
.any(|name| f.fragment_name.eq(name))
9392
{
9493
visited_fragments_names.push(f.fragment_name.clone());
9594

9695
if let Some(fragment) = known_fragments.get(f.fragment_name.as_str()) {
9796
if does_fragment_condition_match(
9897
&Some(fragment.type_condition.clone()),
99-
&parent_type,
98+
parent_type,
10099
context,
101100
) {
102101
collect_fields_inner(
103102
&fragment.selection_set,
104-
&parent_type,
103+
parent_type,
105104
known_fragments,
106105
context,
107106
result_arr,

src/ast/ext.rs

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ impl OperationDefinitionExtension for OperationDefinition {
5757
fn selection_set(&self) -> &SelectionSet {
5858
match self {
5959
OperationDefinition::Query(query) => &query.selection_set,
60-
OperationDefinition::SelectionSet(selection_set) => &selection_set,
60+
OperationDefinition::SelectionSet(selection_set) => selection_set,
6161
OperationDefinition::Mutation(mutation) => &mutation.selection_set,
6262
OperationDefinition::Subscription(subscription) => &subscription.selection_set,
6363
}
@@ -156,7 +156,7 @@ impl SchemaDocumentExtension for schema::Document {
156156
self.schema_definition()
157157
.subscription
158158
.as_ref()
159-
.and_then(|name| self.object_type_by_name(&name))
159+
.and_then(|name| self.object_type_by_name(name))
160160
}
161161

162162
fn object_type_by_name(&self, name: &str) -> Option<&ObjectType> {
@@ -185,7 +185,7 @@ impl SchemaDocumentExtension for schema::Document {
185185
self.type_by_name(sub_type_name),
186186
self.type_by_name(super_type_name),
187187
) {
188-
super_type.is_abstract_type() && self.is_possible_type(&super_type, &sub_type)
188+
super_type.is_abstract_type() && self.is_possible_type(super_type, sub_type)
189189
} else {
190190
false
191191
}
@@ -206,7 +206,7 @@ impl SchemaDocumentExtension for schema::Document {
206206
TypeDefinition::Interface(interface_typedef) => {
207207
let implementes_interfaces = possible_type.interfaces();
208208

209-
return implementes_interfaces.contains(&interface_typedef.name);
209+
implementes_interfaces.contains(&interface_typedef.name)
210210
}
211211
_ => false,
212212
}
@@ -248,12 +248,12 @@ impl SchemaDocumentExtension for schema::Document {
248248
// If superType type is an abstract type, check if it is super type of maybeSubType.
249249
// Otherwise, the child type is not a valid subtype of the parent type.
250250
if let (Some(sub_type), Some(super_type)) = (
251-
self.type_by_name(&sub_type.inner_type()),
252-
self.type_by_name(&super_type.inner_type()),
251+
self.type_by_name(sub_type.inner_type()),
252+
self.type_by_name(super_type.inner_type()),
253253
) {
254254
return super_type.is_abstract_type()
255255
&& (sub_type.is_interface_type() || sub_type.is_object_type())
256-
&& self.is_possible_type(&super_type, &sub_type);
256+
&& self.is_possible_type(super_type, sub_type);
257257
}
258258

259259
false
@@ -350,7 +350,7 @@ pub trait InputValueHelpers {
350350
impl InputValueHelpers for InputValue {
351351
fn is_required(&self) -> bool {
352352
if let Type::NonNullType(_inner_type) = &self.value_type {
353-
if let None = &self.default_value {
353+
if self.default_value.is_none() {
354354
return true;
355355
}
356356
}
@@ -394,22 +394,20 @@ impl ImplementingInterfaceExtension for TypeDefinition {
394394
fn has_sub_type(&self, other_type: &TypeDefinition) -> bool {
395395
match self {
396396
TypeDefinition::Interface(interface_type) => {
397-
return interface_type.is_implemented_by(other_type)
397+
interface_type.is_implemented_by(other_type)
398398
}
399399
TypeDefinition::Union(union_type) => return union_type.has_sub_type(other_type.name()),
400-
_ => return false,
400+
_ => false,
401401
}
402402
}
403403

404404
fn has_concrete_sub_type(&self, concrete_type: &ObjectType) -> bool {
405405
match self {
406406
TypeDefinition::Interface(interface_type) => {
407-
return interface_type.is_implemented_by(concrete_type)
408-
}
409-
TypeDefinition::Union(union_type) => {
410-
return union_type.has_sub_type(&concrete_type.name)
407+
interface_type.is_implemented_by(concrete_type)
411408
}
412-
_ => return false,
409+
TypeDefinition::Union(union_type) => union_type.has_sub_type(&concrete_type.name),
410+
_ => false,
413411
}
414412
}
415413
}
@@ -487,17 +485,13 @@ pub trait SubTypeExtension {
487485

488486
impl SubTypeExtension for UnionType {
489487
fn has_sub_type(&self, other_type_name: &str) -> bool {
490-
self.types.iter().find(|v| other_type_name.eq(*v)).is_some()
488+
self.types.iter().any(|v| other_type_name.eq(v))
491489
}
492490
}
493491

494492
impl AbstractTypeDefinitionExtension for InterfaceType {
495493
fn is_implemented_by(&self, other_type: &dyn ImplementingInterfaceExtension) -> bool {
496-
other_type
497-
.interfaces()
498-
.iter()
499-
.find(|v| self.name.eq(*v))
500-
.is_some()
494+
other_type.interfaces().iter().any(|v| self.name.eq(v))
501495
}
502496
}
503497

src/ast/operation_transformer.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ impl<T> TransformedValue<T> {
3131
}
3232
}
3333

34-
impl<T> Into<Transformed<T>> for TransformedValue<T> {
35-
fn into(self) -> Transformed<T> {
36-
match self {
34+
impl<T> From<TransformedValue<T>> for Transformed<T> {
35+
fn from(val: TransformedValue<T>) -> Self {
36+
match val {
3737
TransformedValue::Keep => Transformed::Keep,
3838
TransformedValue::Replace(replacement) => Transformed::Replace(replacement),
3939
}
@@ -417,7 +417,7 @@ pub trait OperationTransformer<'a, T: Text<'a> + Clone> {
417417
) -> Transformed<(T::Value, Value<'a, T>)> {
418418
let (name, value) = argument;
419419

420-
match self.transform_value(&value) {
420+
match self.transform_value(value) {
421421
TransformedValue::Keep => Transformed::Keep,
422422
TransformedValue::Replace(replacement) => {
423423
Transformed::Replace((name.clone(), replacement))
@@ -486,7 +486,7 @@ pub trait OperationTransformer<'a, T: Text<'a> + Clone> {
486486
}
487487
}
488488

489-
return TransformedValue::Keep;
489+
TransformedValue::Keep
490490
}
491491

492492
fn transform_list<I, F, R>(&mut self, list: &[I], f: F) -> TransformedValue<Vec<I>>

src/ast/operation_visitor.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,11 @@ impl<'a> OperationVisitorContext<'a> {
5555

5656
pub fn with_type<Func>(&mut self, t: Option<&Type>, func: Func)
5757
where
58-
Func: FnOnce(&mut OperationVisitorContext<'a>) -> (),
58+
Func: FnOnce(&mut OperationVisitorContext<'a>),
5959
{
6060
if let Some(t) = t {
6161
self.type_stack
62-
.push(self.schema.type_by_name(&t.inner_type()));
62+
.push(self.schema.type_by_name(t.inner_type()));
6363
} else {
6464
self.type_stack.push(None);
6565
}
@@ -72,17 +72,17 @@ impl<'a> OperationVisitorContext<'a> {
7272

7373
pub fn with_parent_type<Func>(&mut self, func: Func)
7474
where
75-
Func: FnOnce(&mut OperationVisitorContext<'a>) -> (),
75+
Func: FnOnce(&mut OperationVisitorContext<'a>),
7676
{
7777
self.parent_type_stack
78-
.push(self.type_stack.last().unwrap_or(&None).clone());
78+
.push(*self.type_stack.last().unwrap_or(&None));
7979
func(self);
8080
self.parent_type_stack.pop();
8181
}
8282

8383
pub fn with_field<'f, Func>(&mut self, f: Option<&'f schema::Field>, func: Func)
8484
where
85-
Func: FnOnce(&mut OperationVisitorContext<'a>) -> (),
85+
Func: FnOnce(&mut OperationVisitorContext<'a>),
8686
'f: 'a,
8787
{
8888
if let Some(f) = f {
@@ -97,11 +97,11 @@ impl<'a> OperationVisitorContext<'a> {
9797

9898
pub fn with_input_type<Func>(&mut self, t: Option<&'a Type>, func: Func)
9999
where
100-
Func: FnOnce(&mut OperationVisitorContext<'a>) -> (),
100+
Func: FnOnce(&mut OperationVisitorContext<'a>),
101101
{
102-
if let Some(ref t) = t {
102+
if let Some(t) = t {
103103
self.input_type_stack
104-
.push(self.schema.type_by_name(&t.inner_type()));
104+
.push(self.schema.type_by_name(t.inner_type()));
105105
} else {
106106
self.input_type_stack.push(None);
107107
}
@@ -277,8 +277,8 @@ fn visit_input_value<'a, Visitor, UserContext>(
277277
for (sub_key, sub_value) in v.iter() {
278278
let input_type = context
279279
.current_input_type_literal()
280-
.and_then(|v| context.schema.type_by_name(&v.inner_type()))
281-
.and_then(|v| v.input_field_by_name(&sub_key))
280+
.and_then(|v| context.schema.type_by_name(v.inner_type()))
281+
.and_then(|v| v.input_field_by_name(sub_key))
282282
.and_then(|v| Some(&v.value_type));
283283

284284
context.with_input_type(input_type, |context| {
@@ -311,7 +311,7 @@ fn visit_variable_definitions<'a, Visitor, UserContext>(
311311
visitor.enter_variable_definition(context, user_context, variable);
312312

313313
if let Some(default_value) = &variable.default_value {
314-
visit_input_value(visitor, &default_value, context, user_context);
314+
visit_input_value(visitor, default_value, context, user_context);
315315
}
316316

317317
// DOTAN: We should visit the directives as well here, but it's extracted in graphql_parser.
@@ -335,7 +335,7 @@ fn visit_selection<'a, Visitor, UserContext>(
335335
.current_parent_type()
336336
.and_then(|t| t.field_by_name(&field.name));
337337

338-
let field_type = parent_type_def.clone().map(|f| &f.field_type);
338+
let field_type = parent_type_def.map(|f| &f.field_type);
339339
let field_args = parent_type_def.map(|f| &f.arguments);
340340

341341
context.with_type(field_type, |context| {

src/validation/rules/fields_on_correct_type.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ use super::ValidationRule;
1313
/// See https://spec.graphql.org/draft/#sec-Field-Selections
1414
pub struct FieldsOnCorrectType;
1515

16+
impl Default for FieldsOnCorrectType {
17+
fn default() -> Self {
18+
Self::new()
19+
}
20+
}
21+
1622
impl FieldsOnCorrectType {
1723
pub fn new() -> Self {
1824
FieldsOnCorrectType
@@ -56,7 +62,7 @@ impl<'a> OperationVisitor<'a, ValidationErrorContext> for FieldsOnCorrectType {
5662
return;
5763
}
5864

59-
if let None = parent_type.field_by_name(field_name) {
65+
if parent_type.field_by_name(field_name).is_none() {
6066
user_context.report_error(ValidationError {
6167
error_code: self.error_code(),
6268
locations: vec![field.position],
@@ -75,14 +81,14 @@ impl ValidationRule for FieldsOnCorrectType {
7581
"FieldsOnCorrectType"
7682
}
7783

78-
fn validate<'a>(
84+
fn validate(
7985
&self,
80-
ctx: &'a mut OperationVisitorContext,
86+
ctx: &mut OperationVisitorContext,
8187
error_collector: &mut ValidationErrorContext,
8288
) {
8389
visit_document(
8490
&mut FieldsOnCorrectType::new(),
85-
&ctx.operation,
91+
ctx.operation,
8692
ctx,
8793
error_collector,
8894
);

src/validation/rules/fragments_on_composite_types.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ use crate::validation::utils::{ValidationError, ValidationErrorContext};
1515
/// https://spec.graphql.org/draft/#sec-Fragments-On-Composite-Types
1616
pub struct FragmentsOnCompositeTypes;
1717

18+
impl Default for FragmentsOnCompositeTypes {
19+
fn default() -> Self {
20+
Self::new()
21+
}
22+
}
23+
1824
impl FragmentsOnCompositeTypes {
1925
pub fn new() -> Self {
2026
FragmentsOnCompositeTypes
@@ -72,14 +78,14 @@ impl ValidationRule for FragmentsOnCompositeTypes {
7278
"FragmentsOnCompositeTypes"
7379
}
7480

75-
fn validate<'a>(
81+
fn validate(
7682
&self,
77-
ctx: &'a mut OperationVisitorContext,
83+
ctx: &mut OperationVisitorContext,
7884
error_collector: &mut ValidationErrorContext,
7985
) {
8086
visit_document(
8187
&mut FragmentsOnCompositeTypes::new(),
82-
&ctx.operation,
88+
ctx.operation,
8389
ctx,
8490
error_collector,
8591
);

src/validation/rules/known_argument_names.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ enum ArgumentParent<'a> {
2424
Directive(&'a str),
2525
}
2626

27+
impl<'a> Default for KnownArgumentNames<'a> {
28+
fn default() -> Self {
29+
Self::new()
30+
}
31+
}
32+
2733
impl<'a> KnownArgumentNames<'a> {
2834
pub fn new() -> Self {
2935
KnownArgumentNames {
@@ -128,14 +134,14 @@ impl<'k> ValidationRule for KnownArgumentNames<'k> {
128134
"KnownArgumentNames"
129135
}
130136

131-
fn validate<'a>(
137+
fn validate(
132138
&self,
133-
ctx: &'a mut OperationVisitorContext,
139+
ctx: &mut OperationVisitorContext,
134140
error_collector: &mut ValidationErrorContext,
135141
) {
136142
visit_document(
137143
&mut KnownArgumentNames::new(),
138-
&ctx.operation,
144+
ctx.operation,
139145
ctx,
140146
error_collector,
141147
);

0 commit comments

Comments
 (0)