Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignoring events in subscription resolver #1181

Open
dorian-marchal opened this issue Jul 21, 2022 · 1 comment
Open

Ignoring events in subscription resolver #1181

dorian-marchal opened this issue Jul 21, 2022 · 1 comment

Comments

@dorian-marchal
Copy link
Contributor

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: #365 (comment)

@barnabasJ
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants