From 8f98e801abff368e721c4c3538bea224480c545d Mon Sep 17 00:00:00 2001 From: Tobe O Date: Thu, 11 Apr 2019 13:05:47 -0400 Subject: [PATCH] schema@1.0.4 --- example_star_wars/bin/server.dart | 8 ++++---- graphql_schema/CHANGELOG.md | 3 +++ graphql_schema/lib/src/object_type.dart | 2 +- graphql_schema/lib/src/type.dart | 12 ++++++++++++ graphql_schema/pubspec.yaml | 2 +- graphql_server/lib/graphql_server.dart | 5 ++++- 6 files changed, 25 insertions(+), 7 deletions(-) diff --git a/example_star_wars/bin/server.dart b/example_star_wars/bin/server.dart index 5104ac5a..5e7e0e91 100644 --- a/example_star_wars/bin/server.dart +++ b/example_star_wars/bin/server.dart @@ -9,19 +9,19 @@ import 'package:star_wars/star_wars.dart' as star_wars; main() async { Future createServer() async { - var app = new Angel(); hierarchicalLoggingEnabled = true; - app.logger = new Logger.detached('star_wars') + var logger = Logger.detached('star_wars') ..onRecord.listen(star_wars.prettyLog); + var app = Angel(logger: logger); await app.configure(star_wars.configureServer); return app; } - var hot = new HotReloader(createServer, [new Directory('lib')]); + var hot = HotReloader(createServer, [Directory('lib')]); var server = await hot.startServer('127.0.0.1', 3000); var serverUrl = - new Uri(scheme: 'http', host: server.address.address, port: server.port); + Uri(scheme: 'http', host: server.address.address, port: server.port); var graphiQLUrl = serverUrl.replace(path: '/graphiql'); print('Listening at $serverUrl'); print('GraphiQL endpoint: $graphiQLUrl'); diff --git a/graphql_schema/CHANGELOG.md b/graphql_schema/CHANGELOG.md index fc51fd64..ee521008 100644 --- a/graphql_schema/CHANGELOG.md +++ b/graphql_schema/CHANGELOG.md @@ -1,3 +1,6 @@ +# 1.0.4 +* Add `convert` method to types, to avoid some annoying generics bugs. + # 1.0.3 * `enumTypeFromStrings` now returns `GraphQLEnumType`. diff --git a/graphql_schema/lib/src/object_type.dart b/graphql_schema/lib/src/object_type.dart index 05ab99ee..2447aed5 100644 --- a/graphql_schema/lib/src/object_type.dart +++ b/graphql_schema/lib/src/object_type.dart @@ -99,7 +99,7 @@ class GraphQLObjectType 'Unexpected field "$k" encountered in $key. Accepted values on type $name: ${fields.map((f) => f.name).toList()}'); } else { var v = input[k]; - var result = field.type.validate(k.toString(), v); + var result = field.type.validate(k.toString(), field.type.convert(v)); if (!result.successful) { errors.addAll(result.errors.map((s) => '$key: $s')); diff --git a/graphql_schema/lib/src/type.dart b/graphql_schema/lib/src/type.dart index f9d91289..a5c3034e 100644 --- a/graphql_schema/lib/src/type.dart +++ b/graphql_schema/lib/src/type.dart @@ -19,6 +19,9 @@ abstract class GraphQLType { /// Deserializes a serialized value. Value deserialize(Serialized serialized); + /// Attempts to cast a dynamic [value] into a [Serialized] instance. + Serialized convert(value) => value as Serialized; + /// Performs type coercion against an [input] value, and returns a list of errors if the validation was unsuccessful. ValidationResult validate(String key, Serialized input); @@ -45,6 +48,15 @@ class GraphQLListType GraphQLListType(this.ofType); + @override + List convert(value) { + if (value is Iterable) { + return value.cast().toList(); + } else { + return super.convert(value); + } + } + @override String get name => null; diff --git a/graphql_schema/pubspec.yaml b/graphql_schema/pubspec.yaml index 0f3e4a43..1319dc86 100644 --- a/graphql_schema/pubspec.yaml +++ b/graphql_schema/pubspec.yaml @@ -1,5 +1,5 @@ name: graphql_schema -version: 1.0.3 +version: 1.0.4 description: An implementation of GraphQL's type system in Dart. Basis of graphql_server. author: Tobe O homepage: https://github.com/angel-dart/graphql diff --git a/graphql_server/lib/graphql_server.dart b/graphql_server/lib/graphql_server.dart index 8c9240c3..737ab34c 100644 --- a/graphql_server/lib/graphql_server.dart +++ b/graphql_server/lib/graphql_server.dart @@ -571,6 +571,7 @@ class GraphQL { var errors = []; + print(possibleTypes); for (var t in possibleTypes) { try { var validation = @@ -582,7 +583,9 @@ class GraphQL { errors .addAll(validation.errors.map((m) => new GraphQLExceptionError(m))); - } catch (_) {} + } on GraphQLException catch (e) { + errors.addAll(e.errors); + } } errors.insert(