Skip to content

Navigation Menu

Sign in
Sign up

Broadcasting not working on my project. #2652

Unanswered
AbhinavNmdo asked this question in Q&A
Discussion options

My lighthouse broadcasting is not working. I followed the instructions mentioned in the docs, but it is not working.

Here are my codes.
message.graphql (which is imported in the schema.graphql)

type Subscription {
 messageSent(chatId: ID): Message! @subscription(class: "App\\GraphQL\\Subscriptions\\MessageSent")
}
extend type Mutation {
 sendMessage(
 messageId: ID @rules(apply: ["nullable", "exists:messages,id,deletedAt,NULL"])
 chatId: ID! @rules(apply: ["required", "exists:chats,id,deletedAt,NULL"])
 userId: ID! @rules(apply: ["required", "exists:users,id,deletedAt,NULL"])
 message: String! @rules(apply: ["required", "max:2024"])
 ): Message! @create @guard @broadcast(subscription: "messageSent")
 
 reactOnMessage(
 messageId: ID! @rules(apply: ["required", "exists:messages,id,deletedAt,NULL"])
 userId: ID! @rules(apply: ["required", "exists:users,id,deletedAt,NULL"])
 reaction: String! @rules(apply: ["required", "max:255"])
 ): Reaction! @create @guard
 
 removeReaction(
 id: ID! @eq @rules(apply: ["required", "exists:reactions,id"])
 ): Reaction! @delete @guard
}

MessageSent.php

<?php declare(strict_types=1);
namespace App\GraphQL\Subscriptions;
use GraphQL\Type\Definition\ResolveInfo;
use Illuminate\Http\Request;
use Nuwave\Lighthouse\Schema\Types\GraphQLSubscription;
use Nuwave\Lighthouse\Subscriptions\Subscriber;
use Nuwave\Lighthouse\Support\Contracts\GraphQLContext;
final class MessageSent extends GraphQLSubscription
{
 /** Check if subscriber is allowed to listen to the subscription. */
 public function authorize(Subscriber $subscriber, Request $request): bool
 {
 return true;
 }
 /** Filter which subscribers should receive the subscription. */
 public function filter(Subscriber $subscriber, mixed $root): bool
 {
 return true;
 }
}
LIGHTHOUSE_SUBSCRIPTION_STORAGE=file
LIGHTHOUSE_SUBSCRIPTION_STORAGE_TTL=3600

didn't see anything in the debug console.
image
image

You must be logged in to vote

Replies: 0 comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant
Converted from issue

This discussion was converted from issue #2651 on January 13, 2025 10:35.

AltStyle によって変換されたページ (->オリジナル) /