schema@1.0.4

This commit is contained in:
Tobe O 2019-04-11 13:05:47 -04:00
parent 668772353d
commit 8f98e801ab
6 changed files with 25 additions and 7 deletions

View file

@ -9,19 +9,19 @@ import 'package:star_wars/star_wars.dart' as star_wars;
main() async { main() async {
Future<Angel> createServer() async { Future<Angel> createServer() async {
var app = new Angel();
hierarchicalLoggingEnabled = true; hierarchicalLoggingEnabled = true;
app.logger = new Logger.detached('star_wars') var logger = Logger.detached('star_wars')
..onRecord.listen(star_wars.prettyLog); ..onRecord.listen(star_wars.prettyLog);
var app = Angel(logger: logger);
await app.configure(star_wars.configureServer); await app.configure(star_wars.configureServer);
return app; 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 server = await hot.startServer('127.0.0.1', 3000);
var serverUrl = 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'); var graphiQLUrl = serverUrl.replace(path: '/graphiql');
print('Listening at $serverUrl'); print('Listening at $serverUrl');
print('GraphiQL endpoint: $graphiQLUrl'); print('GraphiQL endpoint: $graphiQLUrl');

View file

@ -1,3 +1,6 @@
# 1.0.4
* Add `convert` method to types, to avoid some annoying generics bugs.
# 1.0.3 # 1.0.3
* `enumTypeFromStrings` now returns `GraphQLEnumType<String>`. * `enumTypeFromStrings` now returns `GraphQLEnumType<String>`.

View file

@ -99,7 +99,7 @@ class GraphQLObjectType
'Unexpected field "$k" encountered in $key. Accepted values on type $name: ${fields.map((f) => f.name).toList()}'); 'Unexpected field "$k" encountered in $key. Accepted values on type $name: ${fields.map((f) => f.name).toList()}');
} else { } else {
var v = input[k]; 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) { if (!result.successful) {
errors.addAll(result.errors.map((s) => '$key: $s')); errors.addAll(result.errors.map((s) => '$key: $s'));

View file

@ -19,6 +19,9 @@ abstract class GraphQLType<Value, Serialized> {
/// Deserializes a serialized value. /// Deserializes a serialized value.
Value deserialize(Serialized serialized); 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. /// Performs type coercion against an [input] value, and returns a list of errors if the validation was unsuccessful.
ValidationResult<Serialized> validate(String key, Serialized input); ValidationResult<Serialized> validate(String key, Serialized input);
@ -45,6 +48,15 @@ class GraphQLListType<Value, Serialized>
GraphQLListType(this.ofType); GraphQLListType(this.ofType);
@override
List<Serialized> convert(value) {
if (value is Iterable) {
return value.cast<Serialized>().toList();
} else {
return super.convert(value);
}
}
@override @override
String get name => null; String get name => null;

View file

@ -1,5 +1,5 @@
name: graphql_schema 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. description: An implementation of GraphQL's type system in Dart. Basis of graphql_server.
author: Tobe O <thosakwe@gmail.com> author: Tobe O <thosakwe@gmail.com>
homepage: https://github.com/angel-dart/graphql homepage: https://github.com/angel-dart/graphql

View file

@ -571,6 +571,7 @@ class GraphQL {
var errors = <GraphQLExceptionError>[]; var errors = <GraphQLExceptionError>[];
print(possibleTypes);
for (var t in possibleTypes) { for (var t in possibleTypes) {
try { try {
var validation = var validation =
@ -582,7 +583,9 @@ class GraphQL {
errors errors
.addAll(validation.errors.map((m) => new GraphQLExceptionError(m))); .addAll(validation.errors.map((m) => new GraphQLExceptionError(m)));
} catch (_) {} } on GraphQLException catch (e) {
errors.addAll(e.errors);
}
} }
errors.insert( errors.insert(