Introspection supports union types
This commit is contained in:
parent
c69a53457f
commit
65bba97f1a
3 changed files with 29 additions and 3 deletions
|
@ -19,6 +19,8 @@ part 'scalar.dart';
|
|||
|
||||
part 'type.dart';
|
||||
|
||||
part 'union.dart';
|
||||
|
||||
part 'validation_result.dart';
|
||||
|
||||
class GraphQLSchema {
|
||||
|
|
18
graphql_schema/lib/src/union.dart
Normal file
18
graphql_schema/lib/src/union.dart
Normal file
|
@ -0,0 +1,18 @@
|
|||
part of graphql_schema.src.schema;
|
||||
|
||||
class GraphQLUnionType<Value, Serialized> extends GraphQLType<Value, Serialized>
|
||||
with
|
||||
_NonNullableMixin<Value, Serialized> {
|
||||
final List<GraphQLType<Value, Serialized>> possibleTypes;
|
||||
final String description;
|
||||
|
||||
GraphQLUnionType(this.possibleTypes, {this.description}) {
|
||||
assert(possibleTypes.every((
|
||||
t) => t is GraphQLUnionType), 'The member types of a Union type must all be Object base types; Scalar, Interface and Union types may not be member types of a Union. Similarly, wrapping types may not be member types of a Union');
|
||||
assert(possibleTypes
|
||||
.isNotEmpty, 'A Union type must define one or more member types');
|
||||
}
|
||||
|
||||
@override
|
||||
String get name => possibleTypes.map((t) => t.name).join(' | ')
|
||||
}
|
|
@ -122,6 +122,8 @@ GraphQLObjectType _reflectSchemaTypes() {
|
|||
resolve: (type, _) {
|
||||
if (type is GraphQLObjectType && type.isInterface) {
|
||||
return type.possibleTypes;
|
||||
} else if (type is GraphQLUnionType) {
|
||||
return type.possibleTypes;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
@ -205,9 +207,11 @@ GraphQLObjectType _createTypeType() {
|
|||
return 'NON_NULL';
|
||||
else if (t is GraphQLEnumType)
|
||||
return 'ENUM';
|
||||
else if (t is GraphQLUnionType)
|
||||
return 'UNION';
|
||||
else
|
||||
throw new UnsupportedError(
|
||||
'Cannot get the kind of $t.'); // TODO: union
|
||||
'Cannot get the kind of $t.');
|
||||
},
|
||||
),
|
||||
field(
|
||||
|
@ -445,8 +449,10 @@ Iterable<GraphQLType> _fetchAllTypesFromType(GraphQLType type) {
|
|||
types.addAll(_fetchAllTypesFromObject(type));
|
||||
} else if (type is GraphQLEnumType) {
|
||||
types.add(type);
|
||||
} else if ( type is GraphQLUnionType) {
|
||||
for (var t in type.possibleTypes) {
|
||||
types.addAll(_fetchAllTypesFromType(t));
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: union
|
||||
return types;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue