1
1
import ast
2
- import enum
3
2
from typing import Any , Dict , List , Optional , Tuple , Union , cast
4
3
5
4
from graphql import (
6
5
GraphQLEnumType ,
7
6
GraphQLInputObjectType ,
8
7
GraphQLInterfaceType ,
8
+ GraphQLList ,
9
9
GraphQLNonNull ,
10
10
GraphQLObjectType ,
11
11
GraphQLScalarType ,
12
12
GraphQLUnionType ,
13
- GraphQLList ,
14
13
)
15
14
16
15
from ..codegen import (
25
24
generate_dict ,
26
25
generate_import_from ,
27
26
generate_keyword ,
27
+ generate_list_annotation ,
28
28
generate_name ,
29
29
generate_subscript ,
30
30
generate_tuple ,
31
- generate_list_annotation ,
32
31
)
33
32
from ..exceptions import ParsingError
34
33
from ..plugins .manager import PluginManager
38
37
BASE_MODEL_FILE_PATH ,
39
38
DICT ,
40
39
INPUT_SCALARS_MAP ,
40
+ LIST ,
41
+ TYPING_MODULE ,
41
42
UPLOAD_CLASS_NAME ,
42
43
)
43
44
from .custom_generator_utils import get_final_type
@@ -128,7 +129,13 @@ def _accumulate_return_arguments(
128
129
return_arguments_values : List [ast .expr ],
129
130
arg_name : str ,
130
131
name : str ,
131
- complete_type : Union [GraphQLObjectType , GraphQLInterfaceType , GraphQLUnionType , GraphQLNonNull , GraphQLList ],
132
+ complete_type : Union [
133
+ GraphQLObjectType ,
134
+ GraphQLInterfaceType ,
135
+ GraphQLUnionType ,
136
+ GraphQLNonNull ,
137
+ GraphQLList ,
138
+ ],
132
139
used_custom_scalar : Optional [str ],
133
140
) -> None :
134
141
"""Accumulates return arguments."""
@@ -148,7 +155,13 @@ def _accumulate_return_arguments(
148
155
149
156
def _generate_complete_type_name (
150
157
self ,
151
- complete_type : Union [GraphQLObjectType , GraphQLInterfaceType , GraphQLUnionType , GraphQLNonNull , GraphQLList ]
158
+ complete_type : Union [
159
+ GraphQLObjectType ,
160
+ GraphQLInterfaceType ,
161
+ GraphQLUnionType ,
162
+ GraphQLNonNull ,
163
+ GraphQLList ,
164
+ ],
152
165
) -> str :
153
166
if isinstance (complete_type , GraphQLNonNull ):
154
167
if hasattr (complete_type , "of_type" ):
@@ -225,8 +238,18 @@ def _parse_graphql_type_name(
225
238
self ._used_custom_scalars .append (used_custom_scalar )
226
239
else :
227
240
raise ParsingError (f"Incorrect argument type { name } " )
228
- return generate_annotation_name (name , nullable ) if not is_list else generate_list_annotation (
229
- generate_annotation_name (name , nullable = False ), nullable ), used_custom_scalar
241
+
242
+ if is_list :
243
+ self ._add_import (generate_import_from (names = [LIST ], from_ = TYPING_MODULE ))
244
+
245
+ return (
246
+ generate_annotation_name (name , nullable )
247
+ if not is_list
248
+ else generate_list_annotation (
249
+ generate_annotation_name (name , nullable = False ), nullable
250
+ ),
251
+ used_custom_scalar ,
252
+ )
230
253
231
254
def add_custom_scalar_imports (self ) -> None :
232
255
"""Adds imports for custom scalars used in the schema."""
0 commit comments