part of graphql_schema.src.schema; class GraphQLUnionType extends GraphQLType, Map> with _NonNullableMixin, Map> { final String name; final List possibleTypes = []; GraphQLUnionType( this.name, Iterable possibleTypes, ) { assert(possibleTypes.isNotEmpty, 'A Union type must define one or more member types.'); this.possibleTypes.addAll(possibleTypes.toSet()); } @override String get description => possibleTypes.map((t) => t.name).join(' | '); @override Map serialize(Map value) { for (var type in possibleTypes) { try { return type.serialize(value); } catch (_) {} } throw new ArgumentError(); } @override Map deserialize(Map serialized) { for (var type in possibleTypes) { try { return type.deserialize(serialized); } catch (_) {} } throw new ArgumentError(); } @override ValidationResult> validate( String key, Map input) { List errors = []; for (var type in possibleTypes) { var result = type.validate(key, input); if (result.successful) { return result; } else { errors.addAll(result.errors); } } return new ValidationResult>._failure(errors); } }