我试图在 2 周内找到 Lighthouse 订阅的最佳实践。
但是直到现在我都找不到最佳实践。
这是我的 shema.graphql
type Subscription {
rsvHolidaySub(id: ID): Rsv_holiday }
type Mutation {
updateHoliday(id: ID!, holiday_type: Int!): Rsv_holiday @update
@broadcast(subscription: "rsvHolidaySub") }
type Rsv_holiday {
id: ID!
holiday_type: Int!
start_time: String!
end_time: String! }
updateHoliday
当我像下面这样查询突变时
我希望从调用 RsvHolidaySub 解析函数@broadcast(subscription: "rsvHolidaySub")
所以我可以这样广播
class RsvHolidaySub extends GraphQLSubscription
{
public function __construct() {}
public function authorize(Subscriber $subscriber, Request $request): bool {}
public function filter(Subscriber $subscriber, $root): bool {}
public function encodeTopic(Subscriber $subscriber, string $fieldName): string {}
public function decodeTopic(string $fieldName, $root): string {}
public function resolve($root, array $args, GraphQLContext $context, ResolveInfo $resolveInfo): Rsv_holiday
{
// I wanna call broadcast in here!!!!!!
broadcast(new SomeEvent);
return $root;
}
}
我不知道这是订阅的最佳做法。但我认为这是非常简单和干净的。
但即使我使用 redis + laravel-echo-server 或 Beyondcode/laravel-websockets 安装了 websocket,也不会调用 resolve 函数。
所以我怀疑这是否可能。
我真的很想知道 Lighthouse 订阅的最佳实践。请分享你的知识。