robsontenorio / lighthouse-dashboard
Laravel Lighthouse GraphQL的仪表板
Requires
- illuminate/support: ~8|~9
- inertiajs/inertia-laravel: ^0.2.12|^0.6.9
- nuwave/lighthouse: dev-master||^5
Requires (Dev)
- mockery/mockery: ^1.4
- nunomaduro/collision: ^5.0
- orchestra/testbench: ^6.1
- pestphp/pest: ^0.3.6
- phpunit/phpunit: ^9.3
- spatie/phpunit-watcher: ^1.22
This package is auto-updated.
Last update: 2023-08-25 12:35:29 UTC
README
Laravel Lighthouse GraphQL仪表板
⚠️正在进行中!预计会有破坏性更改!
此包添加了一个独立的分析仪表板,其中包含从Laravel Lighthouse GraphQL服务器收集的指标。
要求
- PHP >= 7.4
- Laravel >= 8.x
- Laravel Lighthouse >= 5.x
有问题?加入我们的Slack频道。





安装
需要此包。
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/
参考模型

路线图
- 针对客户操作摘要。
- 当点击返回类型时,使用锚点href进行UI导航。
- 为仪表板添加保护选项。
- 为保留期添加选项。
鸣谢
由 Robson Tenório 和 贡献者 开发。
此作品深受 Apollo Studio 的启发并由
- Laravel.
- Lighthouse GraphQL.
- InertiaJS.
- Vuetify.