robsontenorio/lighthouse-dashboard

This package is abandoned and no longer maintained. No replacement package was suggested.

Dashboard for Laravel Lighthouse GraphQL.

0.20.2 2023-01-25 17:09 UTC

README

dashboard.png

68747470733a2f2f636f6465636f762e696f2f67682f726f62736f6e74656e6f72696f2f6c69676874686f7573652d64617368626f6172642f6272616e63682f6d61737465722f67726170682f62616467652e737667 68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f726f62736f6e74656e6f72696f2f6c69676874686f7573652d64617368626f6172642e737667 68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f726f62736f6e74656e6f72696f2f6c69676874686f7573652d64617368626f6172642e737667 68747470733a2f2f696d672e736869656c64732e696f2f62616467652f736c61636b2d636861742d626c75652e7376673f6c6f676f3d736c61636b

Dashboard for Laravel Lighthouse GraphQL

⚠️ WORK IN PROGRESS! BREAKING CHANGES ARE EXPECTED!

This package adds a standalone analytics dasbhoard with metrics collected from Laravel Lighthouse GraphQL Server.

Requirements:

  • PHP >= 7.4
  • Laravel >= 8.x
  • Laravel Lighthouse >= 5.x

Questions? Join us in Slack Channel.


readme2.png

readme1.png

readme3.png

readme4.png

readme5.png

Install

Require the package.

composer require robsontenorio/lighthouse-dashboard

Publish package assets and config file.

php artisan lighthouse-dashboard:publish

Configure the package.

// config/lighthouse-dashboard.php

return [
    /**
     * Authenticated user attribute for identify the current client.
     * 
     * If there is no authenticated user a `anonymous` will be used.
     * Default is `Auth::user()->username`
     */

    'client_identifier' => 'username',

    /**
     * Database connection name for the dashboard.
     * 
     * By default it uses different connection. You must create it.
     * Or set it to `null` if want to use same connection from target app.
     */

    'connection' => 'dashboard',
];

Run package migrations.

php artisan lighthouse-dashboard:migrate

Open the dashboard.

http://your-app/lighthouse-dashboard

To keep the assets up-to-date and avoid issues in future updates, we highly recommend adding the command to the post-autoload-dump section in your composer.json file:

{    
    "scripts": {
        "post-autoload-dump": [            
            "@php artisan lighthouse-dashboard:publish-assets"
        ]
    }
}

Note about phpunit tests

This dashboard collects metrics by listening Nuwave\Lighthouse\Events\ManipulateResult . Make sure to disable this on your parent TestCase, in order to prevent metrics collecting while testing your app.

use Nuwave\Lighthouse\Events\ManipulateResult;

abstract class TestCase extends BaseTestCase
{    
    // use this Trait
    use DisableDashboardMetrics;

    public  function setUp(): void
    {
        parent::setUp();

        // Then, disable metrics while testing
        $this->withoutDashboardMetrics();
    }
}

How does it works?

See more ...

This package enables built-in Tracing extension from Laravel Lighthouse GraphQL Server. So, every operation automatically is profiled with its execution metrics.

  • GraphQL request is made.
  • Dashboard listen to ManipulateResult event and collect metrics from current operation.
  • Metrics are stored on dashboard.

The GraphQL server performance is not affected by this package, once metrics are collect after response is sent by server. You can also disable tracing output from server response. See "Configurations" section.

Configurations

See more ...

/config/lighthouse-dashboard.php

return [
    /**
     * Authenticated user attribute for identify the current client.
     * 
     * If there is no authenticated user a `anonymous` will be used.
     * Default is `Auth::user()->username`
     */

    'client_identifier' => 'username',

    /**
     * Database connection name for the dashboard.
     * 
     * By default it uses different connection. You must create it.
     * Or set it to `null` if want to use same connection from target app.
     */

    'connection' => 'dashboard',

    /**
     * Silent tracing.
     * 
     * This package auto-register TracingServiceProvider from "nuwave/lighthouse".     
     * This is a required feature to make this package working.     
     * 
     * If you want including tracing output on server response just set it to `false`.
     * 
     */

    'silent_tracing' => true,

    /**
     * Ignore clients.
     * 
     * Ignore all request from these clients based on `client_identifier`.     
     * 
     */

    'ignore_clients' => []
];

Tests

See more ...

# run once
composer test

# run in watch mode
composer test:watch

# run once with coverage report in terminal
# see full report in ./coverage/html/index.html
composer test:coverage

If you need to tweak UI see "Local development" section.

Local development

See more ...

Once this package includes UI, the only way to see it is by running it through target app.

Uninstall

If you previous installed this package, first uninstall it from target app.

Remove this entry from composer.json.

{    
    "scripts": {
        "post-autoload-dump": [ 
            "@php artisan lighthouse-dashboard:publish-assets"
        ]
    }
}

Remove package.

composer remove robsontenorio/lighthouse-dashboard

Remove package public assets from target app.

rm -rf /path/to/app/public/vendor/lighthouse-dashboard

Install locally

Clone the repository, then on target app add to composer.json

 "repositories": {
        "robsontenorio/lighthouse-dashboard": {
            "type": "path",
            "url": "/local/path/to/lighthouse-dashboard",
            "options": {
                "symlink": true
            }
        }
    }

Require local package version.

composer require robsontenorio/lighthouse-dashboard @dev

Then, create a symlink from package vendor folder to app public assets folder.

ln -s /path/to/app/vendor/robsontenorio/lighthouse-dashboard/public/vendor/lighthouse-dashboard /path/to/app/public/vendor

From target app enter to package vendor folder.

cd vendor/robsontenorio/lighthouse-dashboard

Install frontend dependencies and start it on dev mode.

yarn dev

Now all assets built inside package vendor folder will be symlinked to target app public vendor folder.

Then point to http://localhost:3000/lighthouse-dashboard/

Reference model

dashboard-model.png

Roadmap

  • Sumary for operations per clients.
  • UI navigation with anchor href when clicks on type return.
  • Add option to guard dashboard.
  • Add option for retention period.

Credits

Developed by Robson Tenório and contributors.

This work is highly inspired on Apollo Studio and powered by:

  • Laravel.
  • Lighthouse GraphQL.
  • InertiaJS.
  • Vuetify.