hidjou / classsed-graphql-mern-apollo

408 stars 255 forks source link

Unhandled Rejection (Error): Cannot read property 'req' of undefined #19

Closed ghost closed 3 years ago

ghost commented 3 years ago

When deleting a comment in singlePost view i ll get this error my code looks like this :

`

const [deletePostOrMutation] = useMutation(mutation, {
     update(proxy, result) {
          setModalShow(false);
           if (!commentId) {
                const data = proxy.readQuery({
                    query: FETCH_POSTS_QUERY
               });

            let newData = [...data.getPosts];
            newData = data.getPosts.filter((p) => p.id !== postId);

            proxy.writeQuery({ 
                query: FETCH_POSTS_QUERY, 
                data: {
                    ...data.getPosts,
                    getPosts: {
                        newData
                    }
                }
            });
        }   
        if (callback) callback();
    },
    variables: {
        postId,
        commentId
    }
})`

What am i missing here ? Thanks