You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Having an Eloquent-Model Log (in "App\Models\Log"), and querying a single object or a collection of this model, without specifying the @find- or @paginate-directive with (models: "App\\Models\\Log") results in an internal server error. Lighthouse works fine with every other Model except Log out of the box.
Expected behavior
Resolving the mentioned Model like it does with every other Model out of the box.
The text was updated successfully, but these errors were encountered:
spawnia
changed the title
Problem to solve 'Log'-Model without using directives with 'model' attribute
Default model namespaces fail if the model is named like a Facade, e.g. LogNov 26, 2018
This happens because Lighthouse tries to locate a class that is named after the type, so in this case Log. Only if this is not found, the default model namespace is prepended and tried again.
I can see a few solutions for this:
We can check if the class exists AND is an instanceof Model. This causes an additional check during runtime, and i am not quite sure if it works for all cases.
Add a hint to the docs that tell the user to use explicit namespaces for such occurences. This is probably the easiest fix but makes Lighthouse more complex to use.
Blacklist the Laravel Facades so they are not used as models. This solution would not work for user defined facades, so it might not be the best.
Describe the bug
Having an Eloquent-Model
Log
(in "App\Models\Log"), and querying a single object or a collection of this model, without specifying the@find
- or@paginate
-directive with(models: "App\\Models\\Log")
results in an internal server error. Lighthouse works fine with every other Model exceptLog
out of the box.Expected behavior
Resolving the mentioned Model like it does with every other Model out of the box.
Schema
Output/Logs
Click to expand
Environment
Lighthouse Version: 2.6.3
Laravel Version: 5.5.44 (but also with 5.7.13)
PHP Version: 7.1.24
Additional context
To solve this problem, it is necessary to add the models attribute to the directives:
The text was updated successfully, but these errors were encountered: