overblog / GraphQLBundle

This bundle provides tools to build a complete GraphQL API server in your Symfony App.
MIT License
788 stars 222 forks source link

Validation is called on optional fields that are not passed #1182

Closed joesaunderson closed 6 months ago

joesaunderson commented 7 months ago
Q A
Bug report? yes
Feature request? no
BC Break report? no
RFC? no
Version/Branch 1

When validating a field like so:

    ...
    config:
        description: "An input object for editing a merchant"
        fields:
            name:
                type: "String"
                validation:
                    link: 'App\Entity::$name'
            description:
                type: "String"

And using that in a mutation like

mutation {
  edit(set: {description: "Foo"}) {
    id
  }
}

I am getting an error for validation on the name field, which uses the Symfony "Assert/NotBlank" rule.

 "extensions": {
        "validation": {
          "set.name": [
            {
              "message": "Name must not be blank",
              "code": "c1051bb4-d103-4f74-8988-acbcafc7fdc3"
            }
          ]
        }
      },

Should validation be called for optional fields that are not passed in?