overblog / GraphQLBundle

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

Add support for `parseValue` configuration for `input-object` types #1147

Open sustmi opened 10 months ago

sustmi commented 10 months ago
Q A
Bug report? no
Feature request? yes
BC Break report? no
RFC? no
Version/Branch master

Let's say I have the following Input object:

HeroInput:
    type: input-object
    config:
        fields:
            firstname:
                type: "String!"
            lastname:
                type: "String!"

and a resolver using this as an input:

Query:
  type: object
  config:
    fields:
      heroes:
        type: "Hero"
        args:
          name:
            type: "HeroInput!"
        resolve: "@=query('heroes', args['name'])"

The resolver method in PHP gets the name input as an array containing firstname and lastname keys.

public function heroes(array $name) {
    var_dump($name['firstname'], $name['lastname']);

I would like to have the input object as a real object in my resolver:

public function heroes(HeroInput $name) {

Documentation of webonyx/graphql-php mentions parseValue configuration: https://webonyx.github.io/graphql-php/type-definitions/inputs/#converting-input-object-array-to-value-object that could be used for this conversion.

However, when I try to use parseValue for input-object:

HeroInput:
    type: input-object
    config:
        fields:
            firstname:
                type: "String!"
            lastname:
                type: "String!"
    parseValue: ['HeroInput', 'parseValue']

type I get error:

PHP Fatal error: Uncaught Symfony\Component\Config\Definition\Exception\InvalidConfigurationException: Unrecognized option "parseValue" under "overblog_graphql_types.HeroInput._input_object_config". Available options are "description", "fields", "name", "validation".

So it seems that the parseValue from webonyx/graphql-php is not exposed by overblog/graphql-bundle for input-object. Note: The custom-scalar type supports the parseValue configuration: https://github.com/overblog/GraphQLBundle/blob/master/docs/definitions/type-system/scalars.md#with-yaml .

It would be nice to have the option available so that resolver method could get directly the PHP object instead of a plain array.