Closed Panoplos closed 7 years ago
@Panoplos The SC protocol doesn't require each event to have a cid - It is only necessary to provide one if the client expects a response from the server.
Currently, the socketcluster-client only generates a cid if the emit was given a callback as a third argument like this:
socket.emit('graphql', data, function (err, data) {
// Handle response here.
});
Emitted events which don't have a response handler are not tracked by the client or server so that's why there is no need for a cid. You can provide your own application-level id as part of the data object if you like.
Is there a reason you want to use the cid specifically? We could add an option to the SC client to make it always send a cid...
Well, it is not a request for the cid as much as trying to figure out why the client is not receiving any response back. I am using socket.on('graphql', ...)
after calling emit
. Is this the wrong way to go about it?
OK, I see you are saying that a response from the server will be ignored server-side without a callback being specified on the client. Correct? I changed to a callback mechanism and now am getting a response. I based this code off of a youtube tutorial. Seems they had it wrong. The documentation uses callbacks, so I shall go that route.
@Panoplos You can do it like you mentioned before, but then you'd have to explicitly invoke socket.emit('graphql', ...)
from the server side too and it doesn't guarantee that it's a response to THAT specific emit. If you provide a callback then you can individually track multiple emits of the same event.
The docs for that are here: http://socketcluster.io/#!/docs/handling-failure
Thanks for the help. Closed.
I have the following code that I am using to wire up a network interface for
apollo-client
:The server side is quite simple, too:
Which is called by:
When utilising this code, the server is not responding to the
socket.emit(...)
. I traced into the thescsocket.js
andresponse.js
call stack to see what might be going wrong, and it appears that theResponse.id
is not getting set. With other message types, I can see that thecid
is set to something, so theResponse
constructor sets its id appropriately, but for some reason my 'graphql' message does not have acid
. Here is an example of what is getting sent, pinched fromscsocket.js
`this.socket.on('message',...):I didn't see anywhere in the docs that it is necessary for me to append a
cid
to my message, so there must be something wrong in my code. Any clarification will be greatly appreciated.