Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set include_deprecated default value to true for backwards compatibility #1333

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/absinthe/type/built_ins/introspection.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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} ->
Expand Down Expand Up @@ -187,7 +187,7 @@ defmodule Absinthe.Type.BuiltIns.Introspection do
args: [
include_deprecated: [
type: :boolean,
default_value: false
default_value: true
]
],
resolve: fn
Expand Down Expand Up @@ -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}} ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
83 changes: 79 additions & 4 deletions test/absinthe/introspection_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -211,15 +211,15 @@ 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 =
"""
{
__type(name: "ProfileInput") {
kind
name
description
inputFields {
inputFields(includeDeprecated: false) {
name
description
type {
Expand Down Expand Up @@ -278,15 +278,15 @@ 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 =
"""
{
__type(name: "ProfileInput") {
kind
name
description
inputFields(includeDeprecated: true) {
inputFields {
name
description
type {
Expand Down Expand Up @@ -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

Expand Down