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

Type error in Reverb with GraphQL subscription (Lighthouse package) #120

Closed
wmt-web-pruthvip opened this issue Mar 29, 2024 · 6 comments
Closed
Assignees

Comments

@wmt-web-pruthvip
Copy link

wmt-web-pruthvip commented Mar 29, 2024

Reverb Version

1.0.0-beta4

Laravel Version

10.48.4

PHP Version

8.2.17

Description

I am using the Laravel Reverb package with GraphQL subscriptions implemented using the Lighthouse package (v6.35.0). 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:

{
    "event": "pusher:subscribe",
    "data": {
        "channel_data": {
            "user_id": "f76076ed4081e927b1a54bf510992f2c",
            "user_info": []
        },
        "channel": "private-lighthouse-uyeyl2Vnz2MXRHdVMly4lg2YnTKufVqS-1711692828"
    }
}

When running in --debug mode, an additional error is thrown:

TypeError json_decode(): Argument #1 ($json) must be of type string, array given at vendor/laravel/reverb/src/Loggers/CliLogger.php:57

This error occurs because the channel_data value in the payload is also being treated as an array instead of a string.

A possible fix for --debug might be to add a condition check for the channel_data value, similar to the existing check for the data value, before attempting to decode it using json_decode. The condition could be something like && is_string($message['data']['channel_data']).

Additional Information:

If you need any further details about the Lighthouse implementation or any other relevant information, I will provide them to help better understand and resolve the issue.

Steps To Reproduce

start a reverb server running via reverb:start or reverb:start --debug. Use the lighthouse package with the LIGHTHOUSE_BROADCASTER=echo driver.

@joedixon
Copy link
Contributor

joedixon commented Apr 4, 2024

@wmt-web-pruthvip to confirm, is this an issue only with debug mode enabled?

@wmt-web-pruthvip
Copy link
Author

No, if debug mode is enabled, I get an error at Loggers/CliLogger.php:57. And without it gives at Pusher/EventHandler.php:56.

@wmt-web-pruthvip
Copy link
Author

Even though it is working normally (with events), I am able to subscribe to the channel and receive updates. I am only having problems with graphql subscription.

@joedixon
Copy link
Contributor

joedixon commented Apr 4, 2024

The payload looks incorrect to me. When subscribing to a private channel, the payload should look more like below. Notice the requirement to pass through an auth token.

{
  "event":"pusher:subscribe",
  "data":{
    "auth":"super-secret-token",
    "channel":"private-channel"
  }
}

@wmt-web-pruthvip
Copy link
Author

This payload is set from the lighthouse package here. I think that needs to be updated for support.

Thanks for the update.

@joedixon
Copy link
Contributor

joedixon commented Apr 4, 2024

OK, closing this for now.

@joedixon joedixon closed this as completed Apr 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants