Packages

The extension for building GraphQL APIs with Ash

Current section

Files

Jump to
ash_graphql lib resource transformers require_id_pkey.ex
Raw

lib/resource/transformers/require_id_pkey.ex

defmodule AshGraphql.Resource.Transformers.RequireIdPkey do
@moduledoc "Ensures that the resource has a primary key called `id`"
use Ash.Dsl.Transformer
alias Ash.Dsl.Transformer
def transform(_resource, dsl) do
primary_key =
dsl
|> Transformer.get_entities([:attributes])
|> Enum.filter(& &1.primary_key?)
|> Enum.map(& &1.name)
unless primary_key == [:id] do
raise "AshGraphql currently requires the primary key to be a field called `id`"
end
{:ok, dsl}
end
end