context modified by middlewares is discarded
G3z opened this issue · 2 comments
G3z commented
i built a simple middleware to modify the context like so
field :validate_code, type: :session do
arg :phone, non_null(:string)
arg :code, non_null(:string)
resolve handle_errors(&DoStuff.UserResolver.validate_code/2)
# Update context with current user
middleware fn res, _ ->
case res.value.user do
nil -> res
_ -> %{res | context: Map.put(res.context, :current_user, res.value.user)}
end
end
end
but context modification is discarded after execution
I also tried inspecting absinthe_phoenix internals by substituting https://github.com/absinthe-graphql/absinthe_phoenix/blob/master/lib/absinthe/phoenix/channel.ex#L49 with
pipeline = config.schema
|> Absinthe.Pipeline.for_document(opts)
result = case Absinthe.Pipeline.run(query, pipeline) do
{:ok, data, _phases} ->
data |> IO.inspect
{:ok, data.result}
{:error, msg, _phases} ->
{:error, msg}
end
data
has only a context
key which is inside resolution
and contains the original context.
Is it possible to retrieve the new context from the blueprint and assign it to the socket ?
benwilson512 commented
Hey so you're totally right, this isn't returned from Absinthe properly, that's my bad. I'm working on this now and should have rc.1 out shortly with this improved for both Absinthe and Absinthe.Phoenix.
benwilson512 commented
Fixed in rc.1