executeSelectionSet method
Future<Map<String, dynamic>>
executeSelectionSet(
- DocumentContext document,
- SelectionSetContext selectionSet,
- GraphQLObjectType? objectType,
- dynamic objectValue,
- Map<String, dynamic> variableValues,
- Map<String, dynamic> globalVariables, {
- List<List> lazy = const [],
- GraphQLObjectType? parentType,
})
Implementation
Future<Map<String, dynamic>> executeSelectionSet(
DocumentContext document,
SelectionSetContext selectionSet,
GraphQLObjectType? objectType,
objectValue,
Map<String, dynamic> variableValues,
Map<String, dynamic> globalVariables, {
List<List> lazy = const [],
GraphQLObjectType? parentType,
}) async {
var groupedFieldSet = collectFields(
document, objectType!, selectionSet, variableValues,
parentType: parentType);
var resultMap = <String, dynamic>{};
for (var responseKey in groupedFieldSet.keys) {
if (responseKey == null) {
continue;
}
final nextLazy = <List>[];
final doneLazy = <List>[];
for (final l in lazy) {
if (l.first == responseKey) {
final key = l.elementAt(0);
final arr = l..removeAt(0);
if (l.length > 1) {
nextLazy.add(arr);
} else {
doneLazy.add([key, ...arr]);
}
}
}
final fields = groupedFieldSet[responseKey] ?? [];
for (var field in fields) {
var fieldName =
field.field?.fieldName.alias?.name ?? field.field?.fieldName.name;
FutureOr futureResponseValue;
if (fieldName == '__typename') {
futureResponseValue = objectType.name;
} else {
final fieldType = objectType.fields
.firstWhereOrNull((f) => f.name == fieldName)
?.type;
if (fieldType == null) {
continue;
}
futureResponseValue = executeField(
document,
fieldName,
objectType,
objectValue,
fields,
fieldType,
Map<String, dynamic>.from(globalVariables)
..addAll(variableValues),
globalVariables,
lazy: nextLazy.toList());
}
final val = resultMap[responseKey] = await futureResponseValue;
for (final lz in doneLazy) {
if (lz.first as String == responseKey) {
(lz.last as JsonPathArgument).complete(val);
}
}
}
//final map = resultMap[responseKey];
}
return resultMap;
}