Skip to content

Commit

Permalink
Deprecated input_fields for absinthe.schema.json
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronrenner committed Oct 28, 2024
1 parent e37e285 commit 279e4db
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 2 deletions.
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
2 changes: 1 addition & 1 deletion priv/graphql/introspection.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ fragment FullType on __Type {
isDeprecated
deprecationReason
}
inputFields {
inputFields(includeDeprecated: true) {
...InputValue
}
interfaces {
Expand Down
42 changes: 41 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,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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 279e4db

Please sign in to comment.