Class generator command with custom paths
What problem does this feature proposal attempt to solve?
When running the artisan lighthouse:mutation command to generate a mutation class which is not within the app/ and App namespace, I receive the error: Maximum function nesting level of '256' reached, aborting!. I'm using nWidart modules and the "Modules/" directory is next to "app/".
Which possible solutions should be considered?
The LighthouseGeneratorCommand should implement a new method:
/**
* @return string
*/
protected function rootNamespace(): string
{
return config('lighthouse.namespaces.'.$this->namespaceConfigKey());
}
This way the generator works without throwing an exception. There is just one more adjustment to make because the generator is writing into the app/ directory directly. So we need to tell the generator to really use this namespace. We can do so by overwriting another method within LighthouseGeneratorCommand: protected function getPath($name). $this->laravel['path'] should only be used if the namespace returned from rootNamespace really starts with "App". Otherwise and absolute path to the namespace should be used.
The problem I figured out right now is that if I change a namespace back to start with "App" I'll receive Maximum function nesting level of '256' reached, aborting! if rootNamespace() is implemented like suggested above. So maybe there needs a few more adjustments to be done.
Thanks for the detailed writeup. Changing the generator to deal with namespaces not in App\ seems reasonable. Given the implementation is not too convoluted and existing functionality keeps working, I am up for including a PR for this in Lighthouse. Not looking to implement it myself for the foreseeable future.