@@ -10,8 +10,8 @@ namespace HotChocolate.Types.Mutable;
10
10
/// </summary>
11
11
public class MutableSchemaDefinition
12
12
: INamedTypeSystemMemberDefinition < MutableSchemaDefinition >
13
- , ISchemaDefinition
14
- , IFeatureProvider
13
+ , ISchemaDefinition
14
+ , IFeatureProvider
15
15
{
16
16
private readonly List < SchemaCoordinate > _allDefinitionCoordinates = [ ] ;
17
17
private MutableObjectTypeDefinition ? _queryType ;
@@ -45,7 +45,8 @@ public MutableObjectTypeDefinition? QueryType
45
45
}
46
46
}
47
47
48
- IObjectTypeDefinition ? ISchemaDefinition . QueryType => QueryType ;
48
+ IObjectTypeDefinition ISchemaDefinition . QueryType
49
+ => QueryType ?? throw new InvalidOperationException ( "The query type is not defined." ) ;
49
50
50
51
/// <summary>
51
52
/// Gets or sets the mutation type.
@@ -251,6 +252,48 @@ public MutableObjectTypeDefinition GetOperationType(OperationType operationType)
251
252
IObjectTypeDefinition ISchemaDefinition . GetOperationType ( OperationType operationType )
252
253
=> GetOperationType ( operationType ) ;
253
254
255
+ public IEnumerable < MutableObjectTypeDefinition > GetPossibleTypes ( ITypeDefinition abstractType )
256
+ {
257
+ if ( abstractType . Kind is not TypeKind . Union and not TypeKind . Interface and not TypeKind . Object )
258
+ {
259
+ throw new ArgumentException (
260
+ "The specified type is not an abstract type." ,
261
+ nameof ( abstractType ) ) ;
262
+ }
263
+
264
+ if ( abstractType is MutableUnionTypeDefinition unionType )
265
+ {
266
+ foreach ( var possibleType in unionType . Types . AsEnumerable ( ) )
267
+ {
268
+ yield return possibleType ;
269
+ }
270
+
271
+ yield break ;
272
+ }
273
+
274
+ if ( abstractType is MutableInterfaceTypeDefinition interfaceType )
275
+ {
276
+ foreach ( var type in Types )
277
+ {
278
+ if ( type is MutableObjectTypeDefinition obj
279
+ && obj . Implements . ContainsName ( interfaceType . Name ) )
280
+ {
281
+ yield return obj ;
282
+ }
283
+ }
284
+
285
+ yield break ;
286
+ }
287
+
288
+ if ( abstractType is MutableObjectTypeDefinition objectType )
289
+ {
290
+ yield return objectType ;
291
+ }
292
+ }
293
+
294
+ IEnumerable < IObjectTypeDefinition > ISchemaDefinition . GetPossibleTypes ( ITypeDefinition abstractType )
295
+ => GetPossibleTypes ( abstractType ) ;
296
+
254
297
/// <summary>
255
298
/// Gets the type and directive definitions that are defined in this schema in insert order.
256
299
/// </summary>
0 commit comments