Error when setting argument to allow_nil? true in ash graphql

Hello, I am sending an update request using ashgraphql.

post.ex

...
update :update do
      argument :photos, {:array, :map}, allow_nil?: true
      argument :category_id, :integer, allow_nil?: true
      argument :pre_diary_id, :uuid, allow_nil?: true
      argument :post_diary_id, :uuid, allow_nil?: true

      change management_relationship (:photo, type::direct_control)
      change set_attribute(:question_answer_post_category_id, arg(:category_id), set_when_nil?: false)
      change set_attribute(:pre_diary_id, arg(:pre_diary_id))
      change set_attribute(:post_diary_id, arg(:post_diary_id))
    end


relationships do
    belongs_to :user, Dentallog.Accounts.User do
      api Dentallog.Accounts
    end

    belongs_to :question_answer_post_category, Dentallog.QuestionAnswer.QuestionPostCategory do
      allow_nil? false
      attribute_writable? true
      attribute_type :integer
    end

    belongs_to :pre_diary, Dentallog.DentalDiary.Diary do
      api Dentallog.DentalDiary
    end

    belongs_to :post_diary, Dentallog.DentalDiary.Diary do
      api Dentallog.DentalDiary
    end

    has_many :photos, Dentallog.QuestionAnswer.QuestionPostPhoto

    has_many :comments, Dentallog.QuestionAnswer.QuestionPostComment do
      filter expr(is_nil(parent_id))
    end
  end

Grphaql

{
  "id": "899b2127-5b15-4d53-a319-6854d3e4f920",
  "input": {
    "title": "Edited title",
    "body": "Edited body"    
  }
}

Response.

{
    "Data": {
        "updateQuestionAnswerPost": {
            "errors": [
                {
                    "message": "Required"
                }
            ],
            "Result": null
        }
    }
}

Here, I set the categoryId argument value to allow_nil, but when I send an update request without categoryId, I get an error saying that a required value is missing.
Do you know why?

Hmm…that is interesting.

    belongs_to :question_answer_post_category, Dentallog.QuestionAnswer.QuestionPostCategory do
      allow_nil? false
      attribute_writable? true
      attribute_type :integer
    end

I’m not sure why the set_when_nil option isn’t working TBH. With that said, given that you have

 attribute_writable? true

on that relationship, you shouldn’t need the set_attribute and arguments at all, right?

1 Like

Aha~! Oh right, I used attribute_writable and removed argument, set_attribute

1 Like