From 373c3981c2511e9788a0130691a178fef514eea6 Mon Sep 17 00:00:00 2001 From: Emery Otopalik Date: Tue, 8 Dec 2020 11:49:24 -0800 Subject: [PATCH 1/2] account for nil schema node in argument type suggestions --- .../validation/arguments_of_correct_type.ex | 1 + .../arguments_of_correct_type_test.exs | 30 +++++++++++++++++++ test/support/fixtures/pets_schema.ex | 21 +++++++++++++ 3 files changed, 52 insertions(+) diff --git a/lib/absinthe/phase/document/validation/arguments_of_correct_type.ex b/lib/absinthe/phase/document/validation/arguments_of_correct_type.ex index 4a491ca4cd..f97c3faefc 100644 --- a/lib/absinthe/phase/document/validation/arguments_of_correct_type.ex +++ b/lib/absinthe/phase/document/validation/arguments_of_correct_type.ex @@ -84,6 +84,7 @@ defmodule Absinthe.Phase.Document.Validation.ArgumentsOfCorrectType do case Type.unwrap(node.schema_node) do %Type.Scalar{} -> [] %Type.Enum{} -> [] + nil -> [] _ -> suggested_field_names(node.schema_node, child.name) end diff --git a/test/absinthe/phase/document/validation/arguments_of_correct_type_test.exs b/test/absinthe/phase/document/validation/arguments_of_correct_type_test.exs index 83a6bffa3b..bf23e5394a 100644 --- a/test/absinthe/phase/document/validation/arguments_of_correct_type_test.exs +++ b/test/absinthe/phase/document/validation/arguments_of_correct_type_test.exs @@ -974,6 +974,36 @@ defmodule Absinthe.Phase.Document.Validation.ArgumentsOfCorrectTypeTest do end end + describe "Invalid Custom Scalar value" do + test "Invalid scalar input on mutation, no suggestion" do + assert_fails_validation( + """ + mutation($scalarInput: CustomScalar) { + createDog(customScalarInput: $scalarInput) + } + """, + [ + variables: %{ + "scalarInput" => [ + %{ + "foo" => "BAR" + } + ] + } + ], + [ + bad_argument( + "customScalarInput", + "CustomScalar", + ~s($scalarInput), + 2, + [@phase.unknown_field_error_message("foo")] + ) + ] + ) + end + end + describe "Directive arguments" do test "with directives of valid types" do assert_passes_validation( diff --git a/test/support/fixtures/pets_schema.ex b/test/support/fixtures/pets_schema.ex index aa1b8e3dde..a02cf88083 100644 --- a/test/support/fixtures/pets_schema.ex +++ b/test/support/fixtures/pets_schema.ex @@ -123,6 +123,21 @@ defmodule Absinthe.Fixtures.PetsSchema do field :string_list_field, list_of(:string) end + scalar :custom_scalar do + parse fn + %Absinthe.Blueprint.Input.Object{} = input -> + {:ok, input} + + %Absinthe.Blueprint.Input.Null{} -> + {:ok, nil} + + _other -> + :error + end + + serialize & &1 + end + object :complicated_args do field :int_arg_field, :string do arg :int_arg, :integer @@ -194,6 +209,12 @@ defmodule Absinthe.Fixtures.PetsSchema do field :complicated_args, :complicated_args end + mutation do + field :create_dog, :dog do + arg :custom_scalar_input, non_null(:custom_scalar) + end + end + directive :on_query do on [:query] end From 0f7d52c36bab35f734ad394d23d8c78f2cf94159 Mon Sep 17 00:00:00 2001 From: Emery Otopalik Date: Tue, 8 Dec 2020 12:25:04 -0800 Subject: [PATCH 2/2] make custom scalar more generic --- test/support/fixtures/pets_schema.ex | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/test/support/fixtures/pets_schema.ex b/test/support/fixtures/pets_schema.ex index a02cf88083..b0ecc1bc57 100644 --- a/test/support/fixtures/pets_schema.ex +++ b/test/support/fixtures/pets_schema.ex @@ -124,17 +124,7 @@ defmodule Absinthe.Fixtures.PetsSchema do end scalar :custom_scalar do - parse fn - %Absinthe.Blueprint.Input.Object{} = input -> - {:ok, input} - - %Absinthe.Blueprint.Input.Null{} -> - {:ok, nil} - - _other -> - :error - end - + parse & &1 serialize & &1 end