Skip to content

Allow GraphQL types named like PHP reserved keywords in federation entity resolver #2582

Open
@Maxwell2022

Description

@Maxwell2022

What problem does this feature proposal attempt to solve?

At the moment it seems that lighthouse is not able to resolve entities reference for types that are reserved PHP words out of the box.

For instance we are using this type Class in our graph which we didn't have problem with at first, but now that we need EntityReference resolver this is a problem because lighthouse is looking for a class with the same __typename which is not possible in PHP class Class {}.

Which possible solutions should be considered?

Option 1.

Entity reference resolver could be suffixed by Resolver or ReferenceResolver to allow fo this to work.

namespace App\GraphQL\ReferenceResolvers;

use Nuwave\Lighthouse\Federation\BatchedEntityResolver;

final class ClassResolver implements BatchedEntityResolver
{
...
}

Option 2.

Another solution would be to provide a mapping in the lighthouse configuration

// config/lighthouse.php

return [

   'referenceResolvers' => [
        // '__typename' => 'FQN',
        'class' => 'App\GraphQL\ReferenceResolvers\ClassResolver',
    ],

   ...
];

Option 3.

Another option would be to use a custom EntityResolverProvider (we went down this path)

$this->app->bind(EntityResolverProvider::class, CustomEntityResolverProvider::class);

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementA feature or improvement

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions