Lighthouse: Add Custom NameSpace, then generation command failed.

Created on 17 Mar 2020  路  2Comments  路  Source: nuwave/lighthouse

Describe the bug

add custom namespace , likelighthouse.namespace.mutations and so on , then generation commands failed.

I run command below

 php artisan lighthouse:mutation Message -v

i can get log below

 Maximum function nesting level of '256' reached, aborting! {"exception":"[object] (Symfony\\Component\\Debug\\Exception\\FatalThrowableError(code: 0): Maximum function nesting level of '256' reached, aborting! 

[stacktrace]
... 
#13 ..../vendor/laravel/framework/src/Illuminate/Console/GeneratorCommand.php(102): Illuminate\\Console\\GeneratorCommand->qualifyClass('Message')
#14 ..../vendor/laravel/framework/src/Illuminate/Console/GeneratorCommand.php(102): Illuminate\\Console\\GeneratorCommand->qualifyClass('Message')
#15 ..../vendor/laravel/framework/src/Illuminate/Console/GeneratorCommand.php(102): Illuminate\\Console\\GeneratorCommand->qualifyClass('Message')
#16 ..../vendor/laravel/framework/src/Illuminate/Console/GeneratorCommand.php(102): Illuminate\\Console\\GeneratorCommand->qualifyClass('Message')
#17 ..../vendor/laravel/framework/src/Illuminate/Console/GeneratorCommand.php(102): Illuminate\\Console\\GeneratorCommand->qualifyClass('Message')
....

this is valid configuration. this will work fine.

    'namespaces' => [
        'mutations' => [
            'App\\GraphQL\\Mutations',
            'App\\GraphQL\\Mutations2',
        ],
    ],

But configuration below, command wont work fine.

    'namespaces' => [
        'mutations' => [
            'App\\GraphQL\\Mutations',
            'Acme\\NewService\\GraphQL\\Mutations',
        ],
    ],

Expected behavior/Solution

Steps to reproduce

1.
2.
3.

Output/Logs

Click to expand

# Add in log output/error messages here


Environment

Lighthouse Version:
Laravel Version:

bug

Most helpful comment

Thanks for the report. It is a good idea to handle that case gracefully.

All 2 comments

this will happen because $matching is empty in LighthouseGeneratorCommand::commonNamespace.

https://github.com/nuwave/lighthouse/blob/master/src/Console/LighthouseGeneratorCommand.php#L51

if this return empty, then LighthouseGeneratorCommand::getDefaultNamespace will return empty string, and GeneratorCommand::getDefaultNamespce get infinite loop behavior.

https://github.com/illuminate/console/blob/master/GeneratorCommand.php#L85

I think LighthouseGeneratorCommand::commonNamespace should not return empty string.
What about return end($namespaces) when $matching is empty?
(or just output warning, and add namespace option)

Thanks for the report. It is a good idea to handle that case gracefully.

Was this page helpful?
0 / 5 - 0 ratings