Skip to content

Commit

Permalink
Fix union render with no types (#1085)
Browse files Browse the repository at this point in the history
  • Loading branch information
kdawgwilk committed Jul 15, 2021
1 parent 2f0c14c commit 62483e4
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 18 deletions.
42 changes: 25 additions & 17 deletions lib/absinthe/schema/notation/sdl_render.ex
Original file line number Diff line number Diff line change
Expand Up @@ -150,25 +150,33 @@ defmodule Absinthe.Schema.Notation.SDL.Render do
end

defp render(%Blueprint.Schema.UnionTypeDefinition{} = union_type, type_definitions) do
types =
Enum.map(union_type.types, fn
identifier when is_atom(identifier) ->
render(%Blueprint.TypeReference.Identifier{id: identifier}, type_definitions)
Enum.map(union_type.types, fn
identifier when is_atom(identifier) ->
render(%Blueprint.TypeReference.Identifier{id: identifier}, type_definitions)

%Blueprint.TypeReference.Name{} = ref ->
render(ref, type_definitions)
%Blueprint.TypeReference.Name{} = ref ->
render(ref, type_definitions)

%Blueprint.TypeReference.Identifier{} = ref ->
render(ref, type_definitions)
end)

concat([
"union ",
string(union_type.name),
directives(union_type.directives, type_definitions),
" = ",
join(types, " | ")
])
%Blueprint.TypeReference.Identifier{} = ref ->
render(ref, type_definitions)
end)
|> case do
[] ->
concat([
"union ",
string(union_type.name),
directives(union_type.directives, type_definitions)
])

types ->
concat([
"union ",
string(union_type.name),
directives(union_type.directives, type_definitions),
" = ",
join(types, " | ")
])
end
|> description(union_type.description)
end

Expand Down
8 changes: 7 additions & 1 deletion test/absinthe/schema/sdl_render_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,18 @@ defmodule Absinthe.Schema.SdlRenderTest do
""")
end

test "for a union" do
test "for a union with types" do
assert_rendered("""
union Foo = Bar | Baz
""")
end

test "for a union without types" do
assert_rendered("""
union Foo
""")
end

test "for a scalar" do
assert_rendered("""
scalar MyGreatScalar
Expand Down

0 comments on commit 62483e4

Please sign in to comment.