Search code examples
phplaravelgraphqllaravel-lighthouse

Laravel and Lighthouse, it always read the dafault schema


I'm following the tutorial on Lighthouse website for the master version (4.1).

https://lighthouse-php.com/4.1/getting-started/tutorial.html#installation

I make a fresh intallation of Laravel 5.8, then I execute the commands written in the tutorial (beside npm install)

composer require nuwave/lighthouse mll-lab/laravel-graphql-playground

php artisan vendor:publish --provider="Nuwave\Lighthouse\LighthouseServiceProvider"

php artisan vendor:publish --provider="MLL\GraphQLPlayground\GraphQLPlaygroundServiceProvider"

after that a /graphql/schema.graphql file is created (under the project root, not under the routes folder as happened with the previous versions).

Now I populate the DB with some data and then I copy/paste the schema from the tutorial page to the published schema, I start the server, then I access playground which shows the correct url where to send the requests http://127.0.0.1:8000/graphql.

Clicking on the Schema tab I always see the default schema and not the one published in /graphql/schema.graphql, and of course the queries for the resources different from the users fails with an error like Cannot query field "posts" on type "Query".. I've already tried restarting the server and refreshing the Playground page.

Into the config/lighthouse.php file the schema is registered to the path base_path('graphql/schema.graphql') which looks correct.

Why Playground always shows the default schema and not the published and edited one?

I'm using PHP 7.2.14 and Lighthouse requires PHP>7.1


Solution

  • I thought the problem is related to the caching. I tried to add LIGHTHOUSE_CACHE_ENABLE=false to the laravel .env file and restart the server then refresh the playground page. I recheck the schema and it is updated.

    I hope it's useful.