mirror of
https://github.com/ash-project/ash_graphql.git
synced 2024-09-20 13:24:14 +12:00
20 lines
524 B
Elixir
20 lines
524 B
Elixir
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
|