Update angel_graphql example
This commit is contained in:
parent
d9c2481410
commit
4ff1a5dca9
2 changed files with 22 additions and 19 deletions
|
@ -8,17 +8,17 @@ import 'package:graphql_server/mirrors.dart';
|
|||
import 'package:logging/logging.dart';
|
||||
|
||||
main() async {
|
||||
var app = new Angel();
|
||||
var http = new AngelHttp(app);
|
||||
hierarchicalLoggingEnabled = true;
|
||||
app.logger = new Logger('angel_graphql')
|
||||
var logger = Logger('angel_graphql');
|
||||
var app = Angel(
|
||||
logger: logger
|
||||
..onRecord.listen((rec) {
|
||||
print(rec);
|
||||
if (rec.error != null) print(rec.error);
|
||||
if (rec.stackTrace != null) print(rec.stackTrace);
|
||||
});
|
||||
}));
|
||||
var http = AngelHttp(app);
|
||||
|
||||
var todoService = app.use('api/todos', new MapService());
|
||||
var todoService = app.use('api/todos', MapService());
|
||||
|
||||
var queryType = objectType(
|
||||
'Query',
|
||||
|
@ -34,7 +34,7 @@ main() async {
|
|||
convertDartType(Todo),
|
||||
resolve: resolveViaServiceRead(todoService),
|
||||
inputs: [
|
||||
new GraphQLFieldInput('id', graphQLId.nonNullable()),
|
||||
GraphQLFieldInput('id', graphQLId.nonNullable()),
|
||||
],
|
||||
),
|
||||
],
|
||||
|
@ -56,7 +56,7 @@ main() async {
|
|||
mutationType: mutationType,
|
||||
);
|
||||
|
||||
app.all('/graphql', graphQLHttp(new GraphQL(schema)));
|
||||
app.all('/graphql', graphQLHttp(GraphQL(schema)));
|
||||
app.get('/graphiql', graphiQL());
|
||||
|
||||
await todoService
|
||||
|
@ -70,7 +70,7 @@ main() async {
|
|||
|
||||
var server = await http.startServer('127.0.0.1', 3000);
|
||||
var uri =
|
||||
new Uri(scheme: 'http', host: server.address.address, port: server.port);
|
||||
Uri(scheme: 'http', host: server.address.address, port: server.port);
|
||||
var graphiqlUri = uri.replace(path: 'graphiql');
|
||||
print('Listening at $uri');
|
||||
print('Access graphiql at $graphiqlUri');
|
||||
|
|
|
@ -241,8 +241,8 @@ class GraphQL {
|
|||
'The grouped field set from this query must have exactly one entry.',
|
||||
selectionSet.span);
|
||||
var fields = groupedFieldSet.entries.first.value;
|
||||
// TODO: This value is unaffected if an alias is used. (is this true?)
|
||||
var fieldName = fields.first.field.fieldName.name;
|
||||
var fieldName = fields.first.field.fieldName.alias?.name ??
|
||||
fields.first.field.fieldName.name;
|
||||
var field = fields.first;
|
||||
var argumentValues =
|
||||
coerceArgumentValues(subscriptionType, field, variableValues);
|
||||
|
@ -321,7 +321,8 @@ class GraphQL {
|
|||
var fields = groupedFieldSet[responseKey];
|
||||
|
||||
for (var field in fields) {
|
||||
var fieldName = field.field.fieldName.name;
|
||||
var fieldName =
|
||||
field.field.fieldName.alias?.name ?? field.field.fieldName.name;
|
||||
var responseValue;
|
||||
|
||||
if (fieldName == '__typename') {
|
||||
|
@ -364,7 +365,7 @@ class GraphQL {
|
|||
var argumentValues =
|
||||
coerceArgumentValues(objectType, field, variableValues);
|
||||
var resolvedValue = await resolveFieldValue(
|
||||
objectType, objectValue, field.field.fieldName.name, argumentValues);
|
||||
objectType, objectValue, fieldName, argumentValues);
|
||||
return completeValue(document, fieldName, fieldType, fields, resolvedValue,
|
||||
variableValues, globalVariables);
|
||||
}
|
||||
|
@ -373,7 +374,8 @@ class GraphQL {
|
|||
SelectionContext field, Map<String, dynamic> variableValues) {
|
||||
var coercedValues = <String, dynamic>{};
|
||||
var argumentValues = field.field.arguments;
|
||||
var fieldName = field.field.fieldName.name;
|
||||
var fieldName =
|
||||
field.field.fieldName.alias?.name ?? field.field.fieldName.name;
|
||||
var desiredField = objectType.fields.firstWhere((f) => f.name == fieldName);
|
||||
var argumentDefinitions = desiredField.inputs;
|
||||
|
||||
|
@ -621,7 +623,8 @@ class GraphQL {
|
|||
false) continue;
|
||||
|
||||
if (selection.field != null) {
|
||||
var responseKey = selection.field.fieldName.name;
|
||||
var responseKey = selection.field.fieldName.alias?.alias ??
|
||||
selection.field.fieldName.name;
|
||||
var groupForResponseKey =
|
||||
groupedFields.putIfAbsent(responseKey, () => []);
|
||||
groupForResponseKey.add(selection);
|
||||
|
|
Loading…
Reference in a new issue