LastDragon-ru / lara-asp

Awesome Set of Packages for Laravel
MIT License
11 stars 1 forks source link

Printing schema not works: Type `CanAction` not found in the Schema. #155

Closed webard closed 4 months ago

webard commented 5 months ago

Hello,

I have latest version of Laravel, Lighthouse and Lara ASP. I have simple code that prints schema in SDL:

Route::get('/graphql-sdl', static function (): string {
    $schema = Container::getInstance()->make(SchemaBuilder::class)->schema();
    $printer = Container::getInstance()->make(Printer::class);
    $printed = $printer->print($schema);

    return (string) $printed;
});

but that code generates error:

LastDragon_ru \ LaraASP \ GraphQLPrinter \ Exceptions \ TypeNotFound

Type `CanAction` not found in the Schema.

But this type should be registered by Lighthouse: https://lighthouse-php.com/6/api-reference/directives.html#can-family-of-directives.

There is no info in Lighthouse docs about adding additional ServiceProvider or something.

LastDragon-ru commented 5 months ago

Laravel, Lighthouse and Lara ASP

What versions are you using?

LastDragon-ru commented 5 months ago

For the first look, it seems lighthouse issue. The CanAction type defined in BaseCanDirective::commonTypes(), but the method called in CanFindDirective::definition() only. So seems if @canFind directive is not used in the schema, the type will never add to the schema.

LastDragon-ru commented 5 months ago

As workaround you can try (not tested)

Route::get('/graphql-sdl', static function (): string {
    // Will load all types from the directive
    $resolver = Container::getInstance()->make(\LastDragon_ru\LaraASP\GraphQLPrinter\Contracts\DirectiveResolver::class);
    $resolver->getDefinition('canFind');
    // end

    $schema  = Container::getInstance()->make(SchemaBuilder::class)->schema();
    $printer = Container::getInstance()->make(Printer::class);
    $printed = $printer->print($schema);

    return (string) $printed;
});
webard commented 5 months ago

if @canFind directive is not used in the schema, the type will never add to the schema.

I don't use this directive, so why Schema Printer require type definitions for this directive?

LastDragon-ru commented 5 months ago

Because only this directive will add CanAction type definition)

LastDragon-ru commented 4 months ago

As I said, it is related how Lighthouse adds/loads own types. And thus there is nothing to do with our side.