diff --git a/lib/absinthe/schema/notation/sdl_render.ex b/lib/absinthe/schema/notation/sdl_render.ex index 83496b2d5b..78d38a9dec 100644 --- a/lib/absinthe/schema/notation/sdl_render.ex +++ b/lib/absinthe/schema/notation/sdl_render.ex @@ -103,14 +103,47 @@ 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) + |> deprecation(input_value.deprecation) end defp render(%Blueprint.Schema.FieldDefinition{} = field, type_definitions) do @@ -122,6 +155,7 @@ defmodule Absinthe.Schema.Notation.SDL.Render do directives(field.directives, type_definitions) ]) |> description(field.description) + |> deprecation(field.deprecation) end defp render(%Blueprint.Schema.ObjectTypeDefinition{} = object_type, type_definitions) do @@ -211,6 +245,7 @@ defmodule Absinthe.Schema.Notation.SDL.Render do directives(enum_value.directives, type_definitions) ]) |> description(enum_value.description) + |> deprecation(enum_value.deprecation) end defp render(%Blueprint.Schema.ScalarTypeDefinition{} = scalar_type, type_definitions) do @@ -342,6 +377,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 @@ -358,6 +397,14 @@ defmodule Absinthe.Schema.Notation.SDL.Render do ]) end + defp deprecation(docs, nil) do + docs + end + + defp deprecation(docs, %Absinthe.Type.Deprecation{reason: reason}) do + concat([docs, " @deprecated(reason: \"#{reason}\")"]) + end + defp implements(%{interface_blueprints: [], interfaces: []}, _) do empty() end diff --git a/test/absinthe/schema/sdl_render_test.exs b/test/absinthe/schema/sdl_render_test.exs index f9d27f3df8..d2d3a8ffb7 100644 --- a/test/absinthe/schema/sdl_render_test.exs +++ b/test/absinthe/schema/sdl_render_test.exs @@ -196,7 +196,9 @@ 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_interval, :integer, deprecate: "Old interval" + arg :time_string, :string, default_value: "2021" + arg :order_status, non_null(:order_status), default_value: :processing end field :search, :search_result @@ -219,6 +221,7 @@ defmodule Absinthe.Schema.SdlRenderTest do object :order do field :id, :id field :name, :string + field :braun, :string, deprecate: "Deprecated" field :status, :order_status field :other_status, :status import_fields :imported_fields @@ -251,9 +254,13 @@ defmodule Absinthe.Schema.SdlRenderTest do type RootQueryType { echo( "The number of times" - times: Int + times: Int = 10 - timeInterval: Int + timeInterval: Int @deprecated(reason: \"Old interval\") + + timeString: String = "2021" + + orderStatus: OrderStatus! = PROCESSING ): String search: SearchResult } @@ -280,6 +287,7 @@ defmodule Absinthe.Schema.SdlRenderTest do imported: Boolean! id: ID name: String + braun: String @deprecated(reason: \"Deprecated\") status: OrderStatus otherStatus: Status }