@@ -1579,25 +1579,15 @@ describe('Objects must adhere to Interface they implement', () => {
1579
1579
name : 'AnotherInterface' ,
1580
1580
resolveType : ( ) => null ,
1581
1581
fields : {
1582
- field : {
1583
- type : GraphQLString ,
1584
- args : {
1585
- input : { type : GraphQLString } ,
1586
- }
1587
- }
1582
+ field : { type : GraphQLString }
1588
1583
}
1589
1584
} ) ;
1590
1585
1591
1586
var AnotherObject = new GraphQLObjectType ( {
1592
1587
name : 'AnotherObject' ,
1593
1588
interfaces : [ AnotherInterface ] ,
1594
1589
fields : {
1595
- field : {
1596
- type : SomeScalarType ,
1597
- args : {
1598
- input : { type : GraphQLString } ,
1599
- }
1600
- }
1590
+ field : { type : SomeScalarType }
1601
1591
}
1602
1592
} ) ;
1603
1593
@@ -1608,6 +1598,89 @@ describe('Objects must adhere to Interface they implement', () => {
1608
1598
) ;
1609
1599
} ) ;
1610
1600
1601
+ it ( 'rejects an Object with a differently typed Interface field' , ( ) => {
1602
+ expect ( ( ) => {
1603
+ var TypeA = new GraphQLObjectType ( {
1604
+ name : 'A' ,
1605
+ fields : {
1606
+ foo : { type : GraphQLString }
1607
+ }
1608
+ } ) ;
1609
+
1610
+ var TypeB = new GraphQLObjectType ( {
1611
+ name : 'B' ,
1612
+ fields : {
1613
+ foo : { type : GraphQLString }
1614
+ }
1615
+ } ) ;
1616
+
1617
+ var AnotherInterface = new GraphQLInterfaceType ( {
1618
+ name : 'AnotherInterface' ,
1619
+ resolveType : ( ) => null ,
1620
+ fields : {
1621
+ field : { type : TypeA }
1622
+ }
1623
+ } ) ;
1624
+
1625
+ var AnotherObject = new GraphQLObjectType ( {
1626
+ name : 'AnotherObject' ,
1627
+ interfaces : [ AnotherInterface ] ,
1628
+ fields : {
1629
+ field : { type : TypeB }
1630
+ }
1631
+ } ) ;
1632
+
1633
+ return schemaWithFieldType ( AnotherObject ) ;
1634
+ } ) . to . throw (
1635
+ 'AnotherInterface.field expects type "A" but ' +
1636
+ 'AnotherObject.field provides type "B".'
1637
+ ) ;
1638
+ } ) ;
1639
+
1640
+ it ( 'accepts an Object with a subtyped Interface field (interface)' , ( ) => {
1641
+ expect ( ( ) => {
1642
+ var AnotherInterface = new GraphQLInterfaceType ( {
1643
+ name : 'AnotherInterface' ,
1644
+ resolveType : ( ) => null ,
1645
+ fields : ( ) => ( {
1646
+ field : { type : AnotherInterface }
1647
+ } )
1648
+ } ) ;
1649
+
1650
+ var AnotherObject = new GraphQLObjectType ( {
1651
+ name : 'AnotherObject' ,
1652
+ interfaces : [ AnotherInterface ] ,
1653
+ fields : ( ) => ( {
1654
+ field : { type : AnotherObject }
1655
+ } )
1656
+ } ) ;
1657
+
1658
+ return schemaWithFieldType ( AnotherObject ) ;
1659
+ } ) . not . to . throw ( ) ;
1660
+ } ) ;
1661
+
1662
+ it ( 'accepts an Object with a subtyped Interface field (union)' , ( ) => {
1663
+ expect ( ( ) => {
1664
+ var AnotherInterface = new GraphQLInterfaceType ( {
1665
+ name : 'AnotherInterface' ,
1666
+ resolveType : ( ) => null ,
1667
+ fields : {
1668
+ field : { type : SomeUnionType }
1669
+ }
1670
+ } ) ;
1671
+
1672
+ var AnotherObject = new GraphQLObjectType ( {
1673
+ name : 'AnotherObject' ,
1674
+ interfaces : [ AnotherInterface ] ,
1675
+ fields : {
1676
+ field : { type : SomeObjectType }
1677
+ }
1678
+ } ) ;
1679
+
1680
+ return schemaWithFieldType ( AnotherObject ) ;
1681
+ } ) . not . to . throw ( ) ;
1682
+ } ) ;
1683
+
1611
1684
it ( 'rejects an Object missing an Interface argument' , ( ) => {
1612
1685
expect ( ( ) => {
1613
1686
var AnotherInterface = new GraphQLInterfaceType ( {
@@ -1697,7 +1770,32 @@ describe('Objects must adhere to Interface they implement', () => {
1697
1770
} ) . not . to . throw ( ) ;
1698
1771
} ) ;
1699
1772
1700
- it ( 'rejects an Object with a differently modified Interface field type' , ( ) => {
1773
+ it ( 'rejects an Object with a non-list Interface field list type' , ( ) => {
1774
+ expect ( ( ) => {
1775
+ var AnotherInterface = new GraphQLInterfaceType ( {
1776
+ name : 'AnotherInterface' ,
1777
+ resolveType : ( ) => null ,
1778
+ fields : {
1779
+ field : { type : new GraphQLList ( GraphQLString ) }
1780
+ }
1781
+ } ) ;
1782
+
1783
+ var AnotherObject = new GraphQLObjectType ( {
1784
+ name : 'AnotherObject' ,
1785
+ interfaces : [ AnotherInterface ] ,
1786
+ fields : {
1787
+ field : { type : GraphQLString }
1788
+ }
1789
+ } ) ;
1790
+
1791
+ return schemaWithFieldType ( AnotherObject ) ;
1792
+ } ) . to . throw (
1793
+ 'AnotherInterface.field expects type "[String]" but ' +
1794
+ 'AnotherObject.field provides type "String".'
1795
+ ) ;
1796
+ } ) ;
1797
+
1798
+ it ( 'rejects an Object with a list Interface field non-list type' , ( ) => {
1701
1799
expect ( ( ) => {
1702
1800
var AnotherInterface = new GraphQLInterfaceType ( {
1703
1801
name : 'AnotherInterface' ,
@@ -1711,14 +1809,61 @@ describe('Objects must adhere to Interface they implement', () => {
1711
1809
name : 'AnotherObject' ,
1712
1810
interfaces : [ AnotherInterface ] ,
1713
1811
fields : {
1714
- field : { type : new GraphQLNonNull ( GraphQLString ) }
1812
+ field : { type : new GraphQLList ( GraphQLString ) }
1715
1813
}
1716
1814
} ) ;
1717
1815
1718
1816
return schemaWithFieldType ( AnotherObject ) ;
1719
1817
} ) . to . throw (
1720
1818
'AnotherInterface.field expects type "String" but ' +
1721
- 'AnotherObject.field provides type "String!".'
1819
+ 'AnotherObject.field provides type "[String]".'
1820
+ ) ;
1821
+ } ) ;
1822
+
1823
+ it ( 'accepts an Object with a subset non-null Interface field type' , ( ) => {
1824
+ expect ( ( ) => {
1825
+ var AnotherInterface = new GraphQLInterfaceType ( {
1826
+ name : 'AnotherInterface' ,
1827
+ resolveType : ( ) => null ,
1828
+ fields : {
1829
+ field : { type : GraphQLString }
1830
+ }
1831
+ } ) ;
1832
+
1833
+ var AnotherObject = new GraphQLObjectType ( {
1834
+ name : 'AnotherObject' ,
1835
+ interfaces : [ AnotherInterface ] ,
1836
+ fields : {
1837
+ field : { type : new GraphQLNonNull ( GraphQLString ) }
1838
+ }
1839
+ } ) ;
1840
+
1841
+ return schemaWithFieldType ( AnotherObject ) ;
1842
+ } ) . not . to . throw ( ) ;
1843
+ } ) ;
1844
+
1845
+ it ( 'rejects an Object with a superset nullable Interface field type' , ( ) => {
1846
+ expect ( ( ) => {
1847
+ var AnotherInterface = new GraphQLInterfaceType ( {
1848
+ name : 'AnotherInterface' ,
1849
+ resolveType : ( ) => null ,
1850
+ fields : {
1851
+ field : { type : new GraphQLNonNull ( GraphQLString ) }
1852
+ }
1853
+ } ) ;
1854
+
1855
+ var AnotherObject = new GraphQLObjectType ( {
1856
+ name : 'AnotherObject' ,
1857
+ interfaces : [ AnotherInterface ] ,
1858
+ fields : {
1859
+ field : { type : GraphQLString }
1860
+ }
1861
+ } ) ;
1862
+
1863
+ return schemaWithFieldType ( AnotherObject ) ;
1864
+ } ) . to . throw (
1865
+ 'AnotherInterface.field expects type "String!" but ' +
1866
+ 'AnotherObject.field provides type "String".'
1722
1867
) ;
1723
1868
} ) ;
1724
1869
0 commit comments