moxley
Passing GraphQL variables to a generic action's arguments
I defined a generic mutation action that takes an :id argument and an :input argument with an embedded resource backing :input. When I test the AshGraphql mutation, it doesn’t know about the arguments. It appears that AshGraphql has generated an input type that I can’t control.
[
%{
"locations" => [%{"column" => 36, "line" => 2}],
"message" =>
"Unknown argument \"id\" on field \"silenceConversationNotifications\" of type \"RootMutationType\"."
},
%{
"locations" => [%{"column" => 45, "line" => 2}],
"message" =>
"Argument \"input\" has invalid value $input.\nIn field \"input\": Expected type \"Conversation2InputInput!\", found null.\nIn field \"id\": Expected type \"String!\", found null.\nIn field \"silenceUntil\": Unknown field.\nIn field \"token\": Unknown field."
}
]
mutation SilenceConversationNotifications($id: ID!, $input: SilenceConversationNotificationsInput!) {
silenceConversationNotifications(id: $id, input: $input) {
result {
id
}
errors {
code
fields
message
shortMessage
vars
}
}
}
GraphQL variables:
%{
"id" => conversation.id,
"input" => %{"silenceUntil" => silence_until, "token" => token}
}
Here’s the action:
action :silence_notifications, GF.Messaging.Types.SilenceNotificationsResult do
argument :id, :string, allow_nil?: false
argument :input, SilenceNotificationsInput, allow_nil?: false
Here’s the AshGraphql mutation:
mutations do
action :silence_conversation_notifications, :silence_notifications
The input embedded resource:
defmodule GF.Messaging.Resources.SilenceNotificationsInput do
use Ash.Resource,
data_layer: :embedded,
extensions: [AshGraphql.Resource]
graphql do
type :silence_notifications_input
end
attributes do
attribute :silence_until, :utc_datetime do
allow_nil? false
constraints precision: :second,
cast_dates_as: :start_of_day,
timezone: :utc
public? true
end
attribute :token, :string do
allow_nil? true
constraints trim?: true, allow_empty?: false
public? true
end
end
end
Any ideas?
First Post!
zachdaniel
I think your id just needs to go inside the input. What does the generated GraphQL schema for that look like?
Most Liked
zachdaniel
You could view it in playground or you could use mix absinthe.schema.sdl Your.Schema to see the full schema. Right now it does not look like we have a way for you to put those action inputs outside of the action, but it is not something that would be hard to add. We would likely call it something like input_location :input_object | :top_level.
For your specific case though you should be able to add identity false in the update mutation to not need the id input generated by default, and read_action :get_by_token_or_id that has arguments that you could use to locate the user.
moxley
Last Post!
moxley
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









