I have a long running task that downloads and parses a document. When the parsing is complete it publishes a subscription to notify the client is has completed:
Based on Ben response on slack (#absinthe-graphql)
simply return an error from the root subscription field resolver. by default you don’t need one but you could add one to look for specific published values and return an error
subscription do
field :user_updated, :user do
# other subscription setup stuff
resolve fn %{user_updated: user}, _, _ ->
case user do
%User{} -> {:ok, user}
{:error, reason} -> {:error, reason}
end
end
end
end
then you can publish(PubSub, {:error, "bad things happened}, user_updated: topic)
I had to make one small change in the resolve function signature to get it to work.
subscription do
field :user_updated, :user do
# other subscription setup stuff
resolve fn user, _, _ ->
case user do
%User{} -> {:ok, user}
{:error, reason} -> {:error, reason}
end
end
end
end