@@ -21,6 +21,7 @@ import graphql.language.ScalarTypeExtensionDefinition
2121import graphql.language.SchemaDefinition
2222import graphql.language.SchemaExtensionDefinition
2323import graphql.language.Type
24+ import graphql.language.TypeDefinition
2425import graphql.language.TypeName
2526import graphql.language.UnionTypeDefinition
2627import graphql.language.UnionTypeExtensionDefinition
@@ -48,7 +49,7 @@ inline fun <T> GraphQLFieldsContainer.whenType(
4849 return when (this ) {
4950 is GraphQLInterfaceType -> interfaceType(this )
5051 is GraphQLObjectType -> objectType(this )
51- else -> throw IllegalStateException (" Should never happen " )
52+ else -> throw IllegalStateException (javaClass.name )
5253 }
5354}
5455
@@ -61,7 +62,7 @@ inline fun <T> GraphQLNamedInputType.whenType(
6162 is GraphQLEnumType -> enumType(this )
6263 is GraphQLInputObjectType -> inputObjectType(this )
6364 is GraphQLScalarType -> scalarType(this )
64- else -> throw IllegalStateException (" Should never happen " )
65+ else -> throw IllegalStateException (javaClass.name )
6566 }
6667}
6768
@@ -78,7 +79,7 @@ inline fun <T> GraphQLNamedOutputType.whenType(
7879 is GraphQLObjectType -> objectType(this )
7980 is GraphQLScalarType -> scalarType(this )
8081 is GraphQLUnionType -> unionType(this )
81- else -> throw IllegalStateException (" Should never happen " )
82+ else -> throw IllegalStateException (javaClass.name )
8283 }
8384}
8485
@@ -97,7 +98,7 @@ inline fun <T> GraphQLNamedType.whenType(
9798 is GraphQLObjectType -> objectType(this )
9899 is GraphQLScalarType -> scalarType(this )
99100 is GraphQLUnionType -> unionType(this )
100- else -> throw IllegalStateException (" Should never happen " )
101+ else -> throw IllegalStateException (javaClass.name )
101102 }
102103}
103104
@@ -114,7 +115,7 @@ inline fun <T> GraphQLOutputType.whenUnmodifiedType(
114115 is GraphQLObjectType -> objectType(unmodifiedType)
115116 is GraphQLScalarType -> scalarType(unmodifiedType)
116117 is GraphQLUnionType -> unionType(unmodifiedType)
117- else -> throw IllegalStateException (" Should never happen " )
118+ else -> throw IllegalStateException (javaClass.name )
118119 }
119120}
120121
@@ -127,7 +128,7 @@ inline fun <T> GraphQLInputType.whenUnmodifiedType(
127128 is GraphQLEnumType -> enumType(unmodifiedType)
128129 is GraphQLInputObjectType -> inputObjectType(unmodifiedType)
129130 is GraphQLScalarType -> scalarType(unmodifiedType)
130- else -> throw IllegalStateException (" Should never happen " )
131+ else -> throw IllegalStateException (javaClass.name )
131132 }
132133}
133134
@@ -140,7 +141,7 @@ inline fun <T> GraphQLType.whenType(
140141 is GraphQLList -> listType(this )
141142 is GraphQLNonNull -> nonNull(this )
142143 is GraphQLUnmodifiedType -> unmodifiedType(this )
143- else -> throw IllegalStateException (" Should never happen " )
144+ else -> throw IllegalStateException (javaClass.name )
144145 }
145146}
146147
@@ -153,7 +154,7 @@ inline fun <T> Type<*>.whenType(
153154 is ListType -> listType(this )
154155 is NonNullType -> nonNull(this )
155156 is TypeName -> unmodifiedType(this )
156- else -> throw IllegalStateException (" Should never happen " )
157+ else -> throw IllegalStateException (javaClass.name )
157158 }
158159}
159160
@@ -190,6 +191,70 @@ inline fun <T> AnySDLDefinition.whenType(
190191 is SchemaDefinition -> schemaDefinition(this )
191192 is UnionTypeExtensionDefinition -> unionTypeExtensionDefinition(this )
192193 is UnionTypeDefinition -> unionTypeDefinition(this )
193- else -> throw IllegalStateException (" Should never happen" )
194+ else -> throw IllegalStateException (javaClass.name)
195+ }
196+ }
197+
198+ inline fun <T > AnySDLNamedDefinition.whenType (
199+ directiveDefinition : (DirectiveDefinition ) -> T ,
200+ enumTypeDefinition : (EnumTypeDefinition ) -> T ,
201+ enumTypeExtensionDefinition : (EnumTypeExtensionDefinition ) -> T ,
202+ inputObjectTypeDefinition : (InputObjectTypeDefinition ) -> T ,
203+ inputObjectTypeExtensionDefinition : (InputObjectTypeExtensionDefinition ) -> T ,
204+ interfaceTypeDefinition : (InterfaceTypeDefinition ) -> T ,
205+ interfaceTypeExtensionDefinition : (InterfaceTypeExtensionDefinition ) -> T ,
206+ objectTypeDefinition : (ObjectTypeDefinition ) -> T ,
207+ objectTypeExtensionDefinition : (ObjectTypeExtensionDefinition ) -> T ,
208+ scalarTypeDefinition : (ScalarTypeDefinition ) -> T ,
209+ scalarTypeExtensionDefinition : (ScalarTypeExtensionDefinition ) -> T ,
210+ unionTypeDefinition : (UnionTypeDefinition ) -> T ,
211+ unionTypeExtensionDefinition : (UnionTypeExtensionDefinition ) -> T ,
212+ ): T {
213+ return when (this ) {
214+ is DirectiveDefinition -> directiveDefinition(this )
215+ is EnumTypeExtensionDefinition -> enumTypeExtensionDefinition(this )
216+ is EnumTypeDefinition -> enumTypeDefinition(this )
217+ is InputObjectTypeExtensionDefinition -> inputObjectTypeExtensionDefinition(this )
218+ is InputObjectTypeDefinition -> inputObjectTypeDefinition(this )
219+ is InterfaceTypeExtensionDefinition -> interfaceTypeExtensionDefinition(this )
220+ is InterfaceTypeDefinition -> interfaceTypeDefinition(this )
221+ is ObjectTypeExtensionDefinition -> objectTypeExtensionDefinition(this )
222+ is ObjectTypeDefinition -> objectTypeDefinition(this )
223+ is ScalarTypeExtensionDefinition -> scalarTypeExtensionDefinition(this )
224+ is ScalarTypeDefinition -> scalarTypeDefinition(this )
225+ is UnionTypeExtensionDefinition -> unionTypeExtensionDefinition(this )
226+ is UnionTypeDefinition -> unionTypeDefinition(this )
227+ else -> throw IllegalStateException (javaClass.name)
228+ }
229+ }
230+
231+ inline fun <T > TypeDefinition <* >.whenType (
232+ enumTypeDefinition : (EnumTypeDefinition ) -> T ,
233+ enumTypeExtensionDefinition : (EnumTypeExtensionDefinition ) -> T ,
234+ inputObjectTypeDefinition : (InputObjectTypeDefinition ) -> T ,
235+ inputObjectTypeExtensionDefinition : (InputObjectTypeExtensionDefinition ) -> T ,
236+ interfaceTypeDefinition : (InterfaceTypeDefinition ) -> T ,
237+ interfaceTypeExtensionDefinition : (InterfaceTypeExtensionDefinition ) -> T ,
238+ objectTypeDefinition : (ObjectTypeDefinition ) -> T ,
239+ objectTypeExtensionDefinition : (ObjectTypeExtensionDefinition ) -> T ,
240+ scalarTypeDefinition : (ScalarTypeDefinition ) -> T ,
241+ scalarTypeExtensionDefinition : (ScalarTypeExtensionDefinition ) -> T ,
242+ unionTypeDefinition : (UnionTypeDefinition ) -> T ,
243+ unionTypeExtensionDefinition : (UnionTypeExtensionDefinition ) -> T ,
244+ ): T {
245+ return when (this ) {
246+ is EnumTypeExtensionDefinition -> enumTypeExtensionDefinition(this )
247+ is EnumTypeDefinition -> enumTypeDefinition(this )
248+ is InputObjectTypeExtensionDefinition -> inputObjectTypeExtensionDefinition(this )
249+ is InputObjectTypeDefinition -> inputObjectTypeDefinition(this )
250+ is InterfaceTypeExtensionDefinition -> interfaceTypeExtensionDefinition(this )
251+ is InterfaceTypeDefinition -> interfaceTypeDefinition(this )
252+ is ObjectTypeExtensionDefinition -> objectTypeExtensionDefinition(this )
253+ is ObjectTypeDefinition -> objectTypeDefinition(this )
254+ is ScalarTypeExtensionDefinition -> scalarTypeExtensionDefinition(this )
255+ is ScalarTypeDefinition -> scalarTypeDefinition(this )
256+ is UnionTypeExtensionDefinition -> unionTypeExtensionDefinition(this )
257+ is UnionTypeDefinition -> unionTypeDefinition(this )
258+ else -> throw IllegalStateException (javaClass.name)
194259 }
195260}
0 commit comments