Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ResolverMap is not inherited #284

Open
akomm opened this issue Jan 30, 2018 · 2 comments
Open

ResolverMap is not inherited #284

akomm opened this issue Jan 30, 2018 · 2 comments

Comments

@akomm
Copy link
Member

akomm commented Jan 30, 2018

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.

@mcg-web mcg-web added the bug label Jan 30, 2018
@mcg-web mcg-web added this to the v0.11 milestone Jan 30, 2018
@mcg-web
Copy link
Member

mcg-web commented Jan 30, 2018

Thanks for feedback! Their was just not designed to work together :D

@mcg-web mcg-web added enhancement and removed bug labels Jan 30, 2018
@akomm
Copy link
Member Author

akomm commented Jan 30, 2018

I know, probably work different, the one merges config, the other just matched against on resolve? ;) But I think nothing speaks against it working in this case the same way? :)

@mcg-web mcg-web modified the milestones: v0.11, v0.12 Feb 12, 2018
@mcg-web mcg-web modified the milestones: v0.12, v0.13 May 26, 2019
@mcg-web mcg-web removed this from the v0.13 milestone Dec 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants