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

Include deprecated input_fields for absinthe.schema.json #1345

Open
wants to merge 3 commits 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
1 change: 1 addition & 0 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ defmodule Absinthe.Mixfile do
{:ex_doc, "~> 0.22", only: :dev},
{:benchee, ">= 1.0.0", only: :dev},
{:dialyxir, "~> 1.1", only: [:dev, :test], runtime: false},
{:jason, "~> 1.0", only: :test, runtime: false},
{:mix_test_watch, "~> 1.0", only: :dev, runtime: false},
{:makeup_graphql, "~> 0.1.0", only: :dev}
]
Expand Down
1 change: 1 addition & 0 deletions mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"erlex": {:hex, :erlex, "0.2.6", "c7987d15e899c7a2f34f5420d2a2ea0d659682c06ac607572df55a43753aa12e", [:mix], [], "hexpm", "2ed2e25711feb44d52b17d2780eabf998452f6efda104877a3881c2f8c0c0c75"},
"ex_doc": {:hex, :ex_doc, "0.30.9", "d691453495c47434c0f2052b08dd91cc32bc4e1a218f86884563448ee2502dd2", [:mix], [{:earmark_parser, "~> 1.4.31", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1", [hex: :makeup_erlang, repo: "hexpm", optional: false]}], "hexpm", "d7aaaf21e95dc5cddabf89063327e96867d00013963eadf2c6ad135506a8bc10"},
"file_system": {:hex, :file_system, "0.2.10", "fb082005a9cd1711c05b5248710f8826b02d7d1784e7c3451f9c1231d4fc162d", [:mix], [], "hexpm", "41195edbfb562a593726eda3b3e8b103a309b733ad25f3d642ba49696bf715dc"},
"jason": {:hex, :jason, "1.4.4", "b9226785a9aa77b6857ca22832cffa5d5011a667207eb2a0ad56adb5db443b8a", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "c5eb0cab91f094599f94d55bc63409236a8ec69a21a67814529e8d5f6cc90b3b"},
"makeup": {:hex, :makeup, "1.1.1", "fa0bc768698053b2b3869fa8a62616501ff9d11a562f3ce39580d60860c3a55e", [:mix], [{:nimble_parsec, "~> 1.2.2 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "5dc62fbdd0de44de194898b6710692490be74baa02d9d108bc29f007783b0b48"},
"makeup_elixir": {:hex, :makeup_elixir, "0.16.1", "cc9e3ca312f1cfeccc572b37a09980287e243648108384b97ff2b76e505c3555", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.2.3 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "e127a341ad1b209bd80f7bd1620a15693a9908ed780c3b763bccf7d200c767c6"},
"makeup_erlang": {:hex, :makeup_erlang, "0.1.2", "ad87296a092a46e03b7e9b0be7631ddcf64c790fa68a9ef5323b6cbb36affc72", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "f3f5a1ca93ce6e092d92b6d9c049bcda58a3b617a8d888f8e7231c85630e8108"},
Expand Down
6 changes: 3 additions & 3 deletions priv/graphql/introspection.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ query IntrospectionQuery {
description
locations
isRepeatable
args {
args(includeDeprecated: true) {
...InputValue
}
}
Expand All @@ -32,7 +32,7 @@ fragment FullType on __Type {
fields(includeDeprecated: true) {
name
description
args {
args(includeDeprecated: true) {
...InputValue
}
type {
Expand All @@ -41,7 +41,7 @@ fragment FullType on __Type {
isDeprecated
deprecationReason
}
inputFields {
inputFields(includeDeprecated: true) {
...InputValue
}
interfaces {
Expand Down
96 changes: 95 additions & 1 deletion test/mix/tasks/absinthe.schema.json_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,42 @@ defmodule Mix.Tasks.Absinthe.Schema.JsonTest do
field :item, :item
end

directive :mydirective do
arg :if, non_null(:boolean), description: "Skipped when true."
arg :unless, non_null(:boolean), description: "Skipped when false.", deprecate: "Use if"
on [:field, :fragment_spread, :inline_fragment]

expand fn
%{if: true}, node ->
Absinthe.Blueprint.put_flag(node, :skip, __MODULE__)

_, node ->
node
end
end

mutation do
field :update_item,
type: :item,
args: [
id: [type: non_null(:string), deprecate: true],
item: [type: non_null(:input_item)]
]
end

object :item do
description "A Basic Type"
field :id, :id
field :name, :string
end

input_object :input_item do
description "A thing as input"
field :value, :integer
field :deprecated_field, :string, deprecate: true
field :deprecated_field_with_reason, :string, deprecate: "reason"
field :deprecated_non_null_field, non_null(:string), deprecate: true
end
end

defmodule PersistentTermTestSchema do
Expand Down Expand Up @@ -99,10 +130,73 @@ defmodule Mix.Tasks.Absinthe.Schema.JsonTest do
test "generates a JSON file", %{tmp_dir: tmp_dir} do
path = Path.join(tmp_dir, "schema.json")

argv = ["--schema", @test_schema, "--json-codec", @test_encoder, path]
argv = ["--schema", @test_schema, path]
assert Task.run(argv)

assert File.exists?(path)

decoded_schema = path |> File.read!() |> Jason.decode!()

# Includes deprecated fields by default
input_thing_field_names =
get_in(
decoded_schema,
[
"data",
"__schema",
"types",
Access.filter(&(&1["name"] == "InputItem")),
"inputFields",
Access.all(),
"name"
]
)
|> List.flatten()

assert "value" in input_thing_field_names
assert "deprecatedField" in input_thing_field_names
assert "deprecatedFieldWithReason" in input_thing_field_names
assert "deprecatedNonNullField" in input_thing_field_names

# Includes deprecated args by default
update_item_arg_names =
get_in(
decoded_schema,
[
"data",
"__schema",
"types",
Access.filter(&(&1["name"] == "RootMutationType")),
"fields",
Access.filter(&(&1["name"] == "updateItem")),
"args",
Access.all(),
"name"
]
)
|> List.flatten()

assert "id" in update_item_arg_names
assert "item" in update_item_arg_names

# Includes deprecated directive args by default
my_directive_arg_names =
get_in(
decoded_schema,
[
"data",
"__schema",
"directives",
Access.filter(&(&1["name"] == "mydirective")),
"args",
Access.all(),
"name"
]
)
|> List.flatten()

assert "if" in my_directive_arg_names
assert "unless" in my_directive_arg_names
end

@tag :tmp_dir
Expand Down
Loading