Subscription with Authorization: Skip trigger if condition isn't met

断了今生、忘了曾经 提交于 2019-12-12 01:09:50

问题


I have a Phoenix web application and am using Absinthe for subscriptions that are triggered whenever a new Comment is added to a Topic. I am trying to send a subscription only if the user is a member of a topic, and otherwise not send something at all.

So far I've tried playing with config as mentioned in the Subscription docs but it seems like that it is only executed when creating the subscription and not when it is triggered. I'm hoping it is something as simple as:

resolve fn comment, _, %{context: context} ->
  if User.member_of?(context.user, commment.topic) do
    {:ok, comment}
  else
    :noreply
  end
end

For now, I'm just returning {:ok, nil} but I'm hoping there is a better way to achieve this.

来源:https://stackoverflow.com/questions/54894293/subscription-with-authorization-skip-trigger-if-condition-isnt-met

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!