absinthe-graphql / absinthe

The GraphQL toolkit for Elixir
http://absinthe-graphql.org
Other
4.29k stars 526 forks source link

Ignoring events in subscription resolver #1181

Open dorian-marchal opened 2 years ago

dorian-marchal commented 2 years ago

Hello there!

Currently when a subscription is resolved, we have no way of ignoring events for individual subscriptions. This would be useful to avoid notifying clients when:

For example, consider this subscription:

field :foo, :string do
  arg(:key, non_null(:string))
  config(fn %{key: key}, _ -> {:ok, [topic: key]} end)

  resolve(fn payload, _, %{context: %{user_id: user_id}} ->
    if should_user_receive_event?(user_id, payload) do
      {:ok, payload}
    else
      # Here it would be nice to be able to "cancel" the event push for this particular user.
      # Maybe using a specific return value like :ignore or something.
      {:ok, nil}
    end
  end)
end

Related request: https://github.com/absinthe-graphql/absinthe/issues/365#issuecomment-467621116

barnabasJ commented 6 months ago

Hi @benwilson512,

I'm writing here because of your comment on my PR #1309. I must have missed the error in the playground because I didn't have it in the graphql document, so it looked like it was only sending the null without information about the error.

You also wrote that you had a plan for this in mind using a special return value, I would be happy to take a stab at implementing that if you could give me a couple pointers on what your where thinking.