The use case is that the external client need some extra headers to proper validate the incoming request, in our case the Authorization header needs to be forwarded, and since it is dynamic, it need to be done at runtime level.
What we suggested is something like this:
Add this plug in absinthe_compose library.
defmodule Absinthe.Compose.Plug.ForwardHeader do
@behaviour Plug
import Plug.Conn
def init(opts), do: opts
@spec call(Plug.Conn.t(), any) :: Plug.Conn.t()
def call(conn, opts) do
headers = build_addional_headers(conn, opts)
Absinthe.Plug.put_options(conn, context: %{headers_to_forward: headers_to_forward})
end
defp build_addional_headers(conn) do
# ...
end
end
Users of this library can put this Plug on their router:
# my_app_web/router.ex
pipeline :graphql do
plug Absinthe.Compose.Plug.ForwardHeader, headers: ["authorization"]
end
Then we can take this headers_to_forward when resolving the query and merge in this opts which will be send to the HTTP client.
Another option would be just changing this library to get custom opts from the context and instruct developers to build this plug on their own application.
The use case is that the external client need some extra headers to proper validate the incoming request, in our case the Authorization header needs to be forwarded, and since it is dynamic, it need to be done at runtime level.
What we suggested is something like this:
Add this plug in
absinthe_compose
library.Then we can take this
headers_to_forward
when resolving the query and merge in this opts which will be send to the HTTP client.Does that make sense?