From a8c4f1a4307e27e27b6273094bc9694dc526bbec Mon Sep 17 00:00:00 2001 From: justinakoh Date: Wed, 16 Dec 2020 11:31:23 +1300 Subject: [PATCH 01/50] Add test for macro testing and fix bug in function --- lib/absinthe/schema/notation.ex | 10 +++++----- test/absinthe/type/enum_test.exs | 14 ++++++++++++++ 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/lib/absinthe/schema/notation.ex b/lib/absinthe/schema/notation.ex index 4d89bb32c4..495a3e12c7 100644 --- a/lib/absinthe/schema/notation.ex +++ b/lib/absinthe/schema/notation.ex @@ -1069,7 +1069,7 @@ defmodule Absinthe.Schema.Notation do |> expand_ast(env) |> Keyword.update(:values, [], fn values -> Enum.map(values, fn ident -> - value_attrs = handle_enum_value_attrs(ident, module: env.module) + value_attrs = handle_enum_value_attrs(ident, [], env) struct!(Schema.EnumValueDefinition, value_attrs) end) end) @@ -1410,7 +1410,7 @@ defmodule Absinthe.Schema.Notation do put_attr(env.module, {:desc, text}) end - def handle_enum_value_attrs(identifier, raw_attrs) do + def handle_enum_value_attrs(identifier, raw_attrs, env) do value = case Keyword.get(raw_attrs, :as, identifier) do value when is_tuple(value) -> @@ -1423,7 +1423,7 @@ defmodule Absinthe.Schema.Notation do end raw_attrs - |> expand_ast(raw_attrs) + |> expand_ast(env) |> Keyword.put(:identifier, identifier) |> Keyword.put(:value, value) |> Keyword.put_new(:name, String.upcase(to_string(identifier))) @@ -1434,7 +1434,7 @@ defmodule Absinthe.Schema.Notation do @doc false # Record an enum value in the current scope def record_value!(env, identifier, raw_attrs) do - attrs = handle_enum_value_attrs(identifier, raw_attrs) + attrs = handle_enum_value_attrs(identifier, raw_attrs, env) record!(env, Schema.EnumValueDefinition, identifier, attrs, []) end @@ -1445,7 +1445,7 @@ defmodule Absinthe.Schema.Notation do values |> expand_ast(env) |> Enum.map(fn ident -> - value_attrs = handle_enum_value_attrs(ident, module: env.module) + value_attrs = handle_enum_value_attrs(ident, [], env) struct!(Schema.EnumValueDefinition, value_attrs) end) diff --git a/test/absinthe/type/enum_test.exs b/test/absinthe/type/enum_test.exs index 1a6cc02c14..84a6f5e50e 100644 --- a/test/absinthe/type/enum_test.exs +++ b/test/absinthe/type/enum_test.exs @@ -14,6 +14,14 @@ defmodule Absinthe.Type.EnumTest do end end + enum :test_macro_inputting_ast do + value :red, as: :r, description: hello("red") + end + + def hello(arg1) do + arg1 + end + enum :color_channel do description "The selected color channel" value :red, as: :r, description: "Color Red" @@ -70,5 +78,11 @@ defmodule Absinthe.Type.EnumTest do assert %Type.Enum{} = type assert %Type.Enum.Value{name: "RED", value: :red, description: nil} = type.values[:red] end + + test "checking if schema works correctly" do + type = TestSchema.__absinthe_type__(:test_macro_inputting_ast) + assert %Type.Enum{} = type + assert %Type.Enum.Value{name: "RED", value: :red, description: "red"} = type.values[:red] + end end end From d0240adf047a1b842a72cdbe74ec0812d6935758 Mon Sep 17 00:00:00 2001 From: justinakoh Date: Wed, 16 Dec 2020 15:04:08 +1300 Subject: [PATCH 02/50] Fix description function evaluation --- lib/absinthe/schema/notation.ex | 1 + test/absinthe/type/enum_test.exs | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/absinthe/schema/notation.ex b/lib/absinthe/schema/notation.ex index 495a3e12c7..0eaf088b8a 100644 --- a/lib/absinthe/schema/notation.ex +++ b/lib/absinthe/schema/notation.ex @@ -1428,6 +1428,7 @@ defmodule Absinthe.Schema.Notation do |> Keyword.put(:value, value) |> Keyword.put_new(:name, String.upcase(to_string(identifier))) |> Keyword.delete(:as) + |> Keyword.update(:description, nil, fn existing_value -> {:unquote, [], [existing_value]} end) |> handle_deprecate end diff --git a/test/absinthe/type/enum_test.exs b/test/absinthe/type/enum_test.exs index 84a6f5e50e..9e71f36210 100644 --- a/test/absinthe/type/enum_test.exs +++ b/test/absinthe/type/enum_test.exs @@ -15,7 +15,7 @@ defmodule Absinthe.Type.EnumTest do end enum :test_macro_inputting_ast do - value :red, as: :r, description: hello("red") + value :red, as: :red, description: hello("red") end def hello(arg1) do From f390aebdcb8a02a637a610e2a17ac833ab60a222 Mon Sep 17 00:00:00 2001 From: justinakoh Date: Wed, 16 Dec 2020 15:59:36 +1300 Subject: [PATCH 03/50] Add new tests testing normal functions to ensure expected behaviour --- test/absinthe/type/enum_test.exs | 72 +++++++++++--------------------- 1 file changed, 25 insertions(+), 47 deletions(-) diff --git a/test/absinthe/type/enum_test.exs b/test/absinthe/type/enum_test.exs index 9e71f36210..9d377be277 100644 --- a/test/absinthe/type/enum_test.exs +++ b/test/absinthe/type/enum_test.exs @@ -6,11 +6,9 @@ defmodule Absinthe.Type.EnumTest do defmodule TestSchema do use Absinthe.Schema - query do - field :channel, :color_channel, description: "The active color channel" do - resolve fn _, _ -> - {:ok, :red} - end + defmodule TestNestedModule do + def nestedFunction(arg1) do + arg1 end end @@ -18,43 +16,21 @@ defmodule Absinthe.Type.EnumTest do value :red, as: :red, description: hello("red") end - def hello(arg1) do - arg1 + enum :test_function_called_without_name do + value :red, as: :red, description: Absinthe.Type.EnumTest.TestSchema.hello("red") end - enum :color_channel do - description "The selected color channel" - value :red, as: :r, description: "Color Red" - value :green, as: :g, description: "Color Green" - value :blue, as: :b, description: "Color Blue" - - value :alpha, - as: :a, - deprecate: "We no longer support opacity settings", - description: "Alpha Channel" + enum :test_standard_function_works do + value :red, as: :red, description: hello("red") + String.replace("red", "o", "a") end - enum :color_channel2 do - description "The selected color channel" - - value :red, description: "Color Red" - value :green, description: "Color Green" - value :blue, description: "Color Blue" - - value :alpha, - as: :a, - deprecate: "We no longer support opacity settings", - description: "Alpha Channel" + enum :test_nested_function do + value :red, as: :red, description: TestNestedModule.nestedFunction("hello") end - enum :color_channel3, - values: [:red, :green, :blue, :alpha], - description: "The selected color channel" - - enum :negative_value do - value :positive_one, as: 1 - value :zero, as: 0 - value :negative_one, as: -1 + def hello(arg1) do + arg1 end end @@ -63,26 +39,28 @@ defmodule Absinthe.Type.EnumTest do type = TestSchema.__absinthe_type__(:color_channel) assert %Type.Enum{} = type - assert %Type.Enum.Value{name: "RED", value: :r, description: "Color Red"} = - type.values[:red] + test "checking if schema works correctly" do + type = TestSchema.__absinthe_type__(:test_macro_inputting_ast) + assert %Type.Enum{} = type + assert %Type.Enum.Value{name: "RED", value: :red, description: "red"} = type.values[:red] end - test "can be defined by a map without defined values" do - type = TestSchema.__absinthe_type__(:color_channel2) + test "function can be called without module name" do + type = TestSchema.__absinthe_type__(:test_function_called_without_name) assert %Type.Enum{} = type - assert %Type.Enum.Value{name: "RED", value: :red} = type.values[:red] + assert %Type.Enum.Value{name: "RED", value: :red, description: "red"} = type.values[:red] end - test "can be defined by a shorthand list of atoms" do - type = TestSchema.__absinthe_type__(:color_channel3) + test "calling standard function to ensure it is working correctly" do + type = TestSchema.__absinthe_type__(:test_standard_function_works) assert %Type.Enum{} = type - assert %Type.Enum.Value{name: "RED", value: :red, description: nil} = type.values[:red] + assert %Type.Enum.Value{name: "RED", value: :red, description: "a"} = type.values[:red] end - test "checking if schema works correctly" do - type = TestSchema.__absinthe_type__(:test_macro_inputting_ast) + test "function can be called from nested module" do + type = TestSchema.__absinthe_type__(:test_nested_function) assert %Type.Enum{} = type - assert %Type.Enum.Value{name: "RED", value: :red, description: "red"} = type.values[:red] + assert %Type.Enum.Value{name: "RED", value: :red, description: "hello"} = type.values[:red] end end end From a1bb493a0601dfb6bcf16079336e5b2d61102405 Mon Sep 17 00:00:00 2001 From: justinakoh Date: Wed, 16 Dec 2020 16:51:06 +1300 Subject: [PATCH 04/50] Update formatting and layout of tests --- test/absinthe/type/enum_test.exs | 109 ++++++++++++++++++++++++------- 1 file changed, 85 insertions(+), 24 deletions(-) diff --git a/test/absinthe/type/enum_test.exs b/test/absinthe/type/enum_test.exs index 9d377be277..d45c8820b4 100644 --- a/test/absinthe/type/enum_test.exs +++ b/test/absinthe/type/enum_test.exs @@ -12,25 +12,64 @@ defmodule Absinthe.Type.EnumTest do end end - enum :test_macro_inputting_ast do - value :red, as: :red, description: hello("red") + query do + field :channel, :color_channel, description: "The active color channel" do + resolve fn _, _ -> + {:ok, :red} + end + end end - enum :test_function_called_without_name do - value :red, as: :red, description: Absinthe.Type.EnumTest.TestSchema.hello("red") + enum :description_keyword_argument do + @module_attribute "goodbye" + value :test_local_function_call, description: test_function("red") + + value :test_function_is_called_using_path, + description: Absinthe.Type.EnumTest.TestSchema.test_function("red") + + value :test_standard_library_function_works, description: String.replace("red", "e", "a") + value :test_function_nested_in_module, description: TestNestedModule.nestedFunction("hello") + value :test_module_attribute, description: "hello " <> @module_attribute + value :test_module_attribute_interpolates, description: "hello #{@module_attribute}" end - enum :test_standard_function_works do - value :red, as: :red, description: hello("red") - String.replace("red", "o", "a") + def test_function(arg1) do + arg1 end - enum :test_nested_function do - value :red, as: :red, description: TestNestedModule.nestedFunction("hello") + enum :color_channel do + description "The selected color channel" + value :red, as: :r, description: "Color Red" + value :green, as: :g, description: "Color Green" + value :blue, as: :b, description: "Color Blue" + + value :alpha, + as: :a, + deprecate: "We no longer support opacity settings", + description: "Alpha Channel" end - def hello(arg1) do - arg1 + enum :color_channel2 do + description "The selected color channel" + + value :red, description: "Color Red" + value :green, description: "Color Green" + value :blue, description: "Color Blue" + + value :alpha, + as: :a, + deprecate: "We no longer support opacity settings", + description: "Alpha Channel" + end + + enum :color_channel3, + values: [:red, :green, :blue, :alpha], + description: "The selected color channel" + + enum :negative_value do + value :positive_one, as: 1 + value :zero, as: 0 + value :negative_one, as: -1 end end @@ -39,28 +78,50 @@ defmodule Absinthe.Type.EnumTest do type = TestSchema.__absinthe_type__(:color_channel) assert %Type.Enum{} = type - test "checking if schema works correctly" do - type = TestSchema.__absinthe_type__(:test_macro_inputting_ast) - assert %Type.Enum{} = type - assert %Type.Enum.Value{name: "RED", value: :red, description: "red"} = type.values[:red] + assert %Type.Enum.Value{name: "RED", value: :r, description: "Color Red"} = + type.values[:red] end - test "function can be called without module name" do - type = TestSchema.__absinthe_type__(:test_function_called_without_name) + test "can be defined by a map without defined values" do + type = TestSchema.__absinthe_type__(:color_channel2) assert %Type.Enum{} = type - assert %Type.Enum.Value{name: "RED", value: :red, description: "red"} = type.values[:red] + assert %Type.Enum.Value{name: "RED", value: :red} = type.values[:red] end - test "calling standard function to ensure it is working correctly" do - type = TestSchema.__absinthe_type__(:test_standard_function_works) + test "can be defined by a shorthand list of atoms" do + type = TestSchema.__absinthe_type__(:color_channel3) assert %Type.Enum{} = type - assert %Type.Enum.Value{name: "RED", value: :red, description: "a"} = type.values[:red] + assert %Type.Enum.Value{name: "RED", value: :red, description: nil} = type.values[:red] + end + + test "local function call" do + type = TestSchema.__absinthe_type__(:description_keyword_argument) + assert type.values[:test_local_function_call].description == "red" + end + + test "function can be called using path" do + type = TestSchema.__absinthe_type__(:description_keyword_argument) + assert type.values[:test_function_is_called_using_path].description == "red" + end + + test "standard function is working correctly" do + type = TestSchema.__absinthe_type__(:description_keyword_argument) + assert type.values[:test_standard_library_function_works].description == "rad" end test "function can be called from nested module" do - type = TestSchema.__absinthe_type__(:test_nested_function) - assert %Type.Enum{} = type - assert %Type.Enum.Value{name: "RED", value: :red, description: "hello"} = type.values[:red] + type = TestSchema.__absinthe_type__(:description_keyword_argument) + assert type.values[:test_function_nested_in_module].description == "hello" + end + + test "module attribute function is operating correctly" do + type = TestSchema.__absinthe_type__(:description_keyword_argument) + assert type.values[:test_module_attribute].description == "hello goodbye" + end + + test "module attribute interpolates" do + type = TestSchema.__absinthe_type__(:description_keyword_argument) + assert type.values[:test_module_attribute_interpolates].description == "hello goodbye" end end end From cc8a053f33e3af40de20dd9ca913d338a6f00ad8 Mon Sep 17 00:00:00 2001 From: justinakoh Date: Thu, 17 Dec 2020 10:44:39 +1300 Subject: [PATCH 05/50] Update tests to reduce duplications --- test/absinthe/type/enum_test.exs | 61 ++++++++++++++------------------ 1 file changed, 26 insertions(+), 35 deletions(-) diff --git a/test/absinthe/type/enum_test.exs b/test/absinthe/type/enum_test.exs index d45c8820b4..33fc7f7b90 100644 --- a/test/absinthe/type/enum_test.exs +++ b/test/absinthe/type/enum_test.exs @@ -22,15 +22,15 @@ defmodule Absinthe.Type.EnumTest do enum :description_keyword_argument do @module_attribute "goodbye" - value :test_local_function_call, description: test_function("red") + value :local_function_call, description: test_function("red") - value :test_function_is_called_using_path, + value :function_call_using_absolute_path, description: Absinthe.Type.EnumTest.TestSchema.test_function("red") - value :test_standard_library_function_works, description: String.replace("red", "e", "a") - value :test_function_nested_in_module, description: TestNestedModule.nestedFunction("hello") - value :test_module_attribute, description: "hello " <> @module_attribute - value :test_module_attribute_interpolates, description: "hello #{@module_attribute}" + value :standard_library_function_works, description: String.replace("red", "e", "a") + value :function_nested_in_module, description: TestNestedModule.nestedFunction("hello") + value :module_attribute, description: "hello " <> @module_attribute + value :interpolation_of_module_attribute, description: "hello #{@module_attribute}" end def test_function(arg1) do @@ -73,6 +73,15 @@ defmodule Absinthe.Type.EnumTest do end end + @description_tests [ + %{test_label: :local_function_call, expected_description: "red"}, + %{test_label: :function_call_using_absolute_path, expected_description: "red"}, + %{test_label: :standard_library_function_works, expected_description: "rad"}, + %{test_label: :function_nested_in_module, expected_description: "hello"}, + %{test_label: :module_attribute, expected_description: "hello goodbye"}, + %{test_label: :interpolation_of_module_attribute, expected_description: "hello goodbye"} + ] + describe "enums" do test "can be defined by a map with defined values" do type = TestSchema.__absinthe_type__(:color_channel) @@ -93,35 +102,17 @@ defmodule Absinthe.Type.EnumTest do assert %Type.Enum{} = type assert %Type.Enum.Value{name: "RED", value: :red, description: nil} = type.values[:red] end + end - test "local function call" do - type = TestSchema.__absinthe_type__(:description_keyword_argument) - assert type.values[:test_local_function_call].description == "red" - end - - test "function can be called using path" do - type = TestSchema.__absinthe_type__(:description_keyword_argument) - assert type.values[:test_function_is_called_using_path].description == "red" - end - - test "standard function is working correctly" do - type = TestSchema.__absinthe_type__(:description_keyword_argument) - assert type.values[:test_standard_library_function_works].description == "rad" - end - - test "function can be called from nested module" do - type = TestSchema.__absinthe_type__(:description_keyword_argument) - assert type.values[:test_function_nested_in_module].description == "hello" - end - - test "module attribute function is operating correctly" do - type = TestSchema.__absinthe_type__(:description_keyword_argument) - assert type.values[:test_module_attribute].description == "hello goodbye" - end - - test "module attribute interpolates" do - type = TestSchema.__absinthe_type__(:description_keyword_argument) - assert type.values[:test_module_attribute_interpolates].description == "hello goodbye" - end + describe "enum description evaluation" do + Enum.each(@description_tests, fn %{ + test_label: test_label, + expected_description: expected_description + } -> + test "for #{test_label}" do + type = TestSchema.__absinthe_type__(:description_keyword_argument) + assert type.values[unquote(test_label)].description == unquote(expected_description) + end + end) end end From 44fe0ae9132f8b8f64ea266510a4fa86a816d9a8 Mon Sep 17 00:00:00 2001 From: justinakoh Date: Thu, 17 Dec 2020 10:48:31 +1300 Subject: [PATCH 06/50] Formatting and adding in one more test for string: --- test/absinthe/type/enum_test.exs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/absinthe/type/enum_test.exs b/test/absinthe/type/enum_test.exs index 33fc7f7b90..5aa2db4369 100644 --- a/test/absinthe/type/enum_test.exs +++ b/test/absinthe/type/enum_test.exs @@ -5,6 +5,7 @@ defmodule Absinthe.Type.EnumTest do defmodule TestSchema do use Absinthe.Schema + @module_attribute "goodbye" defmodule TestNestedModule do def nestedFunction(arg1) do @@ -21,7 +22,7 @@ defmodule Absinthe.Type.EnumTest do end enum :description_keyword_argument do - @module_attribute "goodbye" + value :normal_string, description: "string" value :local_function_call, description: test_function("red") value :function_call_using_absolute_path, @@ -74,6 +75,7 @@ defmodule Absinthe.Type.EnumTest do end @description_tests [ + %{test_label: :normal_string, expected_description: "string"}, %{test_label: :local_function_call, expected_description: "red"}, %{test_label: :function_call_using_absolute_path, expected_description: "red"}, %{test_label: :standard_library_function_works, expected_description: "rad"}, From 4bd51be97896976aa69d529c7b81b37592101e00 Mon Sep 17 00:00:00 2001 From: Dylan Chong Date: Thu, 17 Dec 2020 09:25:23 +1300 Subject: [PATCH 07/50] Fix description block --- lib/absinthe/schema/notation.ex | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/absinthe/schema/notation.ex b/lib/absinthe/schema/notation.ex index 0eaf088b8a..ee2f5a5ca8 100644 --- a/lib/absinthe/schema/notation.ex +++ b/lib/absinthe/schema/notation.ex @@ -1401,12 +1401,20 @@ defmodule Absinthe.Schema.Notation do scoped_def(env, :enum, identifier, attrs, block) end - defp reformat_description(text), do: String.trim(text) + defp wrap_in_reformat_description(text) do + quote do + String.trim(unquote(text)) + end + end @doc false # Record a description in the current scope def record_description!(env, text_block) do - text = reformat_description(text_block) + text = + text_block + |> wrap_in_reformat_description() + |> wrap_in_unquote() + put_attr(env.module, {:desc, text}) end From a9bc5363852b343eca1ee6534f4ea395ecf817c1 Mon Sep 17 00:00:00 2001 From: Dylan Chong Date: Thu, 17 Dec 2020 09:25:43 +1300 Subject: [PATCH 08/50] Fix enum with description param --- lib/absinthe/schema/notation.ex | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/absinthe/schema/notation.ex b/lib/absinthe/schema/notation.ex index ee2f5a5ca8..9a8ae17264 100644 --- a/lib/absinthe/schema/notation.ex +++ b/lib/absinthe/schema/notation.ex @@ -1073,6 +1073,7 @@ defmodule Absinthe.Schema.Notation do struct!(Schema.EnumValueDefinition, value_attrs) end) end) + |> Keyword.update(:description, nil, &wrap_in_unquote/1) end @placement {:value, [under: [:enum]]} From f962b933dde6bd52d08dc496050a6a328de31323 Mon Sep 17 00:00:00 2001 From: Dylan Chong Date: Thu, 17 Dec 2020 09:39:49 +1300 Subject: [PATCH 09/50] Remove wrap_in_reformat_description for consistency between descriptions --- lib/absinthe/schema/notation.ex | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/lib/absinthe/schema/notation.ex b/lib/absinthe/schema/notation.ex index 9a8ae17264..c53160b4fb 100644 --- a/lib/absinthe/schema/notation.ex +++ b/lib/absinthe/schema/notation.ex @@ -1402,19 +1402,10 @@ defmodule Absinthe.Schema.Notation do scoped_def(env, :enum, identifier, attrs, block) end - defp wrap_in_reformat_description(text) do - quote do - String.trim(unquote(text)) - end - end - @doc false # Record a description in the current scope def record_description!(env, text_block) do - text = - text_block - |> wrap_in_reformat_description() - |> wrap_in_unquote() + text = wrap_in_unquote(text_block) put_attr(env.module, {:desc, text}) end From c29c262e14e6e692da809f90a2afdaafb4f5ab03 Mon Sep 17 00:00:00 2001 From: Dylan Chong Date: Thu, 17 Dec 2020 09:43:19 +1300 Subject: [PATCH 10/50] Description for input_object --- lib/absinthe/schema/notation.ex | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/absinthe/schema/notation.ex b/lib/absinthe/schema/notation.ex index c53160b4fb..fa62b2ba53 100644 --- a/lib/absinthe/schema/notation.ex +++ b/lib/absinthe/schema/notation.ex @@ -934,7 +934,12 @@ defmodule Absinthe.Schema.Notation do defmacro input_object(identifier, attrs \\ [], do: block) do __CALLER__ |> recordable!(:input_object, @placement[:input_object]) - |> record!(Schema.InputObjectTypeDefinition, identifier, attrs, block) + |> record!( + Schema.InputObjectTypeDefinition, + identifier, + attrs |> Keyword.update(:description, nil, &wrap_in_unquote/1), + block + ) end # UNIONS From 65618afb64a160fd9377ae165d37cd1a9a26a599 Mon Sep 17 00:00:00 2001 From: Dylan Chong Date: Thu, 17 Dec 2020 09:44:18 +1300 Subject: [PATCH 11/50] Fix object --- lib/absinthe/schema/notation.ex | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/absinthe/schema/notation.ex b/lib/absinthe/schema/notation.ex index fa62b2ba53..ae8e869eb9 100644 --- a/lib/absinthe/schema/notation.ex +++ b/lib/absinthe/schema/notation.ex @@ -212,7 +212,12 @@ defmodule Absinthe.Schema.Notation do __CALLER__ |> recordable!(:object, @placement[:object]) - |> record!(Schema.ObjectTypeDefinition, identifier, attrs, block) + |> record!( + Schema.ObjectTypeDefinition, + identifier, + attrs |> Keyword.update(:description, nil, &wrap_in_unquote/1), + block + ) end @placement {:interfaces, [under: [:object]]} From bccf70a73c6d1cfd0133b79e3a13d9813f68890e Mon Sep 17 00:00:00 2001 From: Dylan Chong Date: Thu, 17 Dec 2020 09:50:37 +1300 Subject: [PATCH 12/50] Fix field description kw arg --- lib/absinthe/schema/notation.ex | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/absinthe/schema/notation.ex b/lib/absinthe/schema/notation.ex index ae8e869eb9..3852b299b0 100644 --- a/lib/absinthe/schema/notation.ex +++ b/lib/absinthe/schema/notation.ex @@ -412,6 +412,7 @@ defmodule Absinthe.Schema.Notation do |> expand_ast(caller) |> Keyword.delete(:args) |> Keyword.delete(:meta) + |> Keyword.update(:description, nil, &wrap_in_unquote/1) |> handle_deprecate {attrs, block} From a28730b2c747dacf63714699ea4baced9e100e4e Mon Sep 17 00:00:00 2001 From: Dylan Chong Date: Thu, 17 Dec 2020 09:52:32 +1300 Subject: [PATCH 13/50] Fix arg kw arg --- lib/absinthe/schema/notation.ex | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/absinthe/schema/notation.ex b/lib/absinthe/schema/notation.ex index 3852b299b0..8dc61a95e4 100644 --- a/lib/absinthe/schema/notation.ex +++ b/lib/absinthe/schema/notation.ex @@ -1308,6 +1308,7 @@ defmodule Absinthe.Schema.Notation do raw_attrs |> Keyword.put_new(:name, to_string(identifier)) |> Keyword.put_new(:type, type) + |> Keyword.update(:description, nil, &wrap_in_unquote/1) |> handle_deprecate end From ec144b4073e3c0d10704f88a77c57d0a2722613b Mon Sep 17 00:00:00 2001 From: Dylan Chong Date: Thu, 17 Dec 2020 11:10:09 +1300 Subject: [PATCH 14/50] Fix update description --- lib/absinthe/schema/notation.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/absinthe/schema/notation.ex b/lib/absinthe/schema/notation.ex index 8dc61a95e4..17eaa8a919 100644 --- a/lib/absinthe/schema/notation.ex +++ b/lib/absinthe/schema/notation.ex @@ -1440,7 +1440,7 @@ defmodule Absinthe.Schema.Notation do |> Keyword.put(:value, value) |> Keyword.put_new(:name, String.upcase(to_string(identifier))) |> Keyword.delete(:as) - |> Keyword.update(:description, nil, fn existing_value -> {:unquote, [], [existing_value]} end) + |> Keyword.update(:description, nil, &wrap_in_unquote/1) |> handle_deprecate end From 4f821582173c81ba005ff7c52f6ff168a6467f82 Mon Sep 17 00:00:00 2001 From: Dylan Chong Date: Thu, 17 Dec 2020 11:18:56 +1300 Subject: [PATCH 15/50] Remember to commit function wrap_in_unquote --- lib/absinthe/schema/notation.ex | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/absinthe/schema/notation.ex b/lib/absinthe/schema/notation.ex index 17eaa8a919..053c55b35d 100644 --- a/lib/absinthe/schema/notation.ex +++ b/lib/absinthe/schema/notation.ex @@ -1497,6 +1497,14 @@ defmodule Absinthe.Schema.Notation do put_attr(env.module, {:middleware, [new_middleware]}) end + # We wrap the value (from the user) in an `unquote` call, so that when the schema `blueprint` is + # placed into `__absinthe_blueprint__` via `unquote(Macro.escape(blueprint, unquote: true))` the + # value get's unquoted. This allows us to evaluate function calls in the scope of the schema + # module. + defp wrap_in_unquote(value) do + {:unquote, [], [value]} + end + # ------------------------------ @doc false From 95480bc5a59226b13ee939a66fbd3b62125b9190 Mon Sep 17 00:00:00 2001 From: justinakoh Date: Thu, 17 Dec 2020 13:06:18 +1300 Subject: [PATCH 16/50] Update test files to be in a separate module --- test/absinthe/type/enum_test.exs | 54 +++++++++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) diff --git a/test/absinthe/type/enum_test.exs b/test/absinthe/type/enum_test.exs index 5aa2db4369..e6df987004 100644 --- a/test/absinthe/type/enum_test.exs +++ b/test/absinthe/type/enum_test.exs @@ -74,6 +74,46 @@ defmodule Absinthe.Type.EnumTest do end end + defmodule TestSchemaEnumDescription do + use Absinthe.Schema + @module_attribute "goodbye" + + defmodule TestNestedModule do + def nestedFunction(arg1) do + arg1 + end + end + + query do + end + + enum :normal_string, description: "string" do + end + + enum :local_function_call, description: test_function("red") do + end + + enum :function_call_using_absolute_path, + description: Absinthe.Type.EnumTest.TestSchemaEnumDescription.test_function("red") do + end + + enum :standard_library_function_works, description: String.replace("red", "e", "a") do + end + + enum :function_nested_in_module, description: TestNestedModule.nestedFunction("hello") do + end + + enum :module_attribute, description: "hello " <> @module_attribute do + end + + enum :interpolation_of_module_attribute, description: "hello #{@module_attribute}" do + end + + def test_function(arg1) do + arg1 + end + end + @description_tests [ %{test_label: :normal_string, expected_description: "string"}, %{test_label: :local_function_call, expected_description: "red"}, @@ -106,7 +146,7 @@ defmodule Absinthe.Type.EnumTest do end end - describe "enum description evaluation" do + describe "enum value description evaluation" do Enum.each(@description_tests, fn %{ test_label: test_label, expected_description: expected_description @@ -117,4 +157,16 @@ defmodule Absinthe.Type.EnumTest do end end) end + + describe "enum description evaluation" do + Enum.each(@description_tests, fn %{ + test_label: test_label, + expected_description: expected_description + } -> + test "for #{test_label}" do + type = TestSchemaEnumDescription.__absinthe_type__(unquote(test_label)) + assert type.description == unquote(expected_description) + end + end) + end end From 0aaf957dc8c3806ce3e87814cbd0e8f9e7b021ee Mon Sep 17 00:00:00 2001 From: justinakoh Date: Thu, 17 Dec 2020 13:19:55 +1300 Subject: [PATCH 17/50] Update code tp include tests for description attribute --- test/absinthe/type/enum_test.exs | 71 ++++++++++++++++++++++++++++++-- 1 file changed, 67 insertions(+), 4 deletions(-) diff --git a/test/absinthe/type/enum_test.exs b/test/absinthe/type/enum_test.exs index e6df987004..d1abbfc1e2 100644 --- a/test/absinthe/type/enum_test.exs +++ b/test/absinthe/type/enum_test.exs @@ -74,7 +74,7 @@ defmodule Absinthe.Type.EnumTest do end end - defmodule TestSchemaEnumDescription do + defmodule TestSchemaEnumDescriptionKeyword do use Absinthe.Schema @module_attribute "goodbye" @@ -94,7 +94,7 @@ defmodule Absinthe.Type.EnumTest do end enum :function_call_using_absolute_path, - description: Absinthe.Type.EnumTest.TestSchemaEnumDescription.test_function("red") do + description: Absinthe.Type.EnumTest.TestSchemaEnumDescriptionKeyword.test_function("red") do end enum :standard_library_function_works, description: String.replace("red", "e", "a") do @@ -114,6 +114,53 @@ defmodule Absinthe.Type.EnumTest do end end + defmodule TestSchemaEnumDescriptionAttribute do + use Absinthe.Schema + @module_attribute "goodbye" + + defmodule TestNestedModule do + def nestedFunction(arg1) do + arg1 + end + end + + query do + end + + def test_function(arg1) do + arg1 + end + + @desc "string" + enum :normal_string do + end + + # Test does not work as test_function is not available at compile time + # @desc test_function("red") + # enum :local_function_call do + # end + + # @desc Absinthe.Type.EnumTest.TestSchemaEnumAttribute.test_function("red") + # enum :function_call_using_absolute_path do + # end + + @desc String.replace("red", "e", "a") + enum :standard_library_function_works do + end + + @desc TestNestedModule.nestedFunction("hello") + enum :function_nested_in_module do + end + + @desc "hello " <> @module_attribute + enum :module_attribute do + end + + @desc "hello #{@module_attribute}" + enum :interpolation_of_module_attribute do + end + end + @description_tests [ %{test_label: :normal_string, expected_description: "string"}, %{test_label: :local_function_call, expected_description: "red"}, @@ -158,13 +205,29 @@ defmodule Absinthe.Type.EnumTest do end) end - describe "enum description evaluation" do + describe "enum description keyword evaluation" do Enum.each(@description_tests, fn %{ test_label: test_label, expected_description: expected_description } -> test "for #{test_label}" do - type = TestSchemaEnumDescription.__absinthe_type__(unquote(test_label)) + type = TestSchemaEnumDescriptionKeyword.__absinthe_type__(unquote(test_label)) + assert type.description == unquote(expected_description) + end + end) + end + + describe "enum description attribute evaluation" do + @description_tests + |> Enum.filter(fn %{test_label: test_label} -> + test_label not in [:local_function_call, :function_call_using_absolute_path] + end) + |> Enum.each(fn %{ + test_label: test_label, + expected_description: expected_description + } -> + test "for #{test_label}" do + type = TestSchemaEnumDescriptionAttribute.__absinthe_type__(unquote(test_label)) assert type.description == unquote(expected_description) end end) From 477b7890b9d0c5147c26324c16c59b47b8ba424b Mon Sep 17 00:00:00 2001 From: Dylan Chong Date: Thu, 17 Dec 2020 13:21:39 +1300 Subject: [PATCH 18/50] Update comment --- test/absinthe/type/enum_test.exs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/test/absinthe/type/enum_test.exs b/test/absinthe/type/enum_test.exs index d1abbfc1e2..4a25dcafac 100644 --- a/test/absinthe/type/enum_test.exs +++ b/test/absinthe/type/enum_test.exs @@ -135,7 +135,10 @@ defmodule Absinthe.Type.EnumTest do enum :normal_string do end - # Test does not work as test_function is not available at compile time + # These tests do not work as test_function is not available at compile time, and the + # expression for the @desc attribute is evaluated at compile time. There is nothing we can + # really do about it + # @desc test_function("red") # enum :local_function_call do # end @@ -219,6 +222,9 @@ defmodule Absinthe.Type.EnumTest do describe "enum description attribute evaluation" do @description_tests + # These tests do not work as test_function is not available at compile time, and the + # expression for the @desc attribute is evaluated at compile time. There is nothing we can + # really do about it |> Enum.filter(fn %{test_label: test_label} -> test_label not in [:local_function_call, :function_call_using_absolute_path] end) From 85fb8e790d9f846953e45011960ececf872388e2 Mon Sep 17 00:00:00 2001 From: justinakoh Date: Thu, 17 Dec 2020 13:34:47 +1300 Subject: [PATCH 19/50] Update code to include tests for description macro --- test/absinthe/type/enum_test.exs | 59 ++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/test/absinthe/type/enum_test.exs b/test/absinthe/type/enum_test.exs index 4a25dcafac..705a13bd3e 100644 --- a/test/absinthe/type/enum_test.exs +++ b/test/absinthe/type/enum_test.exs @@ -164,6 +164,52 @@ defmodule Absinthe.Type.EnumTest do end end + defmodule TestSchemaEnumDescriptionMacro do + use Absinthe.Schema + @module_attribute "goodbye" + + defmodule TestNestedModule do + def nestedFunction(arg1) do + arg1 + end + end + + query do + end + + def test_function(arg1) do + arg1 + end + + enum :normal_string do + description "string" + end + + enum :local_function_call do + description test_function("red") + end + + enum :function_call_using_absolute_path do + description Absinthe.Type.EnumTest.TestSchemaEnumDescriptionMacro.test_function("red") + end + + enum :standard_library_function_works do + description String.replace("red", "e", "a") + end + + enum :function_nested_in_module do + description TestNestedModule.nestedFunction("hello") + end + + enum :module_attribute do + description "hello " <> @module_attribute + end + + enum :interpolation_of_module_attribute do + description "hello #{@module_attribute}" + end + end + @description_tests [ %{test_label: :normal_string, expected_description: "string"}, %{test_label: :local_function_call, expected_description: "red"}, @@ -238,4 +284,17 @@ defmodule Absinthe.Type.EnumTest do end end) end + + describe "enum description macro evaluation" do + @description_tests + |> Enum.each(fn %{ + test_label: test_label, + expected_description: expected_description + } -> + test "for #{test_label}" do + type = TestSchemaEnumDescriptionMacro.__absinthe_type__(unquote(test_label)) + assert type.description == unquote(expected_description) + end + end) + end end From f8917a5f028ec2b346177a5fc0cac30b0b3b555f Mon Sep 17 00:00:00 2001 From: justinakoh Date: Thu, 17 Dec 2020 14:22:15 +1300 Subject: [PATCH 20/50] Update tests for input object --- test/absinthe/type/enum_test.exs | 32 ++-- test/absinthe/type/input_object_test.exs | 184 +++++++++++++++++++++++ 2 files changed, 196 insertions(+), 20 deletions(-) diff --git a/test/absinthe/type/enum_test.exs b/test/absinthe/type/enum_test.exs index 705a13bd3e..eb4e4061ce 100644 --- a/test/absinthe/type/enum_test.exs +++ b/test/absinthe/type/enum_test.exs @@ -210,16 +210,6 @@ defmodule Absinthe.Type.EnumTest do end end - @description_tests [ - %{test_label: :normal_string, expected_description: "string"}, - %{test_label: :local_function_call, expected_description: "red"}, - %{test_label: :function_call_using_absolute_path, expected_description: "red"}, - %{test_label: :standard_library_function_works, expected_description: "rad"}, - %{test_label: :function_nested_in_module, expected_description: "hello"}, - %{test_label: :module_attribute, expected_description: "hello goodbye"}, - %{test_label: :interpolation_of_module_attribute, expected_description: "hello goodbye"} - ] - describe "enums" do test "can be defined by a map with defined values" do type = TestSchema.__absinthe_type__(:color_channel) @@ -243,10 +233,11 @@ defmodule Absinthe.Type.EnumTest do end describe "enum value description evaluation" do - Enum.each(@description_tests, fn %{ - test_label: test_label, - expected_description: expected_description - } -> + Absinthe.FunctionEvaluationHelpers.function_evaluation_test_params() + |> Enum.each(fn %{ + test_label: test_label, + expected_description: expected_description + } -> test "for #{test_label}" do type = TestSchema.__absinthe_type__(:description_keyword_argument) assert type.values[unquote(test_label)].description == unquote(expected_description) @@ -255,10 +246,11 @@ defmodule Absinthe.Type.EnumTest do end describe "enum description keyword evaluation" do - Enum.each(@description_tests, fn %{ - test_label: test_label, - expected_description: expected_description - } -> + Absinthe.FunctionEvaluationHelpers.function_evaluation_test_params() + |> Enum.each(fn %{ + test_label: test_label, + expected_description: expected_description + } -> test "for #{test_label}" do type = TestSchemaEnumDescriptionKeyword.__absinthe_type__(unquote(test_label)) assert type.description == unquote(expected_description) @@ -267,7 +259,7 @@ defmodule Absinthe.Type.EnumTest do end describe "enum description attribute evaluation" do - @description_tests + Absinthe.FunctionEvaluationHelpers.function_evaluation_test_params() # These tests do not work as test_function is not available at compile time, and the # expression for the @desc attribute is evaluated at compile time. There is nothing we can # really do about it @@ -286,7 +278,7 @@ defmodule Absinthe.Type.EnumTest do end describe "enum description macro evaluation" do - @description_tests + Absinthe.FunctionEvaluationHelpers.function_evaluation_test_params() |> Enum.each(fn %{ test_label: test_label, expected_description: expected_description diff --git a/test/absinthe/type/input_object_test.exs b/test/absinthe/type/input_object_test.exs index 4857ec7a45..6e19fd28df 100644 --- a/test/absinthe/type/input_object_test.exs +++ b/test/absinthe/type/input_object_test.exs @@ -15,6 +15,145 @@ defmodule Absinthe.Type.InputObjectTest do end end + defmodule TestSchemaInputObjectDescriptionKeyword do + use Absinthe.Schema + @module_attribute "goodbye" + + defmodule TestNestedModule do + def nestedFunction(arg1) do + arg1 + end + end + + query do + end + + input_object :normal_string, description: "string" do + end + + input_object :local_function_call, description: test_function("red") do + end + + input_object :function_call_using_absolute_path, + description: + Absinthe.Type.InputObjectTest.TestSchemaInputObjectDescriptionKeyword.test_function("red") do + end + + input_object :standard_library_function_works, description: String.replace("red", "e", "a") do + end + + input_object :function_nested_in_module, description: TestNestedModule.nestedFunction("hello") do + end + + input_object :module_attribute, description: "hello " <> @module_attribute do + end + + input_object :interpolation_of_module_attribute, description: "hello #{@module_attribute}" do + end + + def test_function(arg1) do + arg1 + end + end + + defmodule TestSchemaInputObjectDescriptionAttribute do + use Absinthe.Schema + @module_attribute "goodbye" + + defmodule TestNestedModule do + def nestedFunction(arg1) do + arg1 + end + end + + query do + end + + def test_function(arg1) do + arg1 + end + + @desc "string" + input_object :normal_string do + end + + # These tests do not work as test_function is not available at compile time, and the + # expression for the @desc attribute is evaluated at compile time. There is nothing we can + # really do about it + + # @desc test_function("red") + # input_object :local_function_call do + # end + + # @desc Absinthe.Type.InputObjectTest.TestSchemaInputObjectAttribute.test_function("red") + # input_object :function_call_using_absolute_path do + # end + + @desc String.replace("red", "e", "a") + input_object :standard_library_function_works do + end + + @desc TestNestedModule.nestedFunction("hello") + input_object :function_nested_in_module do + end + + @desc "hello " <> @module_attribute + input_object :module_attribute do + end + + @desc "hello #{@module_attribute}" + input_object :interpolation_of_module_attribute do + end + end + + defmodule TestSchemaInputObjectDescriptionMacro do + use Absinthe.Schema + @module_attribute "goodbye" + + defmodule TestNestedModule do + def nestedFunction(arg1) do + arg1 + end + end + + query do + end + + def test_function(arg1) do + arg1 + end + + input_object :normal_string do + description "string" + end + + input_object :local_function_call do + description test_function("red") + end + + input_object :function_call_using_absolute_path do + description Absinthe.Type.InputObjectTest.TestSchemaInputObjectDescriptionMacro.test_function( + "red" + ) + end + + input_object :standard_library_function_works do + description String.replace("red", "e", "a") + end + + input_object :function_nested_in_module do + description TestNestedModule.nestedFunction("hello") + end + + input_object :module_attribute do + description "hello " <> @module_attribute + end + + input_object :interpolation_of_module_attribute do + description "hello #{@module_attribute}" + end + end + describe "input object types" do test "can be defined" do assert %Absinthe.Type.InputObject{name: "Profile", description: "A profile"} = @@ -28,4 +167,49 @@ defmodule Absinthe.Type.InputObjectTest do assert %Absinthe.Type.Field{name: "name", type: :string} = obj.fields.name end end + + describe "input object keyword description evaluation" do + Absinthe.FunctionEvaluationHelpers.function_evaluation_test_params() + |> Enum.each(fn %{ + test_label: test_label, + expected_description: expected_description + } -> + test "for #{test_label}" do + type = TestSchemaInputObjectDescriptionKeyword.__absinthe_type__(unquote(test_label)) + assert type.description == unquote(expected_description) + end + end) + end + + describe "input_object description attribute evaluation" do + Absinthe.FunctionEvaluationHelpers.function_evaluation_test_params() + # These tests do not work as test_function is not available at compile time, and the + # expression for the @desc attribute is evaluated at compile time. There is nothing we can + # really do about it + |> Enum.filter(fn %{test_label: test_label} -> + test_label not in [:local_function_call, :function_call_using_absolute_path] + end) + |> Enum.each(fn %{ + test_label: test_label, + expected_description: expected_description + } -> + test "for #{test_label}" do + type = TestSchemaInputObjectDescriptionAttribute.__absinthe_type__(unquote(test_label)) + assert type.description == unquote(expected_description) + end + end) + end + + describe "input_object description macro evaluation" do + Absinthe.FunctionEvaluationHelpers.function_evaluation_test_params() + |> Enum.each(fn %{ + test_label: test_label, + expected_description: expected_description + } -> + test "for #{test_label}" do + type = TestSchemaInputObjectDescriptionMacro.__absinthe_type__(unquote(test_label)) + assert type.description == unquote(expected_description) + end + end) + end end From 4e0adf8422b6e29a431fadcdc783f4607b2e94a3 Mon Sep 17 00:00:00 2001 From: justinakoh Date: Thu, 17 Dec 2020 14:29:32 +1300 Subject: [PATCH 21/50] Add in more tests for field keyword attribute --- test/absinthe/type/input_object_test.exs | 55 ++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/test/absinthe/type/input_object_test.exs b/test/absinthe/type/input_object_test.exs index 6e19fd28df..3adb07ea60 100644 --- a/test/absinthe/type/input_object_test.exs +++ b/test/absinthe/type/input_object_test.exs @@ -154,6 +154,44 @@ defmodule Absinthe.Type.InputObjectTest do end end + defmodule TestSchemaInputObjectFieldKeywordDescription do + use Absinthe.Schema + @module_attribute "goodbye" + + defmodule TestNestedModule do + def nestedFunction(arg1) do + arg1 + end + end + + query do + end + + def test_function(arg1) do + arg1 + end + + input_object :description_keyword_argument do + field :normal_string, :string, description: "string" + field :local_function_call, :string, description: test_function("red") + + field :function_call_using_absolute_path, :string, + description: + Absinthe.Type.InputObjectTest.TestSchemaInputObjectFieldKeywordDescription.test_function( + "red" + ) + + field :standard_library_function_works, :string, + description: String.replace("red", "e", "a") + + field :function_nested_in_module, :string, + description: TestNestedModule.nestedFunction("hello") + + field :module_attribute, :string, description: "hello " <> @module_attribute + field :interpolation_of_module_attribute, :string, description: "hello #{@module_attribute}" + end + end + describe "input object types" do test "can be defined" do assert %Absinthe.Type.InputObject{name: "Profile", description: "A profile"} = @@ -212,4 +250,21 @@ defmodule Absinthe.Type.InputObjectTest do end end) end + + describe "input object field keyword description evaluation" do + Absinthe.FunctionEvaluationHelpers.function_evaluation_test_params() + |> Enum.each(fn %{ + test_label: test_label, + expected_description: expected_description + } -> + test "for #{test_label}" do + type = + TestSchemaInputObjectFieldKeywordDescription.__absinthe_type__( + :description_keyword_argument + ) + + assert type.fields[unquote(test_label)].description == unquote(expected_description) + end + end) + end end From b3e0cbe84e62916d708fa4277afad31c03de46ed Mon Sep 17 00:00:00 2001 From: justinakoh Date: Thu, 17 Dec 2020 14:35:48 +1300 Subject: [PATCH 22/50] Add more tests for input object attribute description --- test/absinthe/type/input_object_test.exs | 48 ++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/test/absinthe/type/input_object_test.exs b/test/absinthe/type/input_object_test.exs index 3adb07ea60..a9b38ae7ae 100644 --- a/test/absinthe/type/input_object_test.exs +++ b/test/absinthe/type/input_object_test.exs @@ -190,6 +190,33 @@ defmodule Absinthe.Type.InputObjectTest do field :module_attribute, :string, description: "hello " <> @module_attribute field :interpolation_of_module_attribute, :string, description: "hello #{@module_attribute}" end + + input_object :description_attribute do + @desc "string" + field :normal_string, :string + + # These tests do not work as test_function is not available at compile time, and the + # expression for the @desc attribute is evaluated at compile time. There is nothing we can + # really do about it + # @desc test_function("red") + # field :local_function_call, :string + + # @desc Absinthe.Type.InputObjectTest.TestSchemaInputObjectFieldKeywordDescription.test_function( + # "red" + # ) + # field :function_call_using_absolute_path, :string + + @desc String.replace("red", "e", "a") + field :standard_library_function_works, :string + + @desc TestNestedModule.nestedFunction("hello") + field :function_nested_in_module, :string + + @desc "hello " <> @module_attribute + field :module_attribute, :string + @desc "hello #{@module_attribute}" + field :interpolation_of_module_attribute, :string + end end describe "input object types" do @@ -267,4 +294,25 @@ defmodule Absinthe.Type.InputObjectTest do end end) end + + describe "input object field attribute description evaluation" do + Absinthe.FunctionEvaluationHelpers.function_evaluation_test_params() + # These tests do not work as test_function is not available at compile time, and the + # expression for the @desc attribute is evaluated at compile time. There is nothing we can + # really do about it + |> Enum.filter(fn %{test_label: test_label} -> + test_label not in [:local_function_call, :function_call_using_absolute_path] + end) + |> Enum.each(fn %{ + test_label: test_label, + expected_description: expected_description + } -> + test "for #{test_label}" do + type = + TestSchemaInputObjectFieldKeywordDescription.__absinthe_type__(:description_attribute) + + assert type.fields[unquote(test_label)].description == unquote(expected_description) + end + end) + end end From c192ec8186aa2f1217a01a8e86175325055044a0 Mon Sep 17 00:00:00 2001 From: justinakoh Date: Thu, 17 Dec 2020 14:36:21 +1300 Subject: [PATCH 23/50] NEW LINE --- test/absinthe/type/input_object_test.exs | 1 + 1 file changed, 1 insertion(+) diff --git a/test/absinthe/type/input_object_test.exs b/test/absinthe/type/input_object_test.exs index a9b38ae7ae..ccb98e4a2d 100644 --- a/test/absinthe/type/input_object_test.exs +++ b/test/absinthe/type/input_object_test.exs @@ -198,6 +198,7 @@ defmodule Absinthe.Type.InputObjectTest do # These tests do not work as test_function is not available at compile time, and the # expression for the @desc attribute is evaluated at compile time. There is nothing we can # really do about it + # @desc test_function("red") # field :local_function_call, :string From 435246b2dfbfd20ed4feb5d4e950704a229568a2 Mon Sep 17 00:00:00 2001 From: justinakoh Date: Thu, 17 Dec 2020 14:40:09 +1300 Subject: [PATCH 24/50] Update tests to include tests for macro description --- test/absinthe/type/input_object_test.exs | 46 ++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/test/absinthe/type/input_object_test.exs b/test/absinthe/type/input_object_test.exs index ccb98e4a2d..9a6b58bd44 100644 --- a/test/absinthe/type/input_object_test.exs +++ b/test/absinthe/type/input_object_test.exs @@ -218,6 +218,38 @@ defmodule Absinthe.Type.InputObjectTest do @desc "hello #{@module_attribute}" field :interpolation_of_module_attribute, :string end + + input_object :description_macro do + field :normal_string, :string do + description "string" + end + + field :local_function_call, :string do + description test_function("red") + end + + field :function_call_using_absolute_path, :string do + description Absinthe.Type.InputObjectTest.TestSchemaInputObjectFieldKeywordDescription.test_function( + "red" + ) + end + + field :standard_library_function_works, :string do + description String.replace("red", "e", "a") + end + + field :function_nested_in_module, :string do + description TestNestedModule.nestedFunction("hello") + end + + field :module_attribute, :string do + description "hello " <> @module_attribute + end + + field :interpolation_of_module_attribute, :string do + description "hello #{@module_attribute}" + end + end end describe "input object types" do @@ -316,4 +348,18 @@ defmodule Absinthe.Type.InputObjectTest do end end) end + + describe "input object field macro description evaluation" do + Absinthe.FunctionEvaluationHelpers.function_evaluation_test_params() + |> Enum.each(fn %{ + test_label: test_label, + expected_description: expected_description + } -> + test "for #{test_label}" do + type = TestSchemaInputObjectFieldKeywordDescription.__absinthe_type__(:description_macro) + + assert type.fields[unquote(test_label)].description == unquote(expected_description) + end + end) + end end From 34f72cec591aa3c3be7a3dc78ee6ef23954bc8e4 Mon Sep 17 00:00:00 2001 From: justinakoh Date: Thu, 17 Dec 2020 15:09:44 +1300 Subject: [PATCH 25/50] Add new test files for testing to test things --- test/absinthe/type/enum_test.exs | 24 ++++---- test/absinthe/type/input_object_test.exs | 47 ++++++++------- test/absinthe/type/query_test.exs | 66 +++++++++++++++++++++ test/support/function_evaluation_helpers.ex | 13 ++++ 4 files changed, 116 insertions(+), 34 deletions(-) create mode 100644 test/absinthe/type/query_test.exs create mode 100644 test/support/function_evaluation_helpers.ex diff --git a/test/absinthe/type/enum_test.exs b/test/absinthe/type/enum_test.exs index eb4e4061ce..b5a084e18c 100644 --- a/test/absinthe/type/enum_test.exs +++ b/test/absinthe/type/enum_test.exs @@ -7,8 +7,8 @@ defmodule Absinthe.Type.EnumTest do use Absinthe.Schema @module_attribute "goodbye" - defmodule TestNestedModule do - def nestedFunction(arg1) do + defmodule NestedModule do + def nested_function(arg1) do arg1 end end @@ -29,7 +29,7 @@ defmodule Absinthe.Type.EnumTest do description: Absinthe.Type.EnumTest.TestSchema.test_function("red") value :standard_library_function_works, description: String.replace("red", "e", "a") - value :function_nested_in_module, description: TestNestedModule.nestedFunction("hello") + value :function_nested_in_module, description: NestedModule.nested_function("hello") value :module_attribute, description: "hello " <> @module_attribute value :interpolation_of_module_attribute, description: "hello #{@module_attribute}" end @@ -78,8 +78,8 @@ defmodule Absinthe.Type.EnumTest do use Absinthe.Schema @module_attribute "goodbye" - defmodule TestNestedModule do - def nestedFunction(arg1) do + defmodule NestedModule do + def nested_function(arg1) do arg1 end end @@ -100,7 +100,7 @@ defmodule Absinthe.Type.EnumTest do enum :standard_library_function_works, description: String.replace("red", "e", "a") do end - enum :function_nested_in_module, description: TestNestedModule.nestedFunction("hello") do + enum :function_nested_in_module, description: NestedModule.nested_function("hello") do end enum :module_attribute, description: "hello " <> @module_attribute do @@ -118,8 +118,8 @@ defmodule Absinthe.Type.EnumTest do use Absinthe.Schema @module_attribute "goodbye" - defmodule TestNestedModule do - def nestedFunction(arg1) do + defmodule NestedModule do + def nested_function(arg1) do arg1 end end @@ -151,7 +151,7 @@ defmodule Absinthe.Type.EnumTest do enum :standard_library_function_works do end - @desc TestNestedModule.nestedFunction("hello") + @desc NestedModule.nested_function("hello") enum :function_nested_in_module do end @@ -168,8 +168,8 @@ defmodule Absinthe.Type.EnumTest do use Absinthe.Schema @module_attribute "goodbye" - defmodule TestNestedModule do - def nestedFunction(arg1) do + defmodule NestedModule do + def nested_function(arg1) do arg1 end end @@ -198,7 +198,7 @@ defmodule Absinthe.Type.EnumTest do end enum :function_nested_in_module do - description TestNestedModule.nestedFunction("hello") + description NestedModule.nested_function("hello") end enum :module_attribute do diff --git a/test/absinthe/type/input_object_test.exs b/test/absinthe/type/input_object_test.exs index 9a6b58bd44..5c36ee3ea1 100644 --- a/test/absinthe/type/input_object_test.exs +++ b/test/absinthe/type/input_object_test.exs @@ -19,8 +19,8 @@ defmodule Absinthe.Type.InputObjectTest do use Absinthe.Schema @module_attribute "goodbye" - defmodule TestNestedModule do - def nestedFunction(arg1) do + defmodule NestedModule do + def nested_function(arg1) do arg1 end end @@ -42,7 +42,7 @@ defmodule Absinthe.Type.InputObjectTest do input_object :standard_library_function_works, description: String.replace("red", "e", "a") do end - input_object :function_nested_in_module, description: TestNestedModule.nestedFunction("hello") do + input_object :function_nested_in_module, description: NestedModule.nested_function("hello") do end input_object :module_attribute, description: "hello " <> @module_attribute do @@ -60,8 +60,8 @@ defmodule Absinthe.Type.InputObjectTest do use Absinthe.Schema @module_attribute "goodbye" - defmodule TestNestedModule do - def nestedFunction(arg1) do + defmodule NestedModule do + def nested_function(arg1) do arg1 end end @@ -93,7 +93,7 @@ defmodule Absinthe.Type.InputObjectTest do input_object :standard_library_function_works do end - @desc TestNestedModule.nestedFunction("hello") + @desc NestedModule.nested_function("hello") input_object :function_nested_in_module do end @@ -110,8 +110,8 @@ defmodule Absinthe.Type.InputObjectTest do use Absinthe.Schema @module_attribute "goodbye" - defmodule TestNestedModule do - def nestedFunction(arg1) do + defmodule NestedModule do + def nested_function(arg1) do arg1 end end @@ -142,7 +142,7 @@ defmodule Absinthe.Type.InputObjectTest do end input_object :function_nested_in_module do - description TestNestedModule.nestedFunction("hello") + description NestedModule.nested_function("hello") end input_object :module_attribute do @@ -154,12 +154,12 @@ defmodule Absinthe.Type.InputObjectTest do end end - defmodule TestSchemaInputObjectFieldKeywordDescription do + defmodule TestSchemaInputObjectFieldsAndArgsDescription do use Absinthe.Schema @module_attribute "goodbye" - defmodule TestNestedModule do - def nestedFunction(arg1) do + defmodule NestedModule do + def nested_function(arg1) do arg1 end end @@ -177,7 +177,7 @@ defmodule Absinthe.Type.InputObjectTest do field :function_call_using_absolute_path, :string, description: - Absinthe.Type.InputObjectTest.TestSchemaInputObjectFieldKeywordDescription.test_function( + Absinthe.Type.InputObjectTest.TestSchemaInputObjectFieldsAndArgsDescription.test_function( "red" ) @@ -185,7 +185,7 @@ defmodule Absinthe.Type.InputObjectTest do description: String.replace("red", "e", "a") field :function_nested_in_module, :string, - description: TestNestedModule.nestedFunction("hello") + description: NestedModule.nested_function("hello") field :module_attribute, :string, description: "hello " <> @module_attribute field :interpolation_of_module_attribute, :string, description: "hello #{@module_attribute}" @@ -202,7 +202,7 @@ defmodule Absinthe.Type.InputObjectTest do # @desc test_function("red") # field :local_function_call, :string - # @desc Absinthe.Type.InputObjectTest.TestSchemaInputObjectFieldKeywordDescription.test_function( + # @desc Absinthe.Type.InputObjectTest.TestSchemaInputObjectFieldsAndArgsDescription.test_function( # "red" # ) # field :function_call_using_absolute_path, :string @@ -210,7 +210,7 @@ defmodule Absinthe.Type.InputObjectTest do @desc String.replace("red", "e", "a") field :standard_library_function_works, :string - @desc TestNestedModule.nestedFunction("hello") + @desc NestedModule.nested_function("hello") field :function_nested_in_module, :string @desc "hello " <> @module_attribute @@ -219,7 +219,7 @@ defmodule Absinthe.Type.InputObjectTest do field :interpolation_of_module_attribute, :string end - input_object :description_macro do + input_object :field_description_macro do field :normal_string, :string do description "string" end @@ -229,7 +229,7 @@ defmodule Absinthe.Type.InputObjectTest do end field :function_call_using_absolute_path, :string do - description Absinthe.Type.InputObjectTest.TestSchemaInputObjectFieldKeywordDescription.test_function( + description Absinthe.Type.InputObjectTest.TestSchemaInputObjectFieldsAndArgsDescription.test_function( "red" ) end @@ -239,7 +239,7 @@ defmodule Absinthe.Type.InputObjectTest do end field :function_nested_in_module, :string do - description TestNestedModule.nestedFunction("hello") + description NestedModule.nested_function("hello") end field :module_attribute, :string do @@ -319,7 +319,7 @@ defmodule Absinthe.Type.InputObjectTest do } -> test "for #{test_label}" do type = - TestSchemaInputObjectFieldKeywordDescription.__absinthe_type__( + TestSchemaInputObjectFieldsAndArgsDescription.__absinthe_type__( :description_keyword_argument ) @@ -342,7 +342,7 @@ defmodule Absinthe.Type.InputObjectTest do } -> test "for #{test_label}" do type = - TestSchemaInputObjectFieldKeywordDescription.__absinthe_type__(:description_attribute) + TestSchemaInputObjectFieldsAndArgsDescription.__absinthe_type__(:description_attribute) assert type.fields[unquote(test_label)].description == unquote(expected_description) end @@ -356,7 +356,10 @@ defmodule Absinthe.Type.InputObjectTest do expected_description: expected_description } -> test "for #{test_label}" do - type = TestSchemaInputObjectFieldKeywordDescription.__absinthe_type__(:description_macro) + type = + TestSchemaInputObjectFieldsAndArgsDescription.__absinthe_type__( + :field_description_macro + ) assert type.fields[unquote(test_label)].description == unquote(expected_description) end diff --git a/test/absinthe/type/query_test.exs b/test/absinthe/type/query_test.exs new file mode 100644 index 0000000000..e959acba4e --- /dev/null +++ b/test/absinthe/type/query_test.exs @@ -0,0 +1,66 @@ +defmodule Absinthe.Type.QueryTest do + use Absinthe.Case, async: true + + alias Absinthe.Type + + defmodule TestSchema do + use Absinthe.Schema + @module_attribute "goodbye" + + defmodule NestedModule do + def nested_function(arg1) do + arg1 + end + end + + def test_function(arg1) do + arg1 + end + + query do + field :normal_string, :string do + arg :arg_example, :string, description: "string" + end + + field :local_function_call, :string do + arg :arg_example, :string, description: test_function("red") + end + + field :function_call_using_absolute_path, :string do + arg :arg_example, :string, + description: Absinthe.Type.QueryTest.TestSchema.test_function("red") + end + + field :standard_library_function_works, :string do + arg :arg_example, :string, description: String.replace("red", "e", "a") + end + + field :function_nested_in_module, :string do + arg :arg_example, :string, description: NestedModule.nested_function("hello") + end + + field :module_attribute, :string do + arg :arg_example, :string, description: "hello " <> @module_attribute + end + + field :interpolation_of_module_attribute, :string do + arg :arg_example, :string, description: "hello #{@module_attribute}" + end + end + end + + describe "input object field arg keyword description evaluation" do + Absinthe.FunctionEvaluationHelpers.function_evaluation_test_params() + |> Enum.each(fn %{ + test_label: test_label, + expected_description: expected_description + } -> + test "for #{test_label}" do + type = TestSchema.__absinthe_type__("RootQueryType") + + assert type.fields[unquote(test_label)].args.arg_example.description == + unquote(expected_description) + end + end) + end +end diff --git a/test/support/function_evaluation_helpers.ex b/test/support/function_evaluation_helpers.ex new file mode 100644 index 0000000000..a3682abe03 --- /dev/null +++ b/test/support/function_evaluation_helpers.ex @@ -0,0 +1,13 @@ +defmodule Absinthe.FunctionEvaluationHelpers do + def function_evaluation_test_params do + [ + %{test_label: :normal_string, expected_description: "string"}, + %{test_label: :local_function_call, expected_description: "red"}, + %{test_label: :function_call_using_absolute_path, expected_description: "red"}, + %{test_label: :standard_library_function_works, expected_description: "rad"}, + %{test_label: :function_nested_in_module, expected_description: "hello"}, + %{test_label: :module_attribute, expected_description: "hello goodbye"}, + %{test_label: :interpolation_of_module_attribute, expected_description: "hello goodbye"} + ] + end +end From aac0a7e4d3b333d84242229681e9cc56f4a2b19e Mon Sep 17 00:00:00 2001 From: justinakoh Date: Thu, 17 Dec 2020 15:14:06 +1300 Subject: [PATCH 26/50] Add test for mutation test --- test/absinthe/type/mutation_test.exs | 70 ++++++++++++++++++++++++++++ test/absinthe/type/query_test.exs | 2 +- 2 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 test/absinthe/type/mutation_test.exs diff --git a/test/absinthe/type/mutation_test.exs b/test/absinthe/type/mutation_test.exs new file mode 100644 index 0000000000..d8437f87bf --- /dev/null +++ b/test/absinthe/type/mutation_test.exs @@ -0,0 +1,70 @@ +defmodule Absinthe.Type.MutationTest do + use Absinthe.Case, async: true + + alias Absinthe.Type + + defmodule TestSchema do + use Absinthe.Schema + @module_attribute "goodbye" + + defmodule NestedModule do + def nested_function(arg1) do + arg1 + end + end + + def test_function(arg1) do + arg1 + end + + query do + + end + + mutation do + field :normal_string, :string do + arg :arg_example, :string, description: "string" + end + + field :local_function_call, :string do + arg :arg_example, :string, description: test_function("red") + end + + field :function_call_using_absolute_path, :string do + arg :arg_example, :string, + description: Absinthe.Type.MutationTest.TestSchema.test_function("red") + end + + field :standard_library_function_works, :string do + arg :arg_example, :string, description: String.replace("red", "e", "a") + end + + field :function_nested_in_module, :string do + arg :arg_example, :string, description: NestedModule.nested_function("hello") + end + + field :module_attribute, :string do + arg :arg_example, :string, description: "hello " <> @module_attribute + end + + field :interpolation_of_module_attribute, :string do + arg :arg_example, :string, description: "hello #{@module_attribute}" + end + end + end + + describe "mutation field arg keyword description evaluation" do + Absinthe.FunctionEvaluationHelpers.function_evaluation_test_params() + |> Enum.each(fn %{ + test_label: test_label, + expected_description: expected_description + } -> + test "for #{test_label}" do + type = TestSchema.__absinthe_type__("RootMutationType") + + assert type.fields[unquote(test_label)].args.arg_example.description == + unquote(expected_description) + end + end) + end +end diff --git a/test/absinthe/type/query_test.exs b/test/absinthe/type/query_test.exs index e959acba4e..9bc39046e3 100644 --- a/test/absinthe/type/query_test.exs +++ b/test/absinthe/type/query_test.exs @@ -49,7 +49,7 @@ defmodule Absinthe.Type.QueryTest do end end - describe "input object field arg keyword description evaluation" do + describe "query field arg keyword description evaluation" do Absinthe.FunctionEvaluationHelpers.function_evaluation_test_params() |> Enum.each(fn %{ test_label: test_label, From ccb6cf3bb9a27cb2f4da08a26c2f0e4f72f5e4ad Mon Sep 17 00:00:00 2001 From: Dylan Chong Date: Thu, 17 Dec 2020 17:54:16 +1300 Subject: [PATCH 27/50] Fix module attributes don't work with multiple types files --- lib/absinthe/schema/notation.ex | 10 ++++++++ test/absinthe/type/import_types_test.exs | 32 ++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/lib/absinthe/schema/notation.ex b/lib/absinthe/schema/notation.ex index 053c55b35d..b29accbd32 100644 --- a/lib/absinthe/schema/notation.ex +++ b/lib/absinthe/schema/notation.ex @@ -1887,6 +1887,16 @@ defmodule Absinthe.Schema.Notation do defp expand_ast(ast, env) do Macro.prewalk(ast, fn + # We don't want to expand `@bla` into Module.get_attribute(module, @bla) because this will + # fail at runtime. Remember that the ast gets put into a generated `__absinthe_blueprint__` + # function which is called at "__after_compile__" time, but may be called at runtime + # depending on the ordering of how modules get compiled. + # + # Also see test "test/absinthe/type/import_types_test.exs" + # "__absinthe_blueprint__ is callable at runtime even if there is a module attribute" + {:@, _, _} = node -> + node + {_, _, _} = node -> Macro.expand(node, env) diff --git a/test/absinthe/type/import_types_test.exs b/test/absinthe/type/import_types_test.exs index a0c01a9900..317065b720 100644 --- a/test/absinthe/type/import_types_test.exs +++ b/test/absinthe/type/import_types_test.exs @@ -39,4 +39,36 @@ defmodule Absinthe.Type.ImportTypesTest do assert Absinthe.Schema.lookup_type(ImportTypes.SelfContainedSchema, :role_enum) end end + + defmodule TestSchema do + use Absinthe.Schema + @module_attribute "module_attribute" + + query do + field :module_attribute, :string, description: @module_attribute + end + end + + # From inside `defp expand_ast` in `Absinthe.Schema.Notation`: + # + # > We don't want to expand `@bla` into Module.get_attribute(module, @bla) because this will + # > fail at runtime. Remember that the ast gets put into a generated `__absinthe_blueprint__` + # > function which is called at "__after_compile__" time, but may be called at runtime + # > depending on the ordering of how modules get compiled. + # + # This test checks that __absinthe_blueprint__ runs and doesn't raise an error saying + # "Module.get_attribute" cannot be called because the module is already compiled". This error + # happens because the `@module_attribute` gets expanded by `expand_ast` into + # `Module.get_attribute(Absinthe.Type.QueryTest.TestSchema, :module_attribute, )`. + # + # We ensure __absinthe_blueprint__ is runnable at runtime because in projects where the schema + # is split into multiple modules, one of the modules may already have completely finished + # compiling, dumping the Module attribute data (they are baked in to the code at compile time) + # which means that the `Module.get_attribute` call will raise the error mentioned above + # + test "__absinthe_blueprint__ is callable at runtime even if there is a module attribute" do + # Sanity check + {:module, TestSchema} = Code.ensure_compiled(TestSchema) + assert match? %Absinthe.Blueprint{}, TestSchema.__absinthe_blueprint__() + end end From dbcb7dea154951cc00be5451676a0e769a0c4a51 Mon Sep 17 00:00:00 2001 From: Dylan Chong Date: Thu, 17 Dec 2020 19:41:09 +1300 Subject: [PATCH 28/50] Add test for import types with module attribute --- test/absinthe/type/import_types_test.exs | 30 ++++++++++++++++-------- test/absinthe/type/mutation_test.exs | 1 - test/support/fixtures/import_types.ex | 18 ++++++++++++++ 3 files changed, 38 insertions(+), 11 deletions(-) diff --git a/test/absinthe/type/import_types_test.exs b/test/absinthe/type/import_types_test.exs index 317065b720..d01c2d0ec4 100644 --- a/test/absinthe/type/import_types_test.exs +++ b/test/absinthe/type/import_types_test.exs @@ -38,14 +38,14 @@ defmodule Absinthe.Type.ImportTypesTest do assert Absinthe.Schema.lookup_type(ImportTypes.SelfContainedSchema, :category) assert Absinthe.Schema.lookup_type(ImportTypes.SelfContainedSchema, :role_enum) end - end - defmodule TestSchema do - use Absinthe.Schema - @module_attribute "module_attribute" + # See test below "__absinthe_blueprint__ is callable at runtime even if there is a module attribute" + # for more information + test "works with module attribute used in imported module" do + type = ImportTypes.SchemaWithModuleAttribute.__absinthe_type__(:example_input_object) + field = type.fields.input_object_module_attribute - query do - field :module_attribute, :string, description: @module_attribute + assert field.description == "module_attribute" end end @@ -59,16 +59,26 @@ defmodule Absinthe.Type.ImportTypesTest do # This test checks that __absinthe_blueprint__ runs and doesn't raise an error saying # "Module.get_attribute" cannot be called because the module is already compiled". This error # happens because the `@module_attribute` gets expanded by `expand_ast` into - # `Module.get_attribute(Absinthe.Type.QueryTest.TestSchema, :module_attribute, )`. + # `Module.get_attribute(Absinthe.Fixtures.ImportTypes.SchemaWithModuleAttribute, + # :module_attribute, )`. # # We ensure __absinthe_blueprint__ is runnable at runtime because in projects where the schema # is split into multiple modules, one of the modules may already have completely finished # compiling, dumping the Module attribute data (they are baked in to the code at compile time) # which means that the `Module.get_attribute` call will raise the error mentioned above # + # Above, test "works with module attribute used in imported module" also checks this same + # functionality + # test "__absinthe_blueprint__ is callable at runtime even if there is a module attribute" do - # Sanity check - {:module, TestSchema} = Code.ensure_compiled(TestSchema) - assert match? %Absinthe.Blueprint{}, TestSchema.__absinthe_blueprint__() + # Sanity check. Shouldn't ever really fail (unless something is very wrong), but ensures that + # the assertion makes sense + {:module, ImportTypes.SchemaWithModuleAttribute} = + Code.ensure_compiled(ImportTypes.SchemaWithModuleAttribute) + + assert match?( + %Absinthe.Blueprint{}, + ImportTypes.SchemaWithModuleAttribute.__absinthe_blueprint__() + ) end end diff --git a/test/absinthe/type/mutation_test.exs b/test/absinthe/type/mutation_test.exs index d8437f87bf..558b18beb9 100644 --- a/test/absinthe/type/mutation_test.exs +++ b/test/absinthe/type/mutation_test.exs @@ -18,7 +18,6 @@ defmodule Absinthe.Type.MutationTest do end query do - end mutation do diff --git a/test/support/fixtures/import_types.ex b/test/support/fixtures/import_types.ex index 97e0b249ad..334f0e2b77 100644 --- a/test/support/fixtures/import_types.ex +++ b/test/support/fixtures/import_types.ex @@ -165,4 +165,22 @@ defmodule Absinthe.Fixtures.ImportTypes do field :credit_cards, list_of(:credit_card) end end + + defmodule SchemaWithModuleAttributeImports do + use Absinthe.Schema.Notation + @module_attribute "module_attribute" + + input_object :example_input_object do + field :input_object_module_attribute, :string, description: @module_attribute + end + end + + defmodule SchemaWithModuleAttribute do + use Absinthe.Schema + + import_types(SchemaWithModuleAttributeImports) + + query do + end + end end From 99ee813edd9c7734557a469b65098d76d6f67f09 Mon Sep 17 00:00:00 2001 From: Dylan Chong Date: Tue, 22 Dec 2020 09:39:23 +1300 Subject: [PATCH 29/50] Better import types test --- test/absinthe/type/import_types_test.exs | 84 +++++++++++++----------- test/support/fixtures/import_types.ex | 36 ++++++++-- 2 files changed, 77 insertions(+), 43 deletions(-) diff --git a/test/absinthe/type/import_types_test.exs b/test/absinthe/type/import_types_test.exs index d01c2d0ec4..fe6f02252f 100644 --- a/test/absinthe/type/import_types_test.exs +++ b/test/absinthe/type/import_types_test.exs @@ -38,47 +38,55 @@ defmodule Absinthe.Type.ImportTypesTest do assert Absinthe.Schema.lookup_type(ImportTypes.SelfContainedSchema, :category) assert Absinthe.Schema.lookup_type(ImportTypes.SelfContainedSchema, :role_enum) end + end - # See test below "__absinthe_blueprint__ is callable at runtime even if there is a module attribute" - # for more information - test "works with module attribute used in imported module" do - type = ImportTypes.SchemaWithModuleAttribute.__absinthe_type__(:example_input_object) - field = type.fields.input_object_module_attribute + describe "import_types with description function evaluation (in input_object field description)" do + # The module attribute iteration of this test is related to the test below. + # See "__absinthe_blueprint__ is callable at runtime even if there is a module attribute" for more + # information + Absinthe.FunctionEvaluationHelpers.function_evaluation_test_params() + |> Enum.each(fn %{ + test_label: test_label, + expected_description: expected_description + } -> + test "for #{test_label}" do + type = ImportTypes.SchemaWithFunctionEvaluation.__absinthe_type__(:example_input_object) - assert field.description == "module_attribute" - end - end + assert type.fields[unquote(test_label)].description == unquote(expected_description) + end + end) - # From inside `defp expand_ast` in `Absinthe.Schema.Notation`: - # - # > We don't want to expand `@bla` into Module.get_attribute(module, @bla) because this will - # > fail at runtime. Remember that the ast gets put into a generated `__absinthe_blueprint__` - # > function which is called at "__after_compile__" time, but may be called at runtime - # > depending on the ordering of how modules get compiled. - # - # This test checks that __absinthe_blueprint__ runs and doesn't raise an error saying - # "Module.get_attribute" cannot be called because the module is already compiled". This error - # happens because the `@module_attribute` gets expanded by `expand_ast` into - # `Module.get_attribute(Absinthe.Fixtures.ImportTypes.SchemaWithModuleAttribute, - # :module_attribute, )`. - # - # We ensure __absinthe_blueprint__ is runnable at runtime because in projects where the schema - # is split into multiple modules, one of the modules may already have completely finished - # compiling, dumping the Module attribute data (they are baked in to the code at compile time) - # which means that the `Module.get_attribute` call will raise the error mentioned above - # - # Above, test "works with module attribute used in imported module" also checks this same - # functionality - # - test "__absinthe_blueprint__ is callable at runtime even if there is a module attribute" do - # Sanity check. Shouldn't ever really fail (unless something is very wrong), but ensures that - # the assertion makes sense - {:module, ImportTypes.SchemaWithModuleAttribute} = - Code.ensure_compiled(ImportTypes.SchemaWithModuleAttribute) + # From inside `defp expand_ast` in `Absinthe.Schema.Notation`: + # + # > We don't want to expand `@bla` into Module.get_attribute(module, @bla) because this will + # > fail at runtime. Remember that the ast gets put into a generated `__absinthe_blueprint__` + # > function which is called at "__after_compile__" time, but may be called at runtime + # > depending on the ordering of how modules get compiled. + # + # This test checks that __absinthe_blueprint__ runs and doesn't raise an error saying + # "Module.get_attribute" cannot be called because the module is already compiled". This error + # happens because the `@module_attribute` gets expanded by `expand_ast` into + # `Module.get_attribute(Absinthe.Fixtures.ImportTypes.SchemaWithModuleAttribute, + # :module_attribute, )`. + # + # We ensure __absinthe_blueprint__ is runnable at runtime because in projects where the schema + # is split into multiple modules, one of the modules may already have completely finished + # compiling, dumping the Module attribute data (they are baked in to the code at compile time) + # which means that the `Module.get_attribute` call will raise the error mentioned above + # + # Above, test "works with module attribute used in imported module" also checks this same + # functionality + # + test "__absinthe_blueprint__ is callable at runtime even if there is a module attribute" do + # Sanity check. Shouldn't ever really fail (unless something is very wrong), but ensures that + # the assertion makes sense + {:module, ImportTypes.SchemaWithFunctionEvaluation} = + Code.ensure_compiled(ImportTypes.SchemaWithFunctionEvaluation) - assert match?( - %Absinthe.Blueprint{}, - ImportTypes.SchemaWithModuleAttribute.__absinthe_blueprint__() - ) + assert match?( + %Absinthe.Blueprint{}, + ImportTypes.SchemaWithFunctionEvaluation.__absinthe_blueprint__() + ) + end end end diff --git a/test/support/fixtures/import_types.ex b/test/support/fixtures/import_types.ex index 334f0e2b77..c5f9de40ec 100644 --- a/test/support/fixtures/import_types.ex +++ b/test/support/fixtures/import_types.ex @@ -166,19 +166,45 @@ defmodule Absinthe.Fixtures.ImportTypes do end end - defmodule SchemaWithModuleAttributeImports do + defmodule SchemaWithFunctionEvaluationImports do use Absinthe.Schema.Notation - @module_attribute "module_attribute" + @module_attribute "goodbye" + + defmodule NestedModule do + def nested_function(arg1) do + arg1 + end + end + + def test_function(arg1) do + arg1 + end input_object :example_input_object do - field :input_object_module_attribute, :string, description: @module_attribute + field :normal_string, :string, description: "string" + field :local_function_call, :string, description: test_function("red") + + field :function_call_using_absolute_path, :string, + description: + Absinthe.Fixtures.ImportTypes.SchemaWithFunctionEvaluationImports.test_function( + "red" + ) + + field :standard_library_function_works, :string, + description: String.replace("red", "e", "a") + + field :function_nested_in_module, :string, + description: NestedModule.nested_function("hello") + + field :module_attribute, :string, description: "hello " <> @module_attribute + field :interpolation_of_module_attribute, :string, description: "hello #{@module_attribute}" end end - defmodule SchemaWithModuleAttribute do + defmodule SchemaWithFunctionEvaluation do use Absinthe.Schema - import_types(SchemaWithModuleAttributeImports) + import_types(SchemaWithFunctionEvaluationImports) query do end From 46d5b660f51c5c725c499405e117ffc847e90cdc Mon Sep 17 00:00:00 2001 From: Dylan Chong Date: Tue, 22 Dec 2020 09:42:04 +1300 Subject: [PATCH 30/50] Rename standard_library_function_works --- test/absinthe/type/enum_test.exs | 8 ++++---- test/absinthe/type/input_object_test.exs | 12 ++++++------ test/absinthe/type/mutation_test.exs | 4 +--- test/absinthe/type/query_test.exs | 4 +--- test/support/fixtures/import_types.ex | 2 +- test/support/function_evaluation_helpers.ex | 2 +- 6 files changed, 14 insertions(+), 18 deletions(-) diff --git a/test/absinthe/type/enum_test.exs b/test/absinthe/type/enum_test.exs index b5a084e18c..d5b1e81cb4 100644 --- a/test/absinthe/type/enum_test.exs +++ b/test/absinthe/type/enum_test.exs @@ -28,7 +28,7 @@ defmodule Absinthe.Type.EnumTest do value :function_call_using_absolute_path, description: Absinthe.Type.EnumTest.TestSchema.test_function("red") - value :standard_library_function_works, description: String.replace("red", "e", "a") + value :standard_library_function, description: String.replace("red", "e", "a") value :function_nested_in_module, description: NestedModule.nested_function("hello") value :module_attribute, description: "hello " <> @module_attribute value :interpolation_of_module_attribute, description: "hello #{@module_attribute}" @@ -97,7 +97,7 @@ defmodule Absinthe.Type.EnumTest do description: Absinthe.Type.EnumTest.TestSchemaEnumDescriptionKeyword.test_function("red") do end - enum :standard_library_function_works, description: String.replace("red", "e", "a") do + enum :standard_library_function, description: String.replace("red", "e", "a") do end enum :function_nested_in_module, description: NestedModule.nested_function("hello") do @@ -148,7 +148,7 @@ defmodule Absinthe.Type.EnumTest do # end @desc String.replace("red", "e", "a") - enum :standard_library_function_works do + enum :standard_library_function do end @desc NestedModule.nested_function("hello") @@ -193,7 +193,7 @@ defmodule Absinthe.Type.EnumTest do description Absinthe.Type.EnumTest.TestSchemaEnumDescriptionMacro.test_function("red") end - enum :standard_library_function_works do + enum :standard_library_function do description String.replace("red", "e", "a") end diff --git a/test/absinthe/type/input_object_test.exs b/test/absinthe/type/input_object_test.exs index 5c36ee3ea1..397f3c2f93 100644 --- a/test/absinthe/type/input_object_test.exs +++ b/test/absinthe/type/input_object_test.exs @@ -39,7 +39,7 @@ defmodule Absinthe.Type.InputObjectTest do Absinthe.Type.InputObjectTest.TestSchemaInputObjectDescriptionKeyword.test_function("red") do end - input_object :standard_library_function_works, description: String.replace("red", "e", "a") do + input_object :standard_library_function, description: String.replace("red", "e", "a") do end input_object :function_nested_in_module, description: NestedModule.nested_function("hello") do @@ -90,7 +90,7 @@ defmodule Absinthe.Type.InputObjectTest do # end @desc String.replace("red", "e", "a") - input_object :standard_library_function_works do + input_object :standard_library_function do end @desc NestedModule.nested_function("hello") @@ -137,7 +137,7 @@ defmodule Absinthe.Type.InputObjectTest do ) end - input_object :standard_library_function_works do + input_object :standard_library_function do description String.replace("red", "e", "a") end @@ -181,7 +181,7 @@ defmodule Absinthe.Type.InputObjectTest do "red" ) - field :standard_library_function_works, :string, + field :standard_library_function, :string, description: String.replace("red", "e", "a") field :function_nested_in_module, :string, @@ -208,7 +208,7 @@ defmodule Absinthe.Type.InputObjectTest do # field :function_call_using_absolute_path, :string @desc String.replace("red", "e", "a") - field :standard_library_function_works, :string + field :standard_library_function, :string @desc NestedModule.nested_function("hello") field :function_nested_in_module, :string @@ -234,7 +234,7 @@ defmodule Absinthe.Type.InputObjectTest do ) end - field :standard_library_function_works, :string do + field :standard_library_function, :string do description String.replace("red", "e", "a") end diff --git a/test/absinthe/type/mutation_test.exs b/test/absinthe/type/mutation_test.exs index 558b18beb9..ed000dbe0a 100644 --- a/test/absinthe/type/mutation_test.exs +++ b/test/absinthe/type/mutation_test.exs @@ -1,8 +1,6 @@ defmodule Absinthe.Type.MutationTest do use Absinthe.Case, async: true - alias Absinthe.Type - defmodule TestSchema do use Absinthe.Schema @module_attribute "goodbye" @@ -34,7 +32,7 @@ defmodule Absinthe.Type.MutationTest do description: Absinthe.Type.MutationTest.TestSchema.test_function("red") end - field :standard_library_function_works, :string do + field :standard_library_function, :string do arg :arg_example, :string, description: String.replace("red", "e", "a") end diff --git a/test/absinthe/type/query_test.exs b/test/absinthe/type/query_test.exs index 9bc39046e3..7aeda9dfb2 100644 --- a/test/absinthe/type/query_test.exs +++ b/test/absinthe/type/query_test.exs @@ -1,8 +1,6 @@ defmodule Absinthe.Type.QueryTest do use Absinthe.Case, async: true - alias Absinthe.Type - defmodule TestSchema do use Absinthe.Schema @module_attribute "goodbye" @@ -31,7 +29,7 @@ defmodule Absinthe.Type.QueryTest do description: Absinthe.Type.QueryTest.TestSchema.test_function("red") end - field :standard_library_function_works, :string do + field :standard_library_function, :string do arg :arg_example, :string, description: String.replace("red", "e", "a") end diff --git a/test/support/fixtures/import_types.ex b/test/support/fixtures/import_types.ex index c5f9de40ec..afe80d9821 100644 --- a/test/support/fixtures/import_types.ex +++ b/test/support/fixtures/import_types.ex @@ -190,7 +190,7 @@ defmodule Absinthe.Fixtures.ImportTypes do "red" ) - field :standard_library_function_works, :string, + field :standard_library_function, :string, description: String.replace("red", "e", "a") field :function_nested_in_module, :string, diff --git a/test/support/function_evaluation_helpers.ex b/test/support/function_evaluation_helpers.ex index a3682abe03..a3deb7bb29 100644 --- a/test/support/function_evaluation_helpers.ex +++ b/test/support/function_evaluation_helpers.ex @@ -4,7 +4,7 @@ defmodule Absinthe.FunctionEvaluationHelpers do %{test_label: :normal_string, expected_description: "string"}, %{test_label: :local_function_call, expected_description: "red"}, %{test_label: :function_call_using_absolute_path, expected_description: "red"}, - %{test_label: :standard_library_function_works, expected_description: "rad"}, + %{test_label: :standard_library_function, expected_description: "rad"}, %{test_label: :function_nested_in_module, expected_description: "hello"}, %{test_label: :module_attribute, expected_description: "hello goodbye"}, %{test_label: :interpolation_of_module_attribute, expected_description: "hello goodbye"} From aa538d8734cb5474704287e0ae2dc0c52c134d4b Mon Sep 17 00:00:00 2001 From: Dylan Chong Date: Tue, 22 Dec 2020 10:10:29 +1300 Subject: [PATCH 31/50] Add external_module_function_call test --- test/absinthe/type/enum_test.exs | 69 +++++++++++++-------- test/absinthe/type/input_object_test.exs | 22 +++++++ test/absinthe/type/mutation_test.exs | 4 ++ test/absinthe/type/query_test.exs | 4 ++ test/support/fixtures/import_types.ex | 3 + test/support/function_evaluation_helpers.ex | 5 ++ 6 files changed, 82 insertions(+), 25 deletions(-) diff --git a/test/absinthe/type/enum_test.exs b/test/absinthe/type/enum_test.exs index d5b1e81cb4..f3a8a70f46 100644 --- a/test/absinthe/type/enum_test.exs +++ b/test/absinthe/type/enum_test.exs @@ -5,13 +5,6 @@ defmodule Absinthe.Type.EnumTest do defmodule TestSchema do use Absinthe.Schema - @module_attribute "goodbye" - - defmodule NestedModule do - def nested_function(arg1) do - arg1 - end - end query do field :channel, :color_channel, description: "The active color channel" do @@ -21,23 +14,6 @@ defmodule Absinthe.Type.EnumTest do end end - enum :description_keyword_argument do - value :normal_string, description: "string" - value :local_function_call, description: test_function("red") - - value :function_call_using_absolute_path, - description: Absinthe.Type.EnumTest.TestSchema.test_function("red") - - value :standard_library_function, description: String.replace("red", "e", "a") - value :function_nested_in_module, description: NestedModule.nested_function("hello") - value :module_attribute, description: "hello " <> @module_attribute - value :interpolation_of_module_attribute, description: "hello #{@module_attribute}" - end - - def test_function(arg1) do - arg1 - end - enum :color_channel do description "The selected color channel" value :red, as: :r, description: "Color Red" @@ -74,6 +50,38 @@ defmodule Absinthe.Type.EnumTest do end end + defmodule TestSchemaEnumValueDescriptionKeyword do + use Absinthe.Schema + @module_attribute "goodbye" + + defmodule NestedModule do + def nested_function(arg1) do + arg1 + end + end + + query do + end + + def test_function(arg1) do + arg1 + end + + enum :description_keyword_argument do + value :normal_string, description: "string" + value :local_function_call, description: test_function("red") + + value :function_call_using_absolute_path, + description: Absinthe.Type.EnumTest.TestSchemaEnumValueDescriptionKeyword.test_function("red") + + value :standard_library_function, description: String.replace("red", "e", "a") + value :function_nested_in_module, description: NestedModule.nested_function("hello") + value :external_module_function_call, description: Absinthe.FunctionEvaluationHelpers.external_function("hello") + value :module_attribute, description: "hello " <> @module_attribute + value :interpolation_of_module_attribute, description: "hello #{@module_attribute}" + end + end + defmodule TestSchemaEnumDescriptionKeyword do use Absinthe.Schema @module_attribute "goodbye" @@ -103,6 +111,9 @@ defmodule Absinthe.Type.EnumTest do enum :function_nested_in_module, description: NestedModule.nested_function("hello") do end + enum :external_module_function_call, description: Absinthe.FunctionEvaluationHelpers.external_function("hello") do + end + enum :module_attribute, description: "hello " <> @module_attribute do end @@ -155,6 +166,10 @@ defmodule Absinthe.Type.EnumTest do enum :function_nested_in_module do end + @desc Absinthe.FunctionEvaluationHelpers.external_function("hello") + enum :external_module_function_call do + end + @desc "hello " <> @module_attribute enum :module_attribute do end @@ -201,6 +216,10 @@ defmodule Absinthe.Type.EnumTest do description NestedModule.nested_function("hello") end + enum :external_module_function_call do + description Absinthe.FunctionEvaluationHelpers.external_function("hello") + end + enum :module_attribute do description "hello " <> @module_attribute end @@ -239,7 +258,7 @@ defmodule Absinthe.Type.EnumTest do expected_description: expected_description } -> test "for #{test_label}" do - type = TestSchema.__absinthe_type__(:description_keyword_argument) + type = TestSchemaEnumValueDescriptionKeyword.__absinthe_type__(:description_keyword_argument) assert type.values[unquote(test_label)].description == unquote(expected_description) end end) diff --git a/test/absinthe/type/input_object_test.exs b/test/absinthe/type/input_object_test.exs index 397f3c2f93..50fd9cc5ce 100644 --- a/test/absinthe/type/input_object_test.exs +++ b/test/absinthe/type/input_object_test.exs @@ -45,6 +45,9 @@ defmodule Absinthe.Type.InputObjectTest do input_object :function_nested_in_module, description: NestedModule.nested_function("hello") do end + input_object :external_module_function_call, description: Absinthe.FunctionEvaluationHelpers.external_function("hello") do + end + input_object :module_attribute, description: "hello " <> @module_attribute do end @@ -97,6 +100,10 @@ defmodule Absinthe.Type.InputObjectTest do input_object :function_nested_in_module do end + @desc Absinthe.FunctionEvaluationHelpers.external_function("hello") + input_object :external_module_function_call do + end + @desc "hello " <> @module_attribute input_object :module_attribute do end @@ -145,6 +152,10 @@ defmodule Absinthe.Type.InputObjectTest do description NestedModule.nested_function("hello") end + input_object :external_module_function_call do + description Absinthe.FunctionEvaluationHelpers.external_function("hello") + end + input_object :module_attribute do description "hello " <> @module_attribute end @@ -187,6 +198,9 @@ defmodule Absinthe.Type.InputObjectTest do field :function_nested_in_module, :string, description: NestedModule.nested_function("hello") + field :external_module_function_call, :string, + description: Absinthe.FunctionEvaluationHelpers.external_function("hello") + field :module_attribute, :string, description: "hello " <> @module_attribute field :interpolation_of_module_attribute, :string, description: "hello #{@module_attribute}" end @@ -213,8 +227,12 @@ defmodule Absinthe.Type.InputObjectTest do @desc NestedModule.nested_function("hello") field :function_nested_in_module, :string + @desc Absinthe.FunctionEvaluationHelpers.external_function("hello") + field :external_module_function_call, :string + @desc "hello " <> @module_attribute field :module_attribute, :string + @desc "hello #{@module_attribute}" field :interpolation_of_module_attribute, :string end @@ -242,6 +260,10 @@ defmodule Absinthe.Type.InputObjectTest do description NestedModule.nested_function("hello") end + field :external_module_function_call, :string do + description Absinthe.FunctionEvaluationHelpers.external_function("hello") + end + field :module_attribute, :string do description "hello " <> @module_attribute end diff --git a/test/absinthe/type/mutation_test.exs b/test/absinthe/type/mutation_test.exs index ed000dbe0a..5dcbc57f75 100644 --- a/test/absinthe/type/mutation_test.exs +++ b/test/absinthe/type/mutation_test.exs @@ -40,6 +40,10 @@ defmodule Absinthe.Type.MutationTest do arg :arg_example, :string, description: NestedModule.nested_function("hello") end + field :external_module_function_call, :string do + arg :arg_example, :string, description: Absinthe.FunctionEvaluationHelpers.external_function("hello") + end + field :module_attribute, :string do arg :arg_example, :string, description: "hello " <> @module_attribute end diff --git a/test/absinthe/type/query_test.exs b/test/absinthe/type/query_test.exs index 7aeda9dfb2..e8c3306b61 100644 --- a/test/absinthe/type/query_test.exs +++ b/test/absinthe/type/query_test.exs @@ -37,6 +37,10 @@ defmodule Absinthe.Type.QueryTest do arg :arg_example, :string, description: NestedModule.nested_function("hello") end + field :external_module_function_call, :string do + arg :arg_example, :string, description: Absinthe.FunctionEvaluationHelpers.external_function("hello") + end + field :module_attribute, :string do arg :arg_example, :string, description: "hello " <> @module_attribute end diff --git a/test/support/fixtures/import_types.ex b/test/support/fixtures/import_types.ex index afe80d9821..90c3e578fd 100644 --- a/test/support/fixtures/import_types.ex +++ b/test/support/fixtures/import_types.ex @@ -196,6 +196,9 @@ defmodule Absinthe.Fixtures.ImportTypes do field :function_nested_in_module, :string, description: NestedModule.nested_function("hello") + field :external_module_function_call, :string, + description: Absinthe.FunctionEvaluationHelpers.external_function("hello") + field :module_attribute, :string, description: "hello " <> @module_attribute field :interpolation_of_module_attribute, :string, description: "hello #{@module_attribute}" end diff --git a/test/support/function_evaluation_helpers.ex b/test/support/function_evaluation_helpers.ex index a3deb7bb29..040c7cae3f 100644 --- a/test/support/function_evaluation_helpers.ex +++ b/test/support/function_evaluation_helpers.ex @@ -6,8 +6,13 @@ defmodule Absinthe.FunctionEvaluationHelpers do %{test_label: :function_call_using_absolute_path, expected_description: "red"}, %{test_label: :standard_library_function, expected_description: "rad"}, %{test_label: :function_nested_in_module, expected_description: "hello"}, + %{test_label: :external_module_function_call, expected_description: "the value is hello"}, %{test_label: :module_attribute, expected_description: "hello goodbye"}, %{test_label: :interpolation_of_module_attribute, expected_description: "hello goodbye"} ] end + + def external_function(arg) do + "the value is #{arg}" + end end From de73de076158f45af5c6a8b0049f8a6b39d919c6 Mon Sep 17 00:00:00 2001 From: Dylan Chong Date: Tue, 22 Dec 2020 10:13:15 +1300 Subject: [PATCH 32/50] Mix format --- test/absinthe/type/enum_test.exs | 15 +++++++++++---- test/absinthe/type/import_types_test.exs | 6 +++--- test/absinthe/type/input_object_test.exs | 6 +++--- test/absinthe/type/mutation_test.exs | 3 ++- test/absinthe/type/query_test.exs | 3 ++- test/support/fixtures/import_types.ex | 7 ++----- 6 files changed, 23 insertions(+), 17 deletions(-) diff --git a/test/absinthe/type/enum_test.exs b/test/absinthe/type/enum_test.exs index f3a8a70f46..cabb64e4d6 100644 --- a/test/absinthe/type/enum_test.exs +++ b/test/absinthe/type/enum_test.exs @@ -72,11 +72,15 @@ defmodule Absinthe.Type.EnumTest do value :local_function_call, description: test_function("red") value :function_call_using_absolute_path, - description: Absinthe.Type.EnumTest.TestSchemaEnumValueDescriptionKeyword.test_function("red") + description: + Absinthe.Type.EnumTest.TestSchemaEnumValueDescriptionKeyword.test_function("red") value :standard_library_function, description: String.replace("red", "e", "a") value :function_nested_in_module, description: NestedModule.nested_function("hello") - value :external_module_function_call, description: Absinthe.FunctionEvaluationHelpers.external_function("hello") + + value :external_module_function_call, + description: Absinthe.FunctionEvaluationHelpers.external_function("hello") + value :module_attribute, description: "hello " <> @module_attribute value :interpolation_of_module_attribute, description: "hello #{@module_attribute}" end @@ -111,7 +115,8 @@ defmodule Absinthe.Type.EnumTest do enum :function_nested_in_module, description: NestedModule.nested_function("hello") do end - enum :external_module_function_call, description: Absinthe.FunctionEvaluationHelpers.external_function("hello") do + enum :external_module_function_call, + description: Absinthe.FunctionEvaluationHelpers.external_function("hello") do end enum :module_attribute, description: "hello " <> @module_attribute do @@ -258,7 +263,9 @@ defmodule Absinthe.Type.EnumTest do expected_description: expected_description } -> test "for #{test_label}" do - type = TestSchemaEnumValueDescriptionKeyword.__absinthe_type__(:description_keyword_argument) + type = + TestSchemaEnumValueDescriptionKeyword.__absinthe_type__(:description_keyword_argument) + assert type.values[unquote(test_label)].description == unquote(expected_description) end end) diff --git a/test/absinthe/type/import_types_test.exs b/test/absinthe/type/import_types_test.exs index fe6f02252f..c6ca351747 100644 --- a/test/absinthe/type/import_types_test.exs +++ b/test/absinthe/type/import_types_test.exs @@ -84,9 +84,9 @@ defmodule Absinthe.Type.ImportTypesTest do Code.ensure_compiled(ImportTypes.SchemaWithFunctionEvaluation) assert match?( - %Absinthe.Blueprint{}, - ImportTypes.SchemaWithFunctionEvaluation.__absinthe_blueprint__() - ) + %Absinthe.Blueprint{}, + ImportTypes.SchemaWithFunctionEvaluation.__absinthe_blueprint__() + ) end end end diff --git a/test/absinthe/type/input_object_test.exs b/test/absinthe/type/input_object_test.exs index 50fd9cc5ce..c6c4b327b1 100644 --- a/test/absinthe/type/input_object_test.exs +++ b/test/absinthe/type/input_object_test.exs @@ -45,7 +45,8 @@ defmodule Absinthe.Type.InputObjectTest do input_object :function_nested_in_module, description: NestedModule.nested_function("hello") do end - input_object :external_module_function_call, description: Absinthe.FunctionEvaluationHelpers.external_function("hello") do + input_object :external_module_function_call, + description: Absinthe.FunctionEvaluationHelpers.external_function("hello") do end input_object :module_attribute, description: "hello " <> @module_attribute do @@ -192,8 +193,7 @@ defmodule Absinthe.Type.InputObjectTest do "red" ) - field :standard_library_function, :string, - description: String.replace("red", "e", "a") + field :standard_library_function, :string, description: String.replace("red", "e", "a") field :function_nested_in_module, :string, description: NestedModule.nested_function("hello") diff --git a/test/absinthe/type/mutation_test.exs b/test/absinthe/type/mutation_test.exs index 5dcbc57f75..79ca97d270 100644 --- a/test/absinthe/type/mutation_test.exs +++ b/test/absinthe/type/mutation_test.exs @@ -41,7 +41,8 @@ defmodule Absinthe.Type.MutationTest do end field :external_module_function_call, :string do - arg :arg_example, :string, description: Absinthe.FunctionEvaluationHelpers.external_function("hello") + arg :arg_example, :string, + description: Absinthe.FunctionEvaluationHelpers.external_function("hello") end field :module_attribute, :string do diff --git a/test/absinthe/type/query_test.exs b/test/absinthe/type/query_test.exs index e8c3306b61..920ec2bafb 100644 --- a/test/absinthe/type/query_test.exs +++ b/test/absinthe/type/query_test.exs @@ -38,7 +38,8 @@ defmodule Absinthe.Type.QueryTest do end field :external_module_function_call, :string do - arg :arg_example, :string, description: Absinthe.FunctionEvaluationHelpers.external_function("hello") + arg :arg_example, :string, + description: Absinthe.FunctionEvaluationHelpers.external_function("hello") end field :module_attribute, :string do diff --git a/test/support/fixtures/import_types.ex b/test/support/fixtures/import_types.ex index 90c3e578fd..d1ef2f5774 100644 --- a/test/support/fixtures/import_types.ex +++ b/test/support/fixtures/import_types.ex @@ -186,12 +186,9 @@ defmodule Absinthe.Fixtures.ImportTypes do field :function_call_using_absolute_path, :string, description: - Absinthe.Fixtures.ImportTypes.SchemaWithFunctionEvaluationImports.test_function( - "red" - ) + Absinthe.Fixtures.ImportTypes.SchemaWithFunctionEvaluationImports.test_function("red") - field :standard_library_function, :string, - description: String.replace("red", "e", "a") + field :standard_library_function, :string, description: String.replace("red", "e", "a") field :function_nested_in_module, :string, description: NestedModule.nested_function("hello") From be8e3b85f31611d5cc2a0d47802fd8b4d1cd7133 Mon Sep 17 00:00:00 2001 From: Dylan Chong Date: Tue, 22 Dec 2020 10:15:27 +1300 Subject: [PATCH 33/50] Rename module_attribute_string_concat --- test/absinthe/type/enum_test.exs | 8 ++++---- test/absinthe/type/input_object_test.exs | 12 ++++++------ test/absinthe/type/mutation_test.exs | 2 +- test/absinthe/type/query_test.exs | 2 +- test/support/fixtures/import_types.ex | 2 +- test/support/function_evaluation_helpers.ex | 2 +- 6 files changed, 14 insertions(+), 14 deletions(-) diff --git a/test/absinthe/type/enum_test.exs b/test/absinthe/type/enum_test.exs index cabb64e4d6..99b5f81a78 100644 --- a/test/absinthe/type/enum_test.exs +++ b/test/absinthe/type/enum_test.exs @@ -81,7 +81,7 @@ defmodule Absinthe.Type.EnumTest do value :external_module_function_call, description: Absinthe.FunctionEvaluationHelpers.external_function("hello") - value :module_attribute, description: "hello " <> @module_attribute + value :module_attribute_string_concat, description: "hello " <> @module_attribute value :interpolation_of_module_attribute, description: "hello #{@module_attribute}" end end @@ -119,7 +119,7 @@ defmodule Absinthe.Type.EnumTest do description: Absinthe.FunctionEvaluationHelpers.external_function("hello") do end - enum :module_attribute, description: "hello " <> @module_attribute do + enum :module_attribute_string_concat, description: "hello " <> @module_attribute do end enum :interpolation_of_module_attribute, description: "hello #{@module_attribute}" do @@ -176,7 +176,7 @@ defmodule Absinthe.Type.EnumTest do end @desc "hello " <> @module_attribute - enum :module_attribute do + enum :module_attribute_string_concat do end @desc "hello #{@module_attribute}" @@ -225,7 +225,7 @@ defmodule Absinthe.Type.EnumTest do description Absinthe.FunctionEvaluationHelpers.external_function("hello") end - enum :module_attribute do + enum :module_attribute_string_concat do description "hello " <> @module_attribute end diff --git a/test/absinthe/type/input_object_test.exs b/test/absinthe/type/input_object_test.exs index c6c4b327b1..7803e026eb 100644 --- a/test/absinthe/type/input_object_test.exs +++ b/test/absinthe/type/input_object_test.exs @@ -49,7 +49,7 @@ defmodule Absinthe.Type.InputObjectTest do description: Absinthe.FunctionEvaluationHelpers.external_function("hello") do end - input_object :module_attribute, description: "hello " <> @module_attribute do + input_object :module_attribute_string_concat, description: "hello " <> @module_attribute do end input_object :interpolation_of_module_attribute, description: "hello #{@module_attribute}" do @@ -106,7 +106,7 @@ defmodule Absinthe.Type.InputObjectTest do end @desc "hello " <> @module_attribute - input_object :module_attribute do + input_object :module_attribute_string_concat do end @desc "hello #{@module_attribute}" @@ -157,7 +157,7 @@ defmodule Absinthe.Type.InputObjectTest do description Absinthe.FunctionEvaluationHelpers.external_function("hello") end - input_object :module_attribute do + input_object :module_attribute_string_concat do description "hello " <> @module_attribute end @@ -201,7 +201,7 @@ defmodule Absinthe.Type.InputObjectTest do field :external_module_function_call, :string, description: Absinthe.FunctionEvaluationHelpers.external_function("hello") - field :module_attribute, :string, description: "hello " <> @module_attribute + field :module_attribute_string_concat, :string, description: "hello " <> @module_attribute field :interpolation_of_module_attribute, :string, description: "hello #{@module_attribute}" end @@ -231,7 +231,7 @@ defmodule Absinthe.Type.InputObjectTest do field :external_module_function_call, :string @desc "hello " <> @module_attribute - field :module_attribute, :string + field :module_attribute_string_concat, :string @desc "hello #{@module_attribute}" field :interpolation_of_module_attribute, :string @@ -264,7 +264,7 @@ defmodule Absinthe.Type.InputObjectTest do description Absinthe.FunctionEvaluationHelpers.external_function("hello") end - field :module_attribute, :string do + field :module_attribute_string_concat, :string do description "hello " <> @module_attribute end diff --git a/test/absinthe/type/mutation_test.exs b/test/absinthe/type/mutation_test.exs index 79ca97d270..449494be43 100644 --- a/test/absinthe/type/mutation_test.exs +++ b/test/absinthe/type/mutation_test.exs @@ -45,7 +45,7 @@ defmodule Absinthe.Type.MutationTest do description: Absinthe.FunctionEvaluationHelpers.external_function("hello") end - field :module_attribute, :string do + field :module_attribute_string_concat, :string do arg :arg_example, :string, description: "hello " <> @module_attribute end diff --git a/test/absinthe/type/query_test.exs b/test/absinthe/type/query_test.exs index 920ec2bafb..c38537dbe4 100644 --- a/test/absinthe/type/query_test.exs +++ b/test/absinthe/type/query_test.exs @@ -42,7 +42,7 @@ defmodule Absinthe.Type.QueryTest do description: Absinthe.FunctionEvaluationHelpers.external_function("hello") end - field :module_attribute, :string do + field :module_attribute_string_concat, :string do arg :arg_example, :string, description: "hello " <> @module_attribute end diff --git a/test/support/fixtures/import_types.ex b/test/support/fixtures/import_types.ex index d1ef2f5774..877c08c080 100644 --- a/test/support/fixtures/import_types.ex +++ b/test/support/fixtures/import_types.ex @@ -196,7 +196,7 @@ defmodule Absinthe.Fixtures.ImportTypes do field :external_module_function_call, :string, description: Absinthe.FunctionEvaluationHelpers.external_function("hello") - field :module_attribute, :string, description: "hello " <> @module_attribute + field :module_attribute_string_concat, :string, description: "hello " <> @module_attribute field :interpolation_of_module_attribute, :string, description: "hello #{@module_attribute}" end end diff --git a/test/support/function_evaluation_helpers.ex b/test/support/function_evaluation_helpers.ex index 040c7cae3f..6fa98bb77a 100644 --- a/test/support/function_evaluation_helpers.ex +++ b/test/support/function_evaluation_helpers.ex @@ -7,7 +7,7 @@ defmodule Absinthe.FunctionEvaluationHelpers do %{test_label: :standard_library_function, expected_description: "rad"}, %{test_label: :function_nested_in_module, expected_description: "hello"}, %{test_label: :external_module_function_call, expected_description: "the value is hello"}, - %{test_label: :module_attribute, expected_description: "hello goodbye"}, + %{test_label: :module_attribute_string_concat, expected_description: "hello goodbye"}, %{test_label: :interpolation_of_module_attribute, expected_description: "hello goodbye"} ] end From ce742efe1f89ebcec56eb9c00bdd2b6698d450f3 Mon Sep 17 00:00:00 2001 From: Dylan Chong Date: Tue, 22 Dec 2020 10:16:01 +1300 Subject: [PATCH 34/50] Rename function_nested_in_module --- test/absinthe/type/enum_test.exs | 8 ++++---- test/absinthe/type/input_object_test.exs | 12 ++++++------ test/absinthe/type/mutation_test.exs | 2 +- test/absinthe/type/query_test.exs | 2 +- test/support/fixtures/import_types.ex | 2 +- test/support/function_evaluation_helpers.ex | 2 +- 6 files changed, 14 insertions(+), 14 deletions(-) diff --git a/test/absinthe/type/enum_test.exs b/test/absinthe/type/enum_test.exs index 99b5f81a78..13f6dfeaa1 100644 --- a/test/absinthe/type/enum_test.exs +++ b/test/absinthe/type/enum_test.exs @@ -76,7 +76,7 @@ defmodule Absinthe.Type.EnumTest do Absinthe.Type.EnumTest.TestSchemaEnumValueDescriptionKeyword.test_function("red") value :standard_library_function, description: String.replace("red", "e", "a") - value :function_nested_in_module, description: NestedModule.nested_function("hello") + value :function_in_nested_module, description: NestedModule.nested_function("hello") value :external_module_function_call, description: Absinthe.FunctionEvaluationHelpers.external_function("hello") @@ -112,7 +112,7 @@ defmodule Absinthe.Type.EnumTest do enum :standard_library_function, description: String.replace("red", "e", "a") do end - enum :function_nested_in_module, description: NestedModule.nested_function("hello") do + enum :function_in_nested_module, description: NestedModule.nested_function("hello") do end enum :external_module_function_call, @@ -168,7 +168,7 @@ defmodule Absinthe.Type.EnumTest do end @desc NestedModule.nested_function("hello") - enum :function_nested_in_module do + enum :function_in_nested_module do end @desc Absinthe.FunctionEvaluationHelpers.external_function("hello") @@ -217,7 +217,7 @@ defmodule Absinthe.Type.EnumTest do description String.replace("red", "e", "a") end - enum :function_nested_in_module do + enum :function_in_nested_module do description NestedModule.nested_function("hello") end diff --git a/test/absinthe/type/input_object_test.exs b/test/absinthe/type/input_object_test.exs index 7803e026eb..f751e9fa90 100644 --- a/test/absinthe/type/input_object_test.exs +++ b/test/absinthe/type/input_object_test.exs @@ -42,7 +42,7 @@ defmodule Absinthe.Type.InputObjectTest do input_object :standard_library_function, description: String.replace("red", "e", "a") do end - input_object :function_nested_in_module, description: NestedModule.nested_function("hello") do + input_object :function_in_nested_module, description: NestedModule.nested_function("hello") do end input_object :external_module_function_call, @@ -98,7 +98,7 @@ defmodule Absinthe.Type.InputObjectTest do end @desc NestedModule.nested_function("hello") - input_object :function_nested_in_module do + input_object :function_in_nested_module do end @desc Absinthe.FunctionEvaluationHelpers.external_function("hello") @@ -149,7 +149,7 @@ defmodule Absinthe.Type.InputObjectTest do description String.replace("red", "e", "a") end - input_object :function_nested_in_module do + input_object :function_in_nested_module do description NestedModule.nested_function("hello") end @@ -195,7 +195,7 @@ defmodule Absinthe.Type.InputObjectTest do field :standard_library_function, :string, description: String.replace("red", "e", "a") - field :function_nested_in_module, :string, + field :function_in_nested_module, :string, description: NestedModule.nested_function("hello") field :external_module_function_call, :string, @@ -225,7 +225,7 @@ defmodule Absinthe.Type.InputObjectTest do field :standard_library_function, :string @desc NestedModule.nested_function("hello") - field :function_nested_in_module, :string + field :function_in_nested_module, :string @desc Absinthe.FunctionEvaluationHelpers.external_function("hello") field :external_module_function_call, :string @@ -256,7 +256,7 @@ defmodule Absinthe.Type.InputObjectTest do description String.replace("red", "e", "a") end - field :function_nested_in_module, :string do + field :function_in_nested_module, :string do description NestedModule.nested_function("hello") end diff --git a/test/absinthe/type/mutation_test.exs b/test/absinthe/type/mutation_test.exs index 449494be43..cb71944636 100644 --- a/test/absinthe/type/mutation_test.exs +++ b/test/absinthe/type/mutation_test.exs @@ -36,7 +36,7 @@ defmodule Absinthe.Type.MutationTest do arg :arg_example, :string, description: String.replace("red", "e", "a") end - field :function_nested_in_module, :string do + field :function_in_nested_module, :string do arg :arg_example, :string, description: NestedModule.nested_function("hello") end diff --git a/test/absinthe/type/query_test.exs b/test/absinthe/type/query_test.exs index c38537dbe4..ed5f0cde71 100644 --- a/test/absinthe/type/query_test.exs +++ b/test/absinthe/type/query_test.exs @@ -33,7 +33,7 @@ defmodule Absinthe.Type.QueryTest do arg :arg_example, :string, description: String.replace("red", "e", "a") end - field :function_nested_in_module, :string do + field :function_in_nested_module, :string do arg :arg_example, :string, description: NestedModule.nested_function("hello") end diff --git a/test/support/fixtures/import_types.ex b/test/support/fixtures/import_types.ex index 877c08c080..60e433dc88 100644 --- a/test/support/fixtures/import_types.ex +++ b/test/support/fixtures/import_types.ex @@ -190,7 +190,7 @@ defmodule Absinthe.Fixtures.ImportTypes do field :standard_library_function, :string, description: String.replace("red", "e", "a") - field :function_nested_in_module, :string, + field :function_in_nested_module, :string, description: NestedModule.nested_function("hello") field :external_module_function_call, :string, diff --git a/test/support/function_evaluation_helpers.ex b/test/support/function_evaluation_helpers.ex index 6fa98bb77a..f1e265e054 100644 --- a/test/support/function_evaluation_helpers.ex +++ b/test/support/function_evaluation_helpers.ex @@ -5,7 +5,7 @@ defmodule Absinthe.FunctionEvaluationHelpers do %{test_label: :local_function_call, expected_description: "red"}, %{test_label: :function_call_using_absolute_path, expected_description: "red"}, %{test_label: :standard_library_function, expected_description: "rad"}, - %{test_label: :function_nested_in_module, expected_description: "hello"}, + %{test_label: :function_in_nested_module, expected_description: "hello"}, %{test_label: :external_module_function_call, expected_description: "the value is hello"}, %{test_label: :module_attribute_string_concat, expected_description: "hello goodbye"}, %{test_label: :interpolation_of_module_attribute, expected_description: "hello goodbye"} From 7df5c50f27fb94f79c91e289d17c06c8ed6dca99 Mon Sep 17 00:00:00 2001 From: Dylan Chong Date: Tue, 22 Dec 2020 10:23:39 +1300 Subject: [PATCH 35/50] Rename test --- test/absinthe/type/enum_test.exs | 8 ++++---- test/absinthe/type/import_types_test.exs | 2 +- test/absinthe/type/input_object_test.exs | 12 ++++++------ test/absinthe/type/mutation_test.exs | 2 +- test/absinthe/type/query_test.exs | 2 +- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/test/absinthe/type/enum_test.exs b/test/absinthe/type/enum_test.exs index 13f6dfeaa1..4d8fb803d3 100644 --- a/test/absinthe/type/enum_test.exs +++ b/test/absinthe/type/enum_test.exs @@ -262,7 +262,7 @@ defmodule Absinthe.Type.EnumTest do test_label: test_label, expected_description: expected_description } -> - test "for #{test_label}" do + test "for #{test_label} (evaluates description to '#{expected_description}')" do type = TestSchemaEnumValueDescriptionKeyword.__absinthe_type__(:description_keyword_argument) @@ -277,7 +277,7 @@ defmodule Absinthe.Type.EnumTest do test_label: test_label, expected_description: expected_description } -> - test "for #{test_label}" do + test "for #{test_label} (evaluates description to '#{expected_description}')" do type = TestSchemaEnumDescriptionKeyword.__absinthe_type__(unquote(test_label)) assert type.description == unquote(expected_description) end @@ -296,7 +296,7 @@ defmodule Absinthe.Type.EnumTest do test_label: test_label, expected_description: expected_description } -> - test "for #{test_label}" do + test "for #{test_label} (evaluates description to '#{expected_description}')" do type = TestSchemaEnumDescriptionAttribute.__absinthe_type__(unquote(test_label)) assert type.description == unquote(expected_description) end @@ -309,7 +309,7 @@ defmodule Absinthe.Type.EnumTest do test_label: test_label, expected_description: expected_description } -> - test "for #{test_label}" do + test "for #{test_label} (evaluates description to '#{expected_description}')" do type = TestSchemaEnumDescriptionMacro.__absinthe_type__(unquote(test_label)) assert type.description == unquote(expected_description) end diff --git a/test/absinthe/type/import_types_test.exs b/test/absinthe/type/import_types_test.exs index c6ca351747..889f67d25b 100644 --- a/test/absinthe/type/import_types_test.exs +++ b/test/absinthe/type/import_types_test.exs @@ -49,7 +49,7 @@ defmodule Absinthe.Type.ImportTypesTest do test_label: test_label, expected_description: expected_description } -> - test "for #{test_label}" do + test "for #{test_label} (evaluates description to '#{expected_description}')" do type = ImportTypes.SchemaWithFunctionEvaluation.__absinthe_type__(:example_input_object) assert type.fields[unquote(test_label)].description == unquote(expected_description) diff --git a/test/absinthe/type/input_object_test.exs b/test/absinthe/type/input_object_test.exs index f751e9fa90..8ceb068516 100644 --- a/test/absinthe/type/input_object_test.exs +++ b/test/absinthe/type/input_object_test.exs @@ -294,7 +294,7 @@ defmodule Absinthe.Type.InputObjectTest do test_label: test_label, expected_description: expected_description } -> - test "for #{test_label}" do + test "for `#{test_label}` (evaluates description to `'#{expected_description}'`)" do type = TestSchemaInputObjectDescriptionKeyword.__absinthe_type__(unquote(test_label)) assert type.description == unquote(expected_description) end @@ -313,7 +313,7 @@ defmodule Absinthe.Type.InputObjectTest do test_label: test_label, expected_description: expected_description } -> - test "for #{test_label}" do + test "for #{test_label} (evaluates description to '#{expected_description}')" do type = TestSchemaInputObjectDescriptionAttribute.__absinthe_type__(unquote(test_label)) assert type.description == unquote(expected_description) end @@ -326,7 +326,7 @@ defmodule Absinthe.Type.InputObjectTest do test_label: test_label, expected_description: expected_description } -> - test "for #{test_label}" do + test "for #{test_label} (evaluates description to '#{expected_description}')" do type = TestSchemaInputObjectDescriptionMacro.__absinthe_type__(unquote(test_label)) assert type.description == unquote(expected_description) end @@ -339,7 +339,7 @@ defmodule Absinthe.Type.InputObjectTest do test_label: test_label, expected_description: expected_description } -> - test "for #{test_label}" do + test "for #{test_label} (evaluates description to '#{expected_description}')" do type = TestSchemaInputObjectFieldsAndArgsDescription.__absinthe_type__( :description_keyword_argument @@ -362,7 +362,7 @@ defmodule Absinthe.Type.InputObjectTest do test_label: test_label, expected_description: expected_description } -> - test "for #{test_label}" do + test "for #{test_label} (evaluates description to '#{expected_description}')" do type = TestSchemaInputObjectFieldsAndArgsDescription.__absinthe_type__(:description_attribute) @@ -377,7 +377,7 @@ defmodule Absinthe.Type.InputObjectTest do test_label: test_label, expected_description: expected_description } -> - test "for #{test_label}" do + test "for #{test_label} (evaluates description to '#{expected_description}')" do type = TestSchemaInputObjectFieldsAndArgsDescription.__absinthe_type__( :field_description_macro diff --git a/test/absinthe/type/mutation_test.exs b/test/absinthe/type/mutation_test.exs index cb71944636..e2a7884dea 100644 --- a/test/absinthe/type/mutation_test.exs +++ b/test/absinthe/type/mutation_test.exs @@ -61,7 +61,7 @@ defmodule Absinthe.Type.MutationTest do test_label: test_label, expected_description: expected_description } -> - test "for #{test_label}" do + test "for #{test_label} (evaluates description to '#{expected_description}')" do type = TestSchema.__absinthe_type__("RootMutationType") assert type.fields[unquote(test_label)].args.arg_example.description == diff --git a/test/absinthe/type/query_test.exs b/test/absinthe/type/query_test.exs index ed5f0cde71..fd490ea7d1 100644 --- a/test/absinthe/type/query_test.exs +++ b/test/absinthe/type/query_test.exs @@ -58,7 +58,7 @@ defmodule Absinthe.Type.QueryTest do test_label: test_label, expected_description: expected_description } -> - test "for #{test_label}" do + test "for #{test_label} (evaluates description to '#{expected_description}')" do type = TestSchema.__absinthe_type__("RootQueryType") assert type.fields[unquote(test_label)].args.arg_example.description == From 25b347e6b1dd881f0fc656229042cf122a6ecfb0 Mon Sep 17 00:00:00 2001 From: Dylan Chong Date: Tue, 22 Dec 2020 10:24:58 +1300 Subject: [PATCH 36/50] Rename expected_value --- test/absinthe/type/enum_test.exs | 24 +++++++------- test/absinthe/type/import_types_test.exs | 6 ++-- test/absinthe/type/input_object_test.exs | 36 ++++++++++----------- test/absinthe/type/mutation_test.exs | 6 ++-- test/absinthe/type/query_test.exs | 6 ++-- test/support/function_evaluation_helpers.ex | 16 ++++----- 6 files changed, 47 insertions(+), 47 deletions(-) diff --git a/test/absinthe/type/enum_test.exs b/test/absinthe/type/enum_test.exs index 4d8fb803d3..38aca13673 100644 --- a/test/absinthe/type/enum_test.exs +++ b/test/absinthe/type/enum_test.exs @@ -260,13 +260,13 @@ defmodule Absinthe.Type.EnumTest do Absinthe.FunctionEvaluationHelpers.function_evaluation_test_params() |> Enum.each(fn %{ test_label: test_label, - expected_description: expected_description + expected_value: expected_value } -> - test "for #{test_label} (evaluates description to '#{expected_description}')" do + test "for #{test_label} (evaluates description to '#{expected_value}')" do type = TestSchemaEnumValueDescriptionKeyword.__absinthe_type__(:description_keyword_argument) - assert type.values[unquote(test_label)].description == unquote(expected_description) + assert type.values[unquote(test_label)].description == unquote(expected_value) end end) end @@ -275,11 +275,11 @@ defmodule Absinthe.Type.EnumTest do Absinthe.FunctionEvaluationHelpers.function_evaluation_test_params() |> Enum.each(fn %{ test_label: test_label, - expected_description: expected_description + expected_value: expected_value } -> - test "for #{test_label} (evaluates description to '#{expected_description}')" do + test "for #{test_label} (evaluates description to '#{expected_value}')" do type = TestSchemaEnumDescriptionKeyword.__absinthe_type__(unquote(test_label)) - assert type.description == unquote(expected_description) + assert type.description == unquote(expected_value) end end) end @@ -294,11 +294,11 @@ defmodule Absinthe.Type.EnumTest do end) |> Enum.each(fn %{ test_label: test_label, - expected_description: expected_description + expected_value: expected_value } -> - test "for #{test_label} (evaluates description to '#{expected_description}')" do + test "for #{test_label} (evaluates description to '#{expected_value}')" do type = TestSchemaEnumDescriptionAttribute.__absinthe_type__(unquote(test_label)) - assert type.description == unquote(expected_description) + assert type.description == unquote(expected_value) end end) end @@ -307,11 +307,11 @@ defmodule Absinthe.Type.EnumTest do Absinthe.FunctionEvaluationHelpers.function_evaluation_test_params() |> Enum.each(fn %{ test_label: test_label, - expected_description: expected_description + expected_value: expected_value } -> - test "for #{test_label} (evaluates description to '#{expected_description}')" do + test "for #{test_label} (evaluates description to '#{expected_value}')" do type = TestSchemaEnumDescriptionMacro.__absinthe_type__(unquote(test_label)) - assert type.description == unquote(expected_description) + assert type.description == unquote(expected_value) end end) end diff --git a/test/absinthe/type/import_types_test.exs b/test/absinthe/type/import_types_test.exs index 889f67d25b..648376cac8 100644 --- a/test/absinthe/type/import_types_test.exs +++ b/test/absinthe/type/import_types_test.exs @@ -47,12 +47,12 @@ defmodule Absinthe.Type.ImportTypesTest do Absinthe.FunctionEvaluationHelpers.function_evaluation_test_params() |> Enum.each(fn %{ test_label: test_label, - expected_description: expected_description + expected_value: expected_value } -> - test "for #{test_label} (evaluates description to '#{expected_description}')" do + test "for #{test_label} (evaluates description to '#{expected_value}')" do type = ImportTypes.SchemaWithFunctionEvaluation.__absinthe_type__(:example_input_object) - assert type.fields[unquote(test_label)].description == unquote(expected_description) + assert type.fields[unquote(test_label)].description == unquote(expected_value) end end) diff --git a/test/absinthe/type/input_object_test.exs b/test/absinthe/type/input_object_test.exs index 8ceb068516..2177297638 100644 --- a/test/absinthe/type/input_object_test.exs +++ b/test/absinthe/type/input_object_test.exs @@ -292,11 +292,11 @@ defmodule Absinthe.Type.InputObjectTest do Absinthe.FunctionEvaluationHelpers.function_evaluation_test_params() |> Enum.each(fn %{ test_label: test_label, - expected_description: expected_description + expected_value: expected_value } -> - test "for `#{test_label}` (evaluates description to `'#{expected_description}'`)" do + test "for `#{test_label}` (evaluates description to `'#{expected_value}'`)" do type = TestSchemaInputObjectDescriptionKeyword.__absinthe_type__(unquote(test_label)) - assert type.description == unquote(expected_description) + assert type.description == unquote(expected_value) end end) end @@ -311,11 +311,11 @@ defmodule Absinthe.Type.InputObjectTest do end) |> Enum.each(fn %{ test_label: test_label, - expected_description: expected_description + expected_value: expected_value } -> - test "for #{test_label} (evaluates description to '#{expected_description}')" do + test "for #{test_label} (evaluates description to '#{expected_value}')" do type = TestSchemaInputObjectDescriptionAttribute.__absinthe_type__(unquote(test_label)) - assert type.description == unquote(expected_description) + assert type.description == unquote(expected_value) end end) end @@ -324,11 +324,11 @@ defmodule Absinthe.Type.InputObjectTest do Absinthe.FunctionEvaluationHelpers.function_evaluation_test_params() |> Enum.each(fn %{ test_label: test_label, - expected_description: expected_description + expected_value: expected_value } -> - test "for #{test_label} (evaluates description to '#{expected_description}')" do + test "for #{test_label} (evaluates description to '#{expected_value}')" do type = TestSchemaInputObjectDescriptionMacro.__absinthe_type__(unquote(test_label)) - assert type.description == unquote(expected_description) + assert type.description == unquote(expected_value) end end) end @@ -337,15 +337,15 @@ defmodule Absinthe.Type.InputObjectTest do Absinthe.FunctionEvaluationHelpers.function_evaluation_test_params() |> Enum.each(fn %{ test_label: test_label, - expected_description: expected_description + expected_value: expected_value } -> - test "for #{test_label} (evaluates description to '#{expected_description}')" do + test "for #{test_label} (evaluates description to '#{expected_value}')" do type = TestSchemaInputObjectFieldsAndArgsDescription.__absinthe_type__( :description_keyword_argument ) - assert type.fields[unquote(test_label)].description == unquote(expected_description) + assert type.fields[unquote(test_label)].description == unquote(expected_value) end end) end @@ -360,13 +360,13 @@ defmodule Absinthe.Type.InputObjectTest do end) |> Enum.each(fn %{ test_label: test_label, - expected_description: expected_description + expected_value: expected_value } -> - test "for #{test_label} (evaluates description to '#{expected_description}')" do + test "for #{test_label} (evaluates description to '#{expected_value}')" do type = TestSchemaInputObjectFieldsAndArgsDescription.__absinthe_type__(:description_attribute) - assert type.fields[unquote(test_label)].description == unquote(expected_description) + assert type.fields[unquote(test_label)].description == unquote(expected_value) end end) end @@ -375,15 +375,15 @@ defmodule Absinthe.Type.InputObjectTest do Absinthe.FunctionEvaluationHelpers.function_evaluation_test_params() |> Enum.each(fn %{ test_label: test_label, - expected_description: expected_description + expected_value: expected_value } -> - test "for #{test_label} (evaluates description to '#{expected_description}')" do + test "for #{test_label} (evaluates description to '#{expected_value}')" do type = TestSchemaInputObjectFieldsAndArgsDescription.__absinthe_type__( :field_description_macro ) - assert type.fields[unquote(test_label)].description == unquote(expected_description) + assert type.fields[unquote(test_label)].description == unquote(expected_value) end end) end diff --git a/test/absinthe/type/mutation_test.exs b/test/absinthe/type/mutation_test.exs index e2a7884dea..388e0af41a 100644 --- a/test/absinthe/type/mutation_test.exs +++ b/test/absinthe/type/mutation_test.exs @@ -59,13 +59,13 @@ defmodule Absinthe.Type.MutationTest do Absinthe.FunctionEvaluationHelpers.function_evaluation_test_params() |> Enum.each(fn %{ test_label: test_label, - expected_description: expected_description + expected_value: expected_value } -> - test "for #{test_label} (evaluates description to '#{expected_description}')" do + test "for #{test_label} (evaluates description to '#{expected_value}')" do type = TestSchema.__absinthe_type__("RootMutationType") assert type.fields[unquote(test_label)].args.arg_example.description == - unquote(expected_description) + unquote(expected_value) end end) end diff --git a/test/absinthe/type/query_test.exs b/test/absinthe/type/query_test.exs index fd490ea7d1..22a097980e 100644 --- a/test/absinthe/type/query_test.exs +++ b/test/absinthe/type/query_test.exs @@ -56,13 +56,13 @@ defmodule Absinthe.Type.QueryTest do Absinthe.FunctionEvaluationHelpers.function_evaluation_test_params() |> Enum.each(fn %{ test_label: test_label, - expected_description: expected_description + expected_value: expected_value } -> - test "for #{test_label} (evaluates description to '#{expected_description}')" do + test "for #{test_label} (evaluates description to '#{expected_value}')" do type = TestSchema.__absinthe_type__("RootQueryType") assert type.fields[unquote(test_label)].args.arg_example.description == - unquote(expected_description) + unquote(expected_value) end end) end diff --git a/test/support/function_evaluation_helpers.ex b/test/support/function_evaluation_helpers.ex index f1e265e054..31cc488724 100644 --- a/test/support/function_evaluation_helpers.ex +++ b/test/support/function_evaluation_helpers.ex @@ -1,14 +1,14 @@ defmodule Absinthe.FunctionEvaluationHelpers do def function_evaluation_test_params do [ - %{test_label: :normal_string, expected_description: "string"}, - %{test_label: :local_function_call, expected_description: "red"}, - %{test_label: :function_call_using_absolute_path, expected_description: "red"}, - %{test_label: :standard_library_function, expected_description: "rad"}, - %{test_label: :function_in_nested_module, expected_description: "hello"}, - %{test_label: :external_module_function_call, expected_description: "the value is hello"}, - %{test_label: :module_attribute_string_concat, expected_description: "hello goodbye"}, - %{test_label: :interpolation_of_module_attribute, expected_description: "hello goodbye"} + %{test_label: :normal_string, expected_value: "string"}, + %{test_label: :local_function_call, expected_value: "red"}, + %{test_label: :function_call_using_absolute_path, expected_value: "red"}, + %{test_label: :standard_library_function, expected_value: "rad"}, + %{test_label: :function_in_nested_module, expected_value: "hello"}, + %{test_label: :external_module_function_call, expected_value: "the value is hello"}, + %{test_label: :module_attribute_string_concat, expected_value: "hello goodbye"}, + %{test_label: :interpolation_of_module_attribute, expected_value: "hello goodbye"} ] end From ef90531a28e11298aa23e62f20e87f3c8fee633c Mon Sep 17 00:00:00 2001 From: Dylan Chong Date: Tue, 22 Dec 2020 10:26:35 +1300 Subject: [PATCH 37/50] Rename function_call_using_absolute_path --- test/absinthe/type/enum_test.exs | 13 +++++++----- test/absinthe/type/input_object_test.exs | 22 +++++++++++++-------- test/absinthe/type/mutation_test.exs | 2 +- test/absinthe/type/query_test.exs | 2 +- test/support/fixtures/import_types.ex | 2 +- test/support/function_evaluation_helpers.ex | 2 +- 6 files changed, 26 insertions(+), 17 deletions(-) diff --git a/test/absinthe/type/enum_test.exs b/test/absinthe/type/enum_test.exs index 38aca13673..63674b45c7 100644 --- a/test/absinthe/type/enum_test.exs +++ b/test/absinthe/type/enum_test.exs @@ -71,7 +71,7 @@ defmodule Absinthe.Type.EnumTest do value :normal_string, description: "string" value :local_function_call, description: test_function("red") - value :function_call_using_absolute_path, + value :function_call_using_absolute_path_to_current_module, description: Absinthe.Type.EnumTest.TestSchemaEnumValueDescriptionKeyword.test_function("red") @@ -105,7 +105,7 @@ defmodule Absinthe.Type.EnumTest do enum :local_function_call, description: test_function("red") do end - enum :function_call_using_absolute_path, + enum :function_call_using_absolute_path_to_current_module, description: Absinthe.Type.EnumTest.TestSchemaEnumDescriptionKeyword.test_function("red") do end @@ -160,7 +160,7 @@ defmodule Absinthe.Type.EnumTest do # end # @desc Absinthe.Type.EnumTest.TestSchemaEnumAttribute.test_function("red") - # enum :function_call_using_absolute_path do + # enum :function_call_using_absolute_path_to_current_module do # end @desc String.replace("red", "e", "a") @@ -209,7 +209,7 @@ defmodule Absinthe.Type.EnumTest do description test_function("red") end - enum :function_call_using_absolute_path do + enum :function_call_using_absolute_path_to_current_module do description Absinthe.Type.EnumTest.TestSchemaEnumDescriptionMacro.test_function("red") end @@ -290,7 +290,10 @@ defmodule Absinthe.Type.EnumTest do # expression for the @desc attribute is evaluated at compile time. There is nothing we can # really do about it |> Enum.filter(fn %{test_label: test_label} -> - test_label not in [:local_function_call, :function_call_using_absolute_path] + test_label not in [ + :local_function_call, + :function_call_using_absolute_path_to_current_module + ] end) |> Enum.each(fn %{ test_label: test_label, diff --git a/test/absinthe/type/input_object_test.exs b/test/absinthe/type/input_object_test.exs index 2177297638..1a8059e053 100644 --- a/test/absinthe/type/input_object_test.exs +++ b/test/absinthe/type/input_object_test.exs @@ -34,7 +34,7 @@ defmodule Absinthe.Type.InputObjectTest do input_object :local_function_call, description: test_function("red") do end - input_object :function_call_using_absolute_path, + input_object :function_call_using_absolute_path_to_current_module, description: Absinthe.Type.InputObjectTest.TestSchemaInputObjectDescriptionKeyword.test_function("red") do end @@ -90,7 +90,7 @@ defmodule Absinthe.Type.InputObjectTest do # end # @desc Absinthe.Type.InputObjectTest.TestSchemaInputObjectAttribute.test_function("red") - # input_object :function_call_using_absolute_path do + # input_object :function_call_using_absolute_path_to_current_module do # end @desc String.replace("red", "e", "a") @@ -139,7 +139,7 @@ defmodule Absinthe.Type.InputObjectTest do description test_function("red") end - input_object :function_call_using_absolute_path do + input_object :function_call_using_absolute_path_to_current_module do description Absinthe.Type.InputObjectTest.TestSchemaInputObjectDescriptionMacro.test_function( "red" ) @@ -187,7 +187,7 @@ defmodule Absinthe.Type.InputObjectTest do field :normal_string, :string, description: "string" field :local_function_call, :string, description: test_function("red") - field :function_call_using_absolute_path, :string, + field :function_call_using_absolute_path_to_current_module, :string, description: Absinthe.Type.InputObjectTest.TestSchemaInputObjectFieldsAndArgsDescription.test_function( "red" @@ -219,7 +219,7 @@ defmodule Absinthe.Type.InputObjectTest do # @desc Absinthe.Type.InputObjectTest.TestSchemaInputObjectFieldsAndArgsDescription.test_function( # "red" # ) - # field :function_call_using_absolute_path, :string + # field :function_call_using_absolute_path_to_current_module, :string @desc String.replace("red", "e", "a") field :standard_library_function, :string @@ -246,7 +246,7 @@ defmodule Absinthe.Type.InputObjectTest do description test_function("red") end - field :function_call_using_absolute_path, :string do + field :function_call_using_absolute_path_to_current_module, :string do description Absinthe.Type.InputObjectTest.TestSchemaInputObjectFieldsAndArgsDescription.test_function( "red" ) @@ -307,7 +307,10 @@ defmodule Absinthe.Type.InputObjectTest do # expression for the @desc attribute is evaluated at compile time. There is nothing we can # really do about it |> Enum.filter(fn %{test_label: test_label} -> - test_label not in [:local_function_call, :function_call_using_absolute_path] + test_label not in [ + :local_function_call, + :function_call_using_absolute_path_to_current_module + ] end) |> Enum.each(fn %{ test_label: test_label, @@ -356,7 +359,10 @@ defmodule Absinthe.Type.InputObjectTest do # expression for the @desc attribute is evaluated at compile time. There is nothing we can # really do about it |> Enum.filter(fn %{test_label: test_label} -> - test_label not in [:local_function_call, :function_call_using_absolute_path] + test_label not in [ + :local_function_call, + :function_call_using_absolute_path_to_current_module + ] end) |> Enum.each(fn %{ test_label: test_label, diff --git a/test/absinthe/type/mutation_test.exs b/test/absinthe/type/mutation_test.exs index 388e0af41a..a108069d6d 100644 --- a/test/absinthe/type/mutation_test.exs +++ b/test/absinthe/type/mutation_test.exs @@ -27,7 +27,7 @@ defmodule Absinthe.Type.MutationTest do arg :arg_example, :string, description: test_function("red") end - field :function_call_using_absolute_path, :string do + field :function_call_using_absolute_path_to_current_module, :string do arg :arg_example, :string, description: Absinthe.Type.MutationTest.TestSchema.test_function("red") end diff --git a/test/absinthe/type/query_test.exs b/test/absinthe/type/query_test.exs index 22a097980e..ac47ac72aa 100644 --- a/test/absinthe/type/query_test.exs +++ b/test/absinthe/type/query_test.exs @@ -24,7 +24,7 @@ defmodule Absinthe.Type.QueryTest do arg :arg_example, :string, description: test_function("red") end - field :function_call_using_absolute_path, :string do + field :function_call_using_absolute_path_to_current_module, :string do arg :arg_example, :string, description: Absinthe.Type.QueryTest.TestSchema.test_function("red") end diff --git a/test/support/fixtures/import_types.ex b/test/support/fixtures/import_types.ex index 60e433dc88..897b2f85ec 100644 --- a/test/support/fixtures/import_types.ex +++ b/test/support/fixtures/import_types.ex @@ -184,7 +184,7 @@ defmodule Absinthe.Fixtures.ImportTypes do field :normal_string, :string, description: "string" field :local_function_call, :string, description: test_function("red") - field :function_call_using_absolute_path, :string, + field :function_call_using_absolute_path_to_current_module, :string, description: Absinthe.Fixtures.ImportTypes.SchemaWithFunctionEvaluationImports.test_function("red") diff --git a/test/support/function_evaluation_helpers.ex b/test/support/function_evaluation_helpers.ex index 31cc488724..24609fa253 100644 --- a/test/support/function_evaluation_helpers.ex +++ b/test/support/function_evaluation_helpers.ex @@ -3,7 +3,7 @@ defmodule Absinthe.FunctionEvaluationHelpers do [ %{test_label: :normal_string, expected_value: "string"}, %{test_label: :local_function_call, expected_value: "red"}, - %{test_label: :function_call_using_absolute_path, expected_value: "red"}, + %{test_label: :function_call_using_absolute_path_to_current_module, expected_value: "red"}, %{test_label: :standard_library_function, expected_value: "rad"}, %{test_label: :function_in_nested_module, expected_value: "hello"}, %{test_label: :external_module_function_call, expected_value: "the value is hello"}, From 1c8ac8777505d9f9055f6fc79a17dd525958bcb4 Mon Sep 17 00:00:00 2001 From: Dylan Chong Date: Tue, 22 Dec 2020 10:45:52 +1300 Subject: [PATCH 38/50] Move stuff into fixtures --- test/absinthe/type/enum_test.exs | 16 ++++++------- test/absinthe/type/import_types_test.exs | 2 +- test/absinthe/type/input_object_test.exs | 24 +++++++++---------- test/absinthe/type/mutation_test.exs | 4 ++-- test/absinthe/type/query_test.exs | 4 ++-- .../function_evaluation_helpers.ex | 2 +- test/support/fixtures/import_types.ex | 2 +- 7 files changed, 27 insertions(+), 27 deletions(-) rename test/support/{ => fixtures}/function_evaluation_helpers.ex (93%) diff --git a/test/absinthe/type/enum_test.exs b/test/absinthe/type/enum_test.exs index 63674b45c7..2814b35fde 100644 --- a/test/absinthe/type/enum_test.exs +++ b/test/absinthe/type/enum_test.exs @@ -79,7 +79,7 @@ defmodule Absinthe.Type.EnumTest do value :function_in_nested_module, description: NestedModule.nested_function("hello") value :external_module_function_call, - description: Absinthe.FunctionEvaluationHelpers.external_function("hello") + description: Absinthe.Fixtures.FunctionEvaluationHelpers.external_function("hello") value :module_attribute_string_concat, description: "hello " <> @module_attribute value :interpolation_of_module_attribute, description: "hello #{@module_attribute}" @@ -116,7 +116,7 @@ defmodule Absinthe.Type.EnumTest do end enum :external_module_function_call, - description: Absinthe.FunctionEvaluationHelpers.external_function("hello") do + description: Absinthe.Fixtures.FunctionEvaluationHelpers.external_function("hello") do end enum :module_attribute_string_concat, description: "hello " <> @module_attribute do @@ -171,7 +171,7 @@ defmodule Absinthe.Type.EnumTest do enum :function_in_nested_module do end - @desc Absinthe.FunctionEvaluationHelpers.external_function("hello") + @desc Absinthe.Fixtures.FunctionEvaluationHelpers.external_function("hello") enum :external_module_function_call do end @@ -222,7 +222,7 @@ defmodule Absinthe.Type.EnumTest do end enum :external_module_function_call do - description Absinthe.FunctionEvaluationHelpers.external_function("hello") + description Absinthe.Fixtures.FunctionEvaluationHelpers.external_function("hello") end enum :module_attribute_string_concat do @@ -257,7 +257,7 @@ defmodule Absinthe.Type.EnumTest do end describe "enum value description evaluation" do - Absinthe.FunctionEvaluationHelpers.function_evaluation_test_params() + Absinthe.Fixtures.FunctionEvaluationHelpers.function_evaluation_test_params() |> Enum.each(fn %{ test_label: test_label, expected_value: expected_value @@ -272,7 +272,7 @@ defmodule Absinthe.Type.EnumTest do end describe "enum description keyword evaluation" do - Absinthe.FunctionEvaluationHelpers.function_evaluation_test_params() + Absinthe.Fixtures.FunctionEvaluationHelpers.function_evaluation_test_params() |> Enum.each(fn %{ test_label: test_label, expected_value: expected_value @@ -285,7 +285,7 @@ defmodule Absinthe.Type.EnumTest do end describe "enum description attribute evaluation" do - Absinthe.FunctionEvaluationHelpers.function_evaluation_test_params() + Absinthe.Fixtures.FunctionEvaluationHelpers.function_evaluation_test_params() # These tests do not work as test_function is not available at compile time, and the # expression for the @desc attribute is evaluated at compile time. There is nothing we can # really do about it @@ -307,7 +307,7 @@ defmodule Absinthe.Type.EnumTest do end describe "enum description macro evaluation" do - Absinthe.FunctionEvaluationHelpers.function_evaluation_test_params() + Absinthe.Fixtures.FunctionEvaluationHelpers.function_evaluation_test_params() |> Enum.each(fn %{ test_label: test_label, expected_value: expected_value diff --git a/test/absinthe/type/import_types_test.exs b/test/absinthe/type/import_types_test.exs index 648376cac8..89c1095414 100644 --- a/test/absinthe/type/import_types_test.exs +++ b/test/absinthe/type/import_types_test.exs @@ -44,7 +44,7 @@ defmodule Absinthe.Type.ImportTypesTest do # The module attribute iteration of this test is related to the test below. # See "__absinthe_blueprint__ is callable at runtime even if there is a module attribute" for more # information - Absinthe.FunctionEvaluationHelpers.function_evaluation_test_params() + Absinthe.Fixtures.FunctionEvaluationHelpers.function_evaluation_test_params() |> Enum.each(fn %{ test_label: test_label, expected_value: expected_value diff --git a/test/absinthe/type/input_object_test.exs b/test/absinthe/type/input_object_test.exs index 1a8059e053..f673171d82 100644 --- a/test/absinthe/type/input_object_test.exs +++ b/test/absinthe/type/input_object_test.exs @@ -46,7 +46,7 @@ defmodule Absinthe.Type.InputObjectTest do end input_object :external_module_function_call, - description: Absinthe.FunctionEvaluationHelpers.external_function("hello") do + description: Absinthe.Fixtures.FunctionEvaluationHelpers.external_function("hello") do end input_object :module_attribute_string_concat, description: "hello " <> @module_attribute do @@ -101,7 +101,7 @@ defmodule Absinthe.Type.InputObjectTest do input_object :function_in_nested_module do end - @desc Absinthe.FunctionEvaluationHelpers.external_function("hello") + @desc Absinthe.Fixtures.FunctionEvaluationHelpers.external_function("hello") input_object :external_module_function_call do end @@ -154,7 +154,7 @@ defmodule Absinthe.Type.InputObjectTest do end input_object :external_module_function_call do - description Absinthe.FunctionEvaluationHelpers.external_function("hello") + description Absinthe.Fixtures.FunctionEvaluationHelpers.external_function("hello") end input_object :module_attribute_string_concat do @@ -199,7 +199,7 @@ defmodule Absinthe.Type.InputObjectTest do description: NestedModule.nested_function("hello") field :external_module_function_call, :string, - description: Absinthe.FunctionEvaluationHelpers.external_function("hello") + description: Absinthe.Fixtures.FunctionEvaluationHelpers.external_function("hello") field :module_attribute_string_concat, :string, description: "hello " <> @module_attribute field :interpolation_of_module_attribute, :string, description: "hello #{@module_attribute}" @@ -227,7 +227,7 @@ defmodule Absinthe.Type.InputObjectTest do @desc NestedModule.nested_function("hello") field :function_in_nested_module, :string - @desc Absinthe.FunctionEvaluationHelpers.external_function("hello") + @desc Absinthe.Fixtures.FunctionEvaluationHelpers.external_function("hello") field :external_module_function_call, :string @desc "hello " <> @module_attribute @@ -261,7 +261,7 @@ defmodule Absinthe.Type.InputObjectTest do end field :external_module_function_call, :string do - description Absinthe.FunctionEvaluationHelpers.external_function("hello") + description Absinthe.Fixtures.FunctionEvaluationHelpers.external_function("hello") end field :module_attribute_string_concat, :string do @@ -289,7 +289,7 @@ defmodule Absinthe.Type.InputObjectTest do end describe "input object keyword description evaluation" do - Absinthe.FunctionEvaluationHelpers.function_evaluation_test_params() + Absinthe.Fixtures.FunctionEvaluationHelpers.function_evaluation_test_params() |> Enum.each(fn %{ test_label: test_label, expected_value: expected_value @@ -302,7 +302,7 @@ defmodule Absinthe.Type.InputObjectTest do end describe "input_object description attribute evaluation" do - Absinthe.FunctionEvaluationHelpers.function_evaluation_test_params() + Absinthe.Fixtures.FunctionEvaluationHelpers.function_evaluation_test_params() # These tests do not work as test_function is not available at compile time, and the # expression for the @desc attribute is evaluated at compile time. There is nothing we can # really do about it @@ -324,7 +324,7 @@ defmodule Absinthe.Type.InputObjectTest do end describe "input_object description macro evaluation" do - Absinthe.FunctionEvaluationHelpers.function_evaluation_test_params() + Absinthe.Fixtures.FunctionEvaluationHelpers.function_evaluation_test_params() |> Enum.each(fn %{ test_label: test_label, expected_value: expected_value @@ -337,7 +337,7 @@ defmodule Absinthe.Type.InputObjectTest do end describe "input object field keyword description evaluation" do - Absinthe.FunctionEvaluationHelpers.function_evaluation_test_params() + Absinthe.Fixtures.FunctionEvaluationHelpers.function_evaluation_test_params() |> Enum.each(fn %{ test_label: test_label, expected_value: expected_value @@ -354,7 +354,7 @@ defmodule Absinthe.Type.InputObjectTest do end describe "input object field attribute description evaluation" do - Absinthe.FunctionEvaluationHelpers.function_evaluation_test_params() + Absinthe.Fixtures.FunctionEvaluationHelpers.function_evaluation_test_params() # These tests do not work as test_function is not available at compile time, and the # expression for the @desc attribute is evaluated at compile time. There is nothing we can # really do about it @@ -378,7 +378,7 @@ defmodule Absinthe.Type.InputObjectTest do end describe "input object field macro description evaluation" do - Absinthe.FunctionEvaluationHelpers.function_evaluation_test_params() + Absinthe.Fixtures.FunctionEvaluationHelpers.function_evaluation_test_params() |> Enum.each(fn %{ test_label: test_label, expected_value: expected_value diff --git a/test/absinthe/type/mutation_test.exs b/test/absinthe/type/mutation_test.exs index a108069d6d..50e55918af 100644 --- a/test/absinthe/type/mutation_test.exs +++ b/test/absinthe/type/mutation_test.exs @@ -42,7 +42,7 @@ defmodule Absinthe.Type.MutationTest do field :external_module_function_call, :string do arg :arg_example, :string, - description: Absinthe.FunctionEvaluationHelpers.external_function("hello") + description: Absinthe.Fixtures.FunctionEvaluationHelpers.external_function("hello") end field :module_attribute_string_concat, :string do @@ -56,7 +56,7 @@ defmodule Absinthe.Type.MutationTest do end describe "mutation field arg keyword description evaluation" do - Absinthe.FunctionEvaluationHelpers.function_evaluation_test_params() + Absinthe.Fixtures.FunctionEvaluationHelpers.function_evaluation_test_params() |> Enum.each(fn %{ test_label: test_label, expected_value: expected_value diff --git a/test/absinthe/type/query_test.exs b/test/absinthe/type/query_test.exs index ac47ac72aa..adb1798b39 100644 --- a/test/absinthe/type/query_test.exs +++ b/test/absinthe/type/query_test.exs @@ -39,7 +39,7 @@ defmodule Absinthe.Type.QueryTest do field :external_module_function_call, :string do arg :arg_example, :string, - description: Absinthe.FunctionEvaluationHelpers.external_function("hello") + description: Absinthe.Fixtures.FunctionEvaluationHelpers.external_function("hello") end field :module_attribute_string_concat, :string do @@ -53,7 +53,7 @@ defmodule Absinthe.Type.QueryTest do end describe "query field arg keyword description evaluation" do - Absinthe.FunctionEvaluationHelpers.function_evaluation_test_params() + Absinthe.Fixtures.FunctionEvaluationHelpers.function_evaluation_test_params() |> Enum.each(fn %{ test_label: test_label, expected_value: expected_value diff --git a/test/support/function_evaluation_helpers.ex b/test/support/fixtures/function_evaluation_helpers.ex similarity index 93% rename from test/support/function_evaluation_helpers.ex rename to test/support/fixtures/function_evaluation_helpers.ex index 24609fa253..7f5d363ade 100644 --- a/test/support/function_evaluation_helpers.ex +++ b/test/support/fixtures/function_evaluation_helpers.ex @@ -1,4 +1,4 @@ -defmodule Absinthe.FunctionEvaluationHelpers do +defmodule Absinthe.Fixtures.FunctionEvaluationHelpers do def function_evaluation_test_params do [ %{test_label: :normal_string, expected_value: "string"}, diff --git a/test/support/fixtures/import_types.ex b/test/support/fixtures/import_types.ex index 897b2f85ec..5210ba5a3b 100644 --- a/test/support/fixtures/import_types.ex +++ b/test/support/fixtures/import_types.ex @@ -194,7 +194,7 @@ defmodule Absinthe.Fixtures.ImportTypes do description: NestedModule.nested_function("hello") field :external_module_function_call, :string, - description: Absinthe.FunctionEvaluationHelpers.external_function("hello") + description: Absinthe.Fixtures.FunctionEvaluationHelpers.external_function("hello") field :module_attribute_string_concat, :string, description: "hello " <> @module_attribute field :interpolation_of_module_attribute, :string, description: "hello #{@module_attribute}" From 043040d680730a8dd32beac587141322d90e310b Mon Sep 17 00:00:00 2001 From: Dylan Chong Date: Tue, 22 Dec 2020 10:55:16 +1300 Subject: [PATCH 39/50] Fixtures --- test/absinthe/type/enum_test.exs | 193 +--------------- test/absinthe/type/input_object_test.exs | 273 +---------------------- test/support/fixtures/enums.ex | 186 +++++++++++++++ test/support/fixtures/input_object.ex | 260 +++++++++++++++++++++ 4 files changed, 459 insertions(+), 453 deletions(-) create mode 100644 test/support/fixtures/enums.ex create mode 100644 test/support/fixtures/input_object.ex diff --git a/test/absinthe/type/enum_test.exs b/test/absinthe/type/enum_test.exs index 2814b35fde..63c44b7ccf 100644 --- a/test/absinthe/type/enum_test.exs +++ b/test/absinthe/type/enum_test.exs @@ -2,6 +2,7 @@ defmodule Absinthe.Type.EnumTest do use Absinthe.Case, async: true alias Absinthe.Type + alias Absinthe.Fixtures.Enums defmodule TestSchema do use Absinthe.Schema @@ -50,190 +51,6 @@ defmodule Absinthe.Type.EnumTest do end end - defmodule TestSchemaEnumValueDescriptionKeyword do - use Absinthe.Schema - @module_attribute "goodbye" - - defmodule NestedModule do - def nested_function(arg1) do - arg1 - end - end - - query do - end - - def test_function(arg1) do - arg1 - end - - enum :description_keyword_argument do - value :normal_string, description: "string" - value :local_function_call, description: test_function("red") - - value :function_call_using_absolute_path_to_current_module, - description: - Absinthe.Type.EnumTest.TestSchemaEnumValueDescriptionKeyword.test_function("red") - - value :standard_library_function, description: String.replace("red", "e", "a") - value :function_in_nested_module, description: NestedModule.nested_function("hello") - - value :external_module_function_call, - description: Absinthe.Fixtures.FunctionEvaluationHelpers.external_function("hello") - - value :module_attribute_string_concat, description: "hello " <> @module_attribute - value :interpolation_of_module_attribute, description: "hello #{@module_attribute}" - end - end - - defmodule TestSchemaEnumDescriptionKeyword do - use Absinthe.Schema - @module_attribute "goodbye" - - defmodule NestedModule do - def nested_function(arg1) do - arg1 - end - end - - query do - end - - enum :normal_string, description: "string" do - end - - enum :local_function_call, description: test_function("red") do - end - - enum :function_call_using_absolute_path_to_current_module, - description: Absinthe.Type.EnumTest.TestSchemaEnumDescriptionKeyword.test_function("red") do - end - - enum :standard_library_function, description: String.replace("red", "e", "a") do - end - - enum :function_in_nested_module, description: NestedModule.nested_function("hello") do - end - - enum :external_module_function_call, - description: Absinthe.Fixtures.FunctionEvaluationHelpers.external_function("hello") do - end - - enum :module_attribute_string_concat, description: "hello " <> @module_attribute do - end - - enum :interpolation_of_module_attribute, description: "hello #{@module_attribute}" do - end - - def test_function(arg1) do - arg1 - end - end - - defmodule TestSchemaEnumDescriptionAttribute do - use Absinthe.Schema - @module_attribute "goodbye" - - defmodule NestedModule do - def nested_function(arg1) do - arg1 - end - end - - query do - end - - def test_function(arg1) do - arg1 - end - - @desc "string" - enum :normal_string do - end - - # These tests do not work as test_function is not available at compile time, and the - # expression for the @desc attribute is evaluated at compile time. There is nothing we can - # really do about it - - # @desc test_function("red") - # enum :local_function_call do - # end - - # @desc Absinthe.Type.EnumTest.TestSchemaEnumAttribute.test_function("red") - # enum :function_call_using_absolute_path_to_current_module do - # end - - @desc String.replace("red", "e", "a") - enum :standard_library_function do - end - - @desc NestedModule.nested_function("hello") - enum :function_in_nested_module do - end - - @desc Absinthe.Fixtures.FunctionEvaluationHelpers.external_function("hello") - enum :external_module_function_call do - end - - @desc "hello " <> @module_attribute - enum :module_attribute_string_concat do - end - - @desc "hello #{@module_attribute}" - enum :interpolation_of_module_attribute do - end - end - - defmodule TestSchemaEnumDescriptionMacro do - use Absinthe.Schema - @module_attribute "goodbye" - - defmodule NestedModule do - def nested_function(arg1) do - arg1 - end - end - - query do - end - - def test_function(arg1) do - arg1 - end - - enum :normal_string do - description "string" - end - - enum :local_function_call do - description test_function("red") - end - - enum :function_call_using_absolute_path_to_current_module do - description Absinthe.Type.EnumTest.TestSchemaEnumDescriptionMacro.test_function("red") - end - - enum :standard_library_function do - description String.replace("red", "e", "a") - end - - enum :function_in_nested_module do - description NestedModule.nested_function("hello") - end - - enum :external_module_function_call do - description Absinthe.Fixtures.FunctionEvaluationHelpers.external_function("hello") - end - - enum :module_attribute_string_concat do - description "hello " <> @module_attribute - end - - enum :interpolation_of_module_attribute do - description "hello #{@module_attribute}" - end - end - describe "enums" do test "can be defined by a map with defined values" do type = TestSchema.__absinthe_type__(:color_channel) @@ -264,7 +81,7 @@ defmodule Absinthe.Type.EnumTest do } -> test "for #{test_label} (evaluates description to '#{expected_value}')" do type = - TestSchemaEnumValueDescriptionKeyword.__absinthe_type__(:description_keyword_argument) + Enums.TestSchemaEnumValueDescriptionKeyword.__absinthe_type__(:description_keyword_argument) assert type.values[unquote(test_label)].description == unquote(expected_value) end @@ -278,7 +95,7 @@ defmodule Absinthe.Type.EnumTest do expected_value: expected_value } -> test "for #{test_label} (evaluates description to '#{expected_value}')" do - type = TestSchemaEnumDescriptionKeyword.__absinthe_type__(unquote(test_label)) + type = Enums.TestSchemaEnumDescriptionKeyword.__absinthe_type__(unquote(test_label)) assert type.description == unquote(expected_value) end end) @@ -300,7 +117,7 @@ defmodule Absinthe.Type.EnumTest do expected_value: expected_value } -> test "for #{test_label} (evaluates description to '#{expected_value}')" do - type = TestSchemaEnumDescriptionAttribute.__absinthe_type__(unquote(test_label)) + type = Enums.TestSchemaEnumDescriptionAttribute.__absinthe_type__(unquote(test_label)) assert type.description == unquote(expected_value) end end) @@ -313,7 +130,7 @@ defmodule Absinthe.Type.EnumTest do expected_value: expected_value } -> test "for #{test_label} (evaluates description to '#{expected_value}')" do - type = TestSchemaEnumDescriptionMacro.__absinthe_type__(unquote(test_label)) + type = Enums.TestSchemaEnumDescriptionMacro.__absinthe_type__(unquote(test_label)) assert type.description == unquote(expected_value) end end) diff --git a/test/absinthe/type/input_object_test.exs b/test/absinthe/type/input_object_test.exs index f673171d82..4f46869776 100644 --- a/test/absinthe/type/input_object_test.exs +++ b/test/absinthe/type/input_object_test.exs @@ -1,6 +1,8 @@ defmodule Absinthe.Type.InputObjectTest do use Absinthe.Case, async: true + alias Absinthe.Fixtures.InputObject + defmodule Schema do use Absinthe.Schema @@ -15,265 +17,6 @@ defmodule Absinthe.Type.InputObjectTest do end end - defmodule TestSchemaInputObjectDescriptionKeyword do - use Absinthe.Schema - @module_attribute "goodbye" - - defmodule NestedModule do - def nested_function(arg1) do - arg1 - end - end - - query do - end - - input_object :normal_string, description: "string" do - end - - input_object :local_function_call, description: test_function("red") do - end - - input_object :function_call_using_absolute_path_to_current_module, - description: - Absinthe.Type.InputObjectTest.TestSchemaInputObjectDescriptionKeyword.test_function("red") do - end - - input_object :standard_library_function, description: String.replace("red", "e", "a") do - end - - input_object :function_in_nested_module, description: NestedModule.nested_function("hello") do - end - - input_object :external_module_function_call, - description: Absinthe.Fixtures.FunctionEvaluationHelpers.external_function("hello") do - end - - input_object :module_attribute_string_concat, description: "hello " <> @module_attribute do - end - - input_object :interpolation_of_module_attribute, description: "hello #{@module_attribute}" do - end - - def test_function(arg1) do - arg1 - end - end - - defmodule TestSchemaInputObjectDescriptionAttribute do - use Absinthe.Schema - @module_attribute "goodbye" - - defmodule NestedModule do - def nested_function(arg1) do - arg1 - end - end - - query do - end - - def test_function(arg1) do - arg1 - end - - @desc "string" - input_object :normal_string do - end - - # These tests do not work as test_function is not available at compile time, and the - # expression for the @desc attribute is evaluated at compile time. There is nothing we can - # really do about it - - # @desc test_function("red") - # input_object :local_function_call do - # end - - # @desc Absinthe.Type.InputObjectTest.TestSchemaInputObjectAttribute.test_function("red") - # input_object :function_call_using_absolute_path_to_current_module do - # end - - @desc String.replace("red", "e", "a") - input_object :standard_library_function do - end - - @desc NestedModule.nested_function("hello") - input_object :function_in_nested_module do - end - - @desc Absinthe.Fixtures.FunctionEvaluationHelpers.external_function("hello") - input_object :external_module_function_call do - end - - @desc "hello " <> @module_attribute - input_object :module_attribute_string_concat do - end - - @desc "hello #{@module_attribute}" - input_object :interpolation_of_module_attribute do - end - end - - defmodule TestSchemaInputObjectDescriptionMacro do - use Absinthe.Schema - @module_attribute "goodbye" - - defmodule NestedModule do - def nested_function(arg1) do - arg1 - end - end - - query do - end - - def test_function(arg1) do - arg1 - end - - input_object :normal_string do - description "string" - end - - input_object :local_function_call do - description test_function("red") - end - - input_object :function_call_using_absolute_path_to_current_module do - description Absinthe.Type.InputObjectTest.TestSchemaInputObjectDescriptionMacro.test_function( - "red" - ) - end - - input_object :standard_library_function do - description String.replace("red", "e", "a") - end - - input_object :function_in_nested_module do - description NestedModule.nested_function("hello") - end - - input_object :external_module_function_call do - description Absinthe.Fixtures.FunctionEvaluationHelpers.external_function("hello") - end - - input_object :module_attribute_string_concat do - description "hello " <> @module_attribute - end - - input_object :interpolation_of_module_attribute do - description "hello #{@module_attribute}" - end - end - - defmodule TestSchemaInputObjectFieldsAndArgsDescription do - use Absinthe.Schema - @module_attribute "goodbye" - - defmodule NestedModule do - def nested_function(arg1) do - arg1 - end - end - - query do - end - - def test_function(arg1) do - arg1 - end - - input_object :description_keyword_argument do - field :normal_string, :string, description: "string" - field :local_function_call, :string, description: test_function("red") - - field :function_call_using_absolute_path_to_current_module, :string, - description: - Absinthe.Type.InputObjectTest.TestSchemaInputObjectFieldsAndArgsDescription.test_function( - "red" - ) - - field :standard_library_function, :string, description: String.replace("red", "e", "a") - - field :function_in_nested_module, :string, - description: NestedModule.nested_function("hello") - - field :external_module_function_call, :string, - description: Absinthe.Fixtures.FunctionEvaluationHelpers.external_function("hello") - - field :module_attribute_string_concat, :string, description: "hello " <> @module_attribute - field :interpolation_of_module_attribute, :string, description: "hello #{@module_attribute}" - end - - input_object :description_attribute do - @desc "string" - field :normal_string, :string - - # These tests do not work as test_function is not available at compile time, and the - # expression for the @desc attribute is evaluated at compile time. There is nothing we can - # really do about it - - # @desc test_function("red") - # field :local_function_call, :string - - # @desc Absinthe.Type.InputObjectTest.TestSchemaInputObjectFieldsAndArgsDescription.test_function( - # "red" - # ) - # field :function_call_using_absolute_path_to_current_module, :string - - @desc String.replace("red", "e", "a") - field :standard_library_function, :string - - @desc NestedModule.nested_function("hello") - field :function_in_nested_module, :string - - @desc Absinthe.Fixtures.FunctionEvaluationHelpers.external_function("hello") - field :external_module_function_call, :string - - @desc "hello " <> @module_attribute - field :module_attribute_string_concat, :string - - @desc "hello #{@module_attribute}" - field :interpolation_of_module_attribute, :string - end - - input_object :field_description_macro do - field :normal_string, :string do - description "string" - end - - field :local_function_call, :string do - description test_function("red") - end - - field :function_call_using_absolute_path_to_current_module, :string do - description Absinthe.Type.InputObjectTest.TestSchemaInputObjectFieldsAndArgsDescription.test_function( - "red" - ) - end - - field :standard_library_function, :string do - description String.replace("red", "e", "a") - end - - field :function_in_nested_module, :string do - description NestedModule.nested_function("hello") - end - - field :external_module_function_call, :string do - description Absinthe.Fixtures.FunctionEvaluationHelpers.external_function("hello") - end - - field :module_attribute_string_concat, :string do - description "hello " <> @module_attribute - end - - field :interpolation_of_module_attribute, :string do - description "hello #{@module_attribute}" - end - end - end - describe "input object types" do test "can be defined" do assert %Absinthe.Type.InputObject{name: "Profile", description: "A profile"} = @@ -295,7 +38,7 @@ defmodule Absinthe.Type.InputObjectTest do expected_value: expected_value } -> test "for `#{test_label}` (evaluates description to `'#{expected_value}'`)" do - type = TestSchemaInputObjectDescriptionKeyword.__absinthe_type__(unquote(test_label)) + type = InputObject.TestSchemaInputObjectDescriptionKeyword.__absinthe_type__(unquote(test_label)) assert type.description == unquote(expected_value) end end) @@ -317,7 +60,7 @@ defmodule Absinthe.Type.InputObjectTest do expected_value: expected_value } -> test "for #{test_label} (evaluates description to '#{expected_value}')" do - type = TestSchemaInputObjectDescriptionAttribute.__absinthe_type__(unquote(test_label)) + type = InputObject.TestSchemaInputObjectDescriptionAttribute.__absinthe_type__(unquote(test_label)) assert type.description == unquote(expected_value) end end) @@ -330,7 +73,7 @@ defmodule Absinthe.Type.InputObjectTest do expected_value: expected_value } -> test "for #{test_label} (evaluates description to '#{expected_value}')" do - type = TestSchemaInputObjectDescriptionMacro.__absinthe_type__(unquote(test_label)) + type = InputObject.TestSchemaInputObjectDescriptionMacro.__absinthe_type__(unquote(test_label)) assert type.description == unquote(expected_value) end end) @@ -344,7 +87,7 @@ defmodule Absinthe.Type.InputObjectTest do } -> test "for #{test_label} (evaluates description to '#{expected_value}')" do type = - TestSchemaInputObjectFieldsAndArgsDescription.__absinthe_type__( + InputObject.TestSchemaInputObjectFieldsAndArgsDescription.__absinthe_type__( :description_keyword_argument ) @@ -370,7 +113,7 @@ defmodule Absinthe.Type.InputObjectTest do } -> test "for #{test_label} (evaluates description to '#{expected_value}')" do type = - TestSchemaInputObjectFieldsAndArgsDescription.__absinthe_type__(:description_attribute) + InputObject.TestSchemaInputObjectFieldsAndArgsDescription.__absinthe_type__(:description_attribute) assert type.fields[unquote(test_label)].description == unquote(expected_value) end @@ -385,7 +128,7 @@ defmodule Absinthe.Type.InputObjectTest do } -> test "for #{test_label} (evaluates description to '#{expected_value}')" do type = - TestSchemaInputObjectFieldsAndArgsDescription.__absinthe_type__( + InputObject.TestSchemaInputObjectFieldsAndArgsDescription.__absinthe_type__( :field_description_macro ) diff --git a/test/support/fixtures/enums.ex b/test/support/fixtures/enums.ex new file mode 100644 index 0000000000..ed6be97f4c --- /dev/null +++ b/test/support/fixtures/enums.ex @@ -0,0 +1,186 @@ +defmodule Absinthe.Fixtures.Enums do + defmodule TestSchemaEnumValueDescriptionKeyword do + use Absinthe.Schema + @module_attribute "goodbye" + + defmodule NestedModule do + def nested_function(arg1) do + arg1 + end + end + + query do + end + + def test_function(arg1) do + arg1 + end + + enum :description_keyword_argument do + value :normal_string, description: "string" + value :local_function_call, description: test_function("red") + + value :function_call_using_absolute_path_to_current_module, + description: + Absinthe.Fixtures.Enums.TestSchemaEnumValueDescriptionKeyword.test_function("red") + + value :standard_library_function, description: String.replace("red", "e", "a") + value :function_in_nested_module, description: NestedModule.nested_function("hello") + + value :external_module_function_call, + description: Absinthe.Fixtures.FunctionEvaluationHelpers.external_function("hello") + + value :module_attribute_string_concat, description: "hello " <> @module_attribute + value :interpolation_of_module_attribute, description: "hello #{@module_attribute}" + end + end + + defmodule TestSchemaEnumDescriptionKeyword do + use Absinthe.Schema + @module_attribute "goodbye" + + defmodule NestedModule do + def nested_function(arg1) do + arg1 + end + end + + query do + end + + enum :normal_string, description: "string" do + end + + enum :local_function_call, description: test_function("red") do + end + + enum :function_call_using_absolute_path_to_current_module, + description: Absinthe.Fixtures.Enums.TestSchemaEnumDescriptionKeyword.test_function("red") do + end + + enum :standard_library_function, description: String.replace("red", "e", "a") do + end + + enum :function_in_nested_module, description: NestedModule.nested_function("hello") do + end + + enum :external_module_function_call, + description: Absinthe.Fixtures.FunctionEvaluationHelpers.external_function("hello") do + end + + enum :module_attribute_string_concat, description: "hello " <> @module_attribute do + end + + enum :interpolation_of_module_attribute, description: "hello #{@module_attribute}" do + end + + def test_function(arg1) do + arg1 + end + end + + defmodule TestSchemaEnumDescriptionAttribute do + use Absinthe.Schema + @module_attribute "goodbye" + + defmodule NestedModule do + def nested_function(arg1) do + arg1 + end + end + + query do + end + + def test_function(arg1) do + arg1 + end + + @desc "string" + enum :normal_string do + end + + # These tests do not work as test_function is not available at compile time, and the + # expression for the @desc attribute is evaluated at compile time. There is nothing we can + # really do about it + + # @desc test_function("red") + # enum :local_function_call do + # end + + # @desc Absinthe.Fixtures.Enums.TestSchemaEnumAttribute.test_function("red") + # enum :function_call_using_absolute_path_to_current_module do + # end + + @desc String.replace("red", "e", "a") + enum :standard_library_function do + end + + @desc NestedModule.nested_function("hello") + enum :function_in_nested_module do + end + + @desc Absinthe.Fixtures.FunctionEvaluationHelpers.external_function("hello") + enum :external_module_function_call do + end + + @desc "hello " <> @module_attribute + enum :module_attribute_string_concat do + end + + @desc "hello #{@module_attribute}" + enum :interpolation_of_module_attribute do + end + end + + defmodule TestSchemaEnumDescriptionMacro do + use Absinthe.Schema + @module_attribute "goodbye" + + defmodule NestedModule do + def nested_function(arg1) do + arg1 + end + end + + query do + end + + def test_function(arg1) do + arg1 + end + + enum :normal_string do + description "string" + end + + enum :local_function_call do + description test_function("red") + end + + enum :function_call_using_absolute_path_to_current_module do + description Absinthe.Fixtures.Enums.TestSchemaEnumDescriptionMacro.test_function("red") + end + + enum :standard_library_function do + description String.replace("red", "e", "a") + end + + enum :function_in_nested_module do + description NestedModule.nested_function("hello") + end + + enum :external_module_function_call do + description Absinthe.Fixtures.FunctionEvaluationHelpers.external_function("hello") + end + + enum :module_attribute_string_concat do + description "hello " <> @module_attribute + end + + enum :interpolation_of_module_attribute do + description "hello #{@module_attribute}" + end + end + +end diff --git a/test/support/fixtures/input_object.ex b/test/support/fixtures/input_object.ex new file mode 100644 index 0000000000..d796c4c42f --- /dev/null +++ b/test/support/fixtures/input_object.ex @@ -0,0 +1,260 @@ +defmodule Absinthe.Fixtures.InputObject do + defmodule TestSchemaInputObjectDescriptionKeyword do + use Absinthe.Schema + @module_attribute "goodbye" + + defmodule NestedModule do + def nested_function(arg1) do + arg1 + end + end + + query do + end + + input_object :normal_string, description: "string" do + end + + input_object :local_function_call, description: test_function("red") do + end + + input_object :function_call_using_absolute_path_to_current_module, + description: + Absinthe.Fixtures.InputObject.TestSchemaInputObjectDescriptionKeyword.test_function("red") do + end + + input_object :standard_library_function, description: String.replace("red", "e", "a") do + end + + input_object :function_in_nested_module, description: NestedModule.nested_function("hello") do + end + + input_object :external_module_function_call, + description: Absinthe.Fixtures.FunctionEvaluationHelpers.external_function("hello") do + end + + input_object :module_attribute_string_concat, description: "hello " <> @module_attribute do + end + + input_object :interpolation_of_module_attribute, description: "hello #{@module_attribute}" do + end + + def test_function(arg1) do + arg1 + end + end + + defmodule TestSchemaInputObjectDescriptionAttribute do + use Absinthe.Schema + @module_attribute "goodbye" + + defmodule NestedModule do + def nested_function(arg1) do + arg1 + end + end + + query do + end + + def test_function(arg1) do + arg1 + end + + @desc "string" + input_object :normal_string do + end + + # These tests do not work as test_function is not available at compile time, and the + # expression for the @desc attribute is evaluated at compile time. There is nothing we can + # really do about it + + # @desc test_function("red") + # input_object :local_function_call do + # end + + # @desc Absinthe.Fixtures.InputObject.TestSchemaInputObjectAttribute.test_function("red") + # input_object :function_call_using_absolute_path_to_current_module do + # end + + @desc String.replace("red", "e", "a") + input_object :standard_library_function do + end + + @desc NestedModule.nested_function("hello") + input_object :function_in_nested_module do + end + + @desc Absinthe.Fixtures.FunctionEvaluationHelpers.external_function("hello") + input_object :external_module_function_call do + end + + @desc "hello " <> @module_attribute + input_object :module_attribute_string_concat do + end + + @desc "hello #{@module_attribute}" + input_object :interpolation_of_module_attribute do + end + end + + defmodule TestSchemaInputObjectDescriptionMacro do + use Absinthe.Schema + @module_attribute "goodbye" + + defmodule NestedModule do + def nested_function(arg1) do + arg1 + end + end + + query do + end + + def test_function(arg1) do + arg1 + end + + input_object :normal_string do + description "string" + end + + input_object :local_function_call do + description test_function("red") + end + + input_object :function_call_using_absolute_path_to_current_module do + description Absinthe.Fixtures.InputObject.TestSchemaInputObjectDescriptionMacro.test_function( + "red" + ) + end + + input_object :standard_library_function do + description String.replace("red", "e", "a") + end + + input_object :function_in_nested_module do + description NestedModule.nested_function("hello") + end + + input_object :external_module_function_call do + description Absinthe.Fixtures.FunctionEvaluationHelpers.external_function("hello") + end + + input_object :module_attribute_string_concat do + description "hello " <> @module_attribute + end + + input_object :interpolation_of_module_attribute do + description "hello #{@module_attribute}" + end + end + + defmodule TestSchemaInputObjectFieldsAndArgsDescription do + use Absinthe.Schema + @module_attribute "goodbye" + + defmodule NestedModule do + def nested_function(arg1) do + arg1 + end + end + + query do + end + + def test_function(arg1) do + arg1 + end + + input_object :description_keyword_argument do + field :normal_string, :string, description: "string" + field :local_function_call, :string, description: test_function("red") + + field :function_call_using_absolute_path_to_current_module, :string, + description: + Absinthe.Fixtures.InputObject.TestSchemaInputObjectFieldsAndArgsDescription.test_function( + "red" + ) + + field :standard_library_function, :string, description: String.replace("red", "e", "a") + + field :function_in_nested_module, :string, + description: NestedModule.nested_function("hello") + + field :external_module_function_call, :string, + description: Absinthe.Fixtures.FunctionEvaluationHelpers.external_function("hello") + + field :module_attribute_string_concat, :string, description: "hello " <> @module_attribute + field :interpolation_of_module_attribute, :string, description: "hello #{@module_attribute}" + end + + input_object :description_attribute do + @desc "string" + field :normal_string, :string + + # These tests do not work as test_function is not available at compile time, and the + # expression for the @desc attribute is evaluated at compile time. There is nothing we can + # really do about it + + # @desc test_function("red") + # field :local_function_call, :string + + # @desc Absinthe.Fixtures.InputObject.TestSchemaInputObjectFieldsAndArgsDescription.test_function( + # "red" + # ) + # field :function_call_using_absolute_path_to_current_module, :string + + @desc String.replace("red", "e", "a") + field :standard_library_function, :string + + @desc NestedModule.nested_function("hello") + field :function_in_nested_module, :string + + @desc Absinthe.Fixtures.FunctionEvaluationHelpers.external_function("hello") + field :external_module_function_call, :string + + @desc "hello " <> @module_attribute + field :module_attribute_string_concat, :string + + @desc "hello #{@module_attribute}" + field :interpolation_of_module_attribute, :string + end + + input_object :field_description_macro do + field :normal_string, :string do + description "string" + end + + field :local_function_call, :string do + description test_function("red") + end + + field :function_call_using_absolute_path_to_current_module, :string do + description Absinthe.Fixtures.InputObject.TestSchemaInputObjectFieldsAndArgsDescription.test_function( + "red" + ) + end + + field :standard_library_function, :string do + description String.replace("red", "e", "a") + end + + field :function_in_nested_module, :string do + description NestedModule.nested_function("hello") + end + + field :external_module_function_call, :string do + description Absinthe.Fixtures.FunctionEvaluationHelpers.external_function("hello") + end + + field :module_attribute_string_concat, :string do + description "hello " <> @module_attribute + end + + field :interpolation_of_module_attribute, :string do + description "hello #{@module_attribute}" + end + end + end +end From bac3f1b67676f84374aaf3b323850af329ee60cf Mon Sep 17 00:00:00 2001 From: Dylan Chong Date: Tue, 22 Dec 2020 10:58:30 +1300 Subject: [PATCH 40/50] Object test --- test/absinthe/type/object_test.exs | 15 ++++++++++ test/support/fixtures/object.ex | 46 ++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 test/support/fixtures/object.ex diff --git a/test/absinthe/type/object_test.exs b/test/absinthe/type/object_test.exs index 079add7b57..435b78dd3d 100644 --- a/test/absinthe/type/object_test.exs +++ b/test/absinthe/type/object_test.exs @@ -1,6 +1,8 @@ defmodule Absinthe.Type.ObjectTest do use Absinthe.Case, async: true + alias Absinthe.Fixtures.Object + defmodule Schema do use Absinthe.Schema @@ -40,4 +42,17 @@ defmodule Absinthe.Type.ObjectTest do assert %Absinthe.Type.Argument{name: "height", type: :integer} = field.args.height end end + + describe "object keyword description evaluation" do + Absinthe.Fixtures.FunctionEvaluationHelpers.function_evaluation_test_params() + |> Enum.each(fn %{ + test_label: test_label, + expected_value: expected_value + } -> + test "for `#{test_label}` (evaluates description to `'#{expected_value}'`)" do + type = Object.TestSchemaDescriptionKeyword.__absinthe_type__(unquote(test_label)) + assert type.description == unquote(expected_value) + end + end) + end end diff --git a/test/support/fixtures/object.ex b/test/support/fixtures/object.ex new file mode 100644 index 0000000000..b3136f72aa --- /dev/null +++ b/test/support/fixtures/object.ex @@ -0,0 +1,46 @@ +defmodule Absinthe.Fixtures.Object do + defmodule TestSchemaDescriptionKeyword do + use Absinthe.Schema + @module_attribute "goodbye" + + defmodule NestedModule do + def nested_function(arg1) do + arg1 + end + end + + query do + end + + input_object :normal_string, description: "string" do + end + + input_object :local_function_call, description: test_function("red") do + end + + input_object :function_call_using_absolute_path_to_current_module, + description: + Absinthe.Fixtures.Object.TestSchemaDescriptionKeyword.test_function("red") do + end + + input_object :standard_library_function, description: String.replace("red", "e", "a") do + end + + input_object :function_in_nested_module, description: NestedModule.nested_function("hello") do + end + + input_object :external_module_function_call, + description: Absinthe.Fixtures.FunctionEvaluationHelpers.external_function("hello") do + end + + input_object :module_attribute_string_concat, description: "hello " <> @module_attribute do + end + + input_object :interpolation_of_module_attribute, description: "hello #{@module_attribute}" do + end + + def test_function(arg1) do + arg1 + end + end +end From 4baef8f6518fbc5d97e289dedd895f571b06cb0a Mon Sep 17 00:00:00 2001 From: Dylan Chong Date: Tue, 22 Dec 2020 11:02:23 +1300 Subject: [PATCH 41/50] Shorten fixtures names --- test/absinthe/type/enum_test.exs | 8 ++++---- test/absinthe/type/input_object_test.exs | 12 ++++++------ test/support/fixtures/enums.ex | 15 +++++++------- test/support/fixtures/input_object.ex | 25 ++++++++++-------------- test/support/fixtures/object.ex | 3 +-- 5 files changed, 28 insertions(+), 35 deletions(-) diff --git a/test/absinthe/type/enum_test.exs b/test/absinthe/type/enum_test.exs index 63c44b7ccf..326521a4ab 100644 --- a/test/absinthe/type/enum_test.exs +++ b/test/absinthe/type/enum_test.exs @@ -81,7 +81,7 @@ defmodule Absinthe.Type.EnumTest do } -> test "for #{test_label} (evaluates description to '#{expected_value}')" do type = - Enums.TestSchemaEnumValueDescriptionKeyword.__absinthe_type__(:description_keyword_argument) + Enums.TestSchemaValueDescriptionKeyword.__absinthe_type__(:description_keyword_argument) assert type.values[unquote(test_label)].description == unquote(expected_value) end @@ -95,7 +95,7 @@ defmodule Absinthe.Type.EnumTest do expected_value: expected_value } -> test "for #{test_label} (evaluates description to '#{expected_value}')" do - type = Enums.TestSchemaEnumDescriptionKeyword.__absinthe_type__(unquote(test_label)) + type = Enums.TestSchemaDescriptionKeyword.__absinthe_type__(unquote(test_label)) assert type.description == unquote(expected_value) end end) @@ -117,7 +117,7 @@ defmodule Absinthe.Type.EnumTest do expected_value: expected_value } -> test "for #{test_label} (evaluates description to '#{expected_value}')" do - type = Enums.TestSchemaEnumDescriptionAttribute.__absinthe_type__(unquote(test_label)) + type = Enums.TestSchemaDescriptionAttribute.__absinthe_type__(unquote(test_label)) assert type.description == unquote(expected_value) end end) @@ -130,7 +130,7 @@ defmodule Absinthe.Type.EnumTest do expected_value: expected_value } -> test "for #{test_label} (evaluates description to '#{expected_value}')" do - type = Enums.TestSchemaEnumDescriptionMacro.__absinthe_type__(unquote(test_label)) + type = Enums.TestSchemaDescriptionMacro.__absinthe_type__(unquote(test_label)) assert type.description == unquote(expected_value) end end) diff --git a/test/absinthe/type/input_object_test.exs b/test/absinthe/type/input_object_test.exs index 4f46869776..d7e6e8bdcd 100644 --- a/test/absinthe/type/input_object_test.exs +++ b/test/absinthe/type/input_object_test.exs @@ -38,7 +38,7 @@ defmodule Absinthe.Type.InputObjectTest do expected_value: expected_value } -> test "for `#{test_label}` (evaluates description to `'#{expected_value}'`)" do - type = InputObject.TestSchemaInputObjectDescriptionKeyword.__absinthe_type__(unquote(test_label)) + type = InputObject.TestSchemaDescriptionKeyword.__absinthe_type__(unquote(test_label)) assert type.description == unquote(expected_value) end end) @@ -60,7 +60,7 @@ defmodule Absinthe.Type.InputObjectTest do expected_value: expected_value } -> test "for #{test_label} (evaluates description to '#{expected_value}')" do - type = InputObject.TestSchemaInputObjectDescriptionAttribute.__absinthe_type__(unquote(test_label)) + type = InputObject.TestSchemaDescriptionAttribute.__absinthe_type__(unquote(test_label)) assert type.description == unquote(expected_value) end end) @@ -73,7 +73,7 @@ defmodule Absinthe.Type.InputObjectTest do expected_value: expected_value } -> test "for #{test_label} (evaluates description to '#{expected_value}')" do - type = InputObject.TestSchemaInputObjectDescriptionMacro.__absinthe_type__(unquote(test_label)) + type = InputObject.TestSchemaDescriptionMacro.__absinthe_type__(unquote(test_label)) assert type.description == unquote(expected_value) end end) @@ -87,7 +87,7 @@ defmodule Absinthe.Type.InputObjectTest do } -> test "for #{test_label} (evaluates description to '#{expected_value}')" do type = - InputObject.TestSchemaInputObjectFieldsAndArgsDescription.__absinthe_type__( + InputObject.TestSchemaFieldsAndArgsDescription.__absinthe_type__( :description_keyword_argument ) @@ -113,7 +113,7 @@ defmodule Absinthe.Type.InputObjectTest do } -> test "for #{test_label} (evaluates description to '#{expected_value}')" do type = - InputObject.TestSchemaInputObjectFieldsAndArgsDescription.__absinthe_type__(:description_attribute) + InputObject.TestSchemaFieldsAndArgsDescription.__absinthe_type__(:description_attribute) assert type.fields[unquote(test_label)].description == unquote(expected_value) end @@ -128,7 +128,7 @@ defmodule Absinthe.Type.InputObjectTest do } -> test "for #{test_label} (evaluates description to '#{expected_value}')" do type = - InputObject.TestSchemaInputObjectFieldsAndArgsDescription.__absinthe_type__( + InputObject.TestSchemaFieldsAndArgsDescription.__absinthe_type__( :field_description_macro ) diff --git a/test/support/fixtures/enums.ex b/test/support/fixtures/enums.ex index ed6be97f4c..d4d3083624 100644 --- a/test/support/fixtures/enums.ex +++ b/test/support/fixtures/enums.ex @@ -1,5 +1,5 @@ defmodule Absinthe.Fixtures.Enums do - defmodule TestSchemaEnumValueDescriptionKeyword do + defmodule TestSchemaValueDescriptionKeyword do use Absinthe.Schema @module_attribute "goodbye" @@ -22,7 +22,7 @@ defmodule Absinthe.Fixtures.Enums do value :function_call_using_absolute_path_to_current_module, description: - Absinthe.Fixtures.Enums.TestSchemaEnumValueDescriptionKeyword.test_function("red") + Absinthe.Fixtures.Enums.TestSchemaValueDescriptionKeyword.test_function("red") value :standard_library_function, description: String.replace("red", "e", "a") value :function_in_nested_module, description: NestedModule.nested_function("hello") @@ -35,7 +35,7 @@ defmodule Absinthe.Fixtures.Enums do end end - defmodule TestSchemaEnumDescriptionKeyword do + defmodule TestSchemaDescriptionKeyword do use Absinthe.Schema @module_attribute "goodbye" @@ -55,7 +55,7 @@ defmodule Absinthe.Fixtures.Enums do end enum :function_call_using_absolute_path_to_current_module, - description: Absinthe.Fixtures.Enums.TestSchemaEnumDescriptionKeyword.test_function("red") do + description: Absinthe.Fixtures.Enums.TestSchemaDescriptionKeyword.test_function("red") do end enum :standard_library_function, description: String.replace("red", "e", "a") do @@ -79,7 +79,7 @@ defmodule Absinthe.Fixtures.Enums do end end - defmodule TestSchemaEnumDescriptionAttribute do + defmodule TestSchemaDescriptionAttribute do use Absinthe.Schema @module_attribute "goodbye" @@ -133,7 +133,7 @@ defmodule Absinthe.Fixtures.Enums do end end - defmodule TestSchemaEnumDescriptionMacro do + defmodule TestSchemaDescriptionMacro do use Absinthe.Schema @module_attribute "goodbye" @@ -159,7 +159,7 @@ defmodule Absinthe.Fixtures.Enums do end enum :function_call_using_absolute_path_to_current_module do - description Absinthe.Fixtures.Enums.TestSchemaEnumDescriptionMacro.test_function("red") + description Absinthe.Fixtures.Enums.TestSchemaDescriptionMacro.test_function("red") end enum :standard_library_function do @@ -182,5 +182,4 @@ defmodule Absinthe.Fixtures.Enums do description "hello #{@module_attribute}" end end - end diff --git a/test/support/fixtures/input_object.ex b/test/support/fixtures/input_object.ex index d796c4c42f..9267a3cd04 100644 --- a/test/support/fixtures/input_object.ex +++ b/test/support/fixtures/input_object.ex @@ -1,5 +1,5 @@ defmodule Absinthe.Fixtures.InputObject do - defmodule TestSchemaInputObjectDescriptionKeyword do + defmodule TestSchemaDescriptionKeyword do use Absinthe.Schema @module_attribute "goodbye" @@ -19,8 +19,7 @@ defmodule Absinthe.Fixtures.InputObject do end input_object :function_call_using_absolute_path_to_current_module, - description: - Absinthe.Fixtures.InputObject.TestSchemaInputObjectDescriptionKeyword.test_function("red") do + description: Absinthe.Fixtures.InputObject.TestSchemaDescriptionKeyword.test_function("red") do end input_object :standard_library_function, description: String.replace("red", "e", "a") do @@ -44,7 +43,7 @@ defmodule Absinthe.Fixtures.InputObject do end end - defmodule TestSchemaInputObjectDescriptionAttribute do + defmodule TestSchemaDescriptionAttribute do use Absinthe.Schema @module_attribute "goodbye" @@ -73,7 +72,7 @@ defmodule Absinthe.Fixtures.InputObject do # input_object :local_function_call do # end - # @desc Absinthe.Fixtures.InputObject.TestSchemaInputObjectAttribute.test_function("red") + # @desc Absinthe.Fixtures.InputObject.TestSchemaAttribute.test_function("red") # input_object :function_call_using_absolute_path_to_current_module do # end @@ -98,7 +97,7 @@ defmodule Absinthe.Fixtures.InputObject do end end - defmodule TestSchemaInputObjectDescriptionMacro do + defmodule TestSchemaDescriptionMacro do use Absinthe.Schema @module_attribute "goodbye" @@ -124,9 +123,7 @@ defmodule Absinthe.Fixtures.InputObject do end input_object :function_call_using_absolute_path_to_current_module do - description Absinthe.Fixtures.InputObject.TestSchemaInputObjectDescriptionMacro.test_function( - "red" - ) + description Absinthe.Fixtures.InputObject.TestSchemaDescriptionMacro.test_function("red") end input_object :standard_library_function do @@ -150,7 +147,7 @@ defmodule Absinthe.Fixtures.InputObject do end end - defmodule TestSchemaInputObjectFieldsAndArgsDescription do + defmodule TestSchemaFieldsAndArgsDescription do use Absinthe.Schema @module_attribute "goodbye" @@ -173,9 +170,7 @@ defmodule Absinthe.Fixtures.InputObject do field :function_call_using_absolute_path_to_current_module, :string, description: - Absinthe.Fixtures.InputObject.TestSchemaInputObjectFieldsAndArgsDescription.test_function( - "red" - ) + Absinthe.Fixtures.InputObject.TestSchemaFieldsAndArgsDescription.test_function("red") field :standard_library_function, :string, description: String.replace("red", "e", "a") @@ -200,7 +195,7 @@ defmodule Absinthe.Fixtures.InputObject do # @desc test_function("red") # field :local_function_call, :string - # @desc Absinthe.Fixtures.InputObject.TestSchemaInputObjectFieldsAndArgsDescription.test_function( + # @desc Absinthe.Fixtures.InputObject.TestSchemaFieldsAndArgsDescription.test_function( # "red" # ) # field :function_call_using_absolute_path_to_current_module, :string @@ -231,7 +226,7 @@ defmodule Absinthe.Fixtures.InputObject do end field :function_call_using_absolute_path_to_current_module, :string do - description Absinthe.Fixtures.InputObject.TestSchemaInputObjectFieldsAndArgsDescription.test_function( + description Absinthe.Fixtures.InputObject.TestSchemaFieldsAndArgsDescription.test_function( "red" ) end diff --git a/test/support/fixtures/object.ex b/test/support/fixtures/object.ex index b3136f72aa..2aa6aa5103 100644 --- a/test/support/fixtures/object.ex +++ b/test/support/fixtures/object.ex @@ -19,8 +19,7 @@ defmodule Absinthe.Fixtures.Object do end input_object :function_call_using_absolute_path_to_current_module, - description: - Absinthe.Fixtures.Object.TestSchemaDescriptionKeyword.test_function("red") do + description: Absinthe.Fixtures.Object.TestSchemaDescriptionKeyword.test_function("red") do end input_object :standard_library_function, description: String.replace("red", "e", "a") do From 9780fa0c5207b9e71946ec0bd7c1adc43aaf5e62 Mon Sep 17 00:00:00 2001 From: Dylan Chong Date: Tue, 22 Dec 2020 11:04:40 +1300 Subject: [PATCH 42/50] More object tests --- test/absinthe/type/object_test.exs | 95 +++++++++++- test/support/fixtures/object.ex | 226 ++++++++++++++++++++++++++++- 2 files changed, 312 insertions(+), 9 deletions(-) diff --git a/test/absinthe/type/object_test.exs b/test/absinthe/type/object_test.exs index 435b78dd3d..873faad28b 100644 --- a/test/absinthe/type/object_test.exs +++ b/test/absinthe/type/object_test.exs @@ -43,7 +43,7 @@ defmodule Absinthe.Type.ObjectTest do end end - describe "object keyword description evaluation" do + describe "input object keyword description evaluation" do Absinthe.Fixtures.FunctionEvaluationHelpers.function_evaluation_test_params() |> Enum.each(fn %{ test_label: test_label, @@ -55,4 +55,97 @@ defmodule Absinthe.Type.ObjectTest do end end) end + + describe "input_object description attribute evaluation" do + Absinthe.Fixtures.FunctionEvaluationHelpers.function_evaluation_test_params() + # These tests do not work as test_function is not available at compile time, and the + # expression for the @desc attribute is evaluated at compile time. There is nothing we can + # really do about it + |> Enum.filter(fn %{test_label: test_label} -> + test_label not in [ + :local_function_call, + :function_call_using_absolute_path_to_current_module + ] + end) + |> Enum.each(fn %{ + test_label: test_label, + expected_value: expected_value + } -> + test "for #{test_label} (evaluates description to '#{expected_value}')" do + type = Object.TestSchemaDescriptionAttribute.__absinthe_type__(unquote(test_label)) + assert type.description == unquote(expected_value) + end + end) + end + + describe "input_object description macro evaluation" do + Absinthe.Fixtures.FunctionEvaluationHelpers.function_evaluation_test_params() + |> Enum.each(fn %{ + test_label: test_label, + expected_value: expected_value + } -> + test "for #{test_label} (evaluates description to '#{expected_value}')" do + type = Object.TestSchemaDescriptionMacro.__absinthe_type__(unquote(test_label)) + assert type.description == unquote(expected_value) + end + end) + end + + describe "input object field keyword description evaluation" do + Absinthe.Fixtures.FunctionEvaluationHelpers.function_evaluation_test_params() + |> Enum.each(fn %{ + test_label: test_label, + expected_value: expected_value + } -> + test "for #{test_label} (evaluates description to '#{expected_value}')" do + type = + Object.TestSchemaFieldsAndArgsDescription.__absinthe_type__( + :description_keyword_argument + ) + + assert type.fields[unquote(test_label)].description == unquote(expected_value) + end + end) + end + + describe "input object field attribute description evaluation" do + Absinthe.Fixtures.FunctionEvaluationHelpers.function_evaluation_test_params() + # These tests do not work as test_function is not available at compile time, and the + # expression for the @desc attribute is evaluated at compile time. There is nothing we can + # really do about it + |> Enum.filter(fn %{test_label: test_label} -> + test_label not in [ + :local_function_call, + :function_call_using_absolute_path_to_current_module + ] + end) + |> Enum.each(fn %{ + test_label: test_label, + expected_value: expected_value + } -> + test "for #{test_label} (evaluates description to '#{expected_value}')" do + type = + Object.TestSchemaFieldsAndArgsDescription.__absinthe_type__(:description_attribute) + + assert type.fields[unquote(test_label)].description == unquote(expected_value) + end + end) + end + + describe "input object field macro description evaluation" do + Absinthe.Fixtures.FunctionEvaluationHelpers.function_evaluation_test_params() + |> Enum.each(fn %{ + test_label: test_label, + expected_value: expected_value + } -> + test "for #{test_label} (evaluates description to '#{expected_value}')" do + type = + Object.TestSchemaFieldsAndArgsDescription.__absinthe_type__( + :field_description_macro + ) + + assert type.fields[unquote(test_label)].description == unquote(expected_value) + end + end) + end end diff --git a/test/support/fixtures/object.ex b/test/support/fixtures/object.ex index 2aa6aa5103..bcba7e18f8 100644 --- a/test/support/fixtures/object.ex +++ b/test/support/fixtures/object.ex @@ -12,34 +12,244 @@ defmodule Absinthe.Fixtures.Object do query do end - input_object :normal_string, description: "string" do + object :normal_string, description: "string" do end - input_object :local_function_call, description: test_function("red") do + object :local_function_call, description: test_function("red") do end - input_object :function_call_using_absolute_path_to_current_module, + object :function_call_using_absolute_path_to_current_module, description: Absinthe.Fixtures.Object.TestSchemaDescriptionKeyword.test_function("red") do end - input_object :standard_library_function, description: String.replace("red", "e", "a") do + object :standard_library_function, description: String.replace("red", "e", "a") do end - input_object :function_in_nested_module, description: NestedModule.nested_function("hello") do + object :function_in_nested_module, description: NestedModule.nested_function("hello") do end - input_object :external_module_function_call, + object :external_module_function_call, description: Absinthe.Fixtures.FunctionEvaluationHelpers.external_function("hello") do end - input_object :module_attribute_string_concat, description: "hello " <> @module_attribute do + object :module_attribute_string_concat, description: "hello " <> @module_attribute do end - input_object :interpolation_of_module_attribute, description: "hello #{@module_attribute}" do + object :interpolation_of_module_attribute, description: "hello #{@module_attribute}" do end def test_function(arg1) do arg1 end end + + defmodule TestSchemaDescriptionAttribute do + use Absinthe.Schema + @module_attribute "goodbye" + + defmodule NestedModule do + def nested_function(arg1) do + arg1 + end + end + + query do + end + + def test_function(arg1) do + arg1 + end + + @desc "string" + object :normal_string do + end + + # These tests do not work as test_function is not available at compile time, and the + # expression for the @desc attribute is evaluated at compile time. There is nothing we can + # really do about it + + # @desc test_function("red") + # object :local_function_call do + # end + + # @desc Absinthe.Fixtures.Object.TestSchemaAttribute.test_function("red") + # object :function_call_using_absolute_path_to_current_module do + # end + + @desc String.replace("red", "e", "a") + object :standard_library_function do + end + + @desc NestedModule.nested_function("hello") + object :function_in_nested_module do + end + + @desc Absinthe.Fixtures.FunctionEvaluationHelpers.external_function("hello") + object :external_module_function_call do + end + + @desc "hello " <> @module_attribute + object :module_attribute_string_concat do + end + + @desc "hello #{@module_attribute}" + object :interpolation_of_module_attribute do + end + end + + defmodule TestSchemaDescriptionMacro do + use Absinthe.Schema + @module_attribute "goodbye" + + defmodule NestedModule do + def nested_function(arg1) do + arg1 + end + end + + query do + end + + def test_function(arg1) do + arg1 + end + + object :normal_string do + description "string" + end + + object :local_function_call do + description test_function("red") + end + + object :function_call_using_absolute_path_to_current_module do + description Absinthe.Fixtures.Object.TestSchemaDescriptionMacro.test_function("red") + end + + object :standard_library_function do + description String.replace("red", "e", "a") + end + + object :function_in_nested_module do + description NestedModule.nested_function("hello") + end + + object :external_module_function_call do + description Absinthe.Fixtures.FunctionEvaluationHelpers.external_function("hello") + end + + object :module_attribute_string_concat do + description "hello " <> @module_attribute + end + + object :interpolation_of_module_attribute do + description "hello #{@module_attribute}" + end + end + + defmodule TestSchemaFieldsAndArgsDescription do + use Absinthe.Schema + @module_attribute "goodbye" + + defmodule NestedModule do + def nested_function(arg1) do + arg1 + end + end + + query do + end + + def test_function(arg1) do + arg1 + end + + object :description_keyword_argument do + field :normal_string, :string, description: "string" + field :local_function_call, :string, description: test_function("red") + + field :function_call_using_absolute_path_to_current_module, :string, + description: + Absinthe.Fixtures.Object.TestSchemaFieldsAndArgsDescription.test_function("red") + + field :standard_library_function, :string, description: String.replace("red", "e", "a") + + field :function_in_nested_module, :string, + description: NestedModule.nested_function("hello") + + field :external_module_function_call, :string, + description: Absinthe.Fixtures.FunctionEvaluationHelpers.external_function("hello") + + field :module_attribute_string_concat, :string, description: "hello " <> @module_attribute + field :interpolation_of_module_attribute, :string, description: "hello #{@module_attribute}" + end + + object :description_attribute do + @desc "string" + field :normal_string, :string + + # These tests do not work as test_function is not available at compile time, and the + # expression for the @desc attribute is evaluated at compile time. There is nothing we can + # really do about it + + # @desc test_function("red") + # field :local_function_call, :string + + # @desc Absinthe.Fixtures.Object.TestSchemaFieldsAndArgsDescription.test_function( + # "red" + # ) + # field :function_call_using_absolute_path_to_current_module, :string + + @desc String.replace("red", "e", "a") + field :standard_library_function, :string + + @desc NestedModule.nested_function("hello") + field :function_in_nested_module, :string + + @desc Absinthe.Fixtures.FunctionEvaluationHelpers.external_function("hello") + field :external_module_function_call, :string + + @desc "hello " <> @module_attribute + field :module_attribute_string_concat, :string + + @desc "hello #{@module_attribute}" + field :interpolation_of_module_attribute, :string + end + + object :field_description_macro do + field :normal_string, :string do + description "string" + end + + field :local_function_call, :string do + description test_function("red") + end + + field :function_call_using_absolute_path_to_current_module, :string do + description Absinthe.Fixtures.Object.TestSchemaFieldsAndArgsDescription.test_function( + "red" + ) + end + + field :standard_library_function, :string do + description String.replace("red", "e", "a") + end + + field :function_in_nested_module, :string do + description NestedModule.nested_function("hello") + end + + field :external_module_function_call, :string do + description Absinthe.Fixtures.FunctionEvaluationHelpers.external_function("hello") + end + + field :module_attribute_string_concat, :string do + description "hello " <> @module_attribute + end + + field :interpolation_of_module_attribute, :string do + description "hello #{@module_attribute}" + end + end + end end From e9403e833da0d10d528f7600279bddd0fb125bee Mon Sep 17 00:00:00 2001 From: Dylan Chong Date: Tue, 22 Dec 2020 11:10:55 +1300 Subject: [PATCH 43/50] Reduce dupe --- test/absinthe/type/enum_test.exs | 10 +--------- test/absinthe/type/input_object_test.exs | 20 ++----------------- test/absinthe/type/object_test.exs | 20 ++----------------- .../fixtures/function_evaluation_helpers.ex | 12 +++++++++++ 4 files changed, 17 insertions(+), 45 deletions(-) diff --git a/test/absinthe/type/enum_test.exs b/test/absinthe/type/enum_test.exs index 326521a4ab..98dc8a0114 100644 --- a/test/absinthe/type/enum_test.exs +++ b/test/absinthe/type/enum_test.exs @@ -103,15 +103,7 @@ defmodule Absinthe.Type.EnumTest do describe "enum description attribute evaluation" do Absinthe.Fixtures.FunctionEvaluationHelpers.function_evaluation_test_params() - # These tests do not work as test_function is not available at compile time, and the - # expression for the @desc attribute is evaluated at compile time. There is nothing we can - # really do about it - |> Enum.filter(fn %{test_label: test_label} -> - test_label not in [ - :local_function_call, - :function_call_using_absolute_path_to_current_module - ] - end) + |> Absinthe.Fixtures.FunctionEvaluationHelpers.filter_test_params_for_description_attribute() |> Enum.each(fn %{ test_label: test_label, expected_value: expected_value diff --git a/test/absinthe/type/input_object_test.exs b/test/absinthe/type/input_object_test.exs index d7e6e8bdcd..481b98efc4 100644 --- a/test/absinthe/type/input_object_test.exs +++ b/test/absinthe/type/input_object_test.exs @@ -46,15 +46,7 @@ defmodule Absinthe.Type.InputObjectTest do describe "input_object description attribute evaluation" do Absinthe.Fixtures.FunctionEvaluationHelpers.function_evaluation_test_params() - # These tests do not work as test_function is not available at compile time, and the - # expression for the @desc attribute is evaluated at compile time. There is nothing we can - # really do about it - |> Enum.filter(fn %{test_label: test_label} -> - test_label not in [ - :local_function_call, - :function_call_using_absolute_path_to_current_module - ] - end) + |> Absinthe.Fixtures.FunctionEvaluationHelpers.filter_test_params_for_description_attribute() |> Enum.each(fn %{ test_label: test_label, expected_value: expected_value @@ -98,15 +90,7 @@ defmodule Absinthe.Type.InputObjectTest do describe "input object field attribute description evaluation" do Absinthe.Fixtures.FunctionEvaluationHelpers.function_evaluation_test_params() - # These tests do not work as test_function is not available at compile time, and the - # expression for the @desc attribute is evaluated at compile time. There is nothing we can - # really do about it - |> Enum.filter(fn %{test_label: test_label} -> - test_label not in [ - :local_function_call, - :function_call_using_absolute_path_to_current_module - ] - end) + |> Absinthe.Fixtures.FunctionEvaluationHelpers.filter_test_params_for_description_attribute() |> Enum.each(fn %{ test_label: test_label, expected_value: expected_value diff --git a/test/absinthe/type/object_test.exs b/test/absinthe/type/object_test.exs index 873faad28b..7ba7408e4c 100644 --- a/test/absinthe/type/object_test.exs +++ b/test/absinthe/type/object_test.exs @@ -58,15 +58,7 @@ defmodule Absinthe.Type.ObjectTest do describe "input_object description attribute evaluation" do Absinthe.Fixtures.FunctionEvaluationHelpers.function_evaluation_test_params() - # These tests do not work as test_function is not available at compile time, and the - # expression for the @desc attribute is evaluated at compile time. There is nothing we can - # really do about it - |> Enum.filter(fn %{test_label: test_label} -> - test_label not in [ - :local_function_call, - :function_call_using_absolute_path_to_current_module - ] - end) + |> Absinthe.Fixtures.FunctionEvaluationHelpers.filter_test_params_for_description_attribute() |> Enum.each(fn %{ test_label: test_label, expected_value: expected_value @@ -110,15 +102,7 @@ defmodule Absinthe.Type.ObjectTest do describe "input object field attribute description evaluation" do Absinthe.Fixtures.FunctionEvaluationHelpers.function_evaluation_test_params() - # These tests do not work as test_function is not available at compile time, and the - # expression for the @desc attribute is evaluated at compile time. There is nothing we can - # really do about it - |> Enum.filter(fn %{test_label: test_label} -> - test_label not in [ - :local_function_call, - :function_call_using_absolute_path_to_current_module - ] - end) + |> Absinthe.Fixtures.FunctionEvaluationHelpers.filter_test_params_for_description_attribute() |> Enum.each(fn %{ test_label: test_label, expected_value: expected_value diff --git a/test/support/fixtures/function_evaluation_helpers.ex b/test/support/fixtures/function_evaluation_helpers.ex index 7f5d363ade..efcdcb0865 100644 --- a/test/support/fixtures/function_evaluation_helpers.ex +++ b/test/support/fixtures/function_evaluation_helpers.ex @@ -12,6 +12,18 @@ defmodule Absinthe.Fixtures.FunctionEvaluationHelpers do ] end + # These tests do not work as test_function is not available at compile time, and the + # expression for the @desc attribute is evaluated at compile time. There is nothing we can + # really do about it + def filter_test_params_for_description_attribute(test_params) do + Enum.filter(test_params, fn %{test_label: test_label} -> + test_label not in [ + :local_function_call, + :function_call_using_absolute_path_to_current_module + ] + end) + end + def external_function(arg) do "the value is #{arg}" end From c8feac5493bf1f067f59cd7ec7653730e709eccb Mon Sep 17 00:00:00 2001 From: Dylan Chong Date: Tue, 22 Dec 2020 11:30:44 +1300 Subject: [PATCH 44/50] Directive tests and fix --- lib/absinthe/schema/notation.ex | 1 + test/absinthe/type/directive_test.exs | 41 ++++++ test/support/fixtures/directive.ex | 171 ++++++++++++++++++++++++++ 3 files changed, 213 insertions(+) create mode 100644 test/support/fixtures/directive.ex diff --git a/lib/absinthe/schema/notation.ex b/lib/absinthe/schema/notation.ex index b29accbd32..b1586b84d8 100644 --- a/lib/absinthe/schema/notation.ex +++ b/lib/absinthe/schema/notation.ex @@ -1332,6 +1332,7 @@ defmodule Absinthe.Schema.Notation do attrs |> Keyword.put(:identifier, identifier) |> Keyword.put_new(:name, to_string(identifier)) + |> Keyword.update(:description, nil, &wrap_in_unquote/1) scoped_def(env, Schema.DirectiveDefinition, identifier, attrs, block) end diff --git a/test/absinthe/type/directive_test.exs b/test/absinthe/type/directive_test.exs index a0b438529d..a5b06cc3d3 100644 --- a/test/absinthe/type/directive_test.exs +++ b/test/absinthe/type/directive_test.exs @@ -2,6 +2,7 @@ defmodule Absinthe.Type.DirectiveTest do use Absinthe.Case, async: true alias Absinthe.Schema + alias Absinthe.Fixtures.Directive defmodule TestSchema do use Absinthe.Schema @@ -224,4 +225,44 @@ defmodule Absinthe.Type.DirectiveTest do Absinthe.run(@query, Absinthe.Fixtures.ContactSchema) end end + + describe "directive keyword description evaluation" do + Absinthe.Fixtures.FunctionEvaluationHelpers.function_evaluation_test_params() + |> Enum.each(fn %{ + test_label: test_label, + expected_value: expected_value + } -> + test "for `#{test_label}` (evaluates description to `'#{expected_value}'`)" do + type = Directive.TestSchemaDescriptionKeyword.__absinthe_directive__(unquote(test_label)) + assert type.description == unquote(expected_value) + end + end) + end + + describe "directive description attribute evaluation" do + Absinthe.Fixtures.FunctionEvaluationHelpers.function_evaluation_test_params() + |> Absinthe.Fixtures.FunctionEvaluationHelpers.filter_test_params_for_description_attribute() + |> Enum.each(fn %{ + test_label: test_label, + expected_value: expected_value + } -> + test "for #{test_label} (evaluates description to '#{expected_value}')" do + type = Directive.TestSchemaDescriptionAttribute.__absinthe_directive__(unquote(test_label)) + assert type.description == unquote(expected_value) + end + end) + end + + describe "directive description macro evaluation" do + Absinthe.Fixtures.FunctionEvaluationHelpers.function_evaluation_test_params() + |> Enum.each(fn %{ + test_label: test_label, + expected_value: expected_value + } -> + test "for #{test_label} (evaluates description to '#{expected_value}')" do + type = Directive.TestSchemaDescriptionMacro.__absinthe_directive__(unquote(test_label)) + assert type.description == unquote(expected_value) + end + end) + end end diff --git a/test/support/fixtures/directive.ex b/test/support/fixtures/directive.ex new file mode 100644 index 0000000000..95740c55f7 --- /dev/null +++ b/test/support/fixtures/directive.ex @@ -0,0 +1,171 @@ +defmodule Absinthe.Fixtures.Directive do + defmodule TestSchemaDescriptionKeyword do + use Absinthe.Schema + @module_attribute "goodbye" + + defmodule NestedModule do + def nested_function(arg1) do + arg1 + end + end + + query do + end + + directive :normal_string, description: "string" do + on [:field] + end + + directive :local_function_call, description: test_function("red") do + on [:field] + end + + directive :function_call_using_absolute_path_to_current_module, description: Absinthe.Fixtures.Directive.TestSchemaDescriptionKeyword.test_function("red") do + on [:field] + end + + directive :standard_library_function, description: String.replace("red", "e", "a") do + on [:field] + end + + directive :function_in_nested_module, description: NestedModule.nested_function("hello") do + on [:field] + end + + directive :external_module_function_call, description: Absinthe.Fixtures.FunctionEvaluationHelpers.external_function("hello") do + on [:field] + end + + directive :module_attribute_string_concat, description: "hello " <> @module_attribute do + on [:field] + end + + directive :interpolation_of_module_attribute, description: "hello #{@module_attribute}" do + on [:field] + end + + def test_function(arg1) do + arg1 + end + end + + defmodule TestSchemaDescriptionAttribute do + use Absinthe.Schema + @module_attribute "goodbye" + + defmodule NestedModule do + def nested_function(arg1) do + arg1 + end + end + + query do + end + + def test_function(arg1) do + arg1 + end + + @desc "string" + directive :normal_string do + on [:field] + end + + # These tests do not work as test_function is not available at compile time, and the + # expression for the @desc attribute is evaluated at compile time. There is nothing we can + # really do about it + + # @desc test_function("red") + # directive :local_function_call do + # on [:field] + # end + + # @desc Absinthe.Fixtures.Directive.TestSchemaEnumAttribute.test_function("red") + # directive :function_call_using_absolute_path_to_current_module do + # on [:field] + # end + + @desc String.replace("red", "e", "a") + directive :standard_library_function do + on [:field] + end + + @desc NestedModule.nested_function("hello") + directive :function_in_nested_module do + on [:field] + end + + @desc Absinthe.Fixtures.FunctionEvaluationHelpers.external_function("hello") + directive :external_module_function_call do + on [:field] + end + + @desc "hello " <> @module_attribute + directive :module_attribute_string_concat do + on [:field] + end + + @desc "hello #{@module_attribute}" + directive :interpolation_of_module_attribute do + on [:field] + end + end + + defmodule TestSchemaDescriptionMacro do + use Absinthe.Schema + @module_attribute "goodbye" + + defmodule NestedModule do + def nested_function(arg1) do + arg1 + end + end + + query do + end + + def test_function(arg1) do + arg1 + end + + directive :normal_string do + on [:field] + description "string" + end + + directive :local_function_call do + on [:field] + description test_function("red") + end + + directive :function_call_using_absolute_path_to_current_module do + on [:field] + description Absinthe.Fixtures.Directive.TestSchemaDescriptionMacro.test_function("red") + end + + directive :standard_library_function do + on [:field] + description String.replace("red", "e", "a") + end + + directive :function_in_nested_module do + on [:field] + description NestedModule.nested_function("hello") + end + + directive :external_module_function_call do + on [:field] + description Absinthe.Fixtures.FunctionEvaluationHelpers.external_function("hello") + end + + directive :module_attribute_string_concat do + on [:field] + description "hello " <> @module_attribute + end + + directive :interpolation_of_module_attribute do + on [:field] + description "hello #{@module_attribute}" + end + end +end From a235e4384a9d24b1cfeebd96b12336346595245c Mon Sep 17 00:00:00 2001 From: Dylan Chong Date: Tue, 22 Dec 2020 11:42:40 +1300 Subject: [PATCH 45/50] Directive arg test --- test/absinthe/type/directive_test.exs | 19 +++++++- test/absinthe/type/object_test.exs | 7 +-- test/support/fixtures/directive.ex | 68 ++++++++++++++++++++++++++- 3 files changed, 86 insertions(+), 8 deletions(-) diff --git a/test/absinthe/type/directive_test.exs b/test/absinthe/type/directive_test.exs index a5b06cc3d3..cba306ffe1 100644 --- a/test/absinthe/type/directive_test.exs +++ b/test/absinthe/type/directive_test.exs @@ -247,7 +247,9 @@ defmodule Absinthe.Type.DirectiveTest do expected_value: expected_value } -> test "for #{test_label} (evaluates description to '#{expected_value}')" do - type = Directive.TestSchemaDescriptionAttribute.__absinthe_directive__(unquote(test_label)) + type = + Directive.TestSchemaDescriptionAttribute.__absinthe_directive__(unquote(test_label)) + assert type.description == unquote(expected_value) end end) @@ -265,4 +267,19 @@ defmodule Absinthe.Type.DirectiveTest do end end) end + + describe "directive arg keyword description evaluation" do + Absinthe.Fixtures.FunctionEvaluationHelpers.function_evaluation_test_params() + |> Enum.each(fn %{ + test_label: test_label, + expected_value: expected_value + } -> + test "for `#{test_label}` (evaluates description to `'#{expected_value}'`)" do + type = + Directive.TestSchemaArgDescriptionKeyword.__absinthe_directive__(unquote(test_label)) + + assert type.args[:arg_example].description == unquote(expected_value) + end + end) + end end diff --git a/test/absinthe/type/object_test.exs b/test/absinthe/type/object_test.exs index 7ba7408e4c..f58ccdd28b 100644 --- a/test/absinthe/type/object_test.exs +++ b/test/absinthe/type/object_test.exs @@ -108,8 +108,7 @@ defmodule Absinthe.Type.ObjectTest do expected_value: expected_value } -> test "for #{test_label} (evaluates description to '#{expected_value}')" do - type = - Object.TestSchemaFieldsAndArgsDescription.__absinthe_type__(:description_attribute) + type = Object.TestSchemaFieldsAndArgsDescription.__absinthe_type__(:description_attribute) assert type.fields[unquote(test_label)].description == unquote(expected_value) end @@ -124,9 +123,7 @@ defmodule Absinthe.Type.ObjectTest do } -> test "for #{test_label} (evaluates description to '#{expected_value}')" do type = - Object.TestSchemaFieldsAndArgsDescription.__absinthe_type__( - :field_description_macro - ) + Object.TestSchemaFieldsAndArgsDescription.__absinthe_type__(:field_description_macro) assert type.fields[unquote(test_label)].description == unquote(expected_value) end diff --git a/test/support/fixtures/directive.ex b/test/support/fixtures/directive.ex index 95740c55f7..911b631738 100644 --- a/test/support/fixtures/directive.ex +++ b/test/support/fixtures/directive.ex @@ -20,7 +20,8 @@ defmodule Absinthe.Fixtures.Directive do on [:field] end - directive :function_call_using_absolute_path_to_current_module, description: Absinthe.Fixtures.Directive.TestSchemaDescriptionKeyword.test_function("red") do + directive :function_call_using_absolute_path_to_current_module, + description: Absinthe.Fixtures.Directive.TestSchemaDescriptionKeyword.test_function("red") do on [:field] end @@ -32,7 +33,8 @@ defmodule Absinthe.Fixtures.Directive do on [:field] end - directive :external_module_function_call, description: Absinthe.Fixtures.FunctionEvaluationHelpers.external_function("hello") do + directive :external_module_function_call, + description: Absinthe.Fixtures.FunctionEvaluationHelpers.external_function("hello") do on [:field] end @@ -168,4 +170,66 @@ defmodule Absinthe.Fixtures.Directive do description "hello #{@module_attribute}" end end + + defmodule TestSchemaArgDescriptionKeyword do + use Absinthe.Schema + @module_attribute "goodbye" + + defmodule NestedModule do + def nested_function(arg1) do + arg1 + end + end + + query do + end + + directive :normal_string do + arg :arg_example, :string, description: "string" + on [:field] + end + + directive :local_function_call do + arg :arg_example, :string, description: test_function("red") + on [:field] + end + + directive :function_call_using_absolute_path_to_current_module do + arg :arg_example, :string, + description: Absinthe.Fixtures.Directive.TestSchemaDescriptionKeyword.test_function("red") + + on [:field] + end + + directive :standard_library_function do + arg :arg_example, :string, description: String.replace("red", "e", "a") + on [:field] + end + + directive :function_in_nested_module do + arg :arg_example, :string, description: NestedModule.nested_function("hello") + on [:field] + end + + directive :external_module_function_call do + arg :arg_example, :string, + description: Absinthe.Fixtures.FunctionEvaluationHelpers.external_function("hello") + + on [:field] + end + + directive :module_attribute_string_concat do + arg :arg_example, :string, description: "hello " <> @module_attribute + on [:field] + end + + directive :interpolation_of_module_attribute do + arg :arg_example, :string, description: "hello #{@module_attribute}" + on [:field] + end + + def test_function(arg1) do + arg1 + end + end end From 93c21a6485b5a2b7fb8655124556ece266c8e31d Mon Sep 17 00:00:00 2001 From: Dylan Chong Date: Tue, 22 Dec 2020 13:15:49 +1300 Subject: [PATCH 46/50] Scalar description --- lib/absinthe/schema/notation.ex | 18 +- .../execution/arguments/scalar_test.exs | 43 ++++ test/support/fixtures/scalar.ex | 200 ++++++++++++++++++ 3 files changed, 258 insertions(+), 3 deletions(-) create mode 100644 test/support/fixtures/scalar.ex diff --git a/lib/absinthe/schema/notation.ex b/lib/absinthe/schema/notation.ex index b1586b84d8..bfcfc366f9 100644 --- a/lib/absinthe/schema/notation.ex +++ b/lib/absinthe/schema/notation.ex @@ -725,7 +725,7 @@ defmodule Absinthe.Schema.Notation do defmacro scalar(identifier, attrs, do: block) do __CALLER__ |> recordable!(:scalar, @placement[:scalar]) - |> record!(Schema.ScalarTypeDefinition, identifier, attrs, block) + |> record_scalar!(identifier, attrs, block) end @doc """ @@ -736,13 +736,13 @@ defmodule Absinthe.Schema.Notation do defmacro scalar(identifier, do: block) do __CALLER__ |> recordable!(:scalar, @placement[:scalar]) - |> record!(Schema.ScalarTypeDefinition, identifier, [], block) + |> record_scalar!(identifier, [], block) end defmacro scalar(identifier, attrs) do __CALLER__ |> recordable!(:scalar, @placement[:scalar]) - |> record!(Schema.ScalarTypeDefinition, identifier, attrs, nil) + |> record_scalar!(identifier, attrs, nil) end @placement {:serialize, [under: [:scalar]]} @@ -1423,6 +1423,18 @@ defmodule Absinthe.Schema.Notation do put_attr(env.module, {:desc, text}) end + @doc false + # Record a scalar + def record_scalar!(env, identifier, attrs, block_or_nil) do + record!( + env, + Schema.ScalarTypeDefinition, + identifier, + attrs |> Keyword.update(:description, nil, &wrap_in_unquote/1), + block_or_nil + ) + end + def handle_enum_value_attrs(identifier, raw_attrs, env) do value = case Keyword.get(raw_attrs, :as, identifier) do diff --git a/test/absinthe/execution/arguments/scalar_test.exs b/test/absinthe/execution/arguments/scalar_test.exs index 384551d489..606a023e07 100644 --- a/test/absinthe/execution/arguments/scalar_test.exs +++ b/test/absinthe/execution/arguments/scalar_test.exs @@ -1,6 +1,8 @@ defmodule Absinthe.Execution.Arguments.ScalarTest do use Absinthe.Case, async: true + alias Absinthe.Blueprint.Input + alias Absinthe.Fixtures.Scalar @schema Absinthe.Fixtures.ArgumentsSchema @@ -58,4 +60,45 @@ defmodule Absinthe.Execution.Arguments.ScalarTest do ) end end + + describe "scalar keyword description evaluation" do + Absinthe.Fixtures.FunctionEvaluationHelpers.function_evaluation_test_params() + |> Enum.each(fn %{ + test_label: test_label, + expected_value: expected_value + } -> + test "for `#{test_label}` (evaluates description to `'#{expected_value}'`)" do + type = Scalar.TestSchemaDescriptionKeyword.__absinthe_type__(unquote(test_label)) + assert type.description == unquote(expected_value) + end + end) + end + + describe "scalar description attribute evaluation" do + Absinthe.Fixtures.FunctionEvaluationHelpers.function_evaluation_test_params() + |> Absinthe.Fixtures.FunctionEvaluationHelpers.filter_test_params_for_description_attribute() + |> Enum.each(fn %{ + test_label: test_label, + expected_value: expected_value + } -> + test "for #{test_label} (evaluates description to '#{expected_value}')" do + type = Scalar.TestSchemaDescriptionAttribute.__absinthe_type__(unquote(test_label)) + + assert type.description == unquote(expected_value) + end + end) + end + + describe "scalar description macro evaluation" do + Absinthe.Fixtures.FunctionEvaluationHelpers.function_evaluation_test_params() + |> Enum.each(fn %{ + test_label: test_label, + expected_value: expected_value + } -> + test "for #{test_label} (evaluates description to '#{expected_value}')" do + type = Scalar.TestSchemaDescriptionMacro.__absinthe_type__(unquote(test_label)) + assert type.description == unquote(expected_value) + end + end) + end end diff --git a/test/support/fixtures/scalar.ex b/test/support/fixtures/scalar.ex new file mode 100644 index 0000000000..549543f494 --- /dev/null +++ b/test/support/fixtures/scalar.ex @@ -0,0 +1,200 @@ +defmodule Absinthe.Fixtures.Scalar do + defmodule Utils do + def parse(value), do: value + def serialize(value), do: value + end + + defmodule TestSchemaDescriptionKeyword do + use Absinthe.Schema + @module_attribute "goodbye" + + defmodule NestedModule do + def nested_function(arg1) do + arg1 + end + end + + query do + end + + scalar :normal_string, description: "string" do + parse &Utils.parse/1 + serialize &Utils.serialize/1 + end + + scalar :local_function_call, description: test_function("red") do + parse &Utils.parse/1 + serialize &Utils.serialize/1 + end + + scalar :function_call_using_absolute_path_to_current_module, + description: Absinthe.Fixtures.Scalar.TestSchemaDescriptionKeyword.test_function("red") do + parse &Utils.parse/1 + serialize &Utils.serialize/1 + end + + scalar :standard_library_function, description: String.replace("red", "e", "a") do + parse &Utils.parse/1 + serialize &Utils.serialize/1 + end + + scalar :function_in_nested_module, description: NestedModule.nested_function("hello") do + parse &Utils.parse/1 + serialize &Utils.serialize/1 + end + + scalar :external_module_function_call, + description: Absinthe.Fixtures.FunctionEvaluationHelpers.external_function("hello") do + parse &Utils.parse/1 + serialize &Utils.serialize/1 + end + + scalar :module_attribute_string_concat, description: "hello " <> @module_attribute do + parse &Utils.parse/1 + serialize &Utils.serialize/1 + end + + scalar :interpolation_of_module_attribute, description: "hello #{@module_attribute}" do + parse &Utils.parse/1 + serialize &Utils.serialize/1 + end + + def test_function(arg1) do + arg1 + end + end + + defmodule TestSchemaDescriptionAttribute do + use Absinthe.Schema + @module_attribute "goodbye" + + defmodule NestedModule do + def nested_function(arg1) do + arg1 + end + end + + query do + end + + def test_function(arg1) do + arg1 + end + + @desc "string" + scalar :normal_string do + parse &Utils.parse/1 + serialize &Utils.serialize/1 + end + + # These tests do not work as test_function is not available at compile time, and the + # expression for the @desc attribute is evaluated at compile time. There is nothing we can + # really do about it + + # @desc test_function("red") + # scalar :local_function_call do + + # end + + # @desc Absinthe.Fixtures.Scalar.TestSchemaEnumAttribute.test_function("red") + # scalar :function_call_using_absolute_path_to_current_module do + + # end + + @desc String.replace("red", "e", "a") + scalar :standard_library_function do + parse &Utils.parse/1 + serialize &Utils.serialize/1 + end + + @desc NestedModule.nested_function("hello") + scalar :function_in_nested_module do + parse &Utils.parse/1 + serialize &Utils.serialize/1 + end + + @desc Absinthe.Fixtures.FunctionEvaluationHelpers.external_function("hello") + scalar :external_module_function_call do + parse &Utils.parse/1 + serialize &Utils.serialize/1 + end + + @desc "hello " <> @module_attribute + scalar :module_attribute_string_concat do + parse &Utils.parse/1 + serialize &Utils.serialize/1 + end + + @desc "hello #{@module_attribute}" + scalar :interpolation_of_module_attribute do + parse &Utils.parse/1 + serialize &Utils.serialize/1 + end + end + + defmodule TestSchemaDescriptionMacro do + use Absinthe.Schema + @module_attribute "goodbye" + + defmodule NestedModule do + def nested_function(arg1) do + arg1 + end + end + + query do + end + + def test_function(arg1) do + arg1 + end + + scalar :normal_string do + parse &Utils.parse/1 + serialize &Utils.serialize/1 + description "string" + end + + scalar :local_function_call do + parse &Utils.parse/1 + serialize &Utils.serialize/1 + description test_function("red") + end + + scalar :function_call_using_absolute_path_to_current_module do + parse &Utils.parse/1 + serialize &Utils.serialize/1 + description Absinthe.Fixtures.Scalar.TestSchemaDescriptionMacro.test_function("red") + end + + scalar :standard_library_function do + parse &Utils.parse/1 + serialize &Utils.serialize/1 + description String.replace("red", "e", "a") + end + + scalar :function_in_nested_module do + parse &Utils.parse/1 + serialize &Utils.serialize/1 + description NestedModule.nested_function("hello") + end + + scalar :external_module_function_call do + parse &Utils.parse/1 + serialize &Utils.serialize/1 + description Absinthe.Fixtures.FunctionEvaluationHelpers.external_function("hello") + end + + scalar :module_attribute_string_concat do + parse &Utils.parse/1 + serialize &Utils.serialize/1 + description "hello " <> @module_attribute + end + + scalar :interpolation_of_module_attribute do + parse &Utils.parse/1 + serialize &Utils.serialize/1 + description "hello #{@module_attribute}" + end + end +end From fba1663a9841c2a079e6f7001aee2de02b017e7e Mon Sep 17 00:00:00 2001 From: Dylan Chong Date: Tue, 22 Dec 2020 13:27:24 +1300 Subject: [PATCH 47/50] Fix union types and add tests --- lib/absinthe/schema/notation.ex | 7 +- test/absinthe/type/union_test.exs | 42 +++++++++ test/support/fixtures/scalar.ex | 6 +- test/support/fixtures/union.ex | 151 ++++++++++++++++++++++++++++++ 4 files changed, 203 insertions(+), 3 deletions(-) create mode 100644 test/support/fixtures/union.ex diff --git a/lib/absinthe/schema/notation.ex b/lib/absinthe/schema/notation.ex index bfcfc366f9..1b189652f8 100644 --- a/lib/absinthe/schema/notation.ex +++ b/lib/absinthe/schema/notation.ex @@ -976,7 +976,12 @@ defmodule Absinthe.Schema.Notation do defmacro union(identifier, attrs \\ [], do: block) do __CALLER__ |> recordable!(:union, @placement[:union]) - |> record!(Schema.UnionTypeDefinition, identifier, attrs, block) + |> record!( + Schema.UnionTypeDefinition, + identifier, + attrs |> Keyword.update(:description, nil, &wrap_in_unquote/1), + block + ) end @placement {:types, [under: [:union]]} diff --git a/test/absinthe/type/union_test.exs b/test/absinthe/type/union_test.exs index e889b12399..c57cd8dbca 100644 --- a/test/absinthe/type/union_test.exs +++ b/test/absinthe/type/union_test.exs @@ -2,6 +2,7 @@ defmodule Absinthe.Type.UnionTest do use Absinthe.Case, async: true alias Absinthe.Type + alias Absinthe.Fixtures.Union defmodule TestSchema do use Absinthe.Schema @@ -82,4 +83,45 @@ defmodule Absinthe.Type.UnionTest do Type.Union.resolve_type(obj, %{name: "asdf"}, %{schema: TestSchema}) end end + + describe "union keyword description evaluation" do + Absinthe.Fixtures.FunctionEvaluationHelpers.function_evaluation_test_params() + |> Enum.each(fn %{ + test_label: test_label, + expected_value: expected_value + } -> + test "for `#{test_label}` (evaluates description to `'#{expected_value}'`)" do + type = Union.TestSchemaDescriptionKeyword.__absinthe_type__(unquote(test_label)) + assert type.description == unquote(expected_value) + end + end) + end + + describe "union description attribute evaluation" do + Absinthe.Fixtures.FunctionEvaluationHelpers.function_evaluation_test_params() + |> Absinthe.Fixtures.FunctionEvaluationHelpers.filter_test_params_for_description_attribute() + |> Enum.each(fn %{ + test_label: test_label, + expected_value: expected_value + } -> + test "for #{test_label} (evaluates description to '#{expected_value}')" do + type = Union.TestSchemaDescriptionAttribute.__absinthe_type__(unquote(test_label)) + + assert type.description == unquote(expected_value) + end + end) + end + + describe "union description macro evaluation" do + Absinthe.Fixtures.FunctionEvaluationHelpers.function_evaluation_test_params() + |> Enum.each(fn %{ + test_label: test_label, + expected_value: expected_value + } -> + test "for #{test_label} (evaluates description to '#{expected_value}')" do + type = Union.TestSchemaDescriptionMacro.__absinthe_type__(unquote(test_label)) + assert type.description == unquote(expected_value) + end + end) + end end diff --git a/test/support/fixtures/scalar.ex b/test/support/fixtures/scalar.ex index 549543f494..b2ba80bb06 100644 --- a/test/support/fixtures/scalar.ex +++ b/test/support/fixtures/scalar.ex @@ -93,12 +93,14 @@ defmodule Absinthe.Fixtures.Scalar do # @desc test_function("red") # scalar :local_function_call do - + # parse &Utils.parse/1 + # serialize &Utils.serialize/1 # end # @desc Absinthe.Fixtures.Scalar.TestSchemaEnumAttribute.test_function("red") # scalar :function_call_using_absolute_path_to_current_module do - + # parse &Utils.parse/1 + # serialize &Utils.serialize/1 # end @desc String.replace("red", "e", "a") diff --git a/test/support/fixtures/union.ex b/test/support/fixtures/union.ex new file mode 100644 index 0000000000..51cd4ad936 --- /dev/null +++ b/test/support/fixtures/union.ex @@ -0,0 +1,151 @@ +defmodule Absinthe.Fixtures.Union do + defmodule TestSchemaDescriptionKeyword do + use Absinthe.Schema + @module_attribute "goodbye" + + defmodule NestedModule do + def nested_function(arg1) do + arg1 + end + end + + query do + end + + union :normal_string, description: "string" do + end + + union :local_function_call, description: test_function("red") do + end + + union :function_call_using_absolute_path_to_current_module, + description: Absinthe.Fixtures.Union.TestSchemaDescriptionKeyword.test_function("red") do + end + + union :standard_library_function, description: String.replace("red", "e", "a") do + end + + union :function_in_nested_module, description: NestedModule.nested_function("hello") do + end + + union :external_module_function_call, + description: Absinthe.Fixtures.FunctionEvaluationHelpers.external_function("hello") do + end + + union :module_attribute_string_concat, description: "hello " <> @module_attribute do + end + + union :interpolation_of_module_attribute, description: "hello #{@module_attribute}" do + end + + def test_function(arg1) do + arg1 + end + end + + defmodule TestSchemaDescriptionAttribute do + use Absinthe.Schema + @module_attribute "goodbye" + + defmodule NestedModule do + def nested_function(arg1) do + arg1 + end + end + + query do + end + + def test_function(arg1) do + arg1 + end + + @desc "string" + union :normal_string do + end + + # These tests do not work as test_function is not available at compile time, and the + # expression for the @desc attribute is evaluated at compile time. There is nothing we can + # really do about it + + # @desc test_function("red") + # union :local_function_call do + + # end + + # @desc Absinthe.Fixtures.Union.TestSchemaEnumAttribute.test_function("red") + # union :function_call_using_absolute_path_to_current_module do + + # end + + @desc String.replace("red", "e", "a") + union :standard_library_function do + end + + @desc NestedModule.nested_function("hello") + union :function_in_nested_module do + end + + @desc Absinthe.Fixtures.FunctionEvaluationHelpers.external_function("hello") + union :external_module_function_call do + end + + @desc "hello " <> @module_attribute + union :module_attribute_string_concat do + end + + @desc "hello #{@module_attribute}" + union :interpolation_of_module_attribute do + end + end + + defmodule TestSchemaDescriptionMacro do + use Absinthe.Schema + @module_attribute "goodbye" + + defmodule NestedModule do + def nested_function(arg1) do + arg1 + end + end + + query do + end + + def test_function(arg1) do + arg1 + end + + union :normal_string do + description "string" + end + + union :local_function_call do + description test_function("red") + end + + union :function_call_using_absolute_path_to_current_module do + description Absinthe.Fixtures.Union.TestSchemaDescriptionMacro.test_function("red") + end + + union :standard_library_function do + description String.replace("red", "e", "a") + end + + union :function_in_nested_module do + description NestedModule.nested_function("hello") + end + + union :external_module_function_call do + description Absinthe.Fixtures.FunctionEvaluationHelpers.external_function("hello") + end + + union :module_attribute_string_concat do + description "hello " <> @module_attribute + end + + union :interpolation_of_module_attribute do + description "hello #{@module_attribute}" + end + end +end From 3e7f31627ae9dd906879abf092558bb4a72a7e9b Mon Sep 17 00:00:00 2001 From: Dylan Chong Date: Tue, 22 Dec 2020 13:56:55 +1300 Subject: [PATCH 48/50] Update comment --- lib/absinthe/schema/notation.ex | 10 ++++++---- test/absinthe/type/import_types_test.exs | 9 +++++---- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/lib/absinthe/schema/notation.ex b/lib/absinthe/schema/notation.ex index 1b189652f8..c964a5a4d2 100644 --- a/lib/absinthe/schema/notation.ex +++ b/lib/absinthe/schema/notation.ex @@ -1905,13 +1905,15 @@ defmodule Absinthe.Schema.Notation do defp expand_ast(ast, env) do Macro.prewalk(ast, fn - # We don't want to expand `@bla` into Module.get_attribute(module, @bla) because this will - # fail at runtime. Remember that the ast gets put into a generated `__absinthe_blueprint__` - # function which is called at "__after_compile__" time, but may be called at runtime - # depending on the ordering of how modules get compiled. + # We don't want to expand `@bla` into `Module.get_attribute(module, @bla)` because this + # function call will fail if the module is already compiled. Remember that the ast gets put + # into a generated `__absinthe_blueprint__` function which is called at "__after_compile__" + # time. This will be after a module has been compiled if there are multiple modules in the + # schema (in the case of an `import_types`). # # Also see test "test/absinthe/type/import_types_test.exs" # "__absinthe_blueprint__ is callable at runtime even if there is a module attribute" + # and it's comment for more information {:@, _, _} = node -> node diff --git a/test/absinthe/type/import_types_test.exs b/test/absinthe/type/import_types_test.exs index 89c1095414..491dd59f52 100644 --- a/test/absinthe/type/import_types_test.exs +++ b/test/absinthe/type/import_types_test.exs @@ -58,10 +58,11 @@ defmodule Absinthe.Type.ImportTypesTest do # From inside `defp expand_ast` in `Absinthe.Schema.Notation`: # - # > We don't want to expand `@bla` into Module.get_attribute(module, @bla) because this will - # > fail at runtime. Remember that the ast gets put into a generated `__absinthe_blueprint__` - # > function which is called at "__after_compile__" time, but may be called at runtime - # > depending on the ordering of how modules get compiled. + # > We don't want to expand `@bla` into `Module.get_attribute(module, @bla)` because this + # > function call will fail if the module is already compiled. Remember that the ast gets put + # > into a generated `__absinthe_blueprint__` function which is called at "__after_compile__" + # > time. This will be after a module has been compiled if there are multiple modules in the + # > schema (in the case of an `import_types`). # # This test checks that __absinthe_blueprint__ runs and doesn't raise an error saying # "Module.get_attribute" cannot be called because the module is already compiled". This error From 2e193dec4602731f4f427a03c55767089f1e8e9d Mon Sep 17 00:00:00 2001 From: Dylan Chong Date: Tue, 22 Dec 2020 14:22:30 +1300 Subject: [PATCH 49/50] Make test naming consistent --- test/absinthe/execution/arguments/scalar_test.exs | 2 +- test/absinthe/type/directive_test.exs | 4 ++-- test/absinthe/type/input_object_test.exs | 2 +- test/absinthe/type/object_test.exs | 2 +- test/absinthe/type/union_test.exs | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/test/absinthe/execution/arguments/scalar_test.exs b/test/absinthe/execution/arguments/scalar_test.exs index 606a023e07..8063e1efb7 100644 --- a/test/absinthe/execution/arguments/scalar_test.exs +++ b/test/absinthe/execution/arguments/scalar_test.exs @@ -67,7 +67,7 @@ defmodule Absinthe.Execution.Arguments.ScalarTest do test_label: test_label, expected_value: expected_value } -> - test "for `#{test_label}` (evaluates description to `'#{expected_value}'`)" do + test "for #{test_label} (evaluates description to `#{expected_value}')" do type = Scalar.TestSchemaDescriptionKeyword.__absinthe_type__(unquote(test_label)) assert type.description == unquote(expected_value) end diff --git a/test/absinthe/type/directive_test.exs b/test/absinthe/type/directive_test.exs index cba306ffe1..f9eed80a8d 100644 --- a/test/absinthe/type/directive_test.exs +++ b/test/absinthe/type/directive_test.exs @@ -232,7 +232,7 @@ defmodule Absinthe.Type.DirectiveTest do test_label: test_label, expected_value: expected_value } -> - test "for `#{test_label}` (evaluates description to `'#{expected_value}'`)" do + test "for #{test_label} (evaluates description to `#{expected_value}')" do type = Directive.TestSchemaDescriptionKeyword.__absinthe_directive__(unquote(test_label)) assert type.description == unquote(expected_value) end @@ -274,7 +274,7 @@ defmodule Absinthe.Type.DirectiveTest do test_label: test_label, expected_value: expected_value } -> - test "for `#{test_label}` (evaluates description to `'#{expected_value}'`)" do + test "for #{test_label} (evaluates description to `#{expected_value}')" do type = Directive.TestSchemaArgDescriptionKeyword.__absinthe_directive__(unquote(test_label)) diff --git a/test/absinthe/type/input_object_test.exs b/test/absinthe/type/input_object_test.exs index 481b98efc4..fa82568e15 100644 --- a/test/absinthe/type/input_object_test.exs +++ b/test/absinthe/type/input_object_test.exs @@ -37,7 +37,7 @@ defmodule Absinthe.Type.InputObjectTest do test_label: test_label, expected_value: expected_value } -> - test "for `#{test_label}` (evaluates description to `'#{expected_value}'`)" do + test "for #{test_label} (evaluates description to `#{expected_value}')" do type = InputObject.TestSchemaDescriptionKeyword.__absinthe_type__(unquote(test_label)) assert type.description == unquote(expected_value) end diff --git a/test/absinthe/type/object_test.exs b/test/absinthe/type/object_test.exs index f58ccdd28b..b4b924bc78 100644 --- a/test/absinthe/type/object_test.exs +++ b/test/absinthe/type/object_test.exs @@ -49,7 +49,7 @@ defmodule Absinthe.Type.ObjectTest do test_label: test_label, expected_value: expected_value } -> - test "for `#{test_label}` (evaluates description to `'#{expected_value}'`)" do + test "for #{test_label} (evaluates description to `#{expected_value}')" do type = Object.TestSchemaDescriptionKeyword.__absinthe_type__(unquote(test_label)) assert type.description == unquote(expected_value) end diff --git a/test/absinthe/type/union_test.exs b/test/absinthe/type/union_test.exs index c57cd8dbca..979712541d 100644 --- a/test/absinthe/type/union_test.exs +++ b/test/absinthe/type/union_test.exs @@ -90,7 +90,7 @@ defmodule Absinthe.Type.UnionTest do test_label: test_label, expected_value: expected_value } -> - test "for `#{test_label}` (evaluates description to `'#{expected_value}'`)" do + test "for #{test_label} (evaluates description to `#{expected_value}')" do type = Union.TestSchemaDescriptionKeyword.__absinthe_type__(unquote(test_label)) assert type.description == unquote(expected_value) end From 5ef5b90e1e026e7c46bd798f069449355179a9b5 Mon Sep 17 00:00:00 2001 From: Dylan Chong Date: Tue, 22 Dec 2020 16:06:51 +1300 Subject: [PATCH 50/50] Bad find and replace --- test/absinthe/execution/arguments/scalar_test.exs | 2 +- test/absinthe/type/directive_test.exs | 4 ++-- test/absinthe/type/input_object_test.exs | 2 +- test/absinthe/type/object_test.exs | 2 +- test/absinthe/type/union_test.exs | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/test/absinthe/execution/arguments/scalar_test.exs b/test/absinthe/execution/arguments/scalar_test.exs index 8063e1efb7..e0f3226d66 100644 --- a/test/absinthe/execution/arguments/scalar_test.exs +++ b/test/absinthe/execution/arguments/scalar_test.exs @@ -67,7 +67,7 @@ defmodule Absinthe.Execution.Arguments.ScalarTest do test_label: test_label, expected_value: expected_value } -> - test "for #{test_label} (evaluates description to `#{expected_value}')" do + test "for #{test_label} (evaluates description to '#{expected_value}')" do type = Scalar.TestSchemaDescriptionKeyword.__absinthe_type__(unquote(test_label)) assert type.description == unquote(expected_value) end diff --git a/test/absinthe/type/directive_test.exs b/test/absinthe/type/directive_test.exs index f9eed80a8d..a547a2adcb 100644 --- a/test/absinthe/type/directive_test.exs +++ b/test/absinthe/type/directive_test.exs @@ -232,7 +232,7 @@ defmodule Absinthe.Type.DirectiveTest do test_label: test_label, expected_value: expected_value } -> - test "for #{test_label} (evaluates description to `#{expected_value}')" do + test "for #{test_label} (evaluates description to '#{expected_value}')" do type = Directive.TestSchemaDescriptionKeyword.__absinthe_directive__(unquote(test_label)) assert type.description == unquote(expected_value) end @@ -274,7 +274,7 @@ defmodule Absinthe.Type.DirectiveTest do test_label: test_label, expected_value: expected_value } -> - test "for #{test_label} (evaluates description to `#{expected_value}')" do + test "for #{test_label} (evaluates description to '#{expected_value}')" do type = Directive.TestSchemaArgDescriptionKeyword.__absinthe_directive__(unquote(test_label)) diff --git a/test/absinthe/type/input_object_test.exs b/test/absinthe/type/input_object_test.exs index fa82568e15..d4e9659124 100644 --- a/test/absinthe/type/input_object_test.exs +++ b/test/absinthe/type/input_object_test.exs @@ -37,7 +37,7 @@ defmodule Absinthe.Type.InputObjectTest do test_label: test_label, expected_value: expected_value } -> - test "for #{test_label} (evaluates description to `#{expected_value}')" do + test "for #{test_label} (evaluates description to '#{expected_value}')" do type = InputObject.TestSchemaDescriptionKeyword.__absinthe_type__(unquote(test_label)) assert type.description == unquote(expected_value) end diff --git a/test/absinthe/type/object_test.exs b/test/absinthe/type/object_test.exs index b4b924bc78..2ebf04a91a 100644 --- a/test/absinthe/type/object_test.exs +++ b/test/absinthe/type/object_test.exs @@ -49,7 +49,7 @@ defmodule Absinthe.Type.ObjectTest do test_label: test_label, expected_value: expected_value } -> - test "for #{test_label} (evaluates description to `#{expected_value}')" do + test "for #{test_label} (evaluates description to '#{expected_value}')" do type = Object.TestSchemaDescriptionKeyword.__absinthe_type__(unquote(test_label)) assert type.description == unquote(expected_value) end diff --git a/test/absinthe/type/union_test.exs b/test/absinthe/type/union_test.exs index 979712541d..074bef85d9 100644 --- a/test/absinthe/type/union_test.exs +++ b/test/absinthe/type/union_test.exs @@ -90,7 +90,7 @@ defmodule Absinthe.Type.UnionTest do test_label: test_label, expected_value: expected_value } -> - test "for #{test_label} (evaluates description to `#{expected_value}')" do + test "for #{test_label} (evaluates description to '#{expected_value}')" do type = Union.TestSchemaDescriptionKeyword.__absinthe_type__(unquote(test_label)) assert type.description == unquote(expected_value) end