Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,8 @@ private function processIsNullable(FieldInterface $field, ?TypeInterface $object
private function processIsList(FieldInterface $field, ?TypeInterface $object = null) : TypeInterface
{
if ($field->isList()) {
if ($field instanceof \Magento\Framework\GraphQl\Config\Element\Argument) {
if ($field->areItemsRequired()) {
$object = $this->typeFactory->createNonNull($object);
}
if ($field->areItemsRequired()) {
$object = $this->typeFactory->createNonNull($object);
}
return $this->typeFactory->createList($object);
}
Expand Down Expand Up @@ -136,10 +134,8 @@ private function processScalarIsList(
) : \GraphQL\Type\Definition\Type {
$object = $object ?: $this->scalarTypes->getScalarTypeInstance($field->getTypeName());
if ($field->isList()) {
if ($field instanceof \Magento\Framework\GraphQl\Config\Element\Argument) {
if ($field->areItemsRequired()) {
$object = $this->scalarTypes->createNonNull($object);
}
if ($field->areItemsRequired()) {
$object = $this->scalarTypes->createNonNull($object);
}
return $this->scalarTypes->createList($object);
}
Expand Down
19 changes: 18 additions & 1 deletion lib/internal/Magento/Framework/GraphQl/Config/Element/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ class Field implements OutputFieldInterface
*/
private $deprecated;

/**
* @var bool
*/
private bool $itemsRequired;

/**
* @param string $name
* @param string $type
Expand All @@ -83,7 +88,8 @@ public function __construct(
string $description = '',
array $arguments = [],
array $cache = [],
array $deprecated = []
array $deprecated = [],
bool $itemsRequired = false
) {
$this->name = $name;
$this->type = $isList ? $itemType : $type;
Expand All @@ -94,6 +100,7 @@ public function __construct(
$this->arguments = $arguments;
$this->cache = $cache;
$this->deprecated = $deprecated;
$this->itemsRequired = $itemsRequired;
}

/**
Expand Down Expand Up @@ -185,4 +192,14 @@ public function getDeprecated() : array
{
return $this->deprecated;
}

/**
* Return true if item is a list, and if that list must be populated by at least one item. False otherwise.
*
* @return bool
*/
public function areItemsRequired() : bool
{
return $this->itemsRequired;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public function createFromConfigData(
'arguments' => $arguments,
'cache' => isset($fieldData['cache']) ? $fieldData['cache'] : [],
'deprecated' => isset($fieldData['deprecated']) ? $fieldData['deprecated'] : [],
'itemsRequired' => isset($fieldData['itemsRequired']) ? $fieldData['itemsRequired'] : false,
]
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ public function getTypeName(): string;
*/
public function isList(): bool;

/**
* @return bool
*/
public function areItemsRequired() : bool;

/**
* Return true if argument is required when invoking the query where the argument is specified. False otherwise.
*
Expand Down