1
1
from __future__ import annotations # Python < 3.10
2
2
3
- from typing import Any , Callable , List , Optional , Union , cast
3
+ from typing import Any , List , Optional , Union , cast
4
4
5
5
from ..language import (
6
6
ArgumentNode ,
52
52
__all__ = ["TypeInfo" , "TypeInfoVisitor" ]
53
53
54
54
55
- GetFieldDefFn = Callable [
56
- [GraphQLSchema , GraphQLType , FieldNode ], Optional [GraphQLField ]
57
- ]
58
-
59
-
60
55
class TypeInfo :
61
56
"""Utility class for keeping track of type definitions.
62
57
@@ -70,14 +65,11 @@ def __init__(
70
65
self ,
71
66
schema : GraphQLSchema ,
72
67
initial_type : Optional [GraphQLType ] = None ,
73
- get_field_def_fn : Optional [GetFieldDefFn ] = None ,
74
68
) -> None :
75
69
"""Initialize the TypeInfo for the given GraphQL schema.
76
70
77
71
Initial type may be provided in rare cases to facilitate traversals beginning
78
72
somewhere other than documents.
79
-
80
- The optional last parameter is deprecated and will be removed in v3.3.
81
73
"""
82
74
self ._schema = schema
83
75
self ._type_stack : List [Optional [GraphQLOutputType ]] = []
@@ -88,7 +80,6 @@ def __init__(
88
80
self ._directive : Optional [GraphQLDirective ] = None
89
81
self ._argument : Optional [GraphQLArgument ] = None
90
82
self ._enum_value : Optional [GraphQLEnumValue ] = None
91
- self ._get_field_def : GetFieldDefFn = get_field_def_fn or get_field_def
92
83
if initial_type :
93
84
if is_input_type (initial_type ):
94
85
self ._input_type_stack .append (cast (GraphQLInputType , initial_type ))
@@ -158,7 +149,7 @@ def enter_selection_set(self, node: SelectionSetNode) -> None:
158
149
def enter_field (self , node : FieldNode ) -> None :
159
150
parent_type = self .get_parent_type ()
160
151
if parent_type :
161
- field_def = self . _get_field_def (self ._schema , parent_type , node )
152
+ field_def = get_field_def (self ._schema , parent_type , node )
162
153
field_type = field_def .type if field_def else None
163
154
else :
164
155
field_def = field_type = None
@@ -277,24 +268,24 @@ def leave_enum_value(self) -> None:
277
268
278
269
279
270
def get_field_def (
280
- schema : GraphQLSchema , parent_type : GraphQLType , field_node : FieldNode
271
+ schema : GraphQLSchema , parent_type : GraphQLCompositeType , field_node : FieldNode
281
272
) -> Optional [GraphQLField ]:
282
273
"""Get field definition.
283
274
284
275
Not exactly the same as the executor's definition of
285
276
:func:`graphql.execution.get_field_def`, in this statically evaluated environment
286
277
we do not always have an Object type, and need to handle Interface and Union types.
287
278
"""
288
- name = field_node .name .value
289
- if name == "__schema" and schema .query_type is parent_type :
279
+ field_name = field_node .name .value
280
+ if field_name == "__schema" and schema .query_type is parent_type :
290
281
return SchemaMetaFieldDef
291
- if name == "__type" and schema .query_type is parent_type :
282
+ if field_name == "__type" and schema .query_type is parent_type :
292
283
return TypeMetaFieldDef
293
- if name == "__typename" and is_composite_type (parent_type ):
284
+ if field_name == "__typename" and is_composite_type (parent_type ):
294
285
return TypeNameMetaFieldDef
295
286
if is_object_type (parent_type ) or is_interface_type (parent_type ):
296
287
parent_type = cast (Union [GraphQLObjectType , GraphQLInterfaceType ], parent_type )
297
- return parent_type .fields .get (name )
288
+ return parent_type .fields .get (field_name )
298
289
return None
299
290
300
291
0 commit comments