Skip to content

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

Open

Description

@sustmi
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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    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