AbsintheUtils.Plug.StatusCodeOverride (absinthe_utils v0.0.1-main-d255e08b6c32fe6449757ed94e6abba8bb9a31e7)
View SourceA plug that allows overriding the HTTP status code of an Absinthe GraphQL response.
Usage
Add the plug to your pipeline:
pipeline :api do
plug :accepts, ["json"]
plug AbsintheUtils.Plug.StatusCodeOverride
end
Then in your GraphQL endpoint configuration, add the before_send
callback:
forward "/graphql",
Absinthe.Plug,
schema: MyApp.Schema,
before_send: {AbsintheUtils.Plug.StatusCodeOverride, :before_absinthe_send}
To override the status code in a middleware, resolver, etc,
set the status_code_override
in the resolution context:
%{resolution | context: %{status_code_override: 500}}
This will cause the response to have the specified HTTP status code (500 in the above example).
Summary
Functions
@spec before_absinthe_send(Plug.Conn.t(), Absinthe.Blueprint.t()) :: Plug.Conn.t()