HTTP response code

Hi, I am trying to setup Apollo Client in a React web app with Cognito JWT Tokens using Amplify.

So, I noticed I was getting 200 as response code on a GraphQL request with an expired token.
Is that correct?

This implementation of how to handle an expired token relies on a 401 http response.
https://blog.benclmnt.com/blog/apollo-auth/
Does anyone here have a good way of handling this?
Thanks

Is that a question related to Dgraph’s GraphQL? If not, maybe you can find support at Dgraph Community (Unofficial).

1 Like

I will read that linked post later but in theory GraphQL should always return 200 and can send an error message by official spec.

1 Like

Yeah, there are several approaches to error dealing/handling in GraphQL world. There are libs just for it.

Ok thanks! I should have read the spec obviously.

For those interested, I found a working approach with custom fetch. This way the token refreshes before making the api request.

  const customFetch = async (uri, options) => {

    const session = await Auth.currentSession();

    options.headers.Bearer = session.getAccessToken().getJwtToken();
    return fetch(uri, options);
  };

  const httpLink = createHttpLink({
    uri: config.dgraph_endpoint,
    fetch: customFetch,
  });
1 Like