AshGraphQL read action has more arguments required than expected

I have a an action:

    read :by_domain do
      primary? false

      argument :domain, :string, allow_nil?: false

      get? true

      filter expr(domain == ^arg(:domain))
    end

Which works as expected calling from Elixir, but when used in GraphQL:

  graphql do
    type :company

    queries do
      list :list_companies, :read, paginate_with: nil
      get :exists, :by_domain
      get :company_by_id, :by_id
      get :company_by_domain, :by_domain
    end

    mutations do
    end
  end

The generated schema wants there to be an argument of id: ID! in addition to the domain string argument.

get :company_by_domain, :by_domain, identity: false

Get queries add an id and do the filtering on the underlying action, so you can point them at your primary read action. You can use the above snippet to make your current code work.

However, you can point both your get queries at a primary read. The get by id will add an id filter automatically, then you can say identity: :org_identity_bame. Helps prevent the proliferation of actions unnecessarily.

1 Like

Ah, that’s great! For anyone following I changed to this:

    queries do
      list :list_companies, :read, paginate_with: nil
      get :company_by_id, :read
      get :company_by_domain, :read, identity: :unique_domain
    end

  identities do
    identity :unique_domain, [:domain]
  end

and get this: