/** * Complete a list value by completing each item in the list with the * inner type * * @param ExecutionContext $exeContext * @param ListOfType $returnType * @param $fieldNodes * @param ResolveInfo $info * @param array $path * @param $result * @return array|Promise * @throws \Exception */ private static function completeListValue(ExecutionContext $exeContext, ListOfType $returnType, $fieldNodes, ResolveInfo $info, $path, &$result) { $itemType = $returnType->getWrappedType(); Utils::invariant(is_array($result) || $result instanceof \Traversable, 'User Error: expected iterable, but did not find one for field ' . $info->parentType . '.' . $info->fieldName . '.'); $containsPromise = false; $i = 0; $completedItems = []; foreach ($result as $item) { $fieldPath = $path; $fieldPath[] = $i++; $completedItem = self::completeValueCatchingError($exeContext, $itemType, $fieldNodes, $info, $fieldPath, $item); if (!$containsPromise && self::$promiseAdapter->isPromise($completedItem)) { $containsPromise = true; } $completedItems[] = $completedItem; } return $containsPromise ? self::$promiseAdapter->createPromiseAll($completedItems) : $completedItems; }
/** * Complete a list value by completing each item in the list with the * inner type * * @param ExecutionContext $exeContext * @param ListOfType $returnType * @param $fieldASTs * @param ResolveInfo $info * @param array $path * @param $result * @return array * @throws \Exception */ private static function completeListValue(ExecutionContext $exeContext, ListOfType $returnType, $fieldASTs, ResolveInfo $info, $path, &$result) { $itemType = $returnType->getWrappedType(); Utils::invariant(is_array($result) || $result instanceof \Traversable, 'User Error: expected iterable, but did not find one for field ' . $info->parentType . '.' . $info->fieldName . '.'); $i = 0; $tmp = []; foreach ($result as $item) { $path[] = $i++; $tmp[] = self::completeValueCatchingError($exeContext, $itemType, $fieldASTs, $info, $path, $item); } return $tmp; }