From 279e4dbb8e8e4bdc3d49616648fb9a2d2fa7aef5 Mon Sep 17 00:00:00 2001 From: Aaron Renner Date: Mon, 28 Oct 2024 12:31:36 -0600 Subject: [PATCH 1/3] Deprecated input_fields for absinthe.schema.json --- mix.exs | 1 + mix.lock | 1 + priv/graphql/introspection.graphql | 2 +- test/mix/tasks/absinthe.schema.json_test.exs | 42 +++++++++++++++++++- 4 files changed, 44 insertions(+), 2 deletions(-) diff --git a/mix.exs b/mix.exs index b4717669f9..c62ea854d1 100644 --- a/mix.exs +++ b/mix.exs @@ -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} ] diff --git a/mix.lock b/mix.lock index 472f9ca11d..a6fe4bb996 100644 --- a/mix.lock +++ b/mix.lock @@ -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"}, diff --git a/priv/graphql/introspection.graphql b/priv/graphql/introspection.graphql index 3f8b0fd5e9..62369e5839 100644 --- a/priv/graphql/introspection.graphql +++ b/priv/graphql/introspection.graphql @@ -41,7 +41,7 @@ fragment FullType on __Type { isDeprecated deprecationReason } - inputFields { + inputFields(includeDeprecated: true) { ...InputValue } interfaces { diff --git a/test/mix/tasks/absinthe.schema.json_test.exs b/test/mix/tasks/absinthe.schema.json_test.exs index d7081cbd42..b4ce25dc65 100644 --- a/test/mix/tasks/absinthe.schema.json_test.exs +++ b/test/mix/tasks/absinthe.schema.json_test.exs @@ -10,11 +10,28 @@ defmodule Mix.Tasks.Absinthe.Schema.JsonTest do field :item, :item end + mutation do + field :update_item, + type: :item, + args: [ + id: [type: non_null(:string)], + 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 @@ -99,10 +116,33 @@ 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 end @tag :tmp_dir From 0db27b3340dbefad4a02b6b867fb4dc524669b38 Mon Sep 17 00:00:00 2001 From: Aaron Renner Date: Tue, 29 Oct 2024 14:03:21 -0600 Subject: [PATCH 2/3] Include deprecated fields args --- priv/graphql/introspection.graphql | 2 +- test/mix/tasks/absinthe.schema.json_test.exs | 23 +++++++++++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/priv/graphql/introspection.graphql b/priv/graphql/introspection.graphql index 62369e5839..c1088e4afd 100644 --- a/priv/graphql/introspection.graphql +++ b/priv/graphql/introspection.graphql @@ -32,7 +32,7 @@ fragment FullType on __Type { fields(includeDeprecated: true) { name description - args { + args(includeDeprecated: true) { ...InputValue } type { diff --git a/test/mix/tasks/absinthe.schema.json_test.exs b/test/mix/tasks/absinthe.schema.json_test.exs index b4ce25dc65..163c1aec5e 100644 --- a/test/mix/tasks/absinthe.schema.json_test.exs +++ b/test/mix/tasks/absinthe.schema.json_test.exs @@ -14,7 +14,7 @@ defmodule Mix.Tasks.Absinthe.Schema.JsonTest do field :update_item, type: :item, args: [ - id: [type: non_null(:string)], + id: [type: non_null(:string), deprecate: true], item: [type: non_null(:input_item)] ] end @@ -143,6 +143,27 @@ defmodule Mix.Tasks.Absinthe.Schema.JsonTest do 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 end @tag :tmp_dir From 271c4340d45c6010389307524a5fb8d376acc10f Mon Sep 17 00:00:00 2001 From: Aaron Renner Date: Tue, 29 Oct 2024 14:08:58 -0600 Subject: [PATCH 3/3] Include deprecated directive args --- priv/graphql/introspection.graphql | 2 +- test/mix/tasks/absinthe.schema.json_test.exs | 33 ++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/priv/graphql/introspection.graphql b/priv/graphql/introspection.graphql index c1088e4afd..763678e570 100644 --- a/priv/graphql/introspection.graphql +++ b/priv/graphql/introspection.graphql @@ -18,7 +18,7 @@ query IntrospectionQuery { description locations isRepeatable - args { + args(includeDeprecated: true) { ...InputValue } } diff --git a/test/mix/tasks/absinthe.schema.json_test.exs b/test/mix/tasks/absinthe.schema.json_test.exs index 163c1aec5e..502e7fc4b4 100644 --- a/test/mix/tasks/absinthe.schema.json_test.exs +++ b/test/mix/tasks/absinthe.schema.json_test.exs @@ -10,6 +10,20 @@ 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, @@ -164,6 +178,25 @@ defmodule Mix.Tasks.Absinthe.Schema.JsonTest do 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