Skip to content
This repository was archived by the owner on Jul 9, 2022. It is now read-only.

feat: implement custom PLug to forward headers using a Absinthe.Plug#5

Open
frfroes wants to merge 3 commits intoSpiffInc:mainfrom
frfroes:main
Open

feat: implement custom PLug to forward headers using a Absinthe.Plug#5
frfroes wants to merge 3 commits intoSpiffInc:mainfrom
frfroes:main

Conversation

@frfroes
Copy link

@frfroes frfroes commented Jan 25, 2021

This PR closes #4

I implemented the solution described in the issue by @feliperenan where we have a custom Plug that takes the given headers from the conn and inject it into the Absinthe.Plug context in other to forward them to the downstream services on the resolver level.

defmodule Absinthe.Compose.Plug.ForwardHeader do
@moduledoc """
This Plug takes the given headers and add it to Absinthe.Plug context in order to be fowarded
on to the Upstream service on the resolver level.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we proceed with this approach, I think it would be nice if we add how users of this library would plug this plug on their application. It could be here though, something like this:

@moduledoc """
omitted...

In order to use this plug, you need to plug this in your router.

  pipeline :my_pipeline do 
    plug Absinthe.Compose.Plug.ForwardHeader, ["authorization"]
  end
"""

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw, I think would be better if we specify a key for the headers name, something like: plug Absinthe.Compose.Plug.ForwardHeader, headers: ["authorization"]

My main concern is if this plug starts to receive new arguments in the future (I don't have an example of that). If that happens, a new release of this library would result in a breaking change, requiring all users of this library to update their code before proceeding with the update.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for forwarding headers to the external client

2 participants