absinthe-graphql / absinthe_plug

Plug support for Absinthe, the GraphQL toolkit for Elixir
https://hex.pm/packages/absinthe_plug
MIT License
260 stars 163 forks source link

Possible to access context during subscription config? #263

Closed artificial-mwatson closed 2 years ago

artificial-mwatson commented 2 years ago

Some customers, when they submit a subscribe document want us to send them the "current" version of what they're subscribing to. The problem is that doing so requires access to the context which contains information about the user, their authentication, and key values that are needed to be able to send them the correct data.

The subscription's config macro doesn't seem to give us access to the context that the plug inserted for that user. Is it possible to access the context from inside the config so we can trigger the proper channel publish operation?

We're migrating from Apollo, and this was something they had in Apollo that we'd like to preserve.

Thanks.

benwilson512 commented 2 years ago

Hi, the context is indeed available, please see the example shown here: https://hexdocs.pm/absinthe/Absinthe.Schema.Notation.html#config/1-examples

artificial-mwatson commented 2 years ago

Many thanks, @benwilson512!

artificial-mwatson commented 2 years ago

Since subscription goes over a Phoenix.Socket, and Sockets don't go through the Plug pipeline (near as I can tell), sockets don't work with conns. So I haven't found a way to get something into the context for access in the absinthe config macro, as @benwilson512 showed.

benwilson512 commented 2 years ago

Hi @artificial-mwatson please use the slack or the forums for questions not the issue tracker. This is also covered in the docs https://hexdocs.pm/absinthe_phoenix/Absinthe.Phoenix.Socket.html#content