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 @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 { class Todo extends Model {
String text; String text;
@GraphQLDocumentation(deprecationReason: 'Booleans are just *sooo* 2015!') @GraphQLDocumentation(deprecationReason: 'Use `completion_status` instead.')
bool completed; 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> { class GraphQLEnumValue<Value> {
final String name; final String name;
final Value value; final Value value;
final String description;
final String deprecationReason; final String deprecationReason;
GraphQLEnumValue(this.name, this.value, {this.deprecationReason}); GraphQLEnumValue(this.name, this.value, {this.description, this.deprecationReason});
bool get isDeprecated => deprecationReason != null; bool get isDeprecated => deprecationReason != null;

View file

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

View file

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