robsontenorio/lighthouse-dashboard

此包已被废弃,不再维护。没有建议的替代包。

Laravel Lighthouse GraphQL的仪表板

0.20.2 2023-01-25 17:09 UTC

README

dashboard.png

68747470733a2f2f636f6465636f762e696f2f67682f726f62736f6e74656e6f72696f2f6c69676874686f7573652d64617368626f6172642f6272616e63682f6d61737465722f67726170682f62616467652e737667 68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f726f62736f6e74656e6f72696f2f6c69676874686f7573652d64617368626f6172642e737667 68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f726f62736f6e74656e6f72696f2f6c69676874686f7573652d64617368626f6172642e737667 68747470733a2f2f696d672e736869656c64732e696f2f62616467652f736c61636b2d636861742d626c75652e7376673f6c6f676f3d736c61636b

Laravel Lighthouse GraphQL仪表板

⚠️正在进行中!预计会有破坏性更改!

此包添加了一个独立的分析仪表板,其中包含从Laravel Lighthouse GraphQL服务器收集的指标。

要求

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

有问题?加入我们的Slack频道


readme2.png

readme1.png

readme3.png

readme4.png

readme5.png

安装

需要此包。

composer require robsontenorio/lighthouse-dashboard

发布包资源和配置文件。

php artisan lighthouse-dashboard:publish

配置此包。

// 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',
];

运行包迁移。

php artisan lighthouse-dashboard:migrate

打开仪表板。

http://your-app/lighthouse-dashboard

为了保持资源更新并避免未来更新中的问题,我们强烈建议将命令添加到您的composer.json文件中的post-autoload-dump部分。

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

关于phpunit测试的说明

此仪表板通过监听Nuwave\Lighthouse\Events\ManipulateResult来收集指标。请确保在您的父TestCase中禁用此功能,以防止在测试您的应用程序时收集指标。

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();
    }
}

它是如何工作的?

查看更多...

此包启用了Laravel Lighthouse GraphQL服务器内置的Tracing扩展。因此,每个操作都会自动进行性能分析,并记录其执行指标。

  • 执行GraphQL请求。
  • 仪表板监听ManipulateResult事件并从当前操作收集指标。
  • 指标存储在仪表板中。

在服务器响应后发送指标后,此包不会影响GraphQL服务器的性能。您还可以禁用服务器响应中的跟踪输出。请参阅“配置”部分。

配置

查看更多...

/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' => []
];

测试

查看更多...

# 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

如果您需要调整UI,请参阅“本地开发”部分。

本地开发

查看更多...

一旦此包包含UI,唯一查看它的方法是运行目标应用程序。

卸载

如果您之前已安装此包,请先从目标应用程序中卸载。

composer.json中删除此条目。

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

删除包。

composer remove robsontenorio/lighthouse-dashboard

从目标应用程序中删除包的公共资源。

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

本地安装

克隆仓库,然后在目标应用程序中将其添加到composer.json

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

需要本地包版本。

composer require robsontenorio/lighthouse-dashboard @dev

然后,从包供应商文件夹创建一个符号链接到应用程序公共资产文件夹。

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

从目标应用程序进入包供应商文件夹。

cd vendor/robsontenorio/lighthouse-dashboard

安装前端依赖项并以开发模式启动它。

yarn dev

现在,在包供应商文件夹内构建的所有资产都将链接到目标应用程序的公共供应商文件夹。

然后指向 https://:3000/lighthouse-dashboard/

参考模型

dashboard-model.png

路线图

  • 针对客户操作摘要。
  • 当点击返回类型时,使用锚点href进行UI导航。
  • 为仪表板添加保护选项。
  • 为保留期添加选项。

鸣谢

Robson Tenório贡献者 开发。

此作品深受 Apollo Studio 的启发并由

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