GraphQLBundle icon indicating copy to clipboard operation
GraphQLBundle copied to clipboard

InputType array of missing validation

Open jsakars opened this issue 2 months ago • 1 comments

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.

jsakars avatar Oct 31 '25 12:10 jsakars

@jsakars schemas defined in YAML and schemas defined with attributes have their own validator implementations, hence the different behavior. There is a big change coming, which should address this issue as well.

murtukov avatar Nov 09 '25 17:11 murtukov