react-apollo icon indicating copy to clipboard operation
react-apollo copied to clipboard

useSubscription doesn't work for new windows

Open developdeez opened this issue 5 years ago • 0 comments

Hello

This is my first time using useSub and I noticed that although my backend sends it's responses to the client. The client using useSub doesn't do anything. I usually use subscribeToMore with query, but for this job I want to only get the most updated info. Is there a way to check if useSub connects correctly? Or is it broken in "@apollo/react-hooks": "^3.1.3"

Client

  const { data, loading } = useSubscription(INCOMING_VIDEO_CHAT, {
    onSubscriptionData: ({  subscriptionData }) => {
      console.log(subscriptionData);
    }
  });

Server:

module.exports = {
  type: chatInfoType,
  subscribe: () => pubsub.asyncIterator(INCOMING_VIDEO_CHAT),
  async resolve(payload, { }, req) {
    if (auth.isAuthenticated(req)) {
      if (!payload) {
        return;
      }
      const { userID, rn, p } = payload;

      try {
        if (req.id === userID) {
          return { rn, p };
        } else {
          return;
        }
      } catch (e) {
        throw new Error(e);
      }
    }
  }
};

developdeez avatar Jun 09 '20 04:06 developdeez