buoy/lighthouse-fairway
最新稳定版本:v0.2.0
Composer 安装命令:
composer require buoy/lighthouse-fairway
包简介
Adding Fairway-compliance to the Lighthouse GraphQL server for Laravel
README 文档
README
This extension brings Fairway-compatibility to Lighthouse, which makes it fully compatible with the Buoy-client.
Installation
composer require buoy/lighthouse-fairway
Then publish the configuration.
php artisan vendor:publish --tag=lighthouse-fairway-config
Then create the class that will handle authorization and filtering for your subscriptions:
<?php namespace App\GraphQL\Subscriptions; use Buoy\LighthouseFairway\Subscriptions\FairwayModelEventSubscription; use Illuminate\Http\Request; use Nuwave\Lighthouse\Subscriptions\Subscriber; class FairwayModelSubscription extends FairwayModelEventSubscription { public function authorize(Subscriber $subscriber, Request $request): bool { // Authorize the user return true; } public function filterSubscription(Subscriber $subscriber, $root): bool { // Add filtering here. Filtering based on event type is handled for you. return true; } }
Lastly, enter the namespace for your subscription-class in the lighthouse-fairway.php config-file
Usage
This library adds some shortcuts to making models subscribable.
Subscribable-directive
The directive is applied to the model type. In this example, we assume the model App\Models\Note exists.
type Note @subscribable { id text }
Applying the @subscribable directive will automatically add following to your schema:
enum EventType { CREATE UPDATE DELETE } type NoteEvent { "ID of the model" id: ID! "Type of the event" event: EventType! "The model that has been modified" model: Note! } type Subscription { noteModified( "Limit the subscription to a specific model" id: ID, "Limit the subscription to specific events" events: [EventType!] ): NoteEvent }
The @subscribable directive can also use a custom subscription class if needed:
type Note @subscribable(class: "\\\\App\\\\GraphQL\\\\Subscriptions\\\\MyCustomSubscription") { id text }
Just make sure that it returns data that conforms to the generated schema.
It is recommended to extend Buoy\LighthouseFairway\Subscriptions\FairwayModelEventSubscription in order to maintain the event-type filtering.
Dispatching events
Events are dispatched with the Broadcast-utility. Simply supply the model and event type, and the event will be broadcast to all authorized subscribers.
$note = App\Models\Note::first(); Buoy\LighthouseFairway\Util\Broadcast::modelEvent($note, 'update');
统计信息
- 总下载量: 12.9k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-01-19