Subscription testing
This commit is contained in:
parent
d8b5904ef5
commit
b28e53d333
79
classes/Aircraft.php
Normal file
79
classes/Aircraft.php
Normal file
@ -0,0 +1,79 @@
|
||||
<?php namespace GermanAirlinesVa\Fleet\Classes;
|
||||
|
||||
use GermanAirlinesVa\Fleet\Models\Aircraft as Model;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Http\Request;
|
||||
use GraphQL\Type\Definition\ResolveInfo;
|
||||
use Nuwave\Lighthouse\Subscriptions\Subscriber;
|
||||
use Nuwave\Lighthouse\Schema\Types\GraphQLSubscription;
|
||||
use Nuwave\Lighthouse\Support\Contracts\GraphQLContext;
|
||||
|
||||
class Aircraft extends GraphQLSubscription
|
||||
{
|
||||
/**
|
||||
* Check if subscriber is allowed to listen to the subscription.
|
||||
*
|
||||
* @param \Nuwave\Lighthouse\Subscriptions\Subscriber $subscriber
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize(Subscriber $subscriber, Request $request): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter which subscribers should receive the subscription.
|
||||
*
|
||||
* @param \Nuwave\Lighthouse\Subscriptions\Subscriber $subscriber
|
||||
* @param mixed $root
|
||||
* @return bool
|
||||
*/
|
||||
public function filter(Subscriber $subscriber, $root): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Encode topic name.
|
||||
*
|
||||
* @param \Nuwave\Lighthouse\Subscriptions\Subscriber $subscriber
|
||||
* @param string $fieldName
|
||||
* @return string
|
||||
*/
|
||||
public function encodeTopic(Subscriber $subscriber, string $fieldName): string
|
||||
{
|
||||
// Create a unique topic name based on the `author` argument
|
||||
return Str::snake($fieldName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode topic name.
|
||||
*
|
||||
* @param string $fieldName
|
||||
* @param \App\Post $root
|
||||
* @return string
|
||||
*/
|
||||
public function decodeTopic(string $fieldName, $root): string
|
||||
{
|
||||
return Str::snake($fieldName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve the subscription.
|
||||
*
|
||||
* @param \App\Post $root
|
||||
* @param array<string, mixed> $args
|
||||
* @param \Nuwave\Lighthouse\Support\Contracts\GraphQLContext $context
|
||||
* @param \GraphQL\Type\Definition\ResolveInfo $resolveInfo
|
||||
* @return mixed
|
||||
*/
|
||||
public function resolve($root, array $args, GraphQLContext $context, ResolveInfo $resolveInfo): Model
|
||||
{
|
||||
// Optionally manipulate the `$root` item before it gets broadcasted to
|
||||
// subscribed client(s).
|
||||
$root->load();
|
||||
|
||||
return $root;
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user