schema@1.0.4
This commit is contained in:
parent
668772353d
commit
8f98e801ab
6 changed files with 25 additions and 7 deletions
|
@ -9,19 +9,19 @@ import 'package:star_wars/star_wars.dart' as star_wars;
|
|||
|
||||
main() async {
|
||||
Future<Angel> 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');
|
||||
|
|
|
@ -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<String>`.
|
||||
|
||||
|
|
|
@ -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'));
|
||||
|
|
|
@ -19,6 +19,9 @@ abstract class GraphQLType<Value, Serialized> {
|
|||
/// 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<Serialized> validate(String key, Serialized input);
|
||||
|
||||
|
@ -45,6 +48,15 @@ class GraphQLListType<Value, Serialized>
|
|||
|
||||
GraphQLListType(this.ofType);
|
||||
|
||||
@override
|
||||
List<Serialized> convert(value) {
|
||||
if (value is Iterable) {
|
||||
return value.cast<Serialized>().toList();
|
||||
} else {
|
||||
return super.convert(value);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
String get name => null;
|
||||
|
||||
|
|
|
@ -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 <thosakwe@gmail.com>
|
||||
homepage: https://github.com/angel-dart/graphql
|
||||
|
|
|
@ -571,6 +571,7 @@ class GraphQL {
|
|||
|
||||
var errors = <GraphQLExceptionError>[];
|
||||
|
||||
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(
|
||||
|
|
Loading…
Reference in a new issue