newsiberian / apollo-link-token-refresh

Apollo Link that performs access tokens (JWT) renew
MIT License
337 stars 45 forks source link

GraphQL based API #31

Open jcampbell05 opened 3 years ago

jcampbell05 commented 3 years ago

Is there an example on how to implement this via a Graph QL API ?

dani-z commented 3 years ago

Hi @jcampbell05

You can use plain fetch and POST to your graphQL server.

return fetch(API_ENDPOINT, {
      method: 'POST',
      headers: {
        Accepts: 'application/json'
      },
      body: `
        mutation {
          regenerateAccessToken(refreshToken: "${refreshToken}")
        }
      `
    });
jcampbell05 commented 3 years ago

Nice 😀 I found a work around I can document sometime

RoelRoel commented 3 years ago

Hi @jcampbell05

You can use plain fetch and POST to your graphQL server.

return fetch(API_ENDPOINT, {
      method: 'POST',
      headers: {
        Accepts: 'application/json'
      },
      body: `
        mutation {
          regenerateAccessToken(refreshToken: "${refreshToken}")
        }
      `
    });

In this case it should be something like:

return fetch(API_ENDPOINT, {
      method: 'POST',
      credentials: 'include',
      headers: {
        accept: '*/*',
        'content-type': 'application/json',
      },
      body:
            JSON.stringify({
                query: `
                  mutation {
                    regenerateAccessToken(refreshToken: "${refreshToken}")
                  }
                `
            })
    });