Doc comments on enum types
This commit is contained in:
parent
3ae666aab6
commit
27c167fc50
1 changed files with 24 additions and 0 deletions
|
@ -1,5 +1,6 @@
|
|||
part of graphql_schema.src.schema;
|
||||
|
||||
/// Shorthand for building a [GraphQLEnumType].
|
||||
GraphQLEnumType enumType<Value>(String name, Map<String, Value> values,
|
||||
{String description}) {
|
||||
return new GraphQLEnumType<Value>(
|
||||
|
@ -7,6 +8,8 @@ GraphQLEnumType enumType<Value>(String name, Map<String, Value> values,
|
|||
description: description);
|
||||
}
|
||||
|
||||
/// Shorthand for building a [GraphQLEnumType] where all the possible values
|
||||
/// are mapped to Dart strings.
|
||||
GraphQLEnumType enumTypeFromStrings(String name, List<String> values,
|
||||
{String description}) {
|
||||
return new GraphQLEnumType<String>(
|
||||
|
@ -14,10 +17,20 @@ GraphQLEnumType enumTypeFromStrings(String name, List<String> values,
|
|||
description: description);
|
||||
}
|
||||
|
||||
/// A [GraphQLType] with only a predetermined number of possible values.
|
||||
///
|
||||
/// Though these are serialized as strings, they carry special meaning with a type system.
|
||||
class GraphQLEnumType<Value> extends GraphQLScalarType<Value, String>
|
||||
with _NonNullableMixin<Value, String> {
|
||||
/// The name of this enum type.
|
||||
final String name;
|
||||
|
||||
/// The defined set of possible values for this type.
|
||||
///
|
||||
/// No other values will be accepted than the ones you define.
|
||||
final List<GraphQLEnumValue<Value>> values;
|
||||
|
||||
/// A description of this enum type, for tools like GraphiQL.
|
||||
final String description;
|
||||
|
||||
GraphQLEnumType(this.name, this.values, {this.description});
|
||||
|
@ -59,15 +72,26 @@ class GraphQLEnumType<Value> extends GraphQLScalarType<Value, String>
|
|||
GraphQLType<Value, String> coerceToInputObject() => this;
|
||||
}
|
||||
|
||||
/// A known value of a [GraphQLEnumType].
|
||||
///
|
||||
/// In practice, you might not directly call this constructor very often.
|
||||
class GraphQLEnumValue<Value> {
|
||||
/// The name of this value.
|
||||
final String name;
|
||||
|
||||
/// The Dart value associated with enum values bearing the given [name].
|
||||
final Value value;
|
||||
|
||||
/// An optional description of this value; useful for tools like GraphiQL.
|
||||
final String description;
|
||||
|
||||
/// The reason, if any, that this value was deprecated, if it indeed is deprecated.
|
||||
final String deprecationReason;
|
||||
|
||||
GraphQLEnumValue(this.name, this.value,
|
||||
{this.description, this.deprecationReason});
|
||||
|
||||
/// Returns `true` if this value has a [deprecationReason].
|
||||
bool get isDeprecated => deprecationReason != null;
|
||||
|
||||
@override
|
||||
|
|
Loading…
Reference in a new issue