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

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

Open
webard opened this issue Apr 25, 2024 · 5 comments
Open

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

webard opened this issue Apr 25, 2024 · 5 comments
Labels
external Related to another/external package pkg: graphql

Comments

@webard
Copy link

webard commented Apr 25, 2024

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
Copy link
Owner

Laravel, Lighthouse and Lara ASP

What versions are you using?

@LastDragon-ru
Copy link
Owner

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
Copy link
Owner

LastDragon-ru commented Apr 25, 2024

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;
});

@LastDragon-ru LastDragon-ru added pkg: graphql external Related to another/external package labels Apr 25, 2024
@webard
Copy link
Author

webard commented Apr 25, 2024

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
Copy link
Owner

Because only this directive will add CanAction type definition)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
external Related to another/external package pkg: graphql
Projects
None yet
Development

No branches or pull requests

2 participants