absinthe icon indicating copy to clipboard operation
absinthe copied to clipboard

Ignoring events in subscription resolver

Open dorian-marchal opened this issue 2 years ago • 1 comments

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:

  • they don't care about the event (e.g. because they chose not to receive them)
  • the event doesn't concern them (e.g.because they don't have sufficient permission).

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

dorian-marchal avatar Jul 21 '22 20:07 dorian-marchal