Skip to content

Commit

Permalink
Default values wheren't rendered in the sdl
Browse files Browse the repository at this point in the history
  • Loading branch information
SvenW committed Oct 8, 2021
1 parent 9ab7af0 commit e5cf7b9
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
38 changes: 37 additions & 1 deletion lib/absinthe/schema/notation/sdl_render.ex
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,43 @@ defmodule Absinthe.Schema.Notation.SDL.Render do

@adapter Absinthe.Adapter.LanguageConventions
defp render(%Blueprint.Schema.InputValueDefinition{} = input_value, type_definitions) do
default_value =
case input_value.default_value do
nil ->
nil

value when is_atom(value) ->
typ =
case input_value.type do
%Absinthe.Blueprint.TypeReference.NonNull{of_type: t} -> t
%Absinthe.Blueprint.TypeReference.List{of_type: t} -> t
t -> t
end

definition = Enum.find(type_definitions, fn d -> typ == d.identifier end)

case definition do
nil ->
value

_ ->
enum = Absinthe.Blueprint.Schema.EnumTypeDefinition.build(definition, nil)

%Blueprint.Input.Enum{
value: Absinthe.Type.Enum.serialize(enum, value),
source_location: input_value.source_location
}
end

value ->
Blueprint.Input.parse(value)
end

concat([
string(@adapter.to_external_name(input_value.name, :argument)),
": ",
render(input_value.type, type_definitions),
default(input_value.default_value_blueprint),
default(input_value.default_value_blueprint || default_value),
directives(input_value.directives, type_definitions)
])
|> description(input_value.description)
Expand Down Expand Up @@ -342,6 +374,10 @@ defmodule Absinthe.Schema.Notation.SDL.Render do
empty()
end

defp default(%{value: nil}) do
empty()
end

defp default(default_value) do
concat([" = ", render_value(default_value)])
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 @@ -197,6 +197,8 @@ defmodule Absinthe.Schema.SdlRenderTest do
field :echo, :string do
arg :times, :integer, default_value: 10, description: "The number of times"
arg :time_interval, :integer
arg :time_string, :string, default_value: "2021"
arg :order_status, non_null(:order_status), default_value: :processing
end

field :search, :search_result
Expand Down Expand Up @@ -251,9 +253,13 @@ defmodule Absinthe.Schema.SdlRenderTest do
type RootQueryType {
echo(
"The number of times"
times: Int
times: Int = 10
timeInterval: Int
timeString: String = "2021"
orderStatus: OrderStatus! = PROCESSING
): String
search: SearchResult
}
Expand Down

0 comments on commit e5cf7b9

Please sign in to comment.