Open crezra opened 3 years ago
Do you actually register your enum class with the TypeRegistry
?
yes
$typeRegistry->register(new LaravelEnumType(\App\Enums\MyEnums::class));
The php enum is working when I do not have the graphql enum defined
This is tricky to validate, given we want generally want to leverage lazy loading. When calling validate-schema
, the following happens in order:
TypeRegistry
MyEnum
is encountered, triggering a call to the lazy type loader - which is TypeRegistry::get()
Lazy type loading is great for performance, we generally want to avoid loading all the types into the schema. During validation, we actually want that, but the order of registering the types and the mechanism of type loading makes it so that programmatic types have precedence and duplicates are undetected. I am sure we can fix this somehow, but we have to keep performance and convenience in mind.
Describe the bug When using native enums, as showcased here https://lighthouse-php.com/master/the-basics/types.html#native-php-definition coupled with https://github.com/BenSampo/laravel-enum Enum name collisions are not detected when running
php artisan lighthouse:validate-schema
Expected behavior/Solution Validating schema should detect enum name collisions when using native php enums
Steps to reproduce
declare(strict_types=1);
namespace App\Enums;
use BenSampo\Enum\Enum;
class MyEnum extends Enum { public const DONE = 'DONE'; }
php artisan lighthouse:validate-schema
The defined schema is valid.
Output/LogsClick to expand
``` # Add in log output/error messages here ```