apollographql / react-apollo

:recycle: React integration for Apollo Client
https://www.apollographql.com/docs/react/
MIT License
6.85k stars 790 forks source link

useSubscription doesn't work for new windows #4016

Open developdeez opened 4 years ago

developdeez commented 4 years ago

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);
      }
    }
  }
};