api-platform / api-platform/core

[GraphQL] Iterable Type is required for mutations

Abierto
#1,944 1 comentario 1 reacción 0 asignados Ver en GitHub
GraphQL
Lenguaje dominante
PHP
Estrellas
2.6k
Forks
980
Merge medio
2 d 5 h
PR fusionados (30 d)
48

Descripción

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 ?? []);
}
```

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.