这是indexloc提供的服务,不要输入任何密码
Skip to content

Subscription not working in console running locally #9475

@marcosfons

Description

@marcosfons

Version Information

CLI Version: Currently using v2.19.0

What is the current behaviour?

Subscriptions does not work in the API Explorer when running the console locally connected to an external Hasura instance that only support HTTPS/WSS. Query and mutations works without problems (uses HTTPS). But, the subscriptions does not work because they are trying to use WS instead of WSS.

What is the expected behaviour?

Subscriptions works in the API Explorer when running the console locally connected to an external Hasura instance that does not support HTTP/WS.

How to reproduce the issue?

  1. Create the configuration files to connect to an external Hasura instance: hasura init --endpoint "https://your-hasura-domain"
  2. Launch the Hasura console: hasura console
  3. Create and track tables to use for subscriptions
  4. Go to the API Explorer tab and create some valid subscription
  5. Open the Network tab of the browser developer tools
  6. Filter the url by the websocket scheme: ws
  7. Run the subscription
  8. Wait until you see some request in the network tab using ws instead of wss

Screenshots or Screencast

The next image show in the left panel that I'm using HTTPS, but in the right side in the network tab it's trying to connect using WS instead of WSS. (The image was edited just to remove the hasura instance domain).

hasura_issue_screenshot

Any possible solutions/workarounds you're aware of?

I searched the codebase and found a commit that probably introduced this "unexpected" behavior. In the code section below the url used to make the connection for the subscription executes the getWebsocketProtocol function using the window.location.protocol.

const websocketProtocol = getWebsocketProtocol(window.location.protocol);

But when running the console locally connected to an external Hasura instance window.location points to http://localhost, with the HTTP protocol (that after is transformed to WS). And instead, it should use the GraphQL Endpoint of the external instance that uses HTTPS.

Keywords

WSS, WS, websocket, subscription

Metadata

Metadata

Assignees

No one assigned

    Labels

    k/bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions