Redirection on Absinthe Resolvers

Hello everyone. Can the resolver of a query or mutation, still use the current connection in order to send a status code to the user (for example a 401 code) ??

From what I’ve read about GraphQL you shouldn’t send or use HTTP status codes at all. Instead you should send info in error message. Here is how to do it in Absinthe https://github.com/absinthe-graphql/absinthe_plug/issues/45#issuecomment-272197806

And keep in mind that GraphQL is transport agnostic, there’s no such thing as HTTP status codes as far as it’s concerned. It can be used over HTTP sure, but just as capably a websocket, TCP channel, file transfers, sneakernet, etc… ^.^

1 Like

Others have noted that this isn’t really a thing you normally do with GraphQL, and they are right. Do note that if you want to do this you can use Absinthe.Plug to manipulate the http connection after absinthe has done its work, but before the response is sent: https://hexdocs.pm/absinthe_plug/Absinthe.Plug.html#module-before-send.

1 Like

BTW, my concern was fulfilled using a middleware, I basically needed to use some sort of connection, like the one Plug.conn offers, so the resolution was what I was needing exactly, in order to check stuff from the context before resolving and actually using a real answer from the API at the end. Thanks for all the answers guys, I really appreciate it!