-
Notifications
You must be signed in to change notification settings - Fork 645
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
How to handle HTTP error with combination of valid graphql response #5886
Comments
Hi 👋 You've just bumped into a loophole of GraphQL, congrats! I'll look into what it takes to let some errors pass through but this might take a while to settle on this. In the short term, your solution is good 👍 Out of curiosity, when the error code is not 2XX, do you have |
both data and errors are null |
Sorry, I meant in your backend response. Does your server return |
I see, it will return only error and according they understanding of graphql specification which should be active from 1.1.2025 they will return just errors with no data at all. As shown in example:
|
Gotcha 👍 Yep, that makes sense. |
Question
Hi,
We found an interesting situation where I'm not sure if it is a missing feature in the Apollo Kotlin client or if we just haven't found the answer.
Our backend currently has a feature where it returns HTTP status codes (401, 429, 500, etc.) along with a valid GraphQL response. This does not seem to be an issue for the iOS client, React client, etc., but for the Kotlin client, it appears to be problematic. When the response is not 2XX, an ApolloHttpException is thrown, and there is no data in response.data nor errors in response.errors. I was able to overcome this issue by changing the status code of the HTTP response in an OkHttp interceptor so that the body is still parsed.
According to the documentation for GraphQL routers, this is a valid response. For example, here: Apollo GraphQL Router Customizations
However, it seems that the Kotlin client doesn't allow processing such requests, and without some "hacks," you cannot access the GraphQL body response when an HTTP code outside the 2XX range is received. How can this problem be solved without "hacks"?
Thank you.
The text was updated successfully, but these errors were encountered: