Use name instead of parsed int index

This commit is contained in:
Tobe O 2019-08-13 22:58:15 -04:00
parent b2fe33f0ad
commit 9fd290ca68

View file

@ -99,16 +99,18 @@ RequestHandler graphQLHttp(GraphQL graphQL,
} }
var variables = Map<String, dynamic>.from(globalVariables); var variables = Map<String, dynamic>.from(globalVariables);
for (var entry in (map as Map).entries) { for (var entry in (map as Map).entries) {
var key = int.parse(entry.key as String); var file = req.uploadedFiles
if (req.uploadedFiles.length < key) { .firstWhere((f) => f.name == entry.key, orElse: () => null);
if (file == null) {
throw AngelHttpException.badRequest( throw AngelHttpException.badRequest(
message: message:
'"map" contained key "$key", but the number of uploaded files was ${req.uploadedFiles.length}.'); '"map" contained key "${entry.key}", but no uploaded file '
'has that name.');
} }
if (entry.value is! List) { if (entry.value is! List) {
throw AngelHttpException.badRequest( throw AngelHttpException.badRequest(
message: message:
'The value for "$key" in the "map" field was not a JSON array.'); 'The value for "${entry.key}" in the "map" field was not a JSON array.');
} }
var objectPaths = entry.value as List; var objectPaths = entry.value as List;
for (var objectPath in objectPaths) { for (var objectPath in objectPaths) {
@ -125,7 +127,7 @@ RequestHandler graphQLHttp(GraphQL graphQL,
'Object "$parent" is not a JSON array, but the ' 'Object "$parent" is not a JSON array, but the '
'"map" field contained a mapping to $parent.$name.'); '"map" field contained a mapping to $parent.$name.');
} }
(current as List)[int.parse(name)] = req.uploadedFiles[key]; (current as List)[int.parse(name)] = file;
} else { } else {
if (current is! Map) { if (current is! Map) {
throw AngelHttpException.badRequest( throw AngelHttpException.badRequest(
@ -133,7 +135,7 @@ RequestHandler graphQLHttp(GraphQL graphQL,
'Object "$parent" is not a JSON object, but the ' 'Object "$parent" is not a JSON object, but the '
'"map" field contained a mapping to $parent.$name.'); '"map" field contained a mapping to $parent.$name.');
} }
(current as Map)[name] = req.uploadedFiles[key]; (current as Map)[name] = file;
} }
} }
} else { } else {