Skip to content

Commit 9d4a06e

Browse files
committed
formatting
1 parent cdb4883 commit 9d4a06e

16 files changed

+91
-53
lines changed

src/validation/rules/known_argument_names.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ impl<'a> OperationVisitor<'a, ValidationErrorContext> for KnownArgumentNames<'a>
9797
match arg_position {
9898
ArgumentParent::Field(field_name, type_name) => {
9999
user_context.report_error(ValidationError {
100-
error_code: self.error_code(),
100+
error_code: self.error_code(),
101101
message: format!(
102102
"Unknown argument \"{}\" on field \"{}.{}\".",
103103
argument_name,
@@ -109,7 +109,7 @@ impl<'a> OperationVisitor<'a, ValidationErrorContext> for KnownArgumentNames<'a>
109109
}
110110
ArgumentParent::Directive(directive_name) => {
111111
user_context.report_error(ValidationError {
112-
error_code: self.error_code(),
112+
error_code: self.error_code(),
113113
message: format!(
114114
"Unknown argument \"{}\" on directive \"@{}\".",
115115
argument_name, directive_name

src/validation/rules/known_directives.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,8 @@ impl<'a> OperationVisitor<'a, ValidationErrorContext> for KnownDirectives {
133133
.iter()
134134
.any(|l| l == current_location)
135135
{
136-
user_context.report_error(ValidationError {error_code: self.error_code(),
136+
user_context.report_error(ValidationError {
137+
error_code: self.error_code(),
137138
locations: vec![directive.position],
138139
message: format!(
139140
"Directive \"@{}\" may not be used on {}",
@@ -144,7 +145,8 @@ impl<'a> OperationVisitor<'a, ValidationErrorContext> for KnownDirectives {
144145
}
145146
}
146147
} else {
147-
user_context.report_error(ValidationError {error_code: self.error_code(),
148+
user_context.report_error(ValidationError {
149+
error_code: self.error_code(),
148150
locations: vec![directive.position],
149151
message: format!("Unknown directive \"@{}\".", directive.name),
150152
});

src/validation/rules/known_fragment_names.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ impl<'a> OperationVisitor<'a, ValidationErrorContext> for KnownFragmentNames {
2828
.known_fragments
2929
.get(fragment_spread.fragment_name.as_str())
3030
{
31-
None => user_context.report_error(ValidationError {error_code: self.error_code(),
31+
None => user_context.report_error(ValidationError {
32+
error_code: self.error_code(),
3233
locations: vec![fragment_spread.position],
3334
message: format!("Unknown fragment \"{}\".", fragment_spread.fragment_name),
3435
}),

src/validation/rules/known_type_names.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ impl<'a> OperationVisitor<'a, ValidationErrorContext> for KnownTypeNames {
3131

3232
if let None = visitor_context.schema.type_by_name(fragment_type_name) {
3333
if !fragment_type_name.starts_with("__") {
34-
user_context.report_error(ValidationError {error_code: self.error_code(),
34+
user_context.report_error(ValidationError {
35+
error_code: self.error_code(),
3536
locations: vec![fragment_definition.position],
3637
message: format!("Unknown type \"{}\".", fragment_type_name),
3738
});
@@ -48,7 +49,8 @@ impl<'a> OperationVisitor<'a, ValidationErrorContext> for KnownTypeNames {
4849
if let Some(TypeCondition::On(fragment_type_name)) = &inline_fragment.type_condition {
4950
if let None = visitor_context.schema.type_by_name(fragment_type_name) {
5051
if !fragment_type_name.starts_with("__") {
51-
user_context.report_error(ValidationError {error_code: self.error_code(),
52+
user_context.report_error(ValidationError {
53+
error_code: self.error_code(),
5254
locations: vec![inline_fragment.position],
5355
message: format!("Unknown type \"{}\".", fragment_type_name),
5456
});
@@ -67,7 +69,8 @@ impl<'a> OperationVisitor<'a, ValidationErrorContext> for KnownTypeNames {
6769

6870
if let None = visitor_context.schema.type_by_name(&base_type) {
6971
if !base_type.starts_with("__") {
70-
user_context.report_error(ValidationError {error_code: self.error_code(),
72+
user_context.report_error(ValidationError {
73+
error_code: self.error_code(),
7174
locations: vec![variable_definition.position],
7275
message: format!("Unknown type \"{}\".", base_type),
7376
});

src/validation/rules/leaf_field_selections.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ impl<'a> OperationVisitor<'a, ValidationErrorContext> for LeafFieldSelections {
3232

3333
if field_type.is_leaf_type() {
3434
if field_selection_count > 0 {
35-
user_context.report_error(ValidationError {error_code: self.error_code(),
35+
user_context.report_error(ValidationError {
36+
error_code: self.error_code(),
3637
locations: vec![field.position],
3738
message: format!(
3839
"Field \"{}\" must not have a selection since type \"{}\" has no subfields.",

src/validation/rules/lone_anonymous_operation.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ impl<'a> OperationVisitor<'a, ValidationErrorContext> for LoneAnonymousOperation
4040
match definition {
4141
Definition::Operation(OperationDefinition::SelectionSet(_)) => {
4242
if operations_count > 1 {
43-
user_context.report_error(ValidationError {error_code: self.error_code(),
43+
user_context.report_error(ValidationError {
44+
error_code: self.error_code(),
4445
message: "This anonymous operation must be the only defined operation."
4546
.to_string(),
4647
locations: vec![],
@@ -49,7 +50,8 @@ impl<'a> OperationVisitor<'a, ValidationErrorContext> for LoneAnonymousOperation
4950
}
5051
Definition::Operation(OperationDefinition::Query(query)) => {
5152
if query.name == None && operations_count > 1 {
52-
user_context.report_error(ValidationError {error_code: self.error_code(),
53+
user_context.report_error(ValidationError {
54+
error_code: self.error_code(),
5355
message: "This anonymous operation must be the only defined operation."
5456
.to_string(),
5557
locations: vec![query.position.clone()],
@@ -58,7 +60,8 @@ impl<'a> OperationVisitor<'a, ValidationErrorContext> for LoneAnonymousOperation
5860
}
5961
Definition::Operation(OperationDefinition::Mutation(mutation)) => {
6062
if mutation.name == None && operations_count > 1 {
61-
user_context.report_error(ValidationError {error_code: self.error_code(),
63+
user_context.report_error(ValidationError {
64+
error_code: self.error_code(),
6265
message: "This anonymous operation must be the only defined operation."
6366
.to_string(),
6467
locations: vec![mutation.position.clone()],
@@ -67,7 +70,8 @@ impl<'a> OperationVisitor<'a, ValidationErrorContext> for LoneAnonymousOperation
6770
}
6871
Definition::Operation(OperationDefinition::Subscription(subscription)) => {
6972
if subscription.name == None && operations_count > 1 {
70-
user_context.report_error(ValidationError {error_code: self.error_code(),
73+
user_context.report_error(ValidationError {
74+
error_code: self.error_code(),
7175
message: "This anonymous operation must be the only defined operation."
7276
.to_string(),
7377
locations: vec![subscription.position.clone()],

src/validation/rules/no_fragments_cycle.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ impl NoFragmentsCycle {
7373
.collect::<Vec<String>>(),
7474
};
7575

76-
error_context.report_error(ValidationError {error_code: self.error_code(),
76+
error_context.report_error(ValidationError {
77+
error_code: self.error_code(),
7778
locations: cycle_path.iter().map(|f| f.position.clone()).collect(),
7879
message: match via_path.len() {
7980
0 => {

src/validation/rules/no_undefined_variables.rs

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ use std::collections::{HashMap, HashSet};
1313
///
1414
/// See https://spec.graphql.org/draft/#sec-All-Variable-Uses-Defined
1515
pub struct NoUndefinedVariables<'a> {
16-
current_scope: Option<Scope<'a>>,
16+
current_scope: Option<NoUndefinedVariablesScope<'a>>,
1717
defined_variables: HashMap<Option<&'a str>, HashSet<&'a str>>,
18-
used_variables: HashMap<Scope<'a>, Vec<&'a str>>,
19-
spreads: HashMap<Scope<'a>, Vec<&'a str>>,
18+
used_variables: HashMap<NoUndefinedVariablesScope<'a>, Vec<&'a str>>,
19+
spreads: HashMap<NoUndefinedVariablesScope<'a>, Vec<&'a str>>,
2020
}
2121

2222
impl<'a> NoUndefinedVariables<'a> {
@@ -33,10 +33,10 @@ impl<'a> NoUndefinedVariables<'a> {
3333
impl<'a> NoUndefinedVariables<'a> {
3434
fn find_undefined_vars(
3535
&self,
36-
from: &Scope<'a>,
36+
from: &NoUndefinedVariablesScope<'a>,
3737
defined: &HashSet<&str>,
3838
unused: &mut HashSet<&'a str>,
39-
visited: &mut HashSet<Scope<'a>>,
39+
visited: &mut HashSet<NoUndefinedVariablesScope<'a>>,
4040
) {
4141
if visited.contains(from) {
4242
return;
@@ -54,14 +54,19 @@ impl<'a> NoUndefinedVariables<'a> {
5454

5555
if let Some(spreads) = self.spreads.get(from) {
5656
for spread in spreads {
57-
self.find_undefined_vars(&Scope::Fragment(spread), defined, unused, visited);
57+
self.find_undefined_vars(
58+
&NoUndefinedVariablesScope::Fragment(spread),
59+
defined,
60+
unused,
61+
visited,
62+
);
5863
}
5964
}
6065
}
6166
}
6267

6368
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
64-
pub enum Scope<'a> {
69+
pub enum NoUndefinedVariablesScope<'a> {
6570
Operation(Option<&'a str>),
6671
Fragment(&'a str),
6772
}
@@ -74,7 +79,7 @@ impl<'a> OperationVisitor<'a, ValidationErrorContext> for NoUndefinedVariables<'
7479
operation_definition: &'a OperationDefinition,
7580
) {
7681
let op_name = operation_definition.node_name();
77-
self.current_scope = Some(Scope::Operation(op_name));
82+
self.current_scope = Some(NoUndefinedVariablesScope::Operation(op_name));
7883
self.defined_variables.insert(op_name, HashSet::new());
7984
}
8085

@@ -84,7 +89,9 @@ impl<'a> OperationVisitor<'a, ValidationErrorContext> for NoUndefinedVariables<'
8489
_: &mut ValidationErrorContext,
8590
fragment_definition: &'a query::FragmentDefinition,
8691
) {
87-
self.current_scope = Some(Scope::Fragment(&fragment_definition.name));
92+
self.current_scope = Some(NoUndefinedVariablesScope::Fragment(
93+
&fragment_definition.name,
94+
));
8895
}
8996

9097
fn enter_fragment_spread(
@@ -107,7 +114,7 @@ impl<'a> OperationVisitor<'a, ValidationErrorContext> for NoUndefinedVariables<'
107114
_: &mut ValidationErrorContext,
108115
variable_definition: &'a query::VariableDefinition,
109116
) {
110-
if let Some(Scope::Operation(ref name)) = self.current_scope {
117+
if let Some(NoUndefinedVariablesScope::Operation(ref name)) = self.current_scope {
111118
if let Some(vars) = self.defined_variables.get_mut(name) {
112119
vars.insert(&variable_definition.name);
113120
}
@@ -139,14 +146,15 @@ impl<'a> OperationVisitor<'a, ValidationErrorContext> for NoUndefinedVariables<'
139146
let mut visited = HashSet::new();
140147

141148
self.find_undefined_vars(
142-
&Scope::Operation(op_name.clone()),
149+
&NoUndefinedVariablesScope::Operation(op_name.clone()),
143150
def_vars,
144151
&mut unused,
145152
&mut visited,
146153
);
147154

148155
unused.iter().for_each(|var| {
149-
user_context.report_error(ValidationError {error_code: self.error_code(),
156+
user_context.report_error(ValidationError {
157+
error_code: self.error_code(),
150158
message: error_message(&var, op_name),
151159
locations: vec![],
152160
})

src/validation/rules/no_unused_variables.rs

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ use crate::validation::utils::{ValidationError, ValidationErrorContext};
1414
///
1515
/// See https://spec.graphql.org/draft/#sec-All-Variables-Used
1616
pub struct NoUnusedVariables<'a> {
17-
current_scope: Option<Scope<'a>>,
17+
current_scope: Option<NoUnusedVariablesScope<'a>>,
1818
defined_variables: HashMap<Option<&'a str>, HashSet<&'a str>>,
19-
used_variables: HashMap<Scope<'a>, Vec<&'a str>>,
20-
spreads: HashMap<Scope<'a>, Vec<&'a str>>,
19+
used_variables: HashMap<NoUnusedVariablesScope<'a>, Vec<&'a str>>,
20+
spreads: HashMap<NoUnusedVariablesScope<'a>, Vec<&'a str>>,
2121
}
2222

2323
impl<'a> NoUnusedVariables<'a> {
@@ -34,10 +34,10 @@ impl<'a> NoUnusedVariables<'a> {
3434
impl<'a> NoUnusedVariables<'a> {
3535
fn find_used_vars(
3636
&self,
37-
from: &Scope<'a>,
37+
from: &NoUnusedVariablesScope<'a>,
3838
defined: &HashSet<&str>,
3939
used: &mut HashSet<&'a str>,
40-
visited: &mut HashSet<Scope<'a>>,
40+
visited: &mut HashSet<NoUnusedVariablesScope<'a>>,
4141
) {
4242
if visited.contains(from) {
4343
return;
@@ -55,14 +55,19 @@ impl<'a> NoUnusedVariables<'a> {
5555

5656
if let Some(spreads) = self.spreads.get(from) {
5757
for spread in spreads {
58-
self.find_used_vars(&Scope::Fragment(spread), defined, used, visited);
58+
self.find_used_vars(
59+
&NoUnusedVariablesScope::Fragment(spread),
60+
defined,
61+
used,
62+
visited,
63+
);
5964
}
6065
}
6166
}
6267
}
6368

6469
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
65-
pub enum Scope<'a> {
70+
pub enum NoUnusedVariablesScope<'a> {
6671
Operation(Option<&'a str>),
6772
Fragment(&'a str),
6873
}
@@ -75,7 +80,7 @@ impl<'a> OperationVisitor<'a, ValidationErrorContext> for NoUnusedVariables<'a>
7580
operation_definition: &'a OperationDefinition,
7681
) {
7782
let op_name = operation_definition.node_name();
78-
self.current_scope = Some(Scope::Operation(op_name));
83+
self.current_scope = Some(NoUnusedVariablesScope::Operation(op_name));
7984
self.defined_variables.insert(op_name, HashSet::new());
8085
}
8186

@@ -85,7 +90,7 @@ impl<'a> OperationVisitor<'a, ValidationErrorContext> for NoUnusedVariables<'a>
8590
_: &mut ValidationErrorContext,
8691
fragment_definition: &'a query::FragmentDefinition,
8792
) {
88-
self.current_scope = Some(Scope::Fragment(&fragment_definition.name));
93+
self.current_scope = Some(NoUnusedVariablesScope::Fragment(&fragment_definition.name));
8994
}
9095

9196
fn enter_fragment_spread(
@@ -108,7 +113,7 @@ impl<'a> OperationVisitor<'a, ValidationErrorContext> for NoUnusedVariables<'a>
108113
_: &mut ValidationErrorContext,
109114
variable_definition: &'a query::VariableDefinition,
110115
) {
111-
if let Some(Scope::Operation(ref name)) = self.current_scope {
116+
if let Some(NoUnusedVariablesScope::Operation(ref name)) = self.current_scope {
112117
if let Some(vars) = self.defined_variables.get_mut(name) {
113118
vars.insert(&variable_definition.name);
114119
}
@@ -140,7 +145,7 @@ impl<'a> OperationVisitor<'a, ValidationErrorContext> for NoUnusedVariables<'a>
140145
let mut visited = HashSet::new();
141146

142147
self.find_used_vars(
143-
&Scope::Operation(op_name.clone()),
148+
&NoUnusedVariablesScope::Operation(op_name.clone()),
144149
&def_vars,
145150
&mut used,
146151
&mut visited,
@@ -150,7 +155,8 @@ impl<'a> OperationVisitor<'a, ValidationErrorContext> for NoUnusedVariables<'a>
150155
.iter()
151156
.filter(|var| !used.contains(*var))
152157
.for_each(|var| {
153-
user_context.report_error(ValidationError {error_code: self.error_code(),
158+
user_context.report_error(ValidationError {
159+
error_code: self.error_code(),
154160
message: error_message(var, op_name),
155161
locations: vec![],
156162
})

src/validation/rules/single_field_subscriptions.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ impl<'a> OperationVisitor<'a, ValidationErrorContext> for SingleFieldSubscriptio
4949
.to_owned(),
5050
};
5151

52-
user_context.report_error(ValidationError {error_code: self.error_code(),
52+
user_context.report_error(ValidationError {
53+
error_code: self.error_code(),
5354
locations: vec![subscription.position],
5455
message: error_message,
5556
});

0 commit comments

Comments
 (0)