I want to remove input as an argument when updating in AshGraphql

There is an API to increment views of post.

graphql do
 mutations do
    update :increment_view_count, :increment_view_count
 end 
end
actions do
  update :increment_view_count do
      argument :id, :uuid, allow_nil?: false
      change set_attribute(:count_of_view, expr(count_of_view + 1))
    end
end

I don’t need the input because I just want to take the ID as an argument and increase the number of views. Do you know how to remove it?

Have you tried adding accept [] to your action? And I think you don’t need ID as an argument, as update always takes the ID. You probably need to get the ID by using Ash.Changeset.get_data to get the ID of the Record that should be changed.

1 Like

Also you can’t use change set_attribute use change atomic_update and you won’t take an id as an argument, ash_graphql adds the id argument to the mutation automatically.

1 Like

So this should just be

update :increment_view_count do

      change atomic_update(:count_of_view, expr(count_of_view + 1))
    end
end

1 Like

I should have looked at the question more holistically :sweat_smile:

The accept [] is still needed to make the input disappear though, right?

1 Like

Correct! :+1:

1 Like

Thank you so much. I think I asked this before, but I’ll be careful.