OnError Apollo i will like to show/display the error
unutoiul opened this issue · 3 comments
unutoiul commented
const errorLink: any = onError(
({ operation, forward, graphQLErrors, networkError }) => {
const { dispatchModal } = useContext<IModalContext>(ModalContext);
console.log(operation);
console.log(forward);
if (graphQLErrors) {
graphQLErrors.forEach(({ message, locations, path }) =>
console.log(
`[GraphQL error]: Message: ${message}, Location: ${locations}, Path: ${path}`
)
);
}
if (networkError) {
console.log(`[Network error]: ${networkError}`);
}
}
);
in the code above I will like to get set the useContext of another react component but I get
Error: Invalid hook call. Hooks can only be called inside of the body of a function component
which is normal, but how can I actually display an error in a component or change the state of another component from onError function with apollo?
cmnstmntmn commented
@unutoiul did you found an workaround for this issue?
unutoiul commented
I have not, Did u find any?
cmnstmntmn commented
a silly hack
return new Observable((observer) => {
return observer.error([...graphQLErrors, networkError]);
});