1+ from typing import Any , Type
2+
13from graphql import GraphQLError , ValidationRule
24from graphql .language .ast import DocumentNode , FieldNode , OperationDefinitionNode
5+ from graphql .validation import ValidationContext
36
47
5- def create_max_depth_rule (max_depth : int ):
8+ def create_max_depth_rule (max_depth : int ) -> Type [ ValidationRule ] :
69 class MaxDepthRule (ValidationRule ):
7- def __init__ (self , context ) :
10+ def __init__ (self , context : ValidationContext ) -> None :
811 super ().__init__ (context )
9- self .operation_depth = 1
10- self .max_depth_reached = False
11- self .max_depth = max_depth
12+ self .operation_depth : int = 1
13+ self .max_depth_reached : bool = False
14+ self .max_depth : int = max_depth
1215
13- def enter_operation_definition (self , node : OperationDefinitionNode , * _args ):
16+ def enter_operation_definition (
17+ self , node : OperationDefinitionNode , * _args : Any
18+ ) -> None :
1419 self .operation_depth = 1
1520 self .max_depth_reached = False
1621
17- def enter_field (self , node : FieldNode , * _args ) :
22+ def enter_field (self , node : FieldNode , * _args : Any ) -> None :
1823 self .operation_depth += 1
1924
2025 if self .operation_depth > self .max_depth and not self .max_depth_reached :
@@ -26,25 +31,25 @@ def enter_field(self, node: FieldNode, *_args):
2631 )
2732 )
2833
29- def leave_field (self , node : FieldNode , * _args ) :
34+ def leave_field (self , node : FieldNode , * _args : Any ) -> None :
3035 self .operation_depth -= 1
3136
3237 return MaxDepthRule
3338
3439
35- def create_max_aliases_rule (max_aliases : int ):
40+ def create_max_aliases_rule (max_aliases : int ) -> Type [ ValidationRule ] :
3641 class MaxAliasesRule (ValidationRule ):
37- def __init__ (self , context ) :
42+ def __init__ (self , context : ValidationContext ) -> None :
3843 super ().__init__ (context )
39- self .alias_count = 0
40- self .has_reported_error = False
41- self .max_aliases = max_aliases
44+ self .alias_count : int = 0
45+ self .has_reported_error : bool = False
46+ self .max_aliases : int = max_aliases
4247
43- def enter_document (self , node : DocumentNode , * _args ) :
48+ def enter_document (self , node : DocumentNode , * _args : Any ) -> None :
4449 self .alias_count = 0
4550 self .has_reported_error = False
4651
47- def enter_field (self , node : FieldNode , * _args ) :
52+ def enter_field (self , node : FieldNode , * _args : Any ) -> None :
4853 if node .alias :
4954 self .alias_count += 1
5055
0 commit comments