Skip to content

Commit

Permalink
Workaround for values defined as list of atoms (#1041)
Browse files Browse the repository at this point in the history
  • Loading branch information
binaryseed authored Feb 5, 2021
1 parent daa79c0 commit 19f1e8d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
19 changes: 17 additions & 2 deletions lib/absinthe/schema/notation/sdl_render.ex
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ defmodule Absinthe.Schema.Notation.SDL.Render do
string(enum_type.name),
directives(enum_type.directives, type_definitions)
]),
render_list(enum_type.values, type_definitions)
render_list(List.flatten(enum_type.values), type_definitions)
)
|> description(enum_type.description)
end
Expand Down Expand Up @@ -380,7 +380,22 @@ defmodule Absinthe.Schema.Notation.SDL.Render do

# Render Helpers

defp render_list(items, type_definitions, seperator \\ line()) do
defp render_list(items, type_definitions, seperator \\ line())

# Workaround for `values` macro which temporarily defines
# values as raw atoms to support dynamic schemas
defp render_list([first | _] = items, type_definitions, seperator) when is_atom(first) do
items
|> Enum.map(
&%Blueprint.Schema.EnumValueDefinition{
value: &1,
name: String.upcase(to_string(&1))
}
)
|> render_list(type_definitions, seperator)
end

defp render_list(items, type_definitions, seperator) do
items = Enum.reject(items, &(&1.module in @skip_modules))

splitter =
Expand Down
10 changes: 10 additions & 0 deletions test/absinthe/schema/sdl_render_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,13 @@ defmodule Absinthe.Schema.SdlRenderTest do
value :picking
end

enum :status, values: [:one, :two, :three]

object :order do
field :id, :id
field :name, :string
field :status, :order_status
field :other_status, :status
import_fields :imported_fields
end

Expand Down Expand Up @@ -255,6 +258,12 @@ defmodule Absinthe.Schema.SdlRenderTest do
union SearchResult = Order | Category
enum Status {
ONE
TWO
THREE
}
enum OrderStatus {
DELIVERED
PROCESSING
Expand All @@ -266,6 +275,7 @@ defmodule Absinthe.Schema.SdlRenderTest do
id: ID
name: String
status: OrderStatus
otherStatus: Status
}
"""
end
Expand Down

0 comments on commit 19f1e8d

Please sign in to comment.