Skip to content

Commit 7ed5f98

Browse files
committed
Default values wheren't rendered in the sdl
1 parent 9ab7af0 commit 7ed5f98

File tree

3 files changed

+39
-2
lines changed

3 files changed

+39
-2
lines changed

lib/absinthe/blueprint/schema/enum_type_definition.ex

+2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ defmodule Absinthe.Blueprint.Schema.EnumTypeDefinition do
2929
flags: Blueprint.flags_t(),
3030
errors: [Absinthe.Phase.Error.t()]
3131
}
32+
33+
@spec build(t, any) :: Absinthe.Type.Enum.t()
3234
def build(type_def, _schema) do
3335
%Absinthe.Type.Enum{
3436
identifier: type_def.identifier,

lib/absinthe/schema/notation/sdl_render.ex

+30-1
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,36 @@ defmodule Absinthe.Schema.Notation.SDL.Render do
103103

104104
@adapter Absinthe.Adapter.LanguageConventions
105105
defp render(%Blueprint.Schema.InputValueDefinition{} = input_value, type_definitions) do
106+
default_value =
107+
case input_value.default_value do
108+
nil ->
109+
nil
110+
111+
value when is_atom(value) ->
112+
definition = Enum.find(type_definitions, fn d -> input_value.type == d.identifier end)
113+
114+
case definition do
115+
nil ->
116+
value
117+
118+
_ ->
119+
enum = Absinthe.Blueprint.Schema.EnumTypeDefinition.build(definition, nil)
120+
121+
%Blueprint.Input.Enum{
122+
value: Absinthe.Type.Enum.serialize(enum, value),
123+
source_location: input_value.source_location
124+
}
125+
end
126+
127+
value ->
128+
Blueprint.Input.parse(value)
129+
end
130+
106131
concat([
107132
string(@adapter.to_external_name(input_value.name, :argument)),
108133
": ",
109134
render(input_value.type, type_definitions),
110-
default(input_value.default_value_blueprint),
135+
default(input_value.default_value_blueprint || default_value),
111136
directives(input_value.directives, type_definitions)
112137
])
113138
|> description(input_value.description)
@@ -342,6 +367,10 @@ defmodule Absinthe.Schema.Notation.SDL.Render do
342367
empty()
343368
end
344369

370+
defp default(%{value: nil}) do
371+
empty()
372+
end
373+
345374
defp default(default_value) do
346375
concat([" = ", render_value(default_value)])
347376
end

test/absinthe/schema/sdl_render_test.exs

+7-1
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,8 @@ defmodule Absinthe.Schema.SdlRenderTest do
197197
field :echo, :string do
198198
arg :times, :integer, default_value: 10, description: "The number of times"
199199
arg :time_interval, :integer
200+
arg :time_string, :string, default_value: "2021"
201+
arg :order_status, :order_status, default_value: :processing
200202
end
201203

202204
field :search, :search_result
@@ -251,9 +253,13 @@ defmodule Absinthe.Schema.SdlRenderTest do
251253
type RootQueryType {
252254
echo(
253255
"The number of times"
254-
times: Int
256+
times: Int = 10
255257
256258
timeInterval: Int
259+
260+
timeString: String = "2021"
261+
262+
orderStatus: OrderStatus = PROCESSING
257263
): String
258264
search: SearchResult
259265
}

0 commit comments

Comments
 (0)