Francesco
Hello!
I have recently discovered that calling Absinthe.Plug.put_options , in my case to add some information to the context, actually overwrites whatever might have been set as the context before. I have two plugs for my router, one that auths and adds the user to the context, and another that adds a workspace ID to the context. I know I could just combine these plugs but that kind of defeats the point of plugs (modular parts of a pipeline).
Absinthe.Plug.put_options(conn, context: %{authenticated: true, current_user: user})
Absinthe.Plug.put_options(conn, context: %{workspace: current_workspace})
So the question is, is there any way that I could modify the context object instead of overwriting it? I’d be happy to just get the current context, merge the new options, and call put_options with the merged object but I can’t see a great way to get the current context. Only way I can see is to grab it from conn.private.absinthe but that doesn’t feel right.
Trending in Questions
Other Trending Topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #blog-post
- #elixirconf-us
- #elixir-ls
- #ai
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 3- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
Catharz
I had the same issue and just ended up merging the context.
e.g. to resolve some subfields in our queries, we need the language passed down to their resolvers like this:
That makes the language value available at the field level where we need to translate strings.
We do something slightly similar in our global middleware(s). e.g.
benwilson512
@Francesco PR welcome for an
update_optionsfunction. In the short term feel free to grab it fromconn.private.Francesco
@Catharz thanks for the help
@benwilson512 I’m definitely keen to try my hand at the PR as soon as I can spare a few hours! But yep just using conn.private is working fine in the meantime