Testing a Laravel GraphQL Query
In this post I'm going to set up the environment to test the queries and mutations, and test the langs
query. It's the same query created in the previous post Basic example Laravel + GraphQL.
#
Configure TestCaseIn order to test a query o mutation I'll create three functions in the file TestCase.php.
#
Test public queries or mutationsTo verify graphql public endpoint.
#
Test private queries or mutationsTo verify graphql private endpoint, it need a user logged.
#
Print the error if its failIf a test fail, it's easy debug in this way.
#
Test LangQueryThis is quere that I used as example in the post Basic example Laravel + GraphQL
And now, just run php artisan test
to test it.
If the query to test need authenticacion, you have to add the trail use WithoutMiddleware;
from use Illuminate\Foundation\Testing\WithoutMiddleware;
. You may see the code here. If you would like to see it live please go here.