mukesh
Absinthe subscription trigger doesn't work for namespaced mutation
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.
Marked As Solved
mukesh
Hey @benwilson512 ,
Yes, my mutation looks something like that.
Here is what I am using in my test
@mutation """
mutation CreateDiscussionCommentMutation(
$discussionThreadId: UUID4!,
$comment: String!
) {
discussions {
createComment(
discussionThreadId: $discussionThreadId,
comment: $comment,
) {
id
comment
authorId
discussionThreadId
status
}
}
}
"""
So, @benwilson512 , I think I have only 2 options
- Make my mutation to be a field directly within the root mutation - meaning it cannot be namespaced under discussions anymore OR
- Keep my mutation namespaced, not use
trigger/2macro & useAbsinthe.Subscription.publish/3directly in the resolver.
Isn’t it?
Or is there any other way to reference my namespaced mutation within trigger macro?
P.S.- Thanks for the swift reply.
Also Liked
benwilson512
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex









