robsontenorio / lighthouse-dashboard

Dashboard for Laravel Lighthouse GraphQL.
21 stars 3 forks source link

Dashboard for Laravel Lighthouse GraphQL

:warning: WORK IN PROGRESS! BREAKING CHANGES ARE EXPECTED!

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

Requirements:

Questions? Join us in Slack Channel.










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 ```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 ...

```bash # 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`. ```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` ```json "repositories": { "robsontenorio/lighthouse-dashboard": { "type": "path", "url": "/local/path/to/lighthouse-dashboard", "options": { "symlink": true } } } ``` Require local package version. ```sh composer require robsontenorio/lighthouse-dashboard @dev ``` Then, create a symlink from package vendor folder to app public assets folder. ```sh 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. ```sh cd vendor/robsontenorio/lighthouse-dashboard ``` Install frontend dependencies and start it on dev mode. ```sh 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

Roadmap

Credits

Developed by Robson Tenório and contributors.

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