1
1
from functools import partial
2
- from typing import cast , List
2
+ from typing import cast , List , Union
3
3
4
4
from pytest import mark , raises # type: ignore
5
5
14
14
GraphQLInputObjectType ,
15
15
GraphQLInterfaceType ,
16
16
GraphQLList ,
17
+ GraphQLNamedType ,
17
18
GraphQLNonNull ,
19
+ GraphQLNullableType ,
18
20
GraphQLObjectType ,
19
21
GraphQLOutputType ,
20
22
GraphQLScalarType ,
52
54
)
53
55
54
56
55
- def with_modifiers (types : List ) -> List :
56
- # noinspection PyTypeChecker
57
+ def with_modifiers (
58
+ types : List [GraphQLNamedType ]
59
+ ) -> List [Union [GraphQLNamedType , GraphQLNonNull , GraphQLList ]]:
57
60
return (
58
- types
61
+ cast ( List [ Union [ GraphQLNamedType , GraphQLNonNull , GraphQLList ]], types )
59
62
+ [GraphQLList (t ) for t in types ]
60
- + [GraphQLNonNull (t ) for t in types ]
63
+ + [GraphQLNonNull (cast ( GraphQLNullableType , t ) ) for t in types ]
61
64
+ [GraphQLNonNull (GraphQLList (t )) for t in types ]
62
65
)
63
66
64
67
65
- output_types : List [ GraphQLOutputType ] = with_modifiers (
68
+ output_types = with_modifiers (
66
69
[
67
70
GraphQLString ,
68
71
SomeScalarType ,
@@ -73,15 +76,13 @@ def with_modifiers(types: List) -> List:
73
76
]
74
77
)
75
78
76
- not_output_types : List [ GraphQLInputType ] = with_modifiers ([SomeInputObjectType ])
79
+ not_output_types = with_modifiers ([SomeInputObjectType ])
77
80
78
- input_types : List [ GraphQLInputType ] = with_modifiers (
81
+ input_types = with_modifiers (
79
82
[GraphQLString , SomeScalarType , SomeEnumType , SomeInputObjectType ]
80
83
)
81
84
82
- not_input_types : List [GraphQLOutputType ] = with_modifiers (
83
- [SomeObjectType , SomeUnionType , SomeInterfaceType ]
84
- )
85
+ not_input_types = with_modifiers ([SomeObjectType , SomeUnionType , SomeInterfaceType ])
85
86
86
87
parametrize_type = partial (
87
88
mark .parametrize ("type_" , ids = lambda type_ : type_ .__class__ .__name__ )
@@ -892,6 +893,7 @@ def accepts_an_output_type_as_an_object_field_type(type_):
892
893
def rejects_an_empty_object_field_type ():
893
894
# invalid schema cannot be built with Python
894
895
with raises (TypeError ) as exc_info :
896
+ # noinspection PyTypeChecker
895
897
_schema_with_object_field_of_type (None )
896
898
msg = str (exc_info .value )
897
899
assert msg == "Field type must be an output type."
@@ -1178,6 +1180,7 @@ def accepts_an_output_type_as_an_interface_field_type(type_):
1178
1180
def rejects_an_empty_interface_field_type ():
1179
1181
# invalid schema cannot be built with Python
1180
1182
with raises (TypeError ) as exc_info :
1183
+ # noinspection PyTypeChecker
1181
1184
_schema_with_interface_field_of_type (None )
1182
1185
msg = str (exc_info .value )
1183
1186
assert msg == "Field type must be an output type."
@@ -1263,6 +1266,7 @@ def accepts_an_input_type_as_a_field_arg_type(type_):
1263
1266
def rejects_an_empty_field_arg_type ():
1264
1267
# invalid schema cannot be built with Python
1265
1268
with raises (TypeError ) as exc_info :
1269
+ # noinspection PyTypeChecker
1266
1270
_schema_with_arg_of_type (None )
1267
1271
msg = str (exc_info .value )
1268
1272
assert msg == "Argument type must be a GraphQL input type."
@@ -1329,6 +1333,7 @@ def accepts_an_input_type_as_an_input_fieldtype(type_):
1329
1333
def rejects_an_empty_input_field_type ():
1330
1334
# invalid schema cannot be built with Python
1331
1335
with raises (TypeError ) as exc_info :
1336
+ # noinspection PyTypeChecker
1332
1337
_schema_with_input_field_of_type (None )
1333
1338
msg = str (exc_info .value )
1334
1339
assert msg == "Input field type must be a GraphQL input type."
0 commit comments