I am using react, apollo and graphql in my application.
Our FE is connected to a gateway that federate multiple API together, including some graphQL ones. The idea is, the FE query the gateway, the gateway call the appropriated APIs and return the response from them.
The gateway currently handle some basic error, like unauthorized clients etc..
The issue I face is, since our gateway is generic and not bound to graphql only, the error it return (for exemple when I query a graphql api but the token is expired) some default error that use
content-type: text/html; charset=utf-8
For example
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Error</title>
</head>
<body>
<pre>UnauthorizedError: No authorization token was found<br> at new UnauthorizedError (/home/node/app/node_modules/express-jwt/dist/errors/UnauthorizedError.js:22:28)<br> at /home/node/app/node_modules/express-jwt/dist/index.js:113:39<br> at step (/home/node/app/node_modules/express-jwt/dist/index.js:33:23)<br> at Object.next (/home/node/app/node_modules/express-jwt/dist/index.js:14:53)<br> at /home/node/app/node_modules/express-jwt/dist/index.js:8:71<br> at new Promise (<anonymous>)<br> at __awaiter (/home/node/app/node_modules/express-jwt/dist/index.js:4:12)<br> at middleware (/home/node/app/node_modules/express-jwt/dist/index.js:66:16)<br> at /home/node/app/node_modules/express-unless/dist/index.js:50:13<br> at Generator.next (<anonymous>)</pre>
</body>
</html>
Now, apollo Error Link is expecting a body to be null and/or parseable, and in such case my graphql Error links fails with
[Network error]: TypeError: Failed to fetch
This is because graphql try to parse the response, but crash since the response is an HTML page, and I lose the scope and code of the error.
Is there a way to allow graphql to ignore certain context type to be parsed ?