Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Workaround for values defined as list of atoms #1041

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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