moxley

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

zachdaniel

Creator of Ash

:thinking: I think your id just needs to go inside the input. What does the generated GraphQL schema for that look like?

Most Liked

zachdaniel

zachdaniel

Creator of Ash

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

moxley

I’ll give that a shot. Thanks!

Last Post!

moxley

moxley

Great, thanks for the help!

Where Next?

Popular in Questions Top

jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
hariharasudhan94
lets say i have a sample like a = 20; b = 10; if (a > b) do {:ok, "a"} end if (a < b) do {:ok, b} end if (a == b) do {:ok, "equa...
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
PeterCarter
There are pre-rolled solutions for other frameworks that do work. However, Phoenix does not seem to have these. Have people had good expe...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New

Other popular topics Top

baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New

We're in Beta

About us Mission Statement