question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error with WebSockets and headers containing arrays

See original GitHub issue

Expected Behavior I expect to be able to connect to the server via WebSocketLink with authentication headers.

Actual Behavior When I have an array in my headers parameters I get the error “start received before the connection is initialised”.

This may be an error with Hasura or the GraphQL engine. I found the error message in the source here, https://github.com/hasura/graphql-engine/blob/master/server/src-lib/Hasura/GraphQL/Transport/WebSocket.hs#L239.

I’ve submitted an issue to apollographql/apollo-link as well, https://github.com/apollographql/apollo-link/issues/1109.

A simple reproduction When including x-hasura-allowed-roles as an array, I get the mentioned error. When I remove x-hasura-allowed-roles and/or replace the array with an empty string, everything works as expected.

  const wsLink = new WebSocketLink({
    uri: GRAPHQL_WSS_DEVELOPMENT,
    options: {
      lazy: true,
      reconnect: true,
      connectionParams: {
        headers: {
          'authorization': "Bearer eyJ0eX...",
          'x-hasura-auth0-user-id': "auth0|5d1...",
          'x-hasura-default-role': "userFree",
          'x-hasura-allowed-roles': ["admin", "driver", "userFree", "userPaid"],
          'x-hasura-email': "aj+d01@riffcreativestudio.com",
          'x-hasura-role': "driver",
        }
      }
    }
  })

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
ighormartinscommented, Feb 22, 2021

Sorry I missed this.

Should I just be putting ‘authorization’: “Bearer eyJ0eX…” into the header and having Hasura read information out of the encrypted token?

Yes, graphql-engine will read the session data from the token (the token isn’t encrypted, it is signed).

Actually, I think this might be a problem in some cases. I’m using JWT auth mode, however, for anonymous users before signing-in, I have to send a header with the x-hasura-org-id. How can I do it?

0reactions
mehtadev17commented, Jan 28, 2021

@marionschleifer When you say “string array” https://hasura.io/docs/1.0/graphql/core/auth/authentication/jwt.html#claims-map

does it mean an array of strings: ["editor","user", "mod"] or a string containing an array: "[\"editor\",\"user\", \"mod\"]"

Read more comments on GitHub >

github_iconTop Results From Across the Web

Failing to get websocket response in python - Stack Overflow
There's a bug in my code on map(lambda x: x.strip().lower(), header) which was essentially changing the key by converting into lower case for ......
Read more >
WebSocket - The Modern JavaScript Tutorial
Here's an example of browser headers for a request made by new WebSocket("wss://javascript.info/chat") . GET /chat Host: javascript.info Origin ...
Read more >
tornado.websocket — Bidirectional communication to the ...
Implementation of the WebSocket protocol. WebSockets allow for bidirectional communication between the browser and server. WebSockets are supported in the ...
Read more >
WebSockets: libsoup Reference Manual
Looks at the response status code and headers in msg and determines if they contain a valid WebSocket handshake response (given the handshake...
Read more >
18 Using the WebSocket Protocol in WebLogic Server
The client applies the same operation to the value of the Sec-WebSocket-Key header. If the result matches the value received from the server,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found