Finished EnumValue type

This commit is contained in:
Tobe O 2018-08-03 18:54:12 -04:00
parent 01e3b067de
commit b7dea3f2e0
4 changed files with 50 additions and 9 deletions

View file

@ -53,12 +53,17 @@ main() async {
}
@serializable
@GraphQLDocumentation(description: 'A task that might not be completed yet. **Yay! Markdown!**')
@GraphQLDocumentation(
description: 'A task that might not be completed yet. **Yay! Markdown!**')
class Todo extends Model {
String text;
@GraphQLDocumentation(deprecationReason: 'Booleans are just *sooo* 2015!')
@GraphQLDocumentation(deprecationReason: 'Use `completion_status` instead.')
bool completed;
Todo({this.text, this.completed});
CompletionStatus completionStatus;
Todo({this.text, this.completed, this.completionStatus});
}
enum CompletionStatus { complete, incomplete }

View file

@ -47,9 +47,10 @@ class GraphQLEnumType<Value> extends GraphQLScalarType<Value, String>
class GraphQLEnumValue<Value> {
final String name;
final Value value;
final String description;
final String deprecationReason;
GraphQLEnumValue(this.name, this.value, {this.deprecationReason});
GraphQLEnumValue(this.name, this.value, {this.description, this.deprecationReason});
bool get isDeprecated => deprecationReason != null;

View file

@ -309,8 +309,16 @@ GraphQLObjectType _reflectDirectiveType() {
),
field(
'locations',
type: listType(graphQLString.nonNullable()).nonNullable(),
// TODO: Enum directiveLocation
type: listType(enumTypeFromStrings('DirectiveLocation', [
'QUERY',
'MUTATION',
'FIELD',
'FRAGMENT_DEFINITION',
'FRAGMENT_SPREAD',
'INLINE_FRAGMENT'
]).nonNullable())
.nonNullable(),
// TODO: Fetch directiveLocation
resolve: (obj, _) => <String>[],
),
field(
@ -324,8 +332,32 @@ GraphQLObjectType _reflectDirectiveType() {
GraphQLObjectType _enumValueType;
GraphQLObjectType _reflectEnumValueType() {
// TODO: Enum values
return _enumValueType ?? objectType('__EnumValue', fields: []);
return _enumValueType ??
objectType(
'__EnumValue',
fields: [
field(
'name',
type: graphQLString.nonNullable(),
resolve: (obj, _) => (obj as GraphQLEnumValue).name,
),
field(
'description',
type: graphQLString,
resolve: (obj, _) => (obj as GraphQLEnumValue).description,
),
field(
'isDeprecated',
type: graphQLBoolean.nonNullable(),
resolve: (obj, _) => (obj as GraphQLEnumValue).isDeprecated,
),
field(
'deprecationReason',
type: graphQLString,
resolve: (obj, _) => (obj as GraphQLEnumValue).deprecationReason,
),
],
);
}
List<GraphQLObjectType> fetchAllTypes(GraphQLSchema schema) {
@ -369,8 +401,10 @@ Iterable<GraphQLType> _fetchAllTypesFromType(GraphQLType type) {
types.addAll(_fetchAllTypesFromType(type.innerType));
} else if (type is GraphQLObjectType) {
types.addAll(_fetchAllTypesFromObject(type));
} else if (type is GraphQLEnumType) {
types.add(type);
}
// TODO: Enum, interface, union
// TODO: Interface, union
return types;
}

View file

@ -84,6 +84,7 @@ GraphQLEnumType enumTypeFromClassMirror(ClassMirror mirror) {
new GraphQLEnumValue(
MirrorSystem.getName(name),
mirror.getField(name).reflectee,
description: _getDescription(methodMirror.metadata),
deprecationReason: _getDeprecationReason(methodMirror.metadata),
),
);