As @robsontenorio has written up his excellent tutorial, i noticed that we deviate from the
Laravel default namespace for Models. While i personally change it to App\Models in each
of my Laravel projects, i think it would be more beginner friendly to just stick with the
default that Laravel provides.
On the same vein, i do have some changes in mind about some other default namespaces.
I feel like the current namespaces/default directories are unnecessarily nested. I propose
to lift them up a level and make Lighthouse/GraphQL more of a first class citizen in the project.
As this is a community-developed project, i figured we might as well vote on it. I added single
comments below with some choices, feel free to add your own opinions.
Changing the defaults should not affect most users, as they will probably have ejected the config. If we do change them, we will make sure to announce this clearly in the next version.
Default Model namespace:
App (Laravel default) 馃憤 App\Models (current) 馃憥 Default namespaces for 'queries', 'mutations', 'interfaces', 'unions', 'scalars', 'directives':
App\GraphQL\Xyz (GraphQL as a first class citizen) 馃憤 App\Http\GraphQL\Xyz (current) 馃憥 Default location for the root schema:
graphql/schema.graphql (GraphQL as a first class citizen) 馃憤 routes/graphql/schema.graphql (current) 馃憥 Just a personal preference, but I prefer the following for the schema file:
routes/schema.graphql
Since that folder also includes api.php, channels.php, console.php, and web.php it makes more sense (to me) to add the schema here rather than creating a new folder on the root level of the project.
Default namespaces for 'queries', 'mutations', 'interfaces', 'unions', 'scalars', 'directives':
I voted for non-Http version because I've in fact used GraphQL also in non-HTTP context. Let's not forget that GraphQL itself is transport agnostic and nothing per se requires HTTP.
@mfn That's a great point
@mfn that makes sense. I think points 2 + 3 go hand in hand, and the change would be a step towards decoupling GraphQL from HTTP.
In general, i dislike nesting the directory structure unless it gets out of hand. Both the app and root directory usually have about 10 directories, and since GraphQL is a central part of a Laravel project, it makes sense to have it highly visible.
Hello,
I am having an issue with the namespaces, my project has a Models where all my Models are except for User.php. Because of this inconsistency I decided to move the User model to the Models folder, in doing that Lighthouse now does not work. What do I need to fix this so that I can have all the models in one folder and have Lighthouse working.
@snetts have you refactor all files related to User? I mean, config/auth.php for example, and related models? I'm sure it is not a lighthouse's problem. I have all models in their custom modules and all works fine.
@enzonotario Thanks it works great. I refactored and used dump-autoload and eveything works fine now.
Most helpful comment
Default Model namespace:
App(Laravel default) 馃憤App\Models(current) 馃憥