Skip to content

Commit 5b751bf

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

File tree

3 files changed

+45
-2
lines changed

3 files changed

+45
-2
lines changed

lib/absinthe/blueprint/schema/enum_type_definition.ex

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ defmodule Absinthe.Blueprint.Schema.EnumTypeDefinition do
2929
flags: Blueprint.flags_t(),
3030
errors: [Absinthe.Phase.Error.t()]
3131
}
32+
3233
def build(type_def, _schema) do
3334
%Absinthe.Type.Enum{
3435
identifier: type_def.identifier,

lib/absinthe/schema/notation/sdl_render.ex

+37-1
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,43 @@ 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+
typ =
113+
case input_value.type do
114+
%Absinthe.Blueprint.TypeReference.NonNull{of_type: t} -> t
115+
%Absinthe.Blueprint.TypeReference.List{of_type: t} -> t
116+
t -> t
117+
end
118+
119+
definition = Enum.find(type_definitions, fn d -> typ == d.identifier end)
120+
121+
case definition do
122+
nil ->
123+
value
124+
125+
_ ->
126+
enum = Absinthe.Blueprint.Schema.EnumTypeDefinition.build(definition, nil)
127+
128+
%Blueprint.Input.Enum{
129+
value: Absinthe.Type.Enum.serialize(enum, value),
130+
source_location: input_value.source_location
131+
}
132+
end
133+
134+
value ->
135+
Blueprint.Input.parse(value)
136+
end
137+
106138
concat([
107139
string(@adapter.to_external_name(input_value.name, :argument)),
108140
": ",
109141
render(input_value.type, type_definitions),
110-
default(input_value.default_value_blueprint),
142+
default(input_value.default_value_blueprint || default_value),
111143
directives(input_value.directives, type_definitions)
112144
])
113145
|> description(input_value.description)
@@ -342,6 +374,10 @@ defmodule Absinthe.Schema.Notation.SDL.Render do
342374
empty()
343375
end
344376

377+
defp default(%{value: nil}) do
378+
empty()
379+
end
380+
345381
defp default(default_value) do
346382
concat([" = ", render_value(default_value)])
347383
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, non_null(: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)