@@ -115,8 +115,7 @@ def with_modifiers(
115
115
116
116
def schema_with_field_type (type_ ):
117
117
return GraphQLSchema (
118
- query = GraphQLObjectType (name = "Query" , fields = {"f" : GraphQLField (type_ )}),
119
- types = [type_ ],
118
+ query = GraphQLObjectType (name = "Query" , fields = {"f" : GraphQLField (type_ )})
120
119
)
121
120
122
121
@@ -520,17 +519,19 @@ def accepts_field_args_with_valid_names():
520
519
)
521
520
assert validate_schema (schema ) == []
522
521
523
- def reject_field_args_with_invalid_names ():
524
- QueryType = GraphQLObjectType (
525
- "SomeObject" ,
526
- {
527
- "badField" : GraphQLField (
528
- GraphQLString ,
529
- args = {"bad-name-with-dashes" : GraphQLArgument (GraphQLString )},
530
- )
531
- },
522
+ def rejects_field_args_with_invalid_names ():
523
+ schema = schema_with_field_type (
524
+ GraphQLObjectType (
525
+ "SomeObject" ,
526
+ {
527
+ "badField" : GraphQLField (
528
+ GraphQLString ,
529
+ args = {"bad-name-with-dashes" : GraphQLArgument (GraphQLString )},
530
+ )
531
+ },
532
+ )
532
533
)
533
- schema = GraphQLSchema ( QueryType )
534
+
534
535
msg = validate_schema (schema )[0 ].message
535
536
assert msg == (
536
537
"Names must match /^[_a-zA-Z][_a-zA-Z0-9]*$/"
@@ -971,7 +972,7 @@ def rejects_an_enum_type_without_values():
971
972
]
972
973
973
974
def rejects_an_enum_type_with_incorrectly_named_values ():
974
- def schema_with_enum (name ) :
975
+ def schema_with_enum (name : str ) -> GraphQLSchema :
975
976
return schema_with_field_type (
976
977
GraphQLEnumType ("SomeEnum" , {name : GraphQLEnumValue (1 )})
977
978
)
@@ -1008,17 +1009,17 @@ def schema_with_enum(name):
1008
1009
1009
1010
1010
1011
def describe_type_system_object_fields_must_have_output_types ():
1011
- def _schema_with_object_field_of_type ( field_type : GraphQLOutputType ):
1012
- if is_output_type (field_type ):
1013
- field = GraphQLField (field_type )
1012
+ def _schema_with_object_field ( type_ : GraphQLOutputType ) -> GraphQLSchema :
1013
+ if is_output_type (type_ ):
1014
+ field = GraphQLField (type_ )
1014
1015
else :
1015
1016
# invalid field cannot be built with Python directly
1016
1017
with raises (TypeError ) as exc_info :
1017
- GraphQLField (field_type )
1018
+ GraphQLField (type_ )
1018
1019
assert str (exc_info .value ) == "Field type must be an output type."
1019
1020
# therefore we need to monkey-patch a valid field
1020
1021
field = GraphQLField (GraphQLString )
1021
- field .type = field_type
1022
+ field .type = type_
1022
1023
bad_object_type = GraphQLObjectType ("BadObject" , {"badField" : field })
1023
1024
return GraphQLSchema (
1024
1025
GraphQLObjectType ("Query" , {"f" : GraphQLField (bad_object_type )}),
@@ -1027,12 +1028,12 @@ def _schema_with_object_field_of_type(field_type: GraphQLOutputType):
1027
1028
1028
1029
@mark .parametrize ("type_" , output_types , ids = get_name )
1029
1030
def accepts_an_output_type_as_an_object_field_type (type_ ):
1030
- schema = _schema_with_object_field_of_type (type_ )
1031
+ schema = _schema_with_object_field (type_ )
1031
1032
assert validate_schema (schema ) == []
1032
1033
1033
1034
def rejects_an_empty_object_field_type ():
1034
1035
# noinspection PyTypeChecker
1035
- schema = _schema_with_object_field_of_type (None ) # type: ignore
1036
+ schema = _schema_with_object_field (None ) # type: ignore
1036
1037
assert validate_schema (schema ) == [
1037
1038
{
1038
1039
"message" : "The type of BadObject.badField must be Output Type"
@@ -1042,7 +1043,7 @@ def rejects_an_empty_object_field_type():
1042
1043
1043
1044
@mark .parametrize ("type_" , not_output_types , ids = get_name )
1044
1045
def rejects_a_non_output_type_as_an_object_field_type (type_ ):
1045
- schema = _schema_with_object_field_of_type (type_ )
1046
+ schema = _schema_with_object_field (type_ )
1046
1047
assert validate_schema (schema ) == [
1047
1048
{
1048
1049
"message" : "The type of BadObject.badField must be Output Type"
@@ -1052,7 +1053,7 @@ def rejects_a_non_output_type_as_an_object_field_type(type_):
1052
1053
1053
1054
@mark .parametrize ("type_" , not_graphql_types , ids = get_name )
1054
1055
def rejects_a_non_type_value_as_an_object_field_type (type_ ):
1055
- schema = _schema_with_object_field_of_type (type_ )
1056
+ schema = _schema_with_object_field (type_ )
1056
1057
assert validate_schema (schema ) == [
1057
1058
{
1058
1059
"message" : "The type of BadObject.badField must be Output Type"
@@ -1325,21 +1326,23 @@ def rejects_object_implementing_extended_interface_due_to_type_mismatch():
1325
1326
1326
1327
1327
1328
def describe_type_system_interface_fields_must_have_output_types ():
1328
- def _schema_with_interface_field_of_type ( field_type : GraphQLOutputType ):
1329
- if is_output_type (field_type ):
1330
- field = GraphQLField (field_type )
1329
+ def _schema_with_interface_field ( type_ : GraphQLOutputType ) -> GraphQLSchema :
1330
+ if is_output_type (type_ ):
1331
+ field = GraphQLField (type_ )
1331
1332
else :
1332
1333
# invalid field cannot be built with Python directly
1333
1334
with raises (TypeError ) as exc_info :
1334
- GraphQLField (field_type )
1335
+ GraphQLField (type_ )
1335
1336
assert str (exc_info .value ) == "Field type must be an output type."
1336
1337
# therefore we need to monkey-patch a valid field
1337
1338
field = GraphQLField (GraphQLString )
1338
- field .type = field_type
1339
- bad_interface_type = GraphQLInterfaceType ("BadInterface" , {"badField" : field })
1339
+ field .type = type_
1340
+ fields = {"badField" : field }
1341
+
1342
+ bad_interface_type = GraphQLInterfaceType ("BadInterface" , fields )
1340
1343
bad_implementing_type = GraphQLObjectType (
1341
1344
"BadImplementing" ,
1342
- { "badField" : field } ,
1345
+ fields ,
1343
1346
interfaces = [bad_interface_type ],
1344
1347
)
1345
1348
return GraphQLSchema (
@@ -1349,12 +1352,12 @@ def _schema_with_interface_field_of_type(field_type: GraphQLOutputType):
1349
1352
1350
1353
@mark .parametrize ("type_" , output_types , ids = get_name )
1351
1354
def accepts_an_output_type_as_an_interface_field_type (type_ ):
1352
- schema = _schema_with_interface_field_of_type (type_ )
1355
+ schema = _schema_with_interface_field (type_ )
1353
1356
assert validate_schema (schema ) == []
1354
1357
1355
1358
def rejects_an_empty_interface_field_type ():
1356
1359
# noinspection PyTypeChecker
1357
- schema = _schema_with_interface_field_of_type (None ) # type: ignore
1360
+ schema = _schema_with_interface_field (None ) # type: ignore
1358
1361
assert validate_schema (schema ) == [
1359
1362
{
1360
1363
"message" : "The type of BadImplementing.badField must be Output Type"
@@ -1368,7 +1371,7 @@ def rejects_an_empty_interface_field_type():
1368
1371
1369
1372
@mark .parametrize ("type_" , not_output_types , ids = get_name )
1370
1373
def rejects_a_non_output_type_as_an_interface_field_type (type_ ):
1371
- schema = _schema_with_interface_field_of_type (type_ )
1374
+ schema = _schema_with_interface_field (type_ )
1372
1375
assert validate_schema (schema ) == [
1373
1376
{
1374
1377
"message" : "The type of BadImplementing.badField must be Output Type"
@@ -1382,7 +1385,7 @@ def rejects_a_non_output_type_as_an_interface_field_type(type_):
1382
1385
1383
1386
@mark .parametrize ("type_" , not_graphql_types , ids = get_name )
1384
1387
def rejects_a_non_type_value_as_an_interface_field_type (type_ ):
1385
- schema = _schema_with_interface_field_of_type (type_ )
1388
+ schema = _schema_with_interface_field (type_ )
1386
1389
assert validate_schema (schema ) == [
1387
1390
{
1388
1391
"message" : "The type of BadImplementing.badField must be Output Type"
@@ -1476,40 +1479,41 @@ def accepts_an_interface_not_implemented_by_at_least_one_object():
1476
1479
1477
1480
1478
1481
def describe_type_system_arguments_must_have_input_types ():
1479
- def _schema_with_arg_of_type ( arg_type : GraphQLInputType ):
1480
- if is_input_type (arg_type ):
1481
- argument = GraphQLArgument (arg_type )
1482
+ def _schema_with_arg ( type_ : GraphQLInputType ) -> GraphQLSchema :
1483
+ if is_input_type (type_ ):
1484
+ argument = GraphQLArgument (type_ )
1482
1485
else :
1483
1486
# invalid argument cannot be built with Python directly
1484
1487
with raises (TypeError ) as exc_info :
1485
- GraphQLArgument (arg_type )
1488
+ GraphQLArgument (type_ )
1486
1489
assert str (exc_info .value ) == "Argument type must be a GraphQL input type."
1487
1490
# therefore we need to monkey-patch a valid argument
1488
1491
argument = GraphQLArgument (GraphQLString )
1489
- argument .type = arg_type
1492
+ argument .type = type_
1493
+ args = {"badArg" : argument }
1490
1494
bad_object_type = GraphQLObjectType (
1491
1495
"BadObject" ,
1492
- {"badField" : GraphQLField (GraphQLString , args = { "badArg" : argument } )},
1496
+ {"badField" : GraphQLField (GraphQLString , args )},
1493
1497
)
1494
1498
return GraphQLSchema (
1495
1499
GraphQLObjectType ("Query" , {"f" : GraphQLField (bad_object_type )}),
1496
1500
directives = [
1497
1501
GraphQLDirective (
1498
1502
"BadDirective" ,
1499
1503
[DirectiveLocation .QUERY ],
1500
- { "badArg" : argument } ,
1504
+ args ,
1501
1505
)
1502
1506
],
1503
1507
)
1504
1508
1505
1509
@mark .parametrize ("type_" , input_types , ids = get_name )
1506
1510
def accepts_an_input_type_as_a_field_arg_type (type_ ):
1507
- schema = _schema_with_arg_of_type (type_ )
1511
+ schema = _schema_with_arg (type_ )
1508
1512
assert validate_schema (schema ) == []
1509
1513
1510
1514
def rejects_an_empty_field_arg_type ():
1511
1515
# noinspection PyTypeChecker
1512
- schema = _schema_with_arg_of_type (None ) # type: ignore
1516
+ schema = _schema_with_arg (None ) # type: ignore
1513
1517
assert validate_schema (schema ) == [
1514
1518
{
1515
1519
"message" : "The type of @BadDirective(badArg:) must be Input Type"
@@ -1523,7 +1527,7 @@ def rejects_an_empty_field_arg_type():
1523
1527
1524
1528
@mark .parametrize ("type_" , not_input_types , ids = get_name )
1525
1529
def rejects_a_non_input_type_as_a_field_arg_type (type_ ):
1526
- schema = _schema_with_arg_of_type (type_ )
1530
+ schema = _schema_with_arg (type_ )
1527
1531
assert validate_schema (schema ) == [
1528
1532
{
1529
1533
"message" : "The type of @BadDirective(badArg:) must be Input Type"
@@ -1537,7 +1541,7 @@ def rejects_a_non_input_type_as_a_field_arg_type(type_):
1537
1541
1538
1542
@mark .parametrize ("type_" , not_graphql_types , ids = get_name )
1539
1543
def rejects_a_non_type_value_as_a_field_arg_type (type_ ):
1540
- schema = _schema_with_arg_of_type (type_ )
1544
+ schema = _schema_with_arg (type_ )
1541
1545
assert validate_schema (schema ) == [
1542
1546
{
1543
1547
"message" : "The type of @BadDirective(badArg:) must be Input Type"
@@ -1592,19 +1596,19 @@ def rejects_a_non_input_type_as_a_field_arg_with_locations():
1592
1596
1593
1597
1594
1598
def describe_type_system_input_object_fields_must_have_input_types ():
1595
- def _schema_with_input_field_of_type ( input_field_type : GraphQLInputType ):
1596
- if is_input_type (input_field_type ):
1597
- input_field = GraphQLInputField (input_field_type )
1599
+ def _schema_with_input_field ( type_ : GraphQLInputType ) -> GraphQLSchema :
1600
+ if is_input_type (type_ ):
1601
+ input_field = GraphQLInputField (type_ )
1598
1602
else :
1599
1603
# invalid input field cannot be built with Python directly
1600
1604
with raises (TypeError ) as exc_info :
1601
- GraphQLInputField (input_field_type )
1605
+ GraphQLInputField (type_ )
1602
1606
assert str (exc_info .value ) == (
1603
1607
"Input field type must be a GraphQL input type."
1604
1608
)
1605
1609
# therefore we need to monkey-patch a valid input field
1606
1610
input_field = GraphQLInputField (GraphQLString )
1607
- input_field .type = input_field_type
1611
+ input_field .type = type_
1608
1612
bad_input_object_type = GraphQLInputObjectType (
1609
1613
"BadInputObject" , {"badField" : input_field }
1610
1614
)
@@ -1622,12 +1626,12 @@ def _schema_with_input_field_of_type(input_field_type: GraphQLInputType):
1622
1626
1623
1627
@mark .parametrize ("type_" , input_types , ids = get_name )
1624
1628
def accepts_an_input_type_as_an_input_field_type (type_ ):
1625
- schema = _schema_with_input_field_of_type (type_ )
1629
+ schema = _schema_with_input_field (type_ )
1626
1630
assert validate_schema (schema ) == []
1627
1631
1628
1632
def rejects_an_empty_input_field_type ():
1629
1633
# noinspection PyTypeChecker
1630
- schema = _schema_with_input_field_of_type (None ) # type: ignore
1634
+ schema = _schema_with_input_field (None ) # type: ignore
1631
1635
assert validate_schema (schema ) == [
1632
1636
{
1633
1637
"message" : "The type of BadInputObject.badField must be Input Type"
@@ -1637,7 +1641,7 @@ def rejects_an_empty_input_field_type():
1637
1641
1638
1642
@mark .parametrize ("type_" , not_input_types , ids = get_name )
1639
1643
def rejects_a_non_input_type_as_an_input_field_type (type_ ):
1640
- schema = _schema_with_input_field_of_type (type_ )
1644
+ schema = _schema_with_input_field (type_ )
1641
1645
assert validate_schema (schema ) == [
1642
1646
{
1643
1647
"message" : "The type of BadInputObject.badField must be Input Type"
@@ -1647,7 +1651,7 @@ def rejects_a_non_input_type_as_an_input_field_type(type_):
1647
1651
1648
1652
@mark .parametrize ("type_" , not_graphql_types , ids = get_name )
1649
1653
def rejects_a_non_type_value_as_an_input_field_type (type_ ):
1650
- schema = _schema_with_input_field_of_type (type_ )
1654
+ schema = _schema_with_input_field (type_ )
1651
1655
assert validate_schema (schema ) == [
1652
1656
{
1653
1657
"message" : "The type of BadInputObject.badField must be Input Type"
0 commit comments