Skip to content

InputType array of missing validation #1213

@jsakars

Description

@jsakars

Having an PHP attribute GQL Input and Provider e.g.

#[GQL\Mutation(name: 'entitiesUpdate', type: Type::BOOLEAN)]
#[GQL\Arg(name: 'entities', type: '[EntityUpdateInput]!')]
public function consumersUpdate(array $entities): bool
{
    foreach ($entities as $entity) {
        ...
    }

    return true;
}
#[GQL\Input]
class EntityUpdateInput
{
    #[GQL\InputField(type: Type::STRING)]
    #[Assert\Email]
    public ?string $email;

    ...
}

and then having a mutation run like so:

mutation {
  entitiesUpdate(
    entities: [
      {
        ...
        email: "invalid1"
      }
      {
        ...
        email: "invalid2"
      }
    ]
  )
}

I would expect to get indexed (so a precise indication which of the array elements has the problem) validation errors:

  • entities[0].email
  • entities[1].email

but instead I get:

Image

which clearly does not indicate which exact array element has the problem.

We pinpointed it down to the logic that Type Builder does not set validation metadata for compiled type classes when argument is an array of Input types.

It works fine if argument is something like this:

#[GQL\Input]
class EntityUpdateListInput {
    #[GQL\Field(type: '[EntityUpdateInput]!')]
    #[Assert\Valid]
    public ?array $entities;
}

which is a bit stupid to wrap it unnecessary and have the following mutation:

mutation {
  entitiesUpdate(
    list: {
      entities: [
        {
          ...
          email: "invalid1"
        }
        {
          ...
          email: "invalid2"
        }
      ]
    }
  )
}

This works fine if those inputs are defined using YAML - the problem is with the PHP attributes.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions