grangerelixx

grangerelixx

Argument \"input\" has invalid value - input object GQL mutations

My tests were passing until I wrote the input_object block. In my ecto schema, the field title is non-null. Since I wanted the updation to take place with either title or slug(there are some cases when I don’t want to update the title but just the slug), I wrote the input_object. But this landed me in a new error which I am not able to fix. Invalid argument value.

Gql muation for update

@desc "Update a Post"
    field :update_post, :post do
      arg(:id, non_null(:string))
      arg(:title, :title_input)
      arg(:slug, :slug_input)
  
      resolve(&Resolvers.Post.update_post/3)
    end

input_object :title_input do
    field :title, :string
  end

  input_object :slug_input do
    field :slug, :string
  end

Resolver function

def update_post(_root, args, %{context: %{current_user: current_user}}) do
post_id = args.id
    post =
      Blog.get_post!(post_id)

    case Blog.update_post(
           post,
           args,
           current_user.current_tenant
         ) do
      {:ok, post} ->
        {:ok, post}

      {:error, changeset} ->
        {:error,
         message: "Could not update post",
         details: ChangesetErrors.error_details(changeset)}
    end

Mutation test

mutation = """
        mutation {
          updatePost(id: "#{context.post.id}", title: "New title") {
            id
            title
            slug
          }
        }
      """


      expected_response = %{
        "updatePost" => %{
          "id" => context.post.id,
          "title" => "New title"
        }
      }

Error message
"message" => "Argument \"title\" has invalid value \"New title\"."

Any help is appreciated.

First Post!

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

Your title argument is an input_object in your schema, not sure why but that’s what you have. Which means that it’s expecting title: {title: "New Title"}.

Where Next?

Popular in Questions Top

senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
ycv005
I have followed this StackOverflow post to install the specific version of Erlang. And When I am running mix ecto.setup then getting fol...
New
script
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this "1000" What is the ...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
LegitStack
I’m trying to make a websocket server in Phoenix or raw Elixir. I heard about gun, I think I could use cowboy, but since I’m not that sma...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
Mooodi
Given a string, how can I get access to its character by index? Enum.at("my_string", 2) doesn't work. Or rather, not char, but a substr...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New

Other popular topics Top

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
lk-geimfari
What is most correct way to open, read and parse JSON file with poison? For example if we have example.json file in root of some projec...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
chrismccord
As promised, the first release candidate of Phoenix 1.3.0 is out! This release focuses on code generators with improved project structure...
New
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers' Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
AstonJ
by Lance Halvorsen Elixir and Phoenix are generating tremendous excitement as an unbeatable platform for building modern web application...
460 27162 124
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New

We're in Beta

About us Mission Statement