diff --git a/example_star_wars/bin/server.dart b/example_star_wars/bin/server.dart index 10ebbaa6..5104ac5a 100644 --- a/example_star_wars/bin/server.dart +++ b/example_star_wars/bin/server.dart @@ -10,13 +10,13 @@ import 'package:star_wars/star_wars.dart' as star_wars; main() async { Future createServer() async { var app = new Angel(); - app.logger = new Logger('star_wars')..onRecord.listen(star_wars.prettyLog); + hierarchicalLoggingEnabled = true; + app.logger = new Logger.detached('star_wars') + ..onRecord.listen(star_wars.prettyLog); await app.configure(star_wars.configureServer); return app; } - hierarchicalLoggingEnabled = true; - var hot = new HotReloader(createServer, [new Directory('lib')]); var server = await hot.startServer('127.0.0.1', 3000); diff --git a/example_star_wars/lib/src/models/character.dart b/example_star_wars/lib/src/models/character.dart index 2e040a66..eacf9adc 100644 --- a/example_star_wars/lib/src/models/character.dart +++ b/example_star_wars/lib/src/models/character.dart @@ -1,7 +1,7 @@ import 'package:angel_model/angel_model.dart'; import 'episode.dart'; -abstract class Character extends Model { +abstract class Character { String get id; String get name; diff --git a/example_star_wars/lib/src/models/droid.g.dart b/example_star_wars/lib/src/models/droid.g.dart index 98b94c5e..bbb4c3c2 100644 --- a/example_star_wars/lib/src/models/droid.g.dart +++ b/example_star_wars/lib/src/models/droid.g.dart @@ -87,9 +87,7 @@ abstract class DroidSerializer { ? (map['appears_in'] as Iterable).cast().toList() : null, friends: map['friends'] is Iterable - ? new List.unmodifiable(((map['friends'] as Iterable) - .where((x) => x is Map) as Iterable) - .map(CharacterSerializer.fromMap)) + ? (map['friends'] as Iterable).cast().toList() : null, createdAt: map['created_at'] != null ? (map['created_at'] is DateTime @@ -111,8 +109,7 @@ abstract class DroidSerializer { 'id': model.id, 'name': model.name, 'appears_in': model.appearsIn, - 'friends': - model.friends?.map((m) => CharacterSerializer.toMap(m))?.toList(), + 'friends': model.friends, 'created_at': model.createdAt?.toIso8601String(), 'updated_at': model.updatedAt?.toIso8601String() }; @@ -120,7 +117,7 @@ abstract class DroidSerializer { } abstract class DroidFields { - static const List allFields = const [ + static const List allFields = [ id, name, appearsIn, diff --git a/example_star_wars/lib/src/models/human.g.dart b/example_star_wars/lib/src/models/human.g.dart index 0bc3a385..be920de6 100644 --- a/example_star_wars/lib/src/models/human.g.dart +++ b/example_star_wars/lib/src/models/human.g.dart @@ -14,7 +14,7 @@ class Human extends _Human { List appearsIn, List friends, this.totalCredits, - List starships, + List starships, this.createdAt, this.updatedAt}) : this.appearsIn = new List.unmodifiable(appearsIn ?? []), @@ -37,7 +37,7 @@ class Human extends _Human { final int totalCredits; @override - final List starships; + final List starships; @override final DateTime createdAt; @@ -51,7 +51,7 @@ class Human extends _Human { List appearsIn, List friends, int totalCredits, - List starships, + List starships, DateTime createdAt, DateTime updatedAt}) { return new Human( @@ -74,7 +74,7 @@ class Human extends _Human { const ListEquality(const DefaultEquality()) .equals(other.friends, friends) && other.totalCredits == totalCredits && - const ListEquality(const DefaultEquality()) + const ListEquality(const DefaultEquality()) .equals(other.starships, starships) && other.createdAt == createdAt && other.updatedAt == updatedAt; @@ -116,9 +116,7 @@ abstract class HumanSerializer { : null, totalCredits: map['total_credits'] as int, starships: map['starships'] is Iterable - ? new List.unmodifiable(((map['starships'] as Iterable) - .where((x) => x is Map) as Iterable) - .map(StarshipSerializer.fromMap)) + ? (map['starships'] as Iterable).cast().toList() : null, createdAt: map['created_at'] != null ? (map['created_at'] is DateTime @@ -142,8 +140,7 @@ abstract class HumanSerializer { 'appears_in': model.appearsIn, 'friends': model.friends, 'total_credits': model.totalCredits, - 'starships': - model.starships?.map((m) => StarshipSerializer.toMap(m))?.toList(), + 'starships': model.starships, 'created_at': model.createdAt?.toIso8601String(), 'updated_at': model.updatedAt?.toIso8601String() }; @@ -151,7 +148,7 @@ abstract class HumanSerializer { } abstract class HumanFields { - static const List allFields = const [ + static const List allFields = [ id, name, appearsIn, diff --git a/example_star_wars/lib/src/models/starship.g.dart b/example_star_wars/lib/src/models/starship.g.dart index 79525410..7fc60049 100644 --- a/example_star_wars/lib/src/models/starship.g.dart +++ b/example_star_wars/lib/src/models/starship.g.dart @@ -95,7 +95,7 @@ abstract class StarshipSerializer { } abstract class StarshipFields { - static const List allFields = const [ + static const List allFields = [ id, name, length, diff --git a/example_star_wars/lib/star_wars.dart b/example_star_wars/lib/star_wars.dart index 2683a8e2..ba1f7a98 100644 --- a/example_star_wars/lib/star_wars.dart +++ b/example_star_wars/lib/star_wars.dart @@ -1,8 +1,8 @@ import 'dart:async'; import 'dart:math'; - import 'package:angel_framework/angel_framework.dart'; import 'package:angel_graphql/angel_graphql.dart'; +import 'package:angel_typed_service/angel_typed_service.dart'; import 'package:graphql_schema/graphql_schema.dart'; import 'package:graphql_server/graphql_server.dart'; import 'package:graphql_server/mirrors.dart'; @@ -15,7 +15,7 @@ Future configureServer(Angel app) async { var droidService = mountService(app, '/api/droids'); var humansService = mountService(app, '/api/humans'); var starshipService = mountService(app, '/api/starships'); - var rnd = new Random(); + var rnd = Random(); // Create the GraphQL schema. // This code uses dart:mirrors to easily create GraphQL types from Dart PODO's. @@ -25,7 +25,7 @@ Future configureServer(Angel app) async { var starshipType = convertDartType(Starship); // A Hero can be either a Droid or Human; create a union type that represents this. - var heroType = new GraphQLUnionType('Hero', [droidType, humanType]); + var heroType = GraphQLUnionType('Hero', [droidType, humanType]); // Create the query type. // @@ -59,7 +59,7 @@ Future configureServer(Angel app) async { description: 'Finds a random hero within the known galaxy, whether a Droid or Human.', inputs: [ - new GraphQLFieldInput('ep', episodeType), + GraphQLFieldInput('ep', episodeType), ], resolve: randomHeroResolver(droidService, humansService, rnd), ), @@ -80,8 +80,8 @@ Future configureServer(Angel app) async { humanType.nonNullable(), description: 'Modifies a human in the database.', inputs: [ - new GraphQLFieldInput('id', graphQLId.nonNullable()), - new GraphQLFieldInput('data', humanChangesType.nonNullable()), + GraphQLFieldInput('id', graphQLId.nonNullable()), + GraphQLFieldInput('data', humanChangesType.nonNullable()), ], resolve: resolveViaServiceModify(humansService), ), @@ -96,7 +96,7 @@ Future configureServer(Angel app) async { // Next, create a GraphQL object, which will be passed to `graphQLHttp`, and // used to mount a spec-compliant GraphQL endpoint on the server. - var graphQL = new GraphQL(schema); + var graphQL = GraphQL(schema); // Mount the GraphQL endpoint. app.all('/graphql', graphQLHttp(graphQL)); @@ -135,12 +135,16 @@ Future configureServer(Angel app) async { }); } +Service mountService( + Angel app, String path) => + app.use(path, TypedService(MapService())); + GraphQLFieldResolver randomHeroResolver( Service droidService, Service humansService, Random rnd) { return (_, args) async { var allHeroes = []; - var allDroids = await droidService.index() as Iterable; - var allHumans = await humansService.index() as Iterable; + var allDroids = await droidService.index(); + var allHumans = await humansService.index(); allHeroes..addAll(allDroids)..addAll(allHumans); // Ignore the annoying cast here, hopefully Dart 2 fixes cases like this @@ -152,4 +156,4 @@ GraphQLFieldResolver randomHeroResolver( return allHeroes.isEmpty ? null : allHeroes[rnd.nextInt(allHeroes.length)]; }; -} \ No newline at end of file +} diff --git a/example_star_wars/pubspec.yaml b/example_star_wars/pubspec.yaml index 401692c5..74d2664c 100644 --- a/example_star_wars/pubspec.yaml +++ b/example_star_wars/pubspec.yaml @@ -6,7 +6,17 @@ dependencies: path: ../angel_graphql angel_hot: ^2.0.0-alpha angel_serialize: ^2.0.0 + angel_typed_service: ^1.0.0 io: ^0.3.2 dev_dependencies: angel_serialize_generator: ^2.0.0 - build_runner: ^1.0.0 \ No newline at end of file + build_runner: ^1.0.0 + graphql_generator: + path: ../graphql_generator +dependency_overrides: + graphql_parser: + path: ../graphql_parser + graphql_schema: + path: ../graphql_schema + graphql_server: + path: ../graphql_server \ No newline at end of file