This repository has been archived by the owner on Apr 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 347
accessing client in apollo-link-error onError() #595
Comments
In your code const clientFunction = location => {
const client = new ApolloClient({
link: ApolloLink.from([
onError(({ graphQLErrors, networkError }) => {
if (
graphQLErrors &&
graphQLErrors.find(isUnauthorized) &&
!location.pathname.startsWith('/login')
) {
client.resetStore();
client.mutate({
mutation: notificationAddMutation,
variables: {
text:
'You did not have rights to this operation. Maybe logged out?',
},
});
}
if (networkError) {
client.mutate({
mutation: notificationAddMutation,
variables: {
text: 'There was a network problem. Please check your connection',
},
});
}
}),
withClientState({
cache,
defaults,
resolvers,
typeDefs,
}),
httpLink,
]),
cache,
});
return client;
};
clientFunction(LOCATION); |
Thank you very much, this worked. For anyone interested: |
@evans thanks. it works. related stackoverflow post: https://stackoverflow.com/questions/51664533/how-to-access-apollo-client-in-apollo-link-error-to-resetstore |
Hey I can't seem to get this working
I have passed graphQLClient to the link functions but graphQLClient is |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Hi,
I have spent several days on this without a success.
What I basically need is to access client, so I can call a mutation to change a global state if there is an error in the arterware.
I get this error: TypeError: client.mutate is not a function
Any ideas how to access client there? Or how to call a local mutation without a client?
The text was updated successfully, but these errors were encountered: