absinthe-graphql / absinthe

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

Bail from subscription if resolver has an error #1309

Closed barnabasJ closed 7 months ago

barnabasJ commented 8 months ago

Would it be possible to do something like this? Right now, null is sent down to the subscriber if the resolver produces an error.

It might depend on the use case, but I was thinking about something where you have a table where users can only see some of the entries and you have a subscription to updates, for example and use the user_id as the context id. Now, in the resolver, you check if the user is authorized to see the updated value and if not, put an error into the resolution. With the current implementation, the user would still get a push from the subscription with the null value. But not notifying the user in this case might be the better thing to do.

benwilson512 commented 7 months ago

Hey @barnabasJ I agree that it's awkward to send null. However, we can't just suppress all publications that have errors. GraphQL results can contain both data and errors.

My plan for a while was to have some sort of special return value from Subscription resolvers that told Absinthe to halt and not send. Can you open up an issue to discuss this? (Take a look around, one may already be open).