absinthe
absinthe copied to clipboard
Ignoring events in subscription resolver
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