Skip to content
Elegant GraphQL testing utilities for Laravel.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

GraphQL Testing Helper for Laravel

Elegant GraphQL testing utilities for Laravel. Works with any GraphQL library. Especially with Lighthouse.


Install this library with composer

composer require --dev marvinrabe/laravel-graphql-test

Add the trait to your TestCase class:


namespace Tests;

abstract class TestCase extends BaseTestCase
    use MarvinRabe\LaravelGraphQLTest\TestGraphQL;

    // ...

When your GraphQL endpoint is not /graphql you have to specify it manually:

public $graphQLEndpoint = 'graphql';



You can write queries like this:

$this->query('account', ['id' => 123], ['id']);

Note that this function returns an \Illuminate\Foundation\Testing\TestResponse. Therefore you might use any Laravel testing methods. For example:

$this->query('account', ['id' => 123], ['id'])
    'id' => 123

With nested resources:

$this->query('account', ['id' => 123], ['transactions' => ['id']]);

Without a third argument it will be assumed that the second one is the selection set:

$this->query('accounts', ['id']);

When you only pass the object name, you get the GraphQLClient instead of the Laravel TestResponse:



Same as queries. But without the third argument, the second one still needs to be a GraphQL argument array:

$this->mutation('accounts', ['id' => 123]); 


The QueryBuilder provided by this library is not safe for use in production code. It is designed for ease of use and does not comply to the GraphQL specifications fully. Use it only for testing purposes! You have been warned.

You can’t perform that action at this time.