@@ -1459,6 +1459,98 @@ def test_rejects_an_object_with_an_incorrectly_typed_interface_argument(self):
14591459 assert str (excinfo .value ) == 'AnotherInterface.field(input:) expects type "String" ' \
14601460 'but AnotherObject.field(input:) provides type "SomeScalar".'
14611461
1462+ def test_rejects_an_object_with_an_incorrectly_typed_interface_field (self ):
1463+ AnotherInterface = GraphQLInterfaceType (
1464+ name = 'AnotherInterface' ,
1465+ resolve_type = _none ,
1466+ fields = {
1467+ 'field' : GraphQLField (GraphQLString )
1468+ }
1469+ )
1470+ AnotherObject = GraphQLObjectType (
1471+ name = 'AnotherObject' ,
1472+ interfaces = [AnotherInterface ],
1473+ fields = {
1474+ 'field' : GraphQLField (SomeScalarType )
1475+ }
1476+ )
1477+
1478+ with raises (AssertionError ) as excinfo :
1479+ schema_with_field_type (AnotherObject )
1480+
1481+ assert str (excinfo .value ) == 'AnotherInterface.field expects type "String" ' \
1482+ 'but AnotherObject.field provides type "SomeScalar".'
1483+
1484+ def test_rejects_an_object_with_a_differently_typed_Interface_field (self ):
1485+ TypeA = GraphQLObjectType (
1486+ name = 'A' ,
1487+ fields = {
1488+ 'foo' : GraphQLField (GraphQLString )
1489+ }
1490+ )
1491+ TypeB = GraphQLObjectType (
1492+ name = 'B' ,
1493+ fields = {
1494+ 'foo' : GraphQLField (GraphQLString )
1495+ }
1496+ )
1497+ AnotherInterface = GraphQLInterfaceType (
1498+ name = 'AnotherInterface' ,
1499+ resolve_type = _none ,
1500+ fields = {
1501+ 'field' : GraphQLField (TypeA )
1502+ }
1503+ )
1504+ AnotherObject = GraphQLObjectType (
1505+ name = 'AnotherObject' ,
1506+ interfaces = [AnotherInterface ],
1507+ fields = {
1508+ 'field' : GraphQLField (TypeB )
1509+ }
1510+ )
1511+
1512+ with raises (AssertionError ) as excinfo :
1513+ schema_with_field_type (AnotherObject )
1514+
1515+ assert str (excinfo .value ) == 'AnotherInterface.field expects type "A" but ' \
1516+ 'AnotherObject.field provides type "B".'
1517+
1518+ def test_accepts_an_object_with_a_subtyped_interface_field_interface (self ):
1519+ AnotherInterface = GraphQLInterfaceType (
1520+ name = 'AnotherInterface' ,
1521+ resolve_type = _none ,
1522+ fields = lambda : {
1523+ 'field' : GraphQLField (AnotherInterface )
1524+ }
1525+ )
1526+ AnotherObject = GraphQLObjectType (
1527+ name = 'AnotherObject' ,
1528+ interfaces = [AnotherInterface ],
1529+ fields = lambda : {
1530+ 'field' : GraphQLField (AnotherObject )
1531+ }
1532+ )
1533+
1534+ assert schema_with_field_type (AnotherObject )
1535+
1536+ def test_accepts_an_object_with_a_subtyped_interface_field_union (self ):
1537+ AnotherInterface = GraphQLInterfaceType (
1538+ name = 'AnotherInterface' ,
1539+ resolve_type = _none ,
1540+ fields = lambda : {
1541+ 'field' : GraphQLField (SomeUnionType )
1542+ }
1543+ )
1544+ AnotherObject = GraphQLObjectType (
1545+ name = 'AnotherObject' ,
1546+ interfaces = [AnotherInterface ],
1547+ fields = lambda : {
1548+ 'field' : GraphQLField (SomeObjectType )
1549+ }
1550+ )
1551+
1552+ assert schema_with_field_type (AnotherObject )
1553+
14621554 def test_accepts_an_object_with_an_equivalently_modified_interface_field_type (self ):
14631555 AnotherInterface = GraphQLInterfaceType (
14641556 name = 'AnotherInterface' ,
@@ -1478,7 +1570,29 @@ def test_accepts_an_object_with_an_equivalently_modified_interface_field_type(se
14781570
14791571 assert schema_with_field_type (AnotherObject )
14801572
1481- def test_rejects_an_object_with_an_differently_modified_interface_field_type (self ):
1573+ def test_rejects_an_object_with_a_non_list_interface_field_list_type (self ):
1574+ AnotherInterface = GraphQLInterfaceType (
1575+ name = 'AnotherInterface' ,
1576+ resolve_type = _none ,
1577+ fields = {
1578+ 'field' : GraphQLField (GraphQLList (GraphQLString ))
1579+ }
1580+ )
1581+ AnotherObject = GraphQLObjectType (
1582+ name = 'AnotherObject' ,
1583+ interfaces = [AnotherInterface ],
1584+ fields = {
1585+ 'field' : GraphQLField (GraphQLString )
1586+ }
1587+ )
1588+
1589+ with raises (AssertionError ) as excinfo :
1590+ schema_with_field_type (AnotherObject )
1591+
1592+ assert str (excinfo .value ) == 'AnotherInterface.field expects type "[String]" ' \
1593+ 'but AnotherObject.field provides type "String".'
1594+
1595+ def test_rejects_a_object_with_a_list_interface_field_non_list_type (self ):
14821596 AnotherInterface = GraphQLInterfaceType (
14831597 name = 'AnotherInterface' ,
14841598 resolve_type = _none ,
@@ -1490,7 +1604,7 @@ def test_rejects_an_object_with_an_differently_modified_interface_field_type(sel
14901604 name = 'AnotherObject' ,
14911605 interfaces = [AnotherInterface ],
14921606 fields = {
1493- 'field' : GraphQLField (GraphQLNonNull (GraphQLString ))
1607+ 'field' : GraphQLField (GraphQLList (GraphQLString ))
14941608
14951609 }
14961610 )
@@ -1499,4 +1613,45 @@ def test_rejects_an_object_with_an_differently_modified_interface_field_type(sel
14991613 schema_with_field_type (AnotherObject )
15001614
15011615 assert str (excinfo .value ) == 'AnotherInterface.field expects type "String" ' \
1502- 'but AnotherObject.field provides type "String!".'
1616+ 'but AnotherObject.field provides type "[String]".'
1617+
1618+ def test_accepts_an_object_with_a_subset_non_null_interface_field_type (self ):
1619+ AnotherInterface = GraphQLInterfaceType (
1620+ name = 'AnotherInterface' ,
1621+ resolve_type = _none ,
1622+ fields = {
1623+ 'field' : GraphQLField (GraphQLString )
1624+ }
1625+ )
1626+ AnotherObject = GraphQLObjectType (
1627+ name = 'AnotherObject' ,
1628+ interfaces = [AnotherInterface ],
1629+ fields = {
1630+ 'field' : GraphQLField (GraphQLNonNull (GraphQLString ))
1631+ }
1632+ )
1633+
1634+ assert schema_with_field_type (AnotherObject )
1635+
1636+ def test_rejects_a_object_with_a_superset_nullable_interface_field_type (self ):
1637+ AnotherInterface = GraphQLInterfaceType (
1638+ name = 'AnotherInterface' ,
1639+ resolve_type = _none ,
1640+ fields = {
1641+ 'field' : GraphQLField (GraphQLNonNull (GraphQLString ))
1642+ }
1643+ )
1644+ AnotherObject = GraphQLObjectType (
1645+ name = 'AnotherObject' ,
1646+ interfaces = [AnotherInterface ],
1647+ fields = {
1648+ 'field' : GraphQLField (GraphQLString )
1649+
1650+ }
1651+ )
1652+
1653+ with raises (AssertionError ) as excinfo :
1654+ schema_with_field_type (AnotherObject )
1655+
1656+ assert str (excinfo .value ) == 'AnotherInterface.field expects type "String!" but ' \
1657+ 'AnotherObject.field provides type "String".'
0 commit comments