graphql-kit icon indicating copy to clipboard operation
graphql-kit copied to clipboard

Overriding response status code

Open itayAmza opened this issue 4 years ago • 3 comments

Hi @alexsteinerde, How can I return response code other that 200 for specific scenarios (unauthorized etc)? I've tried adding a custom error middleware but because RoutesBuilder status is always ok I it never uses it.

itayAmza avatar Dec 17 '21 12:12 itayAmza

Hi, this isn't supported at the moment. If you like you can create a PR for this. Currently I don't have any specific ideas on how to implement that but it could probably be done by analyzing the returned GraphQLResult error array.

alexsteinerde avatar Dec 28 '21 09:12 alexsteinerde

After a second thought I came up with an idea on how this could be implemented. We could introduce a protocol that your custom errors would conform to. Then we could check on that new error type and extract the status code from that which would be returned as the response.

I created a separate branch for that: https://github.com/alexsteinerde/graphql-kit/compare/http-status-error

What do you think about that?

alexsteinerde avatar Dec 28 '21 10:12 alexsteinerde

Sorry for late response. I liked your solution, I played with it a bit but eventually I felt like were ignoring GraphQL best practices, and other users in the future might miss the point and abuse it. I tried to go for a high level solution here. WDYT?

itayAmza avatar Jan 29 '22 14:01 itayAmza