@@ -1067,9 +1067,13 @@ class FastBuilderTest extends Specification {
10671067 .type(postType))
10681068 .build()
10691069
1070+ and : " code registry with type resolver"
1071+ def codeRegistry = GraphQLCodeRegistry . newCodeRegistry()
1072+ .typeResolver(" Node" , { env -> null })
1073+
10701074 when : " building with FastBuilder"
10711075 def schema = new GraphQLSchema.FastBuilder (
1072- GraphQLCodeRegistry . newCodeRegistry() , queryType, null , null )
1076+ codeRegistry , queryType, null , null )
10731077 .addType(nodeInterface)
10741078 .addType(postType)
10751079 .build()
@@ -1120,9 +1124,13 @@ class FastBuilderTest extends Specification {
11201124 .type(entityInterface))
11211125 .build()
11221126
1127+ and : " code registry with type resolver"
1128+ def codeRegistry = GraphQLCodeRegistry . newCodeRegistry()
1129+ .typeResolver(" Entity" , { env -> null })
1130+
11231131 when : " building with FastBuilder"
11241132 def schema = new GraphQLSchema.FastBuilder (
1125- GraphQLCodeRegistry . newCodeRegistry() , queryType, null , null )
1133+ codeRegistry , queryType, null , null )
11261134 .addType(entityInterface)
11271135 .addType(userType)
11281136 .addType(productType)
@@ -1686,6 +1694,42 @@ class FastBuilderTest extends Specification {
16861694 schema. codeRegistry. getTypeResolver(resolvedUnion) != null
16871695 }
16881696
1697+ def " union without type resolver throws error" () {
1698+ given : " a union without type resolver"
1699+ def catType = newObject()
1700+ .name(" Cat" )
1701+ .field(newFieldDefinition()
1702+ .name(" meow" )
1703+ .type(GraphQLString ))
1704+ .build()
1705+
1706+ def petUnion = GraphQLUnionType . newUnionType()
1707+ .name(" Pet" )
1708+ .possibleType(catType)
1709+ // No type resolver!
1710+ .build()
1711+
1712+ and : " a query type"
1713+ def queryType = newObject()
1714+ .name(" Query" )
1715+ .field(newFieldDefinition()
1716+ .name(" pet" )
1717+ .type(petUnion))
1718+ .build()
1719+
1720+ when : " building without type resolver"
1721+ new GraphQLSchema.FastBuilder (
1722+ GraphQLCodeRegistry . newCodeRegistry(), queryType, null , null )
1723+ .addType(catType)
1724+ .addType(petUnion)
1725+ .build()
1726+
1727+ then : " error is thrown"
1728+ def e = thrown(AssertException )
1729+ e. message. contains(" MUST provide a type resolver" )
1730+ e. message. contains(" Pet" )
1731+ }
1732+
16891733 def " union with missing member type reference throws error" () {
16901734 given : " a union with missing type reference"
16911735 def petUnion = GraphQLUnionType . newUnionType()
@@ -1780,7 +1824,7 @@ class FastBuilderTest extends Specification {
17801824 resolvedApplied. getArgument(" info" ). getType() == metaScalar
17811825 }
17821826
1783- def " withValidation(false) allows schema without type resolver" () {
1827+ def " interface without type resolver throws error " () {
17841828 given : " an interface without type resolver"
17851829 def nodeInterface = GraphQLInterfaceType . newInterface()
17861830 .name(" Node" )
@@ -1798,16 +1842,45 @@ class FastBuilderTest extends Specification {
17981842 .type(nodeInterface))
17991843 .build()
18001844
1801- when : " building with validation disabled"
1802- def schema = new GraphQLSchema.FastBuilder (
1845+ when : " building without type resolver"
1846+ new GraphQLSchema.FastBuilder (
1847+ GraphQLCodeRegistry . newCodeRegistry(), queryType, null , null )
1848+ .addType(nodeInterface)
1849+ .build()
1850+
1851+ then : " error is thrown"
1852+ def e = thrown(AssertException )
1853+ e. message. contains(" MUST provide a type resolver" )
1854+ e. message. contains(" Node" )
1855+ }
1856+
1857+ def " withValidation(false) still requires type resolvers" () {
1858+ given : " an interface without type resolver"
1859+ def nodeInterface = GraphQLInterfaceType . newInterface()
1860+ .name(" Node" )
1861+ .field(newFieldDefinition()
1862+ .name(" id" )
1863+ .type(GraphQLString ))
1864+ .build()
1865+
1866+ and : " a query type"
1867+ def queryType = newObject()
1868+ .name(" Query" )
1869+ .field(newFieldDefinition()
1870+ .name(" node" )
1871+ .type(nodeInterface))
1872+ .build()
1873+
1874+ when : " building with validation disabled but no type resolver"
1875+ new GraphQLSchema.FastBuilder (
18031876 GraphQLCodeRegistry . newCodeRegistry(), queryType, null , null )
18041877 .addType(nodeInterface)
18051878 .withValidation(false )
18061879 .build()
18071880
1808- then : " schema builds without error "
1809- schema != null
1810- schema . getType( " Node " ) instanceof GraphQLInterfaceType
1881+ then : " error is still thrown for missing type resolver "
1882+ def e = thrown( AssertException )
1883+ e . message . contains( " MUST provide a type resolver " )
18111884 }
18121885
18131886 def " withValidation(true) rejects schema with incomplete interface implementation" () {
0 commit comments