diff --git a/lib/absinthe/blueprint/schema/enum_type_definition.ex b/lib/absinthe/blueprint/schema/enum_type_definition.ex index 7afbb43248..59951c605f 100644 --- a/lib/absinthe/blueprint/schema/enum_type_definition.ex +++ b/lib/absinthe/blueprint/schema/enum_type_definition.ex @@ -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, diff --git a/lib/absinthe/schema/notation/sdl_render.ex b/lib/absinthe/schema/notation/sdl_render.ex index 83496b2d5b..e7fb38b700 100644 --- a/lib/absinthe/schema/notation/sdl_render.ex +++ b/lib/absinthe/schema/notation/sdl_render.ex @@ -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) @@ -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 diff --git a/test/absinthe/schema/sdl_render_test.exs b/test/absinthe/schema/sdl_render_test.exs index f9d27f3df8..cb4e584ba9 100644 --- a/test/absinthe/schema/sdl_render_test.exs +++ b/test/absinthe/schema/sdl_render_test.exs @@ -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 @@ -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 }