mono_repo
This commit is contained in:
parent
f357fc52ef
commit
ff2aa03784
17 changed files with 505 additions and 42 deletions
|
@ -27,7 +27,7 @@ RequestHandler graphQLHttp(GraphQL graphQL) {
|
|||
};
|
||||
|
||||
executeMap(Map map) async {
|
||||
var body = await req.parseBody();
|
||||
var body = await req.parseBody().then((_) => req.bodyAsMap);
|
||||
var text = body['query'] as String;
|
||||
var operationName = body['operation_name'] as String;
|
||||
var variables = body['variables'];
|
||||
|
@ -50,11 +50,11 @@ RequestHandler graphQLHttp(GraphQL graphQL) {
|
|||
try {
|
||||
if (req.method == 'GET') {
|
||||
if (await validateQuery(graphQlPostBody)(req, res) as bool) {
|
||||
return await executeMap(await req.parseQuery());
|
||||
return await executeMap(req.queryParameters);
|
||||
}
|
||||
} else if (req.method == 'POST') {
|
||||
if (req.headers.contentType?.mimeType == graphQlContentType.mimeType) {
|
||||
var text = utf8.decode(await req.parseRawRequestBuffer());
|
||||
var text = await req.body.transform(utf8.decoder).join();
|
||||
return {
|
||||
'data': await graphQL.parseAndExecute(
|
||||
text,
|
||||
|
@ -64,7 +64,7 @@ RequestHandler graphQLHttp(GraphQL graphQL) {
|
|||
};
|
||||
} else if (req.headers.contentType?.mimeType == 'application/json') {
|
||||
if (await validate(graphQlPostBody)(req, res) as bool) {
|
||||
return await executeMap(await req.parseBody());
|
||||
return await executeMap(req.bodyAsMap);
|
||||
}
|
||||
} else {
|
||||
throw new AngelHttpException.badRequest();
|
||||
|
|
0
angel_graphql/mono_pkg.yaml
Normal file
0
angel_graphql/mono_pkg.yaml
Normal file
|
@ -9,9 +9,7 @@ import 'package:star_wars/star_wars.dart' as star_wars;
|
|||
|
||||
main() async {
|
||||
Future<Angel> createServer() async {
|
||||
var app = new Angel()
|
||||
..lazyParseBodies = true
|
||||
..storeOriginalBuffer = true;
|
||||
var app = new Angel();
|
||||
app.logger = new Logger('star_wars')..onRecord.listen(star_wars.prettyLog);
|
||||
await app.configure(star_wars.configureServer);
|
||||
return app;
|
||||
|
|
11
example_star_wars/build.yaml
Normal file
11
example_star_wars/build.yaml
Normal file
|
@ -0,0 +1,11 @@
|
|||
targets:
|
||||
_standalone:
|
||||
sources:
|
||||
- lib/src/models/character.dart
|
||||
- lib/src/models/droid.dart
|
||||
- lib/src/models/starship.dart
|
||||
$default:
|
||||
dependencies:
|
||||
- ":_standalone"
|
||||
sources:
|
||||
- lib/src/models/human.dart
|
|
@ -1,9 +1,7 @@
|
|||
import 'package:angel_serialize/angel_serialize.dart';
|
||||
|
||||
import 'package:angel_model/angel_model.dart';
|
||||
import 'episode.dart';
|
||||
|
||||
@serializable
|
||||
abstract class Character {
|
||||
abstract class _Character extends Model {
|
||||
String get id;
|
||||
|
||||
String get name;
|
||||
|
|
|
@ -1,15 +1,17 @@
|
|||
import 'package:angel_model/angel_model.dart';
|
||||
import 'package:angel_serialize/angel_serialize.dart';
|
||||
|
||||
import 'package:collection/collection.dart';
|
||||
import 'character.dart';
|
||||
import 'episode.dart';
|
||||
part 'droid.g.dart';
|
||||
|
||||
@serializable
|
||||
class Droid extends Model implements Character {
|
||||
String name;
|
||||
List<Character> friends;
|
||||
List<Episode> appearsIn;
|
||||
String primaryFunction;
|
||||
abstract class _Droid extends Model implements Character {
|
||||
String get id;
|
||||
|
||||
Droid({this.name, this.friends, this.appearsIn, this.primaryFunction});
|
||||
String get name;
|
||||
|
||||
List<Episode> get appearsIn;
|
||||
|
||||
List<Character> get friends;
|
||||
}
|
||||
|
|
143
example_star_wars/lib/src/models/droid.g.dart
Normal file
143
example_star_wars/lib/src/models/droid.g.dart
Normal file
|
@ -0,0 +1,143 @@
|
|||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'droid.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonModelGenerator
|
||||
// **************************************************************************
|
||||
|
||||
@generatedSerializable
|
||||
class Droid extends _Droid {
|
||||
Droid(
|
||||
{this.id,
|
||||
this.name,
|
||||
List<dynamic> appearsIn,
|
||||
List<Character> friends,
|
||||
this.createdAt,
|
||||
this.updatedAt})
|
||||
: this.appearsIn = new List.unmodifiable(appearsIn ?? []),
|
||||
this.friends = new List.unmodifiable(friends ?? []);
|
||||
|
||||
@override
|
||||
final String id;
|
||||
|
||||
@override
|
||||
final String name;
|
||||
|
||||
@override
|
||||
final List<dynamic> appearsIn;
|
||||
|
||||
@override
|
||||
final List<Character> friends;
|
||||
|
||||
@override
|
||||
final DateTime createdAt;
|
||||
|
||||
@override
|
||||
final DateTime updatedAt;
|
||||
|
||||
Droid copyWith(
|
||||
{String id,
|
||||
String name,
|
||||
List<dynamic> appearsIn,
|
||||
List<Character> friends,
|
||||
DateTime createdAt,
|
||||
DateTime updatedAt}) {
|
||||
return new Droid(
|
||||
id: id ?? this.id,
|
||||
name: name ?? this.name,
|
||||
appearsIn: appearsIn ?? this.appearsIn,
|
||||
friends: friends ?? this.friends,
|
||||
createdAt: createdAt ?? this.createdAt,
|
||||
updatedAt: updatedAt ?? this.updatedAt);
|
||||
}
|
||||
|
||||
bool operator ==(other) {
|
||||
return other is _Droid &&
|
||||
other.id == id &&
|
||||
other.name == name &&
|
||||
const ListEquality<dynamic>(const DefaultEquality())
|
||||
.equals(other.appearsIn, appearsIn) &&
|
||||
const ListEquality<Character>(const DefaultEquality<Character>())
|
||||
.equals(other.friends, friends) &&
|
||||
other.createdAt == createdAt &&
|
||||
other.updatedAt == updatedAt;
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
return hashObjects([id, name, appearsIn, friends, createdAt, updatedAt]);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return DroidSerializer.toMap(this);
|
||||
}
|
||||
}
|
||||
|
||||
// **************************************************************************
|
||||
// SerializerGenerator
|
||||
// **************************************************************************
|
||||
|
||||
abstract class DroidSerializer {
|
||||
static Droid fromMap(Map map) {
|
||||
return new Droid(
|
||||
id: map['id'] as String,
|
||||
name: map['name'] as String,
|
||||
appearsIn: map['appears_in'] is Iterable
|
||||
? (map['appears_in'] as Iterable).cast<dynamic>().toList()
|
||||
: null,
|
||||
friends: map['friends'] is Iterable
|
||||
? new List.unmodifiable(((map['friends'] as Iterable)
|
||||
.where((x) => x is Map) as Iterable<Map>)
|
||||
.map(CharacterSerializer.fromMap))
|
||||
: null,
|
||||
createdAt: map['created_at'] != null
|
||||
? (map['created_at'] is DateTime
|
||||
? (map['created_at'] as DateTime)
|
||||
: DateTime.parse(map['created_at'].toString()))
|
||||
: null,
|
||||
updatedAt: map['updated_at'] != null
|
||||
? (map['updated_at'] is DateTime
|
||||
? (map['updated_at'] as DateTime)
|
||||
: DateTime.parse(map['updated_at'].toString()))
|
||||
: null);
|
||||
}
|
||||
|
||||
static Map<String, dynamic> toMap(_Droid model) {
|
||||
if (model == null) {
|
||||
return null;
|
||||
}
|
||||
return {
|
||||
'id': model.id,
|
||||
'name': model.name,
|
||||
'appears_in': model.appearsIn,
|
||||
'friends':
|
||||
model.friends?.map((m) => CharacterSerializer.toMap(m))?.toList(),
|
||||
'created_at': model.createdAt?.toIso8601String(),
|
||||
'updated_at': model.updatedAt?.toIso8601String()
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
abstract class DroidFields {
|
||||
static const List<String> allFields = const <String>[
|
||||
id,
|
||||
name,
|
||||
appearsIn,
|
||||
friends,
|
||||
createdAt,
|
||||
updatedAt
|
||||
];
|
||||
|
||||
static const String id = 'id';
|
||||
|
||||
static const String name = 'name';
|
||||
|
||||
static const String appearsIn = 'appears_in';
|
||||
|
||||
static const String friends = 'friends';
|
||||
|
||||
static const String createdAt = 'created_at';
|
||||
|
||||
static const String updatedAt = 'updated_at';
|
||||
}
|
|
@ -1,24 +1,37 @@
|
|||
import 'package:angel_model/angel_model.dart';
|
||||
import 'package:angel_serialize/angel_serialize.dart';
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:graphql_schema/graphql_schema.dart';
|
||||
|
||||
import 'character.dart';
|
||||
import 'episode.dart';
|
||||
import 'starship.dart';
|
||||
part 'human.g.dart';
|
||||
|
||||
@serializable
|
||||
class Human extends Model implements Character {
|
||||
@GraphQLDocumentation(description: "This human's name, of course.")
|
||||
String name;
|
||||
List<Character> friends;
|
||||
List<Episode> appearsIn;
|
||||
List<Starship> starships;
|
||||
int totalCredits;
|
||||
abstract class _Human extends Model implements Character {
|
||||
// @GraphQLDocumentation(description: "This human's name, of course.")
|
||||
// String name;
|
||||
// List<Character> friends;
|
||||
// List<Episode> appearsIn;
|
||||
// List<Starship> starships;
|
||||
// int totalCredits;
|
||||
|
||||
Human(
|
||||
{this.name,
|
||||
this.friends,
|
||||
this.appearsIn,
|
||||
this.starships,
|
||||
this.totalCredits});
|
||||
String get id;
|
||||
|
||||
String get name;
|
||||
|
||||
List<Episode> get appearsIn;
|
||||
|
||||
List<Character> get friends;
|
||||
|
||||
int get totalCredits;
|
||||
|
||||
List<Starship> get starships;
|
||||
|
||||
// Human(
|
||||
// {this.name,
|
||||
// this.friends,
|
||||
// this.appearsIn,
|
||||
// this.starships,
|
||||
// this.totalCredits});
|
||||
}
|
||||
|
|
180
example_star_wars/lib/src/models/human.g.dart
Normal file
180
example_star_wars/lib/src/models/human.g.dart
Normal file
|
@ -0,0 +1,180 @@
|
|||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'human.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonModelGenerator
|
||||
// **************************************************************************
|
||||
|
||||
@generatedSerializable
|
||||
class Human extends _Human {
|
||||
Human(
|
||||
{this.id,
|
||||
this.name,
|
||||
List<dynamic> appearsIn,
|
||||
List<Character> friends,
|
||||
this.totalCredits,
|
||||
List<Starship> starships,
|
||||
this.createdAt,
|
||||
this.updatedAt})
|
||||
: this.appearsIn = new List.unmodifiable(appearsIn ?? []),
|
||||
this.friends = new List.unmodifiable(friends ?? []),
|
||||
this.starships = new List.unmodifiable(starships ?? []);
|
||||
|
||||
@override
|
||||
final String id;
|
||||
|
||||
@override
|
||||
final String name;
|
||||
|
||||
@override
|
||||
final List<dynamic> appearsIn;
|
||||
|
||||
@override
|
||||
final List<Character> friends;
|
||||
|
||||
@override
|
||||
final int totalCredits;
|
||||
|
||||
@override
|
||||
final List<Starship> starships;
|
||||
|
||||
@override
|
||||
final DateTime createdAt;
|
||||
|
||||
@override
|
||||
final DateTime updatedAt;
|
||||
|
||||
Human copyWith(
|
||||
{String id,
|
||||
String name,
|
||||
List<dynamic> appearsIn,
|
||||
List<Character> friends,
|
||||
int totalCredits,
|
||||
List<Starship> starships,
|
||||
DateTime createdAt,
|
||||
DateTime updatedAt}) {
|
||||
return new Human(
|
||||
id: id ?? this.id,
|
||||
name: name ?? this.name,
|
||||
appearsIn: appearsIn ?? this.appearsIn,
|
||||
friends: friends ?? this.friends,
|
||||
totalCredits: totalCredits ?? this.totalCredits,
|
||||
starships: starships ?? this.starships,
|
||||
createdAt: createdAt ?? this.createdAt,
|
||||
updatedAt: updatedAt ?? this.updatedAt);
|
||||
}
|
||||
|
||||
bool operator ==(other) {
|
||||
return other is _Human &&
|
||||
other.id == id &&
|
||||
other.name == name &&
|
||||
const ListEquality<dynamic>(const DefaultEquality())
|
||||
.equals(other.appearsIn, appearsIn) &&
|
||||
const ListEquality<Character>(const DefaultEquality<Character>())
|
||||
.equals(other.friends, friends) &&
|
||||
other.totalCredits == totalCredits &&
|
||||
const ListEquality<Starship>(const DefaultEquality<Starship>())
|
||||
.equals(other.starships, starships) &&
|
||||
other.createdAt == createdAt &&
|
||||
other.updatedAt == updatedAt;
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
return hashObjects([
|
||||
id,
|
||||
name,
|
||||
appearsIn,
|
||||
friends,
|
||||
totalCredits,
|
||||
starships,
|
||||
createdAt,
|
||||
updatedAt
|
||||
]);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return HumanSerializer.toMap(this);
|
||||
}
|
||||
}
|
||||
|
||||
// **************************************************************************
|
||||
// SerializerGenerator
|
||||
// **************************************************************************
|
||||
|
||||
abstract class HumanSerializer {
|
||||
static Human fromMap(Map map) {
|
||||
return new Human(
|
||||
id: map['id'] as String,
|
||||
name: map['name'] as String,
|
||||
appearsIn: map['appears_in'] is Iterable
|
||||
? (map['appears_in'] as Iterable).cast<dynamic>().toList()
|
||||
: null,
|
||||
friends: map['friends'] is Iterable
|
||||
? (map['friends'] as Iterable).cast<Character>().toList()
|
||||
: 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>)
|
||||
.map(StarshipSerializer.fromMap))
|
||||
: null,
|
||||
createdAt: map['created_at'] != null
|
||||
? (map['created_at'] is DateTime
|
||||
? (map['created_at'] as DateTime)
|
||||
: DateTime.parse(map['created_at'].toString()))
|
||||
: null,
|
||||
updatedAt: map['updated_at'] != null
|
||||
? (map['updated_at'] is DateTime
|
||||
? (map['updated_at'] as DateTime)
|
||||
: DateTime.parse(map['updated_at'].toString()))
|
||||
: null);
|
||||
}
|
||||
|
||||
static Map<String, dynamic> toMap(_Human model) {
|
||||
if (model == null) {
|
||||
return null;
|
||||
}
|
||||
return {
|
||||
'id': model.id,
|
||||
'name': model.name,
|
||||
'appears_in': model.appearsIn,
|
||||
'friends': model.friends,
|
||||
'total_credits': model.totalCredits,
|
||||
'starships':
|
||||
model.starships?.map((m) => StarshipSerializer.toMap(m))?.toList(),
|
||||
'created_at': model.createdAt?.toIso8601String(),
|
||||
'updated_at': model.updatedAt?.toIso8601String()
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
abstract class HumanFields {
|
||||
static const List<String> allFields = const <String>[
|
||||
id,
|
||||
name,
|
||||
appearsIn,
|
||||
friends,
|
||||
totalCredits,
|
||||
starships,
|
||||
createdAt,
|
||||
updatedAt
|
||||
];
|
||||
|
||||
static const String id = 'id';
|
||||
|
||||
static const String name = 'name';
|
||||
|
||||
static const String appearsIn = 'appears_in';
|
||||
|
||||
static const String friends = 'friends';
|
||||
|
||||
static const String totalCredits = 'total_credits';
|
||||
|
||||
static const String starships = 'starships';
|
||||
|
||||
static const String createdAt = 'created_at';
|
||||
|
||||
static const String updatedAt = 'updated_at';
|
||||
}
|
|
@ -1,10 +1,9 @@
|
|||
import 'package:angel_model/angel_model.dart';
|
||||
import 'package:angel_serialize/angel_serialize.dart';
|
||||
part 'starship.g.dart';
|
||||
|
||||
@serializable
|
||||
class Starship extends Model {
|
||||
String name;
|
||||
int length;
|
||||
|
||||
Starship({this.name, this.length});
|
||||
abstract class _Starship extends Model {
|
||||
String get name;
|
||||
int get length;
|
||||
}
|
||||
|
|
115
example_star_wars/lib/src/models/starship.g.dart
Normal file
115
example_star_wars/lib/src/models/starship.g.dart
Normal file
|
@ -0,0 +1,115 @@
|
|||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'starship.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonModelGenerator
|
||||
// **************************************************************************
|
||||
|
||||
@generatedSerializable
|
||||
class Starship extends _Starship {
|
||||
Starship({this.id, this.name, this.length, this.createdAt, this.updatedAt});
|
||||
|
||||
@override
|
||||
final String id;
|
||||
|
||||
@override
|
||||
final String name;
|
||||
|
||||
@override
|
||||
final int length;
|
||||
|
||||
@override
|
||||
final DateTime createdAt;
|
||||
|
||||
@override
|
||||
final DateTime updatedAt;
|
||||
|
||||
Starship copyWith(
|
||||
{String id,
|
||||
String name,
|
||||
int length,
|
||||
DateTime createdAt,
|
||||
DateTime updatedAt}) {
|
||||
return new Starship(
|
||||
id: id ?? this.id,
|
||||
name: name ?? this.name,
|
||||
length: length ?? this.length,
|
||||
createdAt: createdAt ?? this.createdAt,
|
||||
updatedAt: updatedAt ?? this.updatedAt);
|
||||
}
|
||||
|
||||
bool operator ==(other) {
|
||||
return other is _Starship &&
|
||||
other.id == id &&
|
||||
other.name == name &&
|
||||
other.length == length &&
|
||||
other.createdAt == createdAt &&
|
||||
other.updatedAt == updatedAt;
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
return hashObjects([id, name, length, createdAt, updatedAt]);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return StarshipSerializer.toMap(this);
|
||||
}
|
||||
}
|
||||
|
||||
// **************************************************************************
|
||||
// SerializerGenerator
|
||||
// **************************************************************************
|
||||
|
||||
abstract class StarshipSerializer {
|
||||
static Starship fromMap(Map map) {
|
||||
return new Starship(
|
||||
id: map['id'] as String,
|
||||
name: map['name'] as String,
|
||||
length: map['length'] as int,
|
||||
createdAt: map['created_at'] != null
|
||||
? (map['created_at'] is DateTime
|
||||
? (map['created_at'] as DateTime)
|
||||
: DateTime.parse(map['created_at'].toString()))
|
||||
: null,
|
||||
updatedAt: map['updated_at'] != null
|
||||
? (map['updated_at'] is DateTime
|
||||
? (map['updated_at'] as DateTime)
|
||||
: DateTime.parse(map['updated_at'].toString()))
|
||||
: null);
|
||||
}
|
||||
|
||||
static Map<String, dynamic> toMap(_Starship model) {
|
||||
if (model == null) {
|
||||
return null;
|
||||
}
|
||||
return {
|
||||
'id': model.id,
|
||||
'name': model.name,
|
||||
'length': model.length,
|
||||
'created_at': model.createdAt?.toIso8601String(),
|
||||
'updated_at': model.updatedAt?.toIso8601String()
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
abstract class StarshipFields {
|
||||
static const List<String> allFields = const <String>[
|
||||
id,
|
||||
name,
|
||||
length,
|
||||
createdAt,
|
||||
updatedAt
|
||||
];
|
||||
|
||||
static const String id = 'id';
|
||||
|
||||
static const String name = 'name';
|
||||
|
||||
static const String length = 'length';
|
||||
|
||||
static const String createdAt = 'created_at';
|
||||
|
||||
static const String updatedAt = 'updated_at';
|
||||
}
|
0
example_star_wars/mono_pkg.yaml
Normal file
0
example_star_wars/mono_pkg.yaml
Normal file
|
@ -4,5 +4,9 @@ dependencies:
|
|||
#angel_file_service: ^1.0.0
|
||||
angel_graphql:
|
||||
path: ../angel_graphql
|
||||
angel_hot: ^1.0.0
|
||||
io: ^0.3.2
|
||||
angel_hot: ^2.0.0-alpha
|
||||
angel_serialize: ^2.0.0
|
||||
io: ^0.3.2
|
||||
dev_dependencies:
|
||||
angel_serialize_generator: ^2.0.0
|
||||
build_runner: ^1.0.0
|
0
graphql_parser/mono_pkg.yaml
Normal file
0
graphql_parser/mono_pkg.yaml
Normal file
0
graphql_schema/mono_pkg.yaml
Normal file
0
graphql_schema/mono_pkg.yaml
Normal file
|
@ -315,12 +315,12 @@ bool _autoNames(ClassMirror clazz) {
|
|||
String _getDeprecationReason(List<InstanceMirror> metadata) {
|
||||
for (var obj in metadata) {
|
||||
if (obj.reflectee is Deprecated) {
|
||||
var expires = (obj.reflectee as Deprecated).expires;
|
||||
var expires = (obj.reflectee as Deprecated).message;
|
||||
|
||||
if (expires == deprecated.expires) {
|
||||
if (expires == deprecated.message) {
|
||||
return 'Expires after $expires';
|
||||
} else {
|
||||
return deprecated.expires;
|
||||
return deprecated.message;
|
||||
}
|
||||
} else if (obj.reflectee is GraphQLDocumentation) {
|
||||
return (obj.reflectee as GraphQLDocumentation).deprecationReason;
|
||||
|
|
0
graphql_server/mono_pkg.yaml
Normal file
0
graphql_server/mono_pkg.yaml
Normal file
Loading…
Reference in a new issue