Ash FrameworkAF
Ash Framework3y ago
54 replies
moxley

AshGraphql: Updating a managed has_many relationship

I'm getting "In field \"id\": Unknown field." in the GraphQL response error. It's referring to the
id
provided in the has_many related record .

# This is the updateWebSite input argument. It's a UpdateWebSiteInput type.
input = %{
  # The has_many relationship
  components: [
    %{
      # This is the primary key of the associated record (UpdateWebSiteComponentsInput)
      id: "38f61258-0e8f-4a99-8bae-0cb892e6ccaa",
      value: "new value",
      key: "test-component",
    }
  ]
}


Here are the relevant parts of my WebSite resource:

actions do
  # Add a set of simple actions. You'll customize these later.
  defaults [:read, :destroy]

  update :update do
    argument :components, {:array, :map}

    # I'm not sure what options to pass here.
    # These current options I got from looking at the AshGraphql tests
    change manage_relationship(
              :components,
              type: :direct_control,
              on_lookup: :relate,
              on_no_match: :create
            )
  end
end
  
managed_relationships do
  managed_relationship :create, :components

  # I'm not sure what options to pass here
  managed_relationship :update, :components
  # managed_relationship :update, :components, lookup_with_primary_key?: true
end


I tried playing with the options both for change manage_relationship() and managed_relationship(). I got different errors. I'm not quite understanding the documentation yet.
Was this page helpful?