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