api-platform / api-platform/core

[GraphQL] Iterable Type is required for mutations

未關閉
#1,944 1 則留言 1 個 reaction 已指派 0 人 在 GitHub 檢視
GraphQL
主要語言
PHP
星號
2.6k
分支
980
平均合併
2 天 5 小時
30 天內合併 PR
48

描述

When the schema is generated for an array field, it seems like it always lists it as required when the setting has the default value set to an empty array.

For example, the following model will cause the `privileges` field to always be required, even though it should not be.

```php
class User {
/**
* @ORM\Column(type="text_array", nullable=true)
*
* @Groups({"read", "write"})
*/
private $privileges = [];

public function getPrivileges(): ?array
{
return $this->privileges;
}

public function setPrivileges(array $privileges = []): void
{
$this->privileges = array_unique($privileges);
}
}
```

The only way I have found to make it optional like it should be is to modify the setter to this:

```php
public function setPrivileges(array $privileges = null): void
{
$this->privileges = array_unique($privileges ?? []);
}
```

貢獻指南

開啟貢獻指南

評估

這個 Issue 還沒有評估資料。

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。