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 5b751bf
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
1 change: 1 addition & 0 deletions lib/absinthe/blueprint/schema/enum_type_definition.ex
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ defmodule Absinthe.Blueprint.Schema.EnumTypeDefinition do
flags: Blueprint.flags_t(),
errors: [Absinthe.Phase.Error.t()]
}

def build(type_def, _schema) do
%Absinthe.Type.Enum{
identifier: type_def.identifier,
Expand Down
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 5b751bf

Please sign in to comment.