Corrected introspection of enum types

This commit is contained in:
Tobe O 2018-08-04 11:12:26 -04:00
parent aad1404530
commit 7e0eaa387d
3 changed files with 43 additions and 31 deletions

View file

@ -1,3 +1,7 @@
import 'package:graphql_schema/graphql_schema.dart';
@GraphQLDocumentation(
description: 'The episodes of the Star Wars original trilogy.')
enum Episode { enum Episode {
NEWHOPE, NEWHOPE,
EMPIRE, EMPIRE,

View file

@ -51,6 +51,9 @@ Future configureServer(Angel app) async {
field( field(
'hero', 'hero',
type: heroType, type: heroType,
arguments: [
new GraphQLFieldArgument('ep', episodeType),
],
resolve: (_, args) async { resolve: (_, args) async {
var allHeroes = []; var allHeroes = [];
var allDroids = await droidService.index() as Iterable; var allDroids = await droidService.index() as Iterable;
@ -94,18 +97,24 @@ Future configureServer(Angel app) async {
'total_credits': 520, 'total_credits': 520,
}); });
var lando = await humansService.create({
'name': 'Lando Calrissian',
'appears_in': ['EMPIRE', 'JEDI'],
'total_credits': 525430,
});
var hanSolo = await humansService.create({ var hanSolo = await humansService.create({
'name': 'Han Solo', 'name': 'Han Solo',
'appears_in': ['NEWHOPE', 'EMPIRE', 'JEDI'], 'appears_in': ['NEWHOPE', 'EMPIRE', 'JEDI'],
'total_credits': 23, 'total_credits': 23,
'friends': [leia], 'friends': [leia, lando],
}); });
var luke = await humansService.create({ var luke = await humansService.create({
'name': 'Luke Skywalker', 'name': 'Luke Skywalker',
'appears_in': ['NEWHOPE', 'EMPIRE', 'JEDI'], 'appears_in': ['NEWHOPE', 'EMPIRE', 'JEDI'],
'total_credits': 682, 'total_credits': 682,
'friends': [leia, hanSolo], 'friends': [leia, hanSolo, lando],
}); });
} }

View file

@ -207,7 +207,9 @@ GraphQLObjectType _createTypeType() {
resolve: (type, _) { resolve: (type, _) {
var t = type as GraphQLType; var t = type as GraphQLType;
if (t is GraphQLScalarType) if (t is GraphQLEnumType)
return 'ENUM';
else if (t is GraphQLScalarType)
return 'SCALAR'; return 'SCALAR';
else if (t is GraphQLObjectType) else if (t is GraphQLObjectType)
return t.isInterface ? 'INTERFACE' : 'OBJECT'; return t.isInterface ? 'INTERFACE' : 'OBJECT';
@ -215,8 +217,6 @@ GraphQLObjectType _createTypeType() {
return 'LIST'; return 'LIST';
else if (t is GraphQLNonNullableType) else if (t is GraphQLNonNullableType)
return 'NON_NULL'; return 'NON_NULL';
else if (t is GraphQLEnumType)
return 'ENUM';
else if (t is GraphQLUnionType) else if (t is GraphQLUnionType)
return 'UNION'; return 'UNION';
else else
@ -376,32 +376,31 @@ GraphQLObjectType _reflectDirectiveType() {
GraphQLObjectType _enumValueType; GraphQLObjectType _enumValueType;
GraphQLObjectType _reflectEnumValueType() { GraphQLObjectType _reflectEnumValueType() {
return _enumValueType ?? return _enumValueType ??= objectType(
objectType( '__EnumValue',
'__EnumValue', fields: [
fields: [ field(
field( 'name',
'name', type: graphQLString.nonNullable(),
type: graphQLString.nonNullable(), resolve: (obj, _) => (obj as GraphQLEnumValue).name,
resolve: (obj, _) => (obj as GraphQLEnumValue).name, ),
), field(
field( 'description',
'description', type: graphQLString,
type: graphQLString, resolve: (obj, _) => (obj as GraphQLEnumValue).description,
resolve: (obj, _) => (obj as GraphQLEnumValue).description, ),
), field(
field( 'isDeprecated',
'isDeprecated', type: graphQLBoolean.nonNullable(),
type: graphQLBoolean.nonNullable(), resolve: (obj, _) => (obj as GraphQLEnumValue).isDeprecated,
resolve: (obj, _) => (obj as GraphQLEnumValue).isDeprecated, ),
), field(
field( 'deprecationReason',
'deprecationReason', type: graphQLString,
type: graphQLString, resolve: (obj, _) => (obj as GraphQLEnumValue).deprecationReason,
resolve: (obj, _) => (obj as GraphQLEnumValue).deprecationReason, ),
), ],
], );
);
} }
List<GraphQLType> fetchAllTypes( List<GraphQLType> fetchAllTypes(