@Override
public CompletableFuture<ExecutionResult> execute(ExecutionContext executionContext, ExecutionStrategyParameters parameters) throws NonNullableFieldWasNullException {
MergedSelectionSet fields = parameters.getFields();
Map<String, FetchedValue> fetchedValues = new LinkedHashMap<>();
for (String fieldName : fields.keySet()) {
FetchedValue fetchedValue = fetchField(executionContext, parameters, fields, fieldName);
fetchedValues.put(fieldName, fetchedValue);
}
Map<String, Object> results = new LinkedHashMap<>();
for (String fieldName : fetchedValues.keySet()) {
MergedField currentField = fields.getSubField(fieldName);
FetchedValue fetchedValue = fetchedValues.get(fieldName);
ExecutionPath fieldPath = parameters.getPath().segment(fieldName);
ExecutionStrategyParameters newParameters = parameters
.transform(builder -> builder.field(currentField).path(fieldPath));
try {
completeValue(executionContext, results, fieldName, fetchedValue, newParameters);
} catch (NonNullableFieldWasNullException e) {
assertNonNullFieldPrecondition(e);
results = null;
break;
}
}
return CompletableFuture.completedFuture(new ExecutionResultImpl(results, executionContext.getErrors()));
}