All Projects → kikoseijo → lumen-lighthouse-graphql

kikoseijo / lumen-lighthouse-graphql

Licence: MIT license
Lumen example use of a GraphQL PHP server using Lighthouse package

Programming Languages

PHP
23972 projects - #3 most used programming language
HTML
75241 projects

Projects that are alternatives of or similar to lumen-lighthouse-graphql

Jwt Auth Guard
JWT Auth Guard for Laravel and Lumen Frameworks.
Stars: ✭ 319 (+929.03%)
Mutual labels:  composer, lumen
video-downloader
Video Downloader for Facebook.
Stars: ✭ 63 (+103.23%)
Mutual labels:  composer, lumen
jwt-auth
JSON Web Token Authentication for Laravel and Lumen
Stars: ✭ 46 (+48.39%)
Mutual labels:  composer, lumen
Laravel Awesome
Laravel 学习图谱
Stars: ✭ 143 (+361.29%)
Mutual labels:  composer, lumen
pyladies-courseware
Homework/task submit and review web app · based on React and Python aiohttp
Stars: ✭ 14 (-54.84%)
Mutual labels:  relay
laravel-bash-helpers
Daily tasks made easier
Stars: ✭ 20 (-35.48%)
Mutual labels:  lumen
learn-english
📚 Vue + Element-UI + Lumen 开发的背单词应用
Stars: ✭ 53 (+70.97%)
Mutual labels:  lumen
dudestack
A toolkit for creating a new professional WordPress project with deployments. Originally based on Roots/bedrock.
Stars: ✭ 82 (+164.52%)
Mutual labels:  composer
yii2-composer
Yii 2 composer extension
Stars: ✭ 76 (+145.16%)
Mutual labels:  composer
devstack
🐳 Dockette dockerized web devstack (@f3l1x)
Stars: ✭ 42 (+35.48%)
Mutual labels:  composer
osc-simulator
A utility to test Open Sound Control sending and receiving from the browser
Stars: ✭ 23 (-25.81%)
Mutual labels:  relay
docker-laravel-8
A simple Docker - Laravel 8 - MySQL - Redis - PHPAdmin - NGINX - PHP 7.4 - Composer - Artisan - XDebug
Stars: ✭ 130 (+319.35%)
Mutual labels:  composer
roadrunner-laravel
Simple bridge between Symfony and RoadRunner.
Stars: ✭ 43 (+38.71%)
Mutual labels:  lumen
twity
Private composer repository - Packagist mirror
Stars: ✭ 31 (+0%)
Mutual labels:  composer
lumen-oauth2
OAuth2 module for the Lumen PHP framework.
Stars: ✭ 29 (-6.45%)
Mutual labels:  lumen
laravel-mitnick
🔐 laravel-security helps you secure your Laravel apps by setting various HTTP headers.
Stars: ✭ 76 (+145.16%)
Mutual labels:  composer
email
Aplus Framework Email Library
Stars: ✭ 127 (+309.68%)
Mutual labels:  composer
c9phplaravel
This script installs PHP 7.3 and required extensions and Laravel in Cloud9
Stars: ✭ 17 (-45.16%)
Mutual labels:  composer
esp8266-1-channel-relay-board-with-mqtt
Sketch to control an esp8266-01 stc 15f104W powered 1-channel relay board
Stars: ✭ 26 (-16.13%)
Mutual labels:  relay
babel-plugin-flow-relay-query
Babel plugin which converts Flow types into Relay fragments
Stars: ✭ 38 (+22.58%)
Mutual labels:  relay

Lumen + GraphQL - by Lighthouse

This is an example project to show how to implement nuwave/lighthouse on a Lumen (Laravel) project.

Steps to reproduce

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 as so:

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:

$app->withFacades();
$app->withEloquent();
$app->configure('lighthouse');
...
$app->register(Nuwave\Lighthouse\Providers\LighthouseServiceProvider::class);

Add klaravel (Optional)

composer require ksoft/klaravel
cp vendor/ksoft/klaravel/stubs/config/ksoft.php config/ksoft.php
$app->configure('ksoft');

Laravel Passport

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

https://github.com/dusterio/lumen-passport

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()
    {
        Passport::tokensExpireIn(Carbon::now()->addDays(15));
        Passport::refreshTokensExpireIn(Carbon::now()->addDays(30));
        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:

$app->configure('auth');
...
$app->register(Laravel\Passport\PassportServiceProvider::class);
$app->register(Dusterio\LumenPassport\PassportServiceProvider::class);
// Optional if yo want to list your routes.
if ($app->environment() == 'local') {
    $app->register(Appzcoder\LumenRoutesList\RoutesCommandServiceProvider::class);
}

Now your are going to need the migrations:

php artisan make:migration create_users_table
$table->increments('id');
$table->string('name');
$table->string('email')->unique();
$table->string('password');
$table->rememberToken();
$table->timestamps();

Seeder:

php artisan make:seeder UsersTableSeeder
if (!DB::table('users')->where('email', '[email protected]')->first()) {
  DB::table('users')->insert([
    'name' => 'Kiko Seijo',
    'email' => '[email protected]',
    '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 https://laravel.com/docs/master/passport)

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

Testing install:

mutation Login {
  login(username: "[email protected]", password: "secret") {
    user {
      id
      name
      email
    }
    token
  }
}

Should return:

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

Testing auth middleware from Viewer Query:

query ViewerQuery {
  viewer {
    id
    name
    email
  }
}

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": "[email protected]"
    }
  }
}

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


Credits

Sunnyface.com, 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
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].