Laravel Lumen GraphQL Server for React Relay Modern

Having Laravel´s Lumen to work as a GraphQL Server able to provide feeds to client applications for Relay Modern its been a beautiful jurney, and i´ll like to share with the world on this publication.

Laravel its Magic, and this is a fact, thanks to its nature we able to do things like this, in this example all work its done thanks to a recently released v2 of an excellent library known as LightHouse, you can find documentation on nuwave/lighthouse, this library it´s in charge some Magic.

On its core uses another library, lets say Lighthouse its a Laravel Wrapper with supercharged powers, on top of webonyx/graphql-php, the real GraphQL implementation under PHP.

As a result of this implementation you able to access and download resuling proyect implementation on this GitHub Repository:


The Jurney starts

Maybe i have missed some steps, but main logic its here, as you having the repository you can get from there whats not documented here.

Steps to reproduce

Fresh install of Lumen, and initial packages requirements its done on the following bash commands:

lumen new lumen-lighthouse-graphql
cd lumen-lighthouse-graphql
composer update
composer require nuwave/lighthouse
cp .env.example .env

setup your configuration folders, and lighthouse defaults folders needed if you are going to implement some queries, mutactions, etc…

mkdir config && mkdir app/Models && mkdir app/GraphQL && mkdir app/GraphQL/Mutations && mkdir app/GraphQL/Queries && mkdir app/GraphQL/Scalars && mkdir app/GraphQL/Directives
cp vendor/nuwave/lighthouse/config/config.php config/lighthouse.php

Helping Lumen acknowledge regarding Lighthouse:


Add klaravel (Optional)

composer require ksoft/klaravel
cp vendor/ksoft/klaravel/stubs/config/ksoft.php config/ksoft.php

Laravel Passport

Im using a wrapper to be able to have Passport fully integrated on Laravel Lumen´s. For more info or extended usage:

composer require dusterio/lumen-passport
composer require appzcoder/lumen-routes-list
namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use Dusterio\LumenPassport\LumenPassport;
use Laravel\Passport\Passport;
use Carbon\Carbon;

class AppServiceProvider extends ServiceProvider
     * Register any application services.
     * @return void
    public function register()
        LumenPassport::tokensExpireIn(Carbon::now()->addYears(50), 2);

Under AuthServiceProvider.php add this line in the boot method

// use Dusterio\LumenPassport\LumenPassport;
LumenPassport::routes($this->app, ['prefix' => 'v1/oauth']);

User model

use Laravel\Passport\HasApiTokens;

Enable Passport under Lumen:

// Optional if yo want to list your routes.
if ($app->environment() == 'local') {

Now your are going to need the migrations:

php artisan make:migration create_users_table


php artisan make:seeder UsersTableSeeder
if (!DB::table('users')->where('email', '')->first()) {
    'name' => 'Kiko Seijo',
    'email' => '',
    'password' => app('hash')->make('secret'),
    // 'admin' => 1,

Finish install Laravel Passport install with: This is the simplest way to setup a login method that Passport provides, there are many more

php artisan migrate --seed
php artisan passport:keys
php artisan passport:client --personal

Testing install:

mutation Login {
  login(username: "", password: "secret") {
    user {

Should return:

  "data": {
    "login": {
      "user": {
        "id": "1",
        "name": "Kiko Seijo",
        "email": ""
      "token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJS........your token"

Testing auth middleware from Viewer Query:

query ViewerQuery {
  viewer {

Add the headers to your query and adjust the token to the one you are getting from previous login:

  "Authorization": "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJS........your token"

And you should get:

  "data": {
    "viewer": {
      "id": "1",
      "name": "Kiko Seijo",
      "email": ""

GraphQL viewer Query with a Laravel Passport bearer token using Lighthouse auth middleware

Credits, is a software development company from Málaga, Spain. We provide quality software based on the cloud for local & international companies, providing technology solutions with the most modern programming languages.

DevOps Web development
Custom App Development Mobile aplications
Social Apps and Startups Residents mobile application
Graphic designer Freelance senior programmer

Created by Kiko Seijo