@@ -5,7 +5,6 @@ use graphql_tools::ast::FieldByNameExtension;
5
5
use graphql_tools:: ast:: TypeDefinitionExtension ;
6
6
use graphql_tools:: ast:: TypeExtension ;
7
7
use lru:: LruCache ;
8
- use md5;
9
8
use std:: cmp:: Ordering ;
10
9
use std:: collections:: BTreeMap ;
11
10
use std:: collections:: HashMap ;
@@ -48,7 +47,7 @@ pub fn collect_schema_coordinates(
48
47
let mut visit_context = OperationVisitorContext :: new ( document, schema) ;
49
48
let mut visitor = SchemaCoordinatesVisitor { } ;
50
49
51
- visit_document ( & mut visitor, & document, & mut visit_context, & mut ctx) ;
50
+ visit_document ( & mut visitor, document, & mut visit_context, & mut ctx) ;
52
51
53
52
if let Some ( error) = ctx. error {
54
53
Err ( error)
@@ -88,11 +87,11 @@ pub fn collect_schema_coordinates(
88
87
struct SchemaCoordinatesVisitor { }
89
88
90
89
impl SchemaCoordinatesVisitor {
91
- fn resolve_type_name < ' a > ( & self , t : Type < ' a , String > ) -> String {
90
+ fn resolve_type_name ( & self , t : Type < String > ) -> String {
92
91
match t {
93
- Type :: NamedType ( value) => return value,
94
- Type :: ListType ( t) => return self . resolve_type_name ( * t) ,
95
- Type :: NonNullType ( t) => return self . resolve_type_name ( * t) ,
92
+ Type :: NamedType ( value) => value,
93
+ Type :: ListType ( t) => self . resolve_type_name ( * t) ,
94
+ Type :: NonNullType ( t) => self . resolve_type_name ( * t) ,
96
95
}
97
96
}
98
97
@@ -118,19 +117,13 @@ impl SchemaCoordinatesVisitor {
118
117
119
118
visited_types. push ( type_name. to_string ( ) ) ;
120
119
121
- let named_type = schema. type_by_name ( & type_name) ;
120
+ let named_type = schema. type_by_name ( type_name) ;
122
121
123
- match named_type {
124
- Some ( named_type) => match named_type {
125
- TypeDefinition :: InputObject ( input_type) => {
126
- for field in & input_type. fields {
127
- let field_type = self . resolve_type_name ( field. value_type . clone ( ) ) ;
128
- self . _resolve_references ( schema, & field_type, visited_types) ;
129
- }
130
- }
131
- _ => { }
132
- } ,
133
- None => { }
122
+ if let Some ( TypeDefinition :: InputObject ( input_type) ) = named_type {
123
+ for field in & input_type. fields {
124
+ let field_type = self . resolve_type_name ( field. value_type . clone ( ) ) ;
125
+ self . _resolve_references ( schema, & field_type, visited_types) ;
126
+ }
134
127
}
135
128
}
136
129
}
@@ -143,7 +136,7 @@ impl<'a> OperationVisitor<'a, SchemaCoordinatesContext> for SchemaCoordinatesVis
143
136
field : & Field < ' static , String > ,
144
137
) {
145
138
if ctx. is_corrupted ( ) {
146
- return ( ) ;
139
+ return ;
147
140
}
148
141
149
142
let field_name = field. name . to_string ( ) ;
@@ -157,17 +150,14 @@ impl<'a> OperationVisitor<'a, SchemaCoordinatesContext> for SchemaCoordinatesVis
157
150
if let Some ( field_def) = parent_type. field_by_name ( & field_name) {
158
151
// if field's type is an enum, we need to collect all possible values
159
152
let field_output_type = info. schema . type_by_name ( field_def. field_type . inner_type ( ) ) ;
160
- match field_output_type {
161
- Some ( TypeDefinition :: Enum ( enum_type) ) => {
162
- for value in & enum_type. values {
163
- ctx. schema_coordinates . insert ( format ! (
164
- "{}.{}" ,
165
- enum_type. name. as_str( ) ,
166
- value. name
167
- ) ) ;
168
- }
153
+ if let Some ( TypeDefinition :: Enum ( enum_type) ) = field_output_type {
154
+ for value in & enum_type. values {
155
+ ctx. schema_coordinates . insert ( format ! (
156
+ "{}.{}" ,
157
+ enum_type. name. as_str( ) ,
158
+ value. name
159
+ ) ) ;
169
160
}
170
- _ => { }
171
161
}
172
162
}
173
163
} else {
@@ -185,22 +175,19 @@ impl<'a> OperationVisitor<'a, SchemaCoordinatesContext> for SchemaCoordinatesVis
185
175
var : & graphql_tools:: static_graphql:: query:: VariableDefinition ,
186
176
) {
187
177
if ctx. is_corrupted ( ) {
188
- return ( ) ;
178
+ return ;
189
179
}
190
180
191
181
let type_name = self . resolve_type_name ( var. var_type . clone ( ) ) ;
192
182
let type_def = info. schema . type_by_name ( & type_name) ;
193
183
194
- match type_def {
195
- Some ( TypeDefinition :: Scalar ( scalar_def) ) => {
196
- ctx. schema_coordinates
197
- . insert ( format ! ( "{}" , scalar_def. name. as_str( ) , ) ) ;
198
- return ( ) ;
199
- }
200
- _ => { }
184
+ if let Some ( TypeDefinition :: Scalar ( scalar_def) ) = type_def {
185
+ ctx. schema_coordinates
186
+ . insert ( scalar_def. name . as_str ( ) . to_string ( ) ) ;
187
+ return ;
201
188
}
202
189
203
- if let Some ( inner_types) = self . resolve_references ( & info. schema , & type_name) {
190
+ if let Some ( inner_types) = self . resolve_references ( info. schema , & type_name) {
204
191
for inner_type in inner_types {
205
192
ctx. input_types_to_collect . insert ( inner_type) ;
206
193
}
@@ -216,15 +203,15 @@ impl<'a> OperationVisitor<'a, SchemaCoordinatesContext> for SchemaCoordinatesVis
216
203
arg : & ( String , Value < ' static , String > ) ,
217
204
) {
218
205
if ctx. is_corrupted ( ) {
219
- return ( ) ;
206
+ return ;
220
207
}
221
208
222
209
if info. current_parent_type ( ) . is_none ( ) {
223
210
ctx. error = Some ( anyhow ! (
224
211
"Unable to find parent type of '{}' argument" ,
225
212
arg. 0 . clone( )
226
213
) ) ;
227
- return ( ) ;
214
+ return ;
228
215
}
229
216
230
217
let type_name = info. current_parent_type ( ) . unwrap ( ) . name ( ) ;
@@ -240,36 +227,33 @@ impl<'a> OperationVisitor<'a, SchemaCoordinatesContext> for SchemaCoordinatesVis
240
227
241
228
let arg_value = arg. 1 . clone ( ) ;
242
229
243
- match info. current_input_type ( ) {
244
- Some ( input_type) => {
245
- match input_type {
246
- TypeDefinition :: Scalar ( scalar_def) => {
247
- ctx. schema_coordinates . insert ( scalar_def. name . clone ( ) ) ;
248
- }
249
- _ => {
250
- let input_type_name = input_type. name ( ) ;
251
- match arg_value {
252
- Value :: Enum ( value) => {
253
- let value_str = value. to_string ( ) ;
254
- ctx. schema_coordinates . insert (
255
- format ! ( "{input_type_name}.{value_str}" ) . to_string ( ) ,
256
- ) ;
257
- }
258
- Value :: List ( _) => {
259
- // handled by enter_list_value
260
- }
261
- Value :: Object ( _a) => {
262
- // handled by enter_object_field
263
- }
264
- Value :: Variable ( _) => {
265
- // handled by enter_variable_definition
266
- }
267
- _ => { }
230
+ if let Some ( input_type) = info. current_input_type ( ) {
231
+ match input_type {
232
+ TypeDefinition :: Scalar ( scalar_def) => {
233
+ ctx. schema_coordinates . insert ( scalar_def. name . clone ( ) ) ;
234
+ }
235
+ _ => {
236
+ let input_type_name = input_type. name ( ) ;
237
+ match arg_value {
238
+ Value :: Enum ( value) => {
239
+ let value_str = value. to_string ( ) ;
240
+ ctx. schema_coordinates . insert (
241
+ format ! ( "{input_type_name}.{value_str}" ) . to_string ( ) ,
242
+ ) ;
268
243
}
244
+ Value :: List ( _) => {
245
+ // handled by enter_list_value
246
+ }
247
+ Value :: Object ( _a) => {
248
+ // handled by enter_object_field
249
+ }
250
+ Value :: Variable ( _) => {
251
+ // handled by enter_variable_definition
252
+ }
253
+ _ => { }
269
254
}
270
255
}
271
256
}
272
- None => { }
273
257
}
274
258
}
275
259
}
@@ -280,13 +264,8 @@ impl<'a> OperationVisitor<'a, SchemaCoordinatesContext> for SchemaCoordinatesVis
280
264
ctx : & mut SchemaCoordinatesContext ,
281
265
_object_field : & ( String , graphql_tools:: static_graphql:: query:: Value ) ,
282
266
) {
283
- if let Some ( input_type) = info. current_input_type ( ) {
284
- match input_type {
285
- TypeDefinition :: Scalar ( scalar_def) => {
286
- ctx. schema_coordinates . insert ( scalar_def. name . clone ( ) ) ;
287
- }
288
- _ => { }
289
- }
267
+ if let Some ( TypeDefinition :: Scalar ( scalar_def) ) = info. current_input_type ( ) {
268
+ ctx. schema_coordinates . insert ( scalar_def. name . clone ( ) ) ;
290
269
}
291
270
}
292
271
@@ -297,7 +276,7 @@ impl<'a> OperationVisitor<'a, SchemaCoordinatesContext> for SchemaCoordinatesVis
297
276
values : & Vec < Value < ' static , String > > ,
298
277
) {
299
278
if ctx. is_corrupted ( ) {
300
- return ( ) ;
279
+ return ;
301
280
}
302
281
303
282
if let Some ( input_type) = info. current_input_type ( ) {
@@ -487,7 +466,7 @@ impl<'s, T: Text<'s> + Clone> OperationTransformer<'s, T> for SortSelectionsTran
487
466
directives : & [ Directive < ' s , T > ] ,
488
467
) -> TransformedValue < Vec < Directive < ' s , T > > > {
489
468
let mut next_directives = self
490
- . transform_list ( & directives, Self :: transform_directive)
469
+ . transform_list ( directives, Self :: transform_directive)
491
470
. replace_or_else ( || directives. to_vec ( ) ) ;
492
471
next_directives. sort_unstable_by ( |a, b| self . compare_directives ( a, b) ) ;
493
472
TransformedValue :: Replace ( next_directives)
@@ -498,7 +477,7 @@ impl<'s, T: Text<'s> + Clone> OperationTransformer<'s, T> for SortSelectionsTran
498
477
arguments : & [ ( T :: Value , Value < ' s , T > ) ] ,
499
478
) -> TransformedValue < Vec < ( T :: Value , Value < ' s , T > ) > > {
500
479
let mut next_arguments = self
501
- . transform_list ( & arguments, Self :: transform_argument)
480
+ . transform_list ( arguments, Self :: transform_argument)
502
481
. replace_or_else ( || arguments. to_vec ( ) ) ;
503
482
next_arguments. sort_unstable_by ( |a, b| self . compare_arguments ( a, b) ) ;
504
483
TransformedValue :: Replace ( next_arguments)
@@ -509,7 +488,7 @@ impl<'s, T: Text<'s> + Clone> OperationTransformer<'s, T> for SortSelectionsTran
509
488
variable_definitions : & Vec < VariableDefinition < ' s , T > > ,
510
489
) -> TransformedValue < Vec < VariableDefinition < ' s , T > > > {
511
490
let mut next_variable_definitions = self
512
- . transform_list ( & variable_definitions, Self :: transform_variable_definition)
491
+ . transform_list ( variable_definitions, Self :: transform_variable_definition)
513
492
. replace_or_else ( || variable_definitions. to_vec ( ) ) ;
514
493
next_variable_definitions. sort_unstable_by ( |a, b| self . compare_variable_definitions ( a, b) ) ;
515
494
TransformedValue :: Replace ( next_variable_definitions)
@@ -527,11 +506,11 @@ impl<'s, T: Text<'s> + Clone> OperationTransformer<'s, T> for SortSelectionsTran
527
506
Transformed :: Replace ( FragmentDefinition {
528
507
selection_set : SelectionSet {
529
508
items : selections. replace_or_else ( || fragment. selection_set . items . clone ( ) ) ,
530
- span : fragment. selection_set . span . clone ( ) ,
509
+ span : fragment. selection_set . span ,
531
510
} ,
532
511
directives,
533
512
name : fragment. name . clone ( ) ,
534
- position : fragment. position . clone ( ) ,
513
+ position : fragment. position ,
535
514
type_condition : fragment. type_condition . clone ( ) ,
536
515
} )
537
516
}
@@ -673,20 +652,16 @@ impl OperationProcessor {
673
652
. into_static ( ) ;
674
653
675
654
let is_introspection = parsed. definitions . iter ( ) . find ( |def| match def {
676
- Definition :: Operation ( op) => match op {
677
- OperationDefinition :: Query ( query) => query
678
- . selection_set
679
- . items
680
- . iter ( )
681
- . find ( |selection| match selection {
682
- Selection :: Field ( field) => {
683
- field. name == "__schema" || field. name == "__type"
684
- }
685
- _ => false ,
686
- } )
687
- . is_some ( ) ,
688
- _ => false ,
689
- } ,
655
+ Definition :: Operation ( OperationDefinition :: Query ( query) ) => query
656
+ . selection_set
657
+ . items
658
+ . iter ( )
659
+ . any ( |selection| match selection {
660
+ Selection :: Field ( field) => {
661
+ field. name == "__schema" || field. name == "__type"
662
+ }
663
+ _ => false ,
664
+ } ) ,
690
665
_ => false ,
691
666
} ) ;
692
667
0 commit comments