Skip to content

Commit

Permalink
feat: allow providing descriptions for enum values (#117)
Browse files Browse the repository at this point in the history
* chore: update ash to use Ash.Type.Enum descriptions

Contextually, remove an unreachable clause that caused dyalizer to fail,
see ash-project/ash#873 for the commit that made
it unreachable

* feat: allow providing descriptions for enum values

If the module exports `graphql_describe_enum_value/1`, use that. Otherwise,
fallback to the Ash.Type.Enum value descriptions introduced in
ash-project/ash#940.

Close #116
  • Loading branch information
rbino committed Mar 26, 2024
1 parent 1c47c79 commit 98baf6f
Show file tree
Hide file tree
Showing 9 changed files with 158 additions and 21 deletions.
8 changes: 8 additions & 0 deletions documentation/how_to/use-enums-with-graphql.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ defmodule AshPostgres.Test.Types.Status do

def graphql_rename_value(:"10"), do: :ten
def graphql_rename_value(value), do: value

# You can also provide descriptions for the enum values, which will be exposed in the GraphQL
# schema.
# Remember to have a fallback clause that returns nil if you don't provide descriptions for all
# values.

def graphql_describe_enum_value(:open), do: "The post is open"
def graphql_describe_enum_value(_), do: nil
end

```
Expand Down
16 changes: 16 additions & 0 deletions lib/ash_graphql.ex
Original file line number Diff line number Diff line change
Expand Up @@ -268,10 +268,18 @@ defmodule AshGraphql do
value
end

description =
if function_exported?(type, :graphql_describe_enum_value, 1) do
type.graphql_describe_enum_value(value)
else
enum_type_description(type, value)
end

%Absinthe.Blueprint.Schema.EnumValueDefinition{
module: schema,
identifier: value,
__reference__: AshGraphql.Resource.ref(env),
description: description,
name: String.upcase(to_string(name)),
value: value
}
Expand All @@ -283,6 +291,14 @@ defmodule AshGraphql do
|> Enum.uniq_by(& &1.identifier)
end

defp enum_type_description(type, value) do
if Spark.implements_behaviour?(type, Ash.Type.Enum) do
type.description(value)
else
nil
end
end

def global_unions(resources, schema, env) do
resources
|> Enum.flat_map(fn resource ->
Expand Down
15 changes: 0 additions & 15 deletions lib/resource/resource.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1961,21 +1961,6 @@ defmodule AshGraphql.Resource do
field.identifier == relationship.destination_attribute
end)

{:source, nil} ->
[]

{:source, action} ->
action = Ash.Resource.Info.action(relationship.source, action)

relationship.source
|> mutation_fields(schema, action, action.type)
|> Enum.map(fn field ->
{relationship.source, action.name, field}
end)
|> Enum.reject(fn {_, _, field} ->
field.identifier == relationship.source_attribute
end)

{:join, nil, _} ->
[]

Expand Down
17 changes: 16 additions & 1 deletion lib/type.ex
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,23 @@ defmodule AshGraphql.Type do
"""
@callback graphql_unnested_unions(Ash.Type.constraints()) :: [atom()]

@doc """
Used for `Ash.Type.Enum` to provide a description for individual values. For example:
```elixir
defmodule MyEnum do
use Ash.Type.Enum, values: [:foo, :bar, :baz]
def graphql_describe_enum_value(:baz), do: "A baz"
def graphql_describe_enum_value(_), do: nil
end
```
"""
@callback graphql_describe_enum_value(atom) :: String.t() | nil

@optional_callbacks graphql_type: 1,
graphql_input_type: 1,
graphql_rename_value: 1,
graphql_unnested_unions: 1
graphql_unnested_unions: 1,
graphql_describe_enum_value: 1
end
12 changes: 7 additions & 5 deletions mix.lock
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
%{
"absinthe": {:hex, :absinthe, "1.7.5", "a15054f05738e766f7cc7fd352887dfd5e61cec371fb4741cca37c3359ff74ac", [:mix], [{:dataloader, "~> 1.0.0 or ~> 2.0", [hex: :dataloader, repo: "hexpm", optional: true]}, {:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}, {:nimble_parsec, "~> 1.2.2 or ~> 1.3.0", [hex: :nimble_parsec, repo: "hexpm", optional: false]}, {:opentelemetry_process_propagator, "~> 0.2.1", [hex: :opentelemetry_process_propagator, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "22a9a38adca26294ad0ee91226168f5d215b401efd770b8a1b8fd9c9b21ec316"},
"absinthe_plug": {:hex, :absinthe_plug, "1.5.8", "38d230641ba9dca8f72f1fed2dfc8abd53b3907d1996363da32434ab6ee5d6ab", [:mix], [{:absinthe, "~> 1.5", [hex: :absinthe, repo: "hexpm", optional: false]}, {:plug, "~> 1.4", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "bbb04176647b735828861e7b2705465e53e2cf54ccf5a73ddd1ebd855f996e5a"},
"ash": {:hex, :ash, "2.18.2", "3c20d3eb029011972f2ed434c0d267ba8e45d69f2b8bbda42621493b91138213", [:mix], [{:comparable, "~> 1.0", [hex: :comparable, repo: "hexpm", optional: false]}, {:decimal, "~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:earmark, "~> 1.4", [hex: :earmark, repo: "hexpm", optional: false]}, {:ecto, "~> 3.7", [hex: :ecto, repo: "hexpm", optional: false]}, {:ets, "~> 0.8", [hex: :ets, repo: "hexpm", optional: false]}, {:jason, ">= 1.0.0", [hex: :jason, repo: "hexpm", optional: false]}, {:picosat_elixir, "~> 0.2", [hex: :picosat_elixir, repo: "hexpm", optional: false]}, {:plug, ">= 0.0.0", [hex: :plug, repo: "hexpm", optional: true]}, {:spark, ">= 1.1.50 and < 2.0.0-0", [hex: :spark, repo: "hexpm", optional: false]}, {:stream_data, "~> 0.6", [hex: :stream_data, repo: "hexpm", optional: false]}, {:telemetry, "~> 1.1", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "0402b0a7d27b920a565fc9f97137affae035ee7937ff274da706e91be1bfaaa5"},
"ash": {:hex, :ash, "2.21.1", "4b098f68ba0bb20b49216f4771b885c88f72446ea98ad97eb3ea5a2b3543770b", [:mix], [{:comparable, "~> 1.0", [hex: :comparable, repo: "hexpm", optional: false]}, {:decimal, "~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:earmark, "~> 1.4", [hex: :earmark, repo: "hexpm", optional: false]}, {:ecto, "~> 3.7", [hex: :ecto, repo: "hexpm", optional: false]}, {:ets, "~> 0.8", [hex: :ets, repo: "hexpm", optional: false]}, {:jason, ">= 1.0.0", [hex: :jason, repo: "hexpm", optional: false]}, {:picosat_elixir, "~> 0.2", [hex: :picosat_elixir, repo: "hexpm", optional: false]}, {:plug, ">= 0.0.0", [hex: :plug, repo: "hexpm", optional: true]}, {:reactor, "~> 0.6", [hex: :reactor, repo: "hexpm", optional: false]}, {:spark, ">= 1.1.55 and < 2.0.0-0", [hex: :spark, repo: "hexpm", optional: false]}, {:stream_data, "~> 0.6", [hex: :stream_data, repo: "hexpm", optional: false]}, {:telemetry, "~> 1.1", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "8890215fe59c85325af302ca307e2d103d555383f7d20b4da98bde79ec6dd76c"},
"bunt": {:hex, :bunt, "1.0.0", "081c2c665f086849e6d57900292b3a161727ab40431219529f13c4ddcf3e7a44", [:mix], [], "hexpm", "dc5f86aa08a5f6fa6b8096f0735c4e76d54ae5c9fa2c143e5a1fc7c1cd9bb6b5"},
"comparable": {:hex, :comparable, "1.0.0", "bb669e91cedd14ae9937053e5bcbc3c52bb2f22422611f43b6e38367d94a495f", [:mix], [{:typable, "~> 0.1", [hex: :typable, repo: "hexpm", optional: false]}], "hexpm", "277c11eeb1cd726e7cd41c6c199e7e52fa16ee6830b45ad4cdc62e51f62eb60c"},
"credo": {:hex, :credo, "1.7.4", "68ca5cf89071511c12fd9919eb84e388d231121988f6932756596195ccf7fd35", [:mix], [{:bunt, "~> 0.2.1 or ~> 1.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:file_system, "~> 0.2 or ~> 1.0", [hex: :file_system, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "9cf776d062c78bbe0f0de1ecaee183f18f2c3ec591326107989b054b7dddefc2"},
"decimal": {:hex, :decimal, "2.1.1", "5611dca5d4b2c3dd497dec8f68751f1f1a54755e8ed2a966c2633cf885973ad6", [:mix], [], "hexpm", "53cfe5f497ed0e7771ae1a475575603d77425099ba5faef9394932b35020ffcc"},
"dialyxir": {:hex, :dialyxir, "1.4.1", "a22ed1e7bd3a3e3f197b68d806ef66acb61ee8f57b3ac85fc5d57354c5482a93", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "84b795d6d7796297cca5a3118444b80c7d94f7ce247d49886e7c291e1ae49801"},
"earmark": {:hex, :earmark, "1.4.46", "8c7287bd3137e99d26ae4643e5b7ef2129a260e3dcf41f251750cb4563c8fb81", [:mix], [], "hexpm", "798d86db3d79964e759ddc0c077d5eb254968ed426399fbf5a62de2b5ff8910a"},
"earmark_parser": {:hex, :earmark_parser, "1.4.39", "424642f8335b05bb9eb611aa1564c148a8ee35c9c8a8bba6e129d51a3e3c6769", [:mix], [], "hexpm", "06553a88d1f1846da9ef066b87b57c6f605552cfbe40d20bd8d59cc6bde41944"},
"ecto": {:hex, :ecto, "3.11.1", "4b4972b717e7ca83d30121b12998f5fcdc62ba0ed4f20fd390f16f3270d85c3e", [:mix], [{:decimal, "~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "ebd3d3772cd0dfcd8d772659e41ed527c28b2a8bde4b00fe03e0463da0f1983b"},
"elixir_make": {:hex, :elixir_make, "0.7.8", "505026f266552ee5aabca0b9f9c229cbb496c689537c9f922f3eb5431157efc7", [:mix], [{:castore, "~> 0.1 or ~> 1.0", [hex: :castore, repo: "hexpm", optional: true]}, {:certifi, "~> 2.0", [hex: :certifi, repo: "hexpm", optional: true]}], "hexpm", "7a71945b913d37ea89b06966e1342c85cfe549b15e6d6d081e8081c493062c07"},
"ecto": {:hex, :ecto, "3.11.2", "e1d26be989db350a633667c5cda9c3d115ae779b66da567c68c80cfb26a8c9ee", [:mix], [{:decimal, "~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "3c38bca2c6f8d8023f2145326cc8a80100c3ffe4dcbd9842ff867f7fc6156c65"},
"elixir_make": {:hex, :elixir_make, "0.8.3", "d38d7ee1578d722d89b4d452a3e36bcfdc644c618f0d063b874661876e708683", [:mix], [{:castore, "~> 0.1 or ~> 1.0", [hex: :castore, repo: "hexpm", optional: true]}, {:certifi, "~> 2.0", [hex: :certifi, repo: "hexpm", optional: true]}], "hexpm", "5c99a18571a756d4af7a4d89ca75c28ac899e6103af6f223982f09ce44942cc9"},
"erlex": {:hex, :erlex, "0.2.6", "c7987d15e899c7a2f34f5420d2a2ea0d659682c06ac607572df55a43753aa12e", [:mix], [], "hexpm", "2ed2e25711feb44d52b17d2780eabf998452f6efda104877a3881c2f8c0c0c75"},
"ets": {:hex, :ets, "0.9.0", "79c6a6c205436780486f72d84230c6cba2f8a9920456750ddd1e47389107d5fd", [:mix], [], "hexpm", "2861fdfb04bcaeff370f1a5904eec864f0a56dcfebe5921ea9aadf2a481c822b"},
"ex_check": {:hex, :ex_check, "0.15.0", "074b94c02de11c37bba1ca82ae5cc4926e6ccee862e57a485b6ba60fca2d8dc1", [:mix], [], "hexpm", "33848031a0c7e4209c3b4369ce154019788b5219956220c35ca5474299fb6a0e"},
Expand All @@ -20,6 +20,7 @@
"git_cli": {:hex, :git_cli, "0.3.0", "a5422f9b95c99483385b976f5d43f7e8233283a47cda13533d7c16131cb14df5", [:mix], [], "hexpm", "78cb952f4c86a41f4d3511f1d3ecb28edb268e3a7df278de2faa1bd4672eaf9b"},
"git_ops": {:hex, :git_ops, "2.6.0", "e0791ee1cf5db03f2c61b7ebd70e2e95cba2bb9b9793011f26609f22c0900087", [:mix], [{:git_cli, "~> 0.2", [hex: :git_cli, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.0", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "b98fca849b18aaf490f4ac7d1dd8c6c469b0cc3e6632562d366cab095e666ffe"},
"jason": {:hex, :jason, "1.4.1", "af1504e35f629ddcdd6addb3513c3853991f694921b1b9368b0bd32beb9f1b63", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "fbb01ecdfd565b56261302f7e1fcc27c4fb8f32d56eab74db621fc154604a7a1"},
"libgraph": {:hex, :libgraph, "0.16.0", "3936f3eca6ef826e08880230f806bfea13193e49bf153f93edcf0239d4fd1d07", [:mix], [], "hexpm", "41ca92240e8a4138c30a7e06466acc709b0cbb795c643e9e17174a178982d6bf"},
"makeup": {:hex, :makeup, "1.1.0", "6b67c8bc2882a6b6a445859952a602afc1a41c2e08379ca057c0f525366fc3ca", [:mix], [{:nimble_parsec, "~> 1.2.2 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "0a45ed501f4a8897f580eabf99a2e5234ea3e75a4373c8a52824f6e873be57a6"},
"makeup_elixir": {:hex, :makeup_elixir, "0.16.1", "cc9e3ca312f1cfeccc572b37a09980287e243648108384b97ff2b76e505c3555", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.2.3 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "e127a341ad1b209bd80f7bd1620a15693a9908ed780c3b763bccf7d200c767c6"},
"makeup_erlang": {:hex, :makeup_erlang, "0.1.2", "ad87296a092a46e03b7e9b0be7631ddcf64c790fa68a9ef5323b6cbb36affc72", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "f3f5a1ca93ce6e092d92b6d9c049bcda58a3b617a8d888f8e7231c85630e8108"},
Expand All @@ -30,9 +31,10 @@
"picosat_elixir": {:hex, :picosat_elixir, "0.2.3", "bf326d0f179fbb3b706bb2c15fbc367dacfa2517157d090fdfc32edae004c597", [:make, :mix], [{:elixir_make, "~> 0.6", [hex: :elixir_make, repo: "hexpm", optional: false]}], "hexpm", "f76c9db2dec9d2561ffaa9be35f65403d53e984e8cd99c832383b7ab78c16c66"},
"plug": {:hex, :plug, "1.15.3", "712976f504418f6dff0a3e554c40d705a9bcf89a7ccef92fc6a5ef8f16a30a97", [:mix], [{:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_crypto, "~> 1.1.1 or ~> 1.2 or ~> 2.0", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.3 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "cc4365a3c010a56af402e0809208873d113e9c38c401cabd88027ef4f5c01fd2"},
"plug_crypto": {:hex, :plug_crypto, "2.0.0", "77515cc10af06645abbfb5e6ad7a3e9714f805ae118fa1a70205f80d2d70fe73", [:mix], [], "hexpm", "53695bae57cc4e54566d993eb01074e4d894b65a3766f1c43e2c61a1b0f45ea9"},
"reactor": {:hex, :reactor, "0.7.0", "fb76d23d95829b28ac9b9d654620c43c890c6a32ea26ac13086c48540b34e8c5", [:mix], [{:libgraph, "~> 0.16", [hex: :libgraph, repo: "hexpm", optional: false]}, {:spark, "~> 1.0", [hex: :spark, repo: "hexpm", optional: false]}, {:telemetry, "~> 1.2", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "4310da820d753aafd7dc4ee8cc687b84565dd6d9536e38806ee211da792178fd"},
"sobelow": {:hex, :sobelow, "0.13.0", "218afe9075904793f5c64b8837cc356e493d88fddde126a463839351870b8d1e", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "cd6e9026b85fc35d7529da14f95e85a078d9dd1907a9097b3ba6ac7ebbe34a0d"},
"sourceror": {:hex, :sourceror, "0.14.1", "c6fb848d55bd34362880da671debc56e77fd722fa13b4dcbeac89a8998fc8b09", [:mix], [], "hexpm", "8b488a219e4c4d7d9ff29d16346fd4a5858085ccdd010e509101e226bbfd8efc"},
"spark": {:hex, :spark, "1.1.54", "54dac39403a2960f738ba5d60678d20b30de7381fb51b787b6bcb6aeabb73d9d", [:mix], [{:jason, "~> 1.4", [hex: :jason, repo: "hexpm", optional: false]}, {:nimble_options, "~> 0.5 or ~> 1.0", [hex: :nimble_options, repo: "hexpm", optional: false]}, {:sourceror, "~> 0.1", [hex: :sourceror, repo: "hexpm", optional: false]}], "hexpm", "abc9a67cfb60a97d2f3c7e270fa968a2ace94f389e2741d406239d237ec6dbb1"},
"sourceror": {:hex, :sourceror, "1.0.2", "c5e86fdc14881f797749d1fe5df017ca66727a8146e7ee3e736605a3df78f3e6", [:mix], [], "hexpm", "832335e87d0913658f129d58b2a7dc0490ddd4487b02de6d85bca0169ec2bd79"},
"spark": {:hex, :spark, "1.1.55", "d20c3f899b23d841add29edc912ffab4463d3bb801bc73448738631389291d2e", [:mix], [{:jason, "~> 1.4", [hex: :jason, repo: "hexpm", optional: false]}, {:nimble_options, "~> 0.5 or ~> 1.0", [hex: :nimble_options, repo: "hexpm", optional: false]}, {:sourceror, "~> 1.0", [hex: :sourceror, repo: "hexpm", optional: false]}], "hexpm", "bbc15a4223d8e610c81ceca825d5d0bae3738d1c4ac4dbb1061749966776c3f1"},
"stream_data": {:hex, :stream_data, "0.6.0", "e87a9a79d7ec23d10ff83eb025141ef4915eeb09d4491f79e52f2562b73e5f47", [:mix], [], "hexpm", "b92b5031b650ca480ced047578f1d57ea6dd563f5b57464ad274718c9c29501c"},
"telemetry": {:hex, :telemetry, "1.2.1", "68fdfe8d8f05a8428483a97d7aab2f268aaff24b49e0f599faa091f1d4e7f61c", [:rebar3], [], "hexpm", "dad9ce9d8effc621708f99eac538ef1cbe05d6a874dd741de2e689c47feafed5"},
"typable": {:hex, :typable, "0.3.0", "0431e121d124cd26f312123e313d2689b9a5322b15add65d424c07779eaa3ca1", [:mix], [], "hexpm", "880a0797752da1a4c508ac48f94711e04c86156f498065a83d160eef945858f8"},
Expand Down
84 changes: 84 additions & 0 deletions test/enum_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
defmodule AshGraphql.EnumTest do
use ExUnit.Case, async: false

setup do
on_exit(fn ->
Application.delete_env(:ash_graphql, AshGraphql.Test.Api)

AshGraphql.TestHelpers.stop_ets()
end)
end

test "enum without value descriptions returns a nil description" do
{:ok, %{data: data}} =
"""
query {
__type(name: "StatusEnum") {
enumValues {
name
description
}
}
}
"""
|> Absinthe.run(AshGraphql.Test.Schema)

assert %{"name" => "CLOSED", "description" => nil} =
data["__type"]["enumValues"]
|> Enum.find(fn value -> value["name"] == "CLOSED" end)

assert %{"name" => "OPEN", "description" => nil} =
data["__type"]["enumValues"]
|> Enum.find(fn value -> value["name"] == "OPEN" end)
end

test "Ash.Type.Enum value descriptions are used as description source" do
{:ok, %{data: data}} =
"""
query {
__type(name: "EnumWithAshDescription") {
enumValues {
name
description
}
}
}
"""
|> Absinthe.run(AshGraphql.Test.Schema)

assert %{"name" => "FIZZ", "description" => "A fizz"} =
data["__type"]["enumValues"]
|> Enum.find(fn value -> value["name"] == "FIZZ" end)

assert %{"name" => "BUZZ", "description" => "A buzz"} =
data["__type"]["enumValues"]
|> Enum.find(fn value -> value["name"] == "BUZZ" end)
end

test "graphql_describe_enum_value/1 overrides Ash.Type.Enum descriptions" do
{:ok, %{data: data}} =
"""
query {
__type(name: "EnumWithAshGraphqlDescription") {
enumValues {
name
description
}
}
}
"""
|> Absinthe.run(AshGraphql.Test.Schema)

assert %{"name" => "FOO", "description" => "A foo"} =
data["__type"]["enumValues"]
|> Enum.find(fn value -> value["name"] == "FOO" end)

assert %{"name" => "BAR", "description" => "A bar"} =
data["__type"]["enumValues"]
|> Enum.find(fn value -> value["name"] == "BAR" end)

assert %{"name" => "NO_DESCRIPTION", "description" => nil} =
data["__type"]["enumValues"]
|> Enum.find(fn value -> value["name"] == "NO_DESCRIPTION" end)
end
end
2 changes: 2 additions & 0 deletions test/support/resources/post.ex
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,8 @@ defmodule AshGraphql.Test.Post do
attribute(:foo, AshGraphql.Test.Foo)
attribute(:status, AshGraphql.Test.Status)
attribute(:status_enum, AshGraphql.Test.StatusEnum)
attribute(:enum_with_ash_graphql_description, AshGraphql.Test.EnumWithAshGraphqlDescription)
attribute(:enum_with_ash_description, AshGraphql.Test.EnumWithAshDescription)
attribute(:best, :boolean)
attribute(:score, :float)
attribute(:integer_as_string_in_api, :integer)
Expand Down
10 changes: 10 additions & 0 deletions test/support/types/enum_with_ash_description.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
defmodule AshGraphql.Test.EnumWithAshDescription do
@moduledoc false
use Ash.Type.Enum,
values: [
fizz: "A fizz",
buzz: "A buzz"
]

def graphql_type, do: :enum_with_ash_description
end
15 changes: 15 additions & 0 deletions test/support/types/enum_with_ash_graphql_description.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
defmodule AshGraphql.Test.EnumWithAshGraphqlDescription do
@moduledoc false
use Ash.Type.Enum,
values: [
foo: "This should get ignored by AshGraphQL",
bar: "This too",
no_description: "And also this"
]

def graphql_type, do: :enum_with_ash_graphql_description

def graphql_describe_enum_value(:foo), do: "A foo"
def graphql_describe_enum_value(:bar), do: "A bar"
def graphql_describe_enum_value(_), do: nil
end

0 comments on commit 98baf6f

Please sign in to comment.