Skip to content

Commit

Permalink
Merge pull request #1000 from emeryotopalik/argument_of_correct_type_bug
Browse files Browse the repository at this point in the history
Account for `nil` schema_node in ArgumentsOfCorrectType suggestions
  • Loading branch information
binaryseed committed Dec 8, 2020
2 parents 1a03ef2 + 0f7d52c commit 07cbdb6
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
11 changes: 11 additions & 0 deletions test/support/fixtures/pets_schema.ex
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ defmodule Absinthe.Fixtures.PetsSchema do
field :string_list_field, list_of(:string)
end

scalar :custom_scalar do
parse & &1
serialize & &1
end

object :complicated_args do
field :int_arg_field, :string do
arg :int_arg, :integer
Expand Down Expand Up @@ -194,6 +199,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
Expand Down

0 comments on commit 07cbdb6

Please sign in to comment.