I get the error Cannot read property 'handler' of undefined at WebSocket.client.onmessage when I run this code:
import ApolloClient, { createNetworkInterface } from 'apollo-client';
import {SubscriptionClient, addGraphQLSubscriptions} from 'subscriptions-transport-ws';
//import { Client } from 'subscriptions-transport-ws';
// creates a subscription ready Apollo Client instance
// Note that scaphldUrl expects the url without the http:// or wss://
function makeApolloClient(scapholdUrl) {
const graphqlUrl = `https://${scapholdUrl}`;
const websocketUrl = `wss://${scapholdUrl}`;
// Create regular NetworkInterface by using apollo-client's API:
const networkInterface = createNetworkInterface({uri: graphqlUrl});
console.log("websocketUrl", websocketUrl)
// Create WebSocket client
const wsClient = new SubscriptionClient(websocketUrl, {
reconnect: true,
connectionParams: {
// Pass any arguments you want for initialization
}
});
//.......
}
Subscriptions seems to be working (my list of items gets longer when I insert items in an other browser)
Is this error important ?
@kjetilge , can you please share a repository with code that reproduce the error?
Also, which version of subscriptions-transport-ws do you use?
Thanks
Here is a repo: https://github.com/kjetilge/messageApp
And the subscriptions-transport-ws version is: 0.5.4
@kjetilge I've ran your code and it looks like scaphold server is using an older version of the transport that doesn't recognize the INIT message.
I guess it's a bit of our fault as it was a breaking change but released as a patch version...
pinging @vning93 @mlp5ab
Thanks!
I am getting the same error. It seems the message handler cannot handle initialization errors, that happen before a connection is stablished.
Hey @Urigo @kjetilge @marano! Thanks for raising the issue. We'll upgrade the server package shortly.
@Urigo It seems to me that even if the server can't handle the INIT message, which was the case, the client message handler should not break with an exception like this.
@marano , I would generally agree with you, but the change has a big impact on the socket flow.
It should have been a major version change, but we are still not on 1.0. But we are getting closer..
Thank you @vning93
@Urigo @marano I just pushed an updated version of this. We do some extra wizardry in our websocket implementation but it should be working now. Please let me know if you experience any further issues 馃憤
hey @Urigo, I'm occasionally seeing a race condition here when I unsubscribe() around the time that I get SUBSCRIPTION_DATA -- adding a simple check in #78 but thought it was worth mentioning
Fixed and released (0.7.0), thank you @kjetilge
Most helpful comment
Hey @Urigo @kjetilge @marano! Thanks for raising the issue. We'll upgrade the server package shortly.