-
Notifications
You must be signed in to change notification settings - Fork 45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use Apollo to fetch the fresh token #12
Comments
@obsessen did u get through with it? |
@akkhan20 unfortunately no. I'm still new to GraphQL and Apollo, so some help would be appreciated. I think I know what my problem is. I'm trying to call an Apollo mutation in the fetchAccessToken function but the tokenRefreshLink catches this request as well and adds it to the "query waiting list"... Is there a way I can make this work? |
@obsessen @da3monHunter Have you tried something like this? fetchAccessToken: async () => {
const resp = await fetch(environment.graphqlRemote, {
method: 'POST',
headers: {
Authorization: `JWT ${currentAccessToken}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
query: `mutation RefreshToken { refreshToken(refreshToken: "${refreshToken}") { token refreshToken } }`
})
});
return resp.json();
},
handleResponse: (operation, accessTokenField) => (response: RefreshReponse) => {
console.log('handleResponse', response);
} |
|
Accidentally found this. I myself end up with the similar solution to refresh the access token using axios, with mutation query inside the axios request. Haven't found the solution to use mutation inside ApolloClient onError link... |
Im getting a status 500 when body: (...)
bodyUsed: false
headers: Headers {}
ok: false
redirected: false
status: 500
statusText: "Internal Server Error"
type: "cors"
url: "http://localhost:3000/graphql" Any idea what could be happening? fetch('http://localhost:3000/graphql', {
method: 'POST',
headers: { 'content-type': 'application/json' },
credentials: 'include',
body: JSON.stringify({ query: '{ refreshToken { accessToken } }' })
}); I'm just using a normal fetch |
Hello,
I have a GraphQL mutation to refresh the token. Can I somehow use the mutation in the fetchAccessToken function?
The text was updated successfully, but these errors were encountered: