Skip to content

Commit

Permalink
Merge contexts
Browse files Browse the repository at this point in the history
  • Loading branch information
binaryseed committed Apr 23, 2021
1 parent f806d19 commit 97ace36
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 7 additions & 1 deletion lib/absinthe/plug.ex
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ defmodule Absinthe.Plug do

@init_options [
:adapter,
:context,
:no_query_message,
:json_codec,
:pipeline,
Expand Down Expand Up @@ -325,6 +326,7 @@ defmodule Absinthe.Plug do
|> update_config(:raw_options, conn)
|> update_config(:init_options, conn)
|> update_config(:pubsub, conn)
|> update_config(:context, conn)
end

defp update_config(config, :pubsub, conn) do
Expand All @@ -343,7 +345,11 @@ defmodule Absinthe.Plug do
end

defp update_config(config, :init_options, %{private: %{absinthe: absinthe}}) do
Map.merge(config, Map.take(absinthe, @init_options -- @raw_options))
Map.merge(config, Map.take(absinthe, @init_options -- [:context | @raw_options]))
end

defp update_config(config, :context, %{private: %{absinthe: %{context: context}}}) do
update_in(config.context, &Map.merge(&1, context))
end

defp update_config(config, _, _conn) do
Expand Down
2 changes: 1 addition & 1 deletion test/lib/absinthe/plug_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ defmodule Absinthe.PlugTest do
config = Absinthe.Plug.init(schema: TestSchema, context: %{user: "Foo"})

conn =
conn(:post, "/", %{"query" => @query})
conn(:post, "/")
|> Absinthe.Plug.assign_context(foo: "bar")

updated_config = Absinthe.Plug.update_config(conn, config)
Expand Down

0 comments on commit 97ace36

Please sign in to comment.