WebSocket connection fails.
See original GitHub issueHi,
I am trying to implement WebSocket subscriptions to Hasura and here is my client setup:
import ApolloClient from 'apollo-client';
import { WebSocketLink } from 'apollo-link-ws';
import { HttpLink } from 'apollo-link-http';
import { split } from 'apollo-link';
import { getMainDefinition } from 'apollo-utilities';
import { InMemoryCache } from 'apollo-cache-inmemory';
import { getToken } from 'services/auth0'
import { hasura } from 'config'
class HasuraDAO {
constructor() {
const wsLink = new WebSocketLink({
uri: hasura.wsUrl,
options: {
reconnect: true,
timeout: 30000
}
});
const httpLink = new HttpLink({
uri: hasura.httpUrl,
headers: {
'Authorization': `Bearer ${getToken()}`
}
})
const link = split(
({ query }) => {
const { kind, operation } = getMainDefinition(query);
return kind === 'OperationDefinition' && operation === 'subscription';
},
wsLink,
httpLink,
)
this.client = new ApolloClient({
link,
cache: new InMemoryCache()
});
}
}
export default new HasuraDAO()
This is the call of client.subscribe function:
import Hasura from 'dao/hasura/HasuraDAO';
import gql from 'graphql-tag';
const query = gql`subscription {
users {
id
}
}`
const observable = Hasura.client.subscribe({ query });
observable.subscribe({
next: ({ data }) => console.log(data)
});
I think I’m doing it all right, but still getting this error:
client.js:426 WebSocket connection to 'ws://localhost:8081/v1alpha1/graphql' failed: Data frame received after close
Can you please help me finding my mistake?
Issue Analytics
- State:
- Created 5 years ago
- Reactions:5
- Comments:9 (4 by maintainers)
Top Results From Across the Web
WebSocket connection failed: Error during ... - Stack Overflow
I just realized that websockets is working partially. I see a 101 Switching Protocols request in the Chrome developer console. However the only ......
Read more >WebSocket connection failed. Error in browser console, since ...
Starting from version 8.0.4, a lot of this messages: WebSocket connection to 'ws://ip_host:port/api/live/ws' failed: centrifuge.js:544 , started ...
Read more >WebSocket: error event - Web APIs | MDN
The error event is fired when a connection with a WebSocket has been closed due to an error (some data couldn't be sent...
Read more >Troubleshooting connection issues | Socket.IO
You are trying to reach a plain WebSocket server; The server is not reachable; The client is not compatible with the version of...
Read more >Error with WebSocket - Microsoft Q&A
The error event is fired when a connection with a WebSocket has been closed due to an error (some data couldn't be sent...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
Top Related Hashnode Post
No results found
Re-opening this issue so that we add it to our docs! Thanks @russc for bringing it back up.
Even with the solution of @louisdvs I still get this error when using
wss:
instead ofws:
.Does anybody know how to fix this?