part of graphql_schema.src.schema; GraphQLEnumType enumType(String name, Map values, {String description}) { return new GraphQLEnumType( name, values.keys.map((k) => new GraphQLEnumValue(k, values[k])).toList(), description: description); } GraphQLEnumType enumTypeFromStrings(String name, List values, {String description}) { return new GraphQLEnumType( name, values.map((s) => new GraphQLEnumValue(s, s)).toList(), description: description); } class GraphQLEnumType extends GraphQLScalarType with _NonNullableMixin { final String name; final List> values; final String description; GraphQLEnumType(this.name, this.values, {this.description}); @override String serialize(Value value) { return values.firstWhere((v) => v.value == value).name; } @override Value deserialize(String serialized) { return values.firstWhere((v) => v.name == serialized).value; } @override ValidationResult validate(String key, String input) { if (!values.any((v) => v.name == input)) { return new ValidationResult._failure( ['"$input" is not a valid value for the enum "$name".']); } return new ValidationResult._ok(input); } } class GraphQLEnumValue { final String name; final Value value; final String deprecationReason; GraphQLEnumValue(this.name, this.value, {this.deprecationReason}); bool get isDeprecated => deprecationReason != null; @override bool operator ==(other) => other is GraphQLEnumValue && other.name == name; }