0

This is my first time using useSub and I noticed that although my backend sends it's responses to the client (at least the console.log shows it is). 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"

Query

export const INCOMING_VIDEO_CHAT = gql`
  subscription {
    incomingVideoChat {
      rn
      p
    }
  }
`;

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);
  }
}
}
};
notElonMusk
  • 314
  • 1
  • 4
  • 21

1 Answers1

1

You can use Chrome Dev Tools to check if useSubscription connects correctly. In the Network tab of the Chrome DevTools, you should switch the filter to WS to see and debug your Apollo GraphQL subscription. You should read it.

Michael
  • 1,806
  • 2
  • 11
  • 20