diff --git a/angel_graphql/example/main.dart b/angel_graphql/example/main.dart index 8c5ac793..45865fc6 100644 --- a/angel_graphql/example/main.dart +++ b/angel_graphql/example/main.dart @@ -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') - ..onRecord.listen((rec) { - print(rec); - if (rec.error != null) print(rec.error); - if (rec.stackTrace != null) print(rec.stackTrace); - }); + 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'); diff --git a/graphql_server/lib/graphql_server.dart b/graphql_server/lib/graphql_server.dart index 478c6f65..8c9240c3 100644 --- a/graphql_server/lib/graphql_server.dart +++ b/graphql_server/lib/graphql_server.dart @@ -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 variableValues) { var coercedValues = {}; 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);