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

Open
#2,582 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
25/100
Issue type
Feature
Clarity
Needs clarification
Activity status
Stale
Tech stack
graphql, laravel, php
Domain
api, backend

Research direction

Start by reading the federation entity-resolution flow around EntityResolverProvider and the configuration in config/lighthouse.php. Compare the proposed resolver naming and referenceResolvers mapping approaches, then define how a GraphQL type such as Class should resolve without requiring an invalid PHP class name. Done means reserved-keyword entity references resolve through a documented, tested approach.

Written by the indexing model from the issue text.

Description

enhancement

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);
Dominant language
PHP
Stars
3.5k
Forks
468
Avg merge
3h 9m
Merged PRs (30d)
2

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from nuwave/lighthouse

All issues in nuwave/lighthouse

Similar issues

More PHP issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.