Skip to content

ResolverMap is not inherited #284

@akomm

Description

@akomm
Q A
Bug report? yes
Feature request? no
BC Break report? no
RFC? no
Version/Branch dev-master

Example:

NodeInterface:
  type: 'interface'
  config:
    fields:
      id: {type: 'ID!'}

Node:
  type: 'object'
  config:
    interfaces: ['NodeInterface']
    fields:
      id: {type: 'ID!'}

Product:
  type: 'object'
  inherits: ['Node']
  config:
    fields:
      name:
        type: 'String!'
# ...

And the following ResolverMap:

<?php declare(strict_types=1);
namespace App\GraphQL\Resolver\Query;

use App\GraphQL\Relay\GlobalId;
use App\GraphQL\Relay\NodeInterface;
use Overblog\GraphQLBundle\Resolver\ResolverMap;
use Overblog\GraphQLBundle\Resolver\UnresolvableException;

final class NodeResolver extends ResolverMap
{
    protected function map()
    {
        return [
            'NodeInterface' => [
                static::RESOLVE_TYPE => function($value) {
                    if ($value instanceof NodeInterface) {
                        return $value->getTypeName();
                    }
                    throw new UnresolvableException();
                },
            ],
            'Node' => [
                'id' => function($value) {
                    if ($value instanceof NodeInterface) {
                        return GlobalId::toGlobalId($value->getTypeName(), $value->getId());
                    }
                    throw new UnresolvableException();
                },
            ],
        ];
    }
}

It is also added in the graphql extension as "resolver_map".

The RESOLVE_TYPE works, but the Node.id is not invoked and the plain ID is returned.

Contrary, the resolver is correctly inherited, when defining it using the expression language:

NodeInterface:
  type: 'interface'
  config:
    fields:
      id: {type: 'ID!'}

Node:
  type: 'object'
  config:
    interfaces: ['NodeInterface']
    fields:
      id: {type: 'ID!', resolver: '@=resolver("myresolver", [value])'}

Product:
  type: 'object'
  inherits: ['Node']
  config:
    fields:
      name:
        type: 'String!'
# ...

I started using ResolverMap instead of ResolverInterface, because it safes me implementing two interfaces to achieve the exact same result, even though it was added as a requirement for the new graphql type configuration.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions