diff --git a/example_star_wars/lib/src/models/episode.dart b/example_star_wars/lib/src/models/episode.dart index 3f0d4a71..dea803dd 100644 --- a/example_star_wars/lib/src/models/episode.dart +++ b/example_star_wars/lib/src/models/episode.dart @@ -1,3 +1,7 @@ +import 'package:graphql_schema/graphql_schema.dart'; + +@GraphQLDocumentation( + description: 'The episodes of the Star Wars original trilogy.') enum Episode { NEWHOPE, EMPIRE, diff --git a/example_star_wars/lib/star_wars.dart b/example_star_wars/lib/star_wars.dart index f85dc14f..2360caa8 100644 --- a/example_star_wars/lib/star_wars.dart +++ b/example_star_wars/lib/star_wars.dart @@ -51,6 +51,9 @@ Future configureServer(Angel app) async { field( 'hero', type: heroType, + arguments: [ + new GraphQLFieldArgument('ep', episodeType), + ], resolve: (_, args) async { var allHeroes = []; var allDroids = await droidService.index() as Iterable; @@ -94,18 +97,24 @@ Future configureServer(Angel app) async { 'total_credits': 520, }); + var lando = await humansService.create({ + 'name': 'Lando Calrissian', + 'appears_in': ['EMPIRE', 'JEDI'], + 'total_credits': 525430, + }); + var hanSolo = await humansService.create({ 'name': 'Han Solo', 'appears_in': ['NEWHOPE', 'EMPIRE', 'JEDI'], 'total_credits': 23, - 'friends': [leia], + 'friends': [leia, lando], }); var luke = await humansService.create({ 'name': 'Luke Skywalker', 'appears_in': ['NEWHOPE', 'EMPIRE', 'JEDI'], 'total_credits': 682, - 'friends': [leia, hanSolo], + 'friends': [leia, hanSolo, lando], }); } diff --git a/graphql_server/lib/introspection.dart b/graphql_server/lib/introspection.dart index 263b2d5c..a9b55470 100644 --- a/graphql_server/lib/introspection.dart +++ b/graphql_server/lib/introspection.dart @@ -207,7 +207,9 @@ GraphQLObjectType _createTypeType() { resolve: (type, _) { var t = type as GraphQLType; - if (t is GraphQLScalarType) + if (t is GraphQLEnumType) + return 'ENUM'; + else if (t is GraphQLScalarType) return 'SCALAR'; else if (t is GraphQLObjectType) return t.isInterface ? 'INTERFACE' : 'OBJECT'; @@ -215,8 +217,6 @@ GraphQLObjectType _createTypeType() { return 'LIST'; else if (t is GraphQLNonNullableType) return 'NON_NULL'; - else if (t is GraphQLEnumType) - return 'ENUM'; else if (t is GraphQLUnionType) return 'UNION'; else @@ -376,32 +376,31 @@ GraphQLObjectType _reflectDirectiveType() { GraphQLObjectType _enumValueType; GraphQLObjectType _reflectEnumValueType() { - 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, - ), - ], - ); + 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 fetchAllTypes(