nuwave / nuwave/lighthouse

Subscription send only to others

Open
#2,293 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
PHP
Stars
3.5k
Forks
468
Avg merge
3h 9m
Merged PRs (30d)
2

Description

https://laravel.com/docs/9.x/broadcasting#only-to-others

I think it is a really nice feature to have and it should be very simple to achieve it, since it's only a ready function that needs to be called.

What problem does this feature proposal attempt to solve?

When building an application that utilizes event broadcasting, you may occasionally need to broadcast an event to all subscribers to a given channel except for the current user.

Which possible solutions should be considered?

I think this feature is only for the Laravel Echo's broadcaster searching in your codebase I think I found where that method should be added: https://github.com/nuwave/lighthouse/blob/8756e1e5131aad489609eefd3424321d6cb76d99/src/Subscriptions/Broadcasters/EchoBroadcaster.php#L26

I noticed the autocompletion working there making this possible:

    public function broadcast(Subscriber $subscriber, $data): void
    {
        $this->broadcaster->event(
            new EchoSubscriptionEvent($subscriber->channel, $data)
        )->toOthers();
    }

Let me share my findings (haven't actually run the code just looked for now), this is the trace I did:

\Nuwave\Lighthouse\Execution\Utils\Subscription::broadcast

Going in:

/vendor/nuwave/lighthouse/src/Execution/Utils/Subscription.php

            if ($shouldQueue) {
                $broadcaster->queueBroadcast($subscription, $subscriptionField, $root);
            } else {
                $broadcaster->broadcast($subscription, $subscriptionField, $root);
            }

queue's job calls $broadcaster->broadcast again internally so let's see:

/vendor/nuwave/lighthouse/src/Subscriptions/SubscriptionBroadcaster.php
                $this->broadcastManager->broadcast(
                    $subscriber,
                    $this->graphQL->serializable($executionResult)
                );

Which leads to:

vendor/nuwave/lighthouse/src/Subscriptions/BroadcastManager.php

and there we find the echo driver:

vendor/nuwave/lighthouse/src/Subscriptions/Broadcasters/EchoBroadcaster.php

Inside that we'll reach
https://github.com/nuwave/lighthouse/blob/8756e1e5131aad489609eefd3424321d6cb76d99/src/Subscriptions/Broadcasters/EchoBroadcaster.php#L26

So that should be it, we could pass along some data to the Queue Job and the other one, for an extra $toOthers and that can be used, it sounds like a pretty important feature that I still doubt whether this is already implemented and I missed it, nevertheless let me know what you think.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with src/Subscriptions/Broadcasters/EchoBroadcaster.php and trace the calls through src/Execution/Utils/Subscription.php, src/Subscriptions/SubscriptionBroadcaster.php, and src/Subscriptions/BroadcastManager.php. Compare the direct and queued broadcast paths, then determine how the requested send-to-others behavior should be represented and verify that both paths support it.

Written by the indexing model from the issue text.

Assessment

Tech stack
graphql, laravel, php
Domain
api, backend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.