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

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

Open
Maxwell2022 opened this issue Jul 10, 2024 · 1 comment
Labels
enhancement A feature or improvement

Comments

@Maxwell2022
Copy link

Maxwell2022 commented Jul 10, 2024

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);
@Maxwell2022 Maxwell2022 changed the title Support GraphQL types that are PHP reserved words [Federation] Support GraphQL types that are PHP reserved words Jul 10, 2024
@spawnia spawnia changed the title [Federation] Support GraphQL types that are PHP reserved words Allow GraphQL types named like PHP reserved keywords in federation entity resolver Jul 11, 2024
@spawnia spawnia added the enhancement A feature or improvement label Jul 11, 2024
@spawnia
Copy link
Collaborator

spawnia commented Jul 11, 2024

Does any passed in __typename have to be present as a type in the schema 100% of the time? If so, we could add a mapping at the schema level through a directive, such as:

type Class @class(name: "ClassType") { ... }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement A feature or improvement
Projects
None yet
Development

No branches or pull requests

2 participants