I'm trying to create a subscription in Apollo client, but every time I save my component, which causes a refresh, I get this error:
Here's my code:
const QUERY = gql`
{
getEventsSection(id: "trending") {
_id,
events
}
}
`;
const SUBSCRIPTION = gql`
subscription {
getEventsSection(id: "trending") {
_id,
events
}
}
`;
const [state, setState] = useState(null);
const { loading, error, data, subscribeToMore } = useQuery(QUERY);
useEffect(() => {
const unsubscribe = subscribeToMore({
document: SUBSCRIPTION,
updateQuery: (prev, {subscriptionData}) => {
console.log(subscriptionData);
}
});
return () => unsubscribe();
}, [data])
What am I doing wrong? Thanks!