To navigate around in my react-native app, I am using "react-navigation".
With the code below, I can successfully intercept all necessary errors that are coming from the server.
const linkError = onError(({ graphQLErrors, networkError }) => {
if (graphQLErrors) {
// Logout user
// 1. Issue logout mutation
// 2. Navigate to Login screen
graphQLErrors.map(({ message, locations, path }) =>
console.log(
`[GraphQL error]: Message: ${message}, Location: ${locations}, Path: ${path}`
)
);
}
if (networkError) console.log(`[Network error]: ${networkError}`);
});
const client = new ApolloClient({
link: ApolloLink.from([linkError, stateLink, authLink, httpLink]),
cache,
});
The question is how to navigate the user to "Login" screen and issue "Logout" mutation if an error happens?