Skip to content

[GraphQL] Iterable Type is required for mutations #1944

Open
@bwegrzyn

Description

@bwegrzyn

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.

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:

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions