@@ -13,10 +13,10 @@ use std::collections::{HashMap, HashSet};
1313///
1414/// See https://spec.graphql.org/draft/#sec-All-Variable-Uses-Defined
1515pub 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
2222impl < ' a > NoUndefinedVariables < ' a > {
@@ -33,10 +33,10 @@ impl<'a> NoUndefinedVariables<'a> {
3333impl < ' 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 } )
0 commit comments