Error with WebSockets and headers containing arrays
See original GitHub issueExpected 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:
- Created 4 years ago
- Comments:6 (3 by maintainers)
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?
@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\"]"