Hello lovely people,
I did a tremendous research but couldn’t figure out why my mutation is not recognized by the subscription > trigger/2
macro.
I have the following in my types
defmodule MyAppWeb.Graphql.Discussions.Types do
...
# helper to namespace queries and mutations:
defp resolver_self(parent, _res, _context), do: {:ok, parent}
# Queries and mutations for Discussions and DisccusionComments are namespaced under the field
# `discussions`:
object :discussions_namespace_mutations do
field(:discussions, :discussions_mutations) do
resolve(&resolver_self/3)
end
end
#
# Mutations
#
object :discussions_mutations do
field :create_comment, :discussion_comment do
arg(:discussion_thread_id, non_null(:uuid4))
arg(:comment, non_null(:string))
resolve(&Resolver.create_comment/2)
end
end
#
# Subscriptions
#
object :discussions_subscription do
field :discussion_thread, list_of(:discussion_comment) do
arg :id, non_null(:uuid4)
# set subscription topic(s)
config fn args, _info ->
{:ok, topic: args.id}
end
**# This is where the issue is -- the mutation is not recognized as it is namespaced above**
trigger :create_comment, topic: fn
discussion_comment -> discussion_comment.discussion_thread_id
end
resolve fn discussion_comment, _, _ ->
{:ok, discussion_comment}
end
end
end
end
I didn’t find a way to trigger my namespaced mutation from the [Absinthe.Schema.Notation.trigger/2](https://hexdocs.pm/absinthe/Absinthe.Schema.Notation.html#trigger/2)
macro.
However, if I don’t use the trigger/2
macro & just run [Absinthe.Subscription.publish/3](https://hexdocs.pm/absinthe/Absinthe.Subscription.html#publish/3)
in the resolver Resolver.create_comment/2
- everything works as expected. But I want to figure out how to make the trigger/2
macro work in this scenario.
Any help is highly appreciated. Thank you all.