From a376cc6efd559f388f333a355fd9a6c50b1cba5e Mon Sep 17 00:00:00 2001 From: Filipe Monteiro Date: Wed, 31 Jul 2024 11:12:35 -0300 Subject: [PATCH] Set include_deprecated default value to true for backwards compatibility --- lib/absinthe/type/built_ins/introspection.ex | 6 +- .../fragments/introspection_test.exs | 8 +- test/absinthe/introspection_test.exs | 83 ++++++++++++++++++- 3 files changed, 89 insertions(+), 8 deletions(-) diff --git a/lib/absinthe/type/built_ins/introspection.ex b/lib/absinthe/type/built_ins/introspection.ex index 7275c661ca..057611afde 100644 --- a/lib/absinthe/type/built_ins/introspection.ex +++ b/lib/absinthe/type/built_ins/introspection.ex @@ -72,7 +72,7 @@ defmodule Absinthe.Type.BuiltIns.Introspection do args: [ include_deprecated: [ type: :boolean, - default_value: false + default_value: true ] ], resolve: fn %{include_deprecated: show_deprecated}, %{source: source} -> @@ -187,7 +187,7 @@ defmodule Absinthe.Type.BuiltIns.Introspection do args: [ include_deprecated: [ type: :boolean, - default_value: false + default_value: true ] ], resolve: fn @@ -230,7 +230,7 @@ defmodule Absinthe.Type.BuiltIns.Introspection do args: [ include_deprecated: [ type: :boolean, - default_value: false + default_value: true ] ], resolve: fn %{include_deprecated: show_deprecated}, %{source: %{args: args}} -> diff --git a/test/absinthe/integration/execution/fragments/introspection_test.exs b/test/absinthe/integration/execution/fragments/introspection_test.exs index 2ac96c6f5e..e00ece193f 100644 --- a/test/absinthe/integration/execution/fragments/introspection_test.exs +++ b/test/absinthe/integration/execution/fragments/introspection_test.exs @@ -33,7 +33,13 @@ defmodule Elixir.Absinthe.Integration.Execution.Fragments.IntrospectionTest do } }} = result - correct = [%{"name" => "code"}, %{"name" => "name"}, %{"name" => "age"}] + correct = [ + %{"name" => "address"}, + %{"name" => "code"}, + %{"name" => "name"}, + %{"name" => "age"} + ] + sort = & &1["name"] assert Enum.sort_by(input_fields, sort) == Enum.sort_by(correct, sort) end diff --git a/test/absinthe/introspection_test.exs b/test/absinthe/introspection_test.exs index c2e5dd1eba..c884e99d15 100644 --- a/test/absinthe/introspection_test.exs +++ b/test/absinthe/introspection_test.exs @@ -211,7 +211,7 @@ defmodule Absinthe.IntrospectionTest do end describe "introspection of an input object type" do - test "can use __type and ignore deprecated fields" do + test "can use __type and ignore deprecated fields based on an arg" do result = """ { @@ -219,7 +219,7 @@ defmodule Absinthe.IntrospectionTest do kind name description - inputFields { + inputFields(includeDeprecated: false) { name description type { @@ -278,7 +278,7 @@ defmodule Absinthe.IntrospectionTest do assert !match?({:ok, %{data: %{"__type" => %{"fields" => _}}}}, result) end - test "can include deprecated fields based on an arg" do + test "includes deprecated fields by default" do result = """ { @@ -286,7 +286,7 @@ defmodule Absinthe.IntrospectionTest do kind name description - inputFields(includeDeprecated: true) { + inputFields { name description type { @@ -365,6 +365,81 @@ defmodule Absinthe.IntrospectionTest do assert !match?({:ok, %{data: %{"__type" => %{"fields" => _}}}}, result) end + test "can remove deprecated fields based on an arg" do + result = + """ + { + __type(name: "ProfileInput") { + kind + name + description + inputFields(includeDeprecated: false) { + name + description + type { + kind + name + ofType { + kind + name + } + } + defaultValue + isDeprecated + deprecationReason + } + } + } + """ + |> run(Absinthe.Fixtures.ContactSchema) + + assert_result( + {:ok, + %{ + data: %{ + "__type" => %{ + "description" => "The basic details for a person", + "inputFields" => [ + %{ + "defaultValue" => "43", + "description" => "The person's age", + "name" => "age", + "type" => %{"kind" => "SCALAR", "name" => "Int", "ofType" => nil}, + "deprecationReason" => nil, + "isDeprecated" => false + }, + %{ + "defaultValue" => nil, + "description" => nil, + "name" => "code", + "type" => %{ + "kind" => "NON_NULL", + "name" => nil, + "ofType" => %{"kind" => "SCALAR", "name" => "String"} + }, + "deprecationReason" => nil, + "isDeprecated" => false + }, + %{ + "defaultValue" => "\"Janet\"", + "description" => "The person's name", + "name" => "name", + "type" => %{"kind" => "SCALAR", "name" => "String", "ofType" => nil}, + "deprecationReason" => nil, + "isDeprecated" => false + } + ], + "kind" => "INPUT_OBJECT", + "name" => "ProfileInput" + } + } + }}, + result + ) + + assert !match?({:ok, %{data: %{"__type" => %{"fields" => _}}}}, result) + end + defmodule ComplexDefaultSchema do use Absinthe.Schema