Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GraphQL subscription with Laravel Reverb #2564

Closed
michaelLoeffelmann opened this issue Jun 7, 2024 · 5 comments · Fixed by #2639
Closed

GraphQL subscription with Laravel Reverb #2564

michaelLoeffelmann opened this issue Jun 7, 2024 · 5 comments · Fixed by #2639
Labels
bug An error within Lighthouse

Comments

@michaelLoeffelmann
Copy link

When a subscription request is received by Reverb, it throws the following error:

TypeError Laravel\Reverb\Protocols\Pusher\EventHandler::subscribe(): Argument #4 ($data) must be of type ?string, array given, called in /var/www/DemoGraphQL/vendor/laravel/reverb/src/Protocols/Pusher/EventHandler.php on line 29 at vendor/laravel/reverb/src/Protocols/Pusher/EventHandler.php:56

The error is caused by the payload data being an array instead of a string, which is expected by the subscribe method in the EventHandler class.

The payload that triggers the error looks like this:

[
  "channel_data" => [
    "user_id" => "363c7a56eee7c386bf2c4ac980b661e6"
    "user_info" => []
  ]
  "channel" => "private-lighthouse-vEibwD5lS5FA0xmHHrMuH3Z5A8nVSvbC-1717741629"
]

The authorizedMethod in the EchoBroadcaster Class should send an string for 'channel_data' instead an array.

Steps to reproduce

  1. Starting laravel reverb
  2. Add an Subscription to the Frontend

Output/Logs

Laravel Exception
  TypeError 

  Laravel\Reverb\Protocols\Pusher\EventHandler::subscribe(): Argument #4 ($data) must be of type ?string, array given, called in /Users/dev/Herd/lv-ep-gw-api/vendor/laravel/reverb/src/Protocols/Pusher/EventHandler.php on line 29

  at vendor/laravel/reverb/src/Protocols/Pusher/EventHandler.php:56
     52▕ 
     53▕     /**
     54▕      * Subscribe to the given channel.
     55▕      */
  ➜  56▕     public function subscribe(Connection $connection, string $channel, ?string $auth = null, ?string $data = null): void
     57▕     {
     58▕         $channel = $this->channels
     59▕             ->for($connection->app())
     60▕             ->findOrCreate($channel);

Lighthouse Version

6.36.3

@spawnia spawnia added the bug An error within Lighthouse label Jun 28, 2024
@spawnia
Copy link
Collaborator

spawnia commented Jun 28, 2024

Could it be the case that previous versions of Laravel Reverb required an array? How can we fix this without breaking backwards compatibility?

@sOmiloef
Copy link

I don't know if older versions required an array. Maybe you can add a new Driver for laravel reverb, that can be set like this: LIGHTHOUSE_BROADCASTER=reverb in the config.

@spawnia
Copy link
Collaborator

spawnia commented Jul 15, 2024

I personally do not use subscriptions, so I do not plan to work on this. Feel free to contribute.

@dstemberger
Copy link

I faced the same issue and fixed it by reusing the pusher driver for the reverb connection. #2612

@spawnia
Copy link
Collaborator

spawnia commented Dec 11, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An error within Lighthouse
Projects
None yet
4 participants