Skip to content

Input validation broken in v0.14: "Cannot use object of type Closure as array" #973

@bravik

Description

@bravik
Q A
Bug report? yes
Feature request? no
BC Break report? yes
RFC? no
Version/Branch 14.0.1

Getting Exception:

 Cannot use object of type Closure as array[0] (caught throwable) at /app/vendor/overblog/graphql-bundle/sr
c/Validator/InputValidator.php line 139

Here:

$property = $arg['name'] ?? $name;

Here are my definitions:

FitnessSwapExerciseForProgramMutation:
  type: object
  config:
    fields:
      fitnessSwapExerciseForProgram:
        type: 'Void'
        args:
          input:
            type: 'FitnessSwapExerciseForProgramInput!'
            validation: cascade
        resolve: "@=mutation('fitness:program:swap_exercise', args['input'], getUser().getId())"
        access: "@=hasRole('ROLE_ATHLETE')"

FitnessSwapExerciseForProgramInput:
  type: input-object
  config:
    fields:
      exerciseId:
        type: 'ID!'
        validation:
          - NotBlank: ~
          - Type:
              type: numeric
      suitableLocation:
        type: 'FitnessExerciseLocation!'

FitnessExerciseLocation:
  type: enum
  config:
    description: Location type of exercises.
    values:
      ANY:
        value: 'any'
      GYM:
        value: 'gym'
      HOME:
        value: 'home'

Here is an input dump on the line before error:

InputValidator.php on line 138:
array:2 [
  "exerciseId" => array:2 [
    "type" => GraphQL\Type\Definition\NonNull {#4080
          // ...
      }
    }
    "validation" => Closure() {#4083
      class: "Overblog\GraphQLBundle\__DEFINITIONS__\FitnessSwapExerciseForProgramInputType"
      this: Overblog\GraphQLBundle\__DEFINITIONS__\FitnessSwapExerciseForProgramInputType {#3605 …}
    }
  ]
  "suitableLocation" => Closure() {#4022
    class: "Overblog\GraphQLBundle\__DEFINITIONS__\FitnessSwapExerciseForProgramInputType"
    this: Overblog\GraphQLBundle\__DEFINITIONS__\FitnessSwapExerciseForProgramInputType {#3605 …}
    use: {
      $services: Overblog\GraphQLBundle\Definition\GraphQLServices {#2145 …}
    }
  }
]

So the problem is with suitableLocation property, which is a closure.

I am not sure if it's not supposed to be a closure here,
or this is some regression introduced by recent InputValidator class refactoring in #815
@murtukov

I'm also having some similar errors witth validation after upgrading to v0.14:

  • Cannot use object of type GraphQL\Type\Definition\NonNull as array[0]
  • Cannot use object of type GraphQL\Type\Definition\BooleanType as array[0] (caught throwable) at /app/vendo r/overblog/graphql-bundle/src/Validator/InputValidator.php line 139.
  • Array to string conversion[2] (caught throwable) at /app/vendor/symfony/validato r/Constraints/Composite.php line 74

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions