Skip to content

Commit

Permalink
Warn on invalid wrapped arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
Clifton McIntosh committed Nov 17, 2023
1 parent 0fa561b commit 5afb370
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
19 changes: 18 additions & 1 deletion lib/absinthe/phase/validation/known_type_names.ex
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ defmodule Absinthe.Phase.Validation.KnownTypeNames do
# }
# ```

require Logger

alias Absinthe.{Blueprint, Phase}
alias Absinthe.Phase.Document.Validation.Utils

Expand All @@ -34,7 +36,7 @@ defmodule Absinthe.Phase.Validation.KnownTypeNames do
|> put_error(error(node, name))
end

defp handle_node(%Blueprint.Document.VariableDefinition{} = node, schema) do
defp handle_node(%Blueprint.Document.VariableDefinition{schema_node: nil} = node, schema) do
name = Blueprint.TypeReference.unwrap(node.type).name
inner_schema_type = schema.__absinthe_lookup__(name)

Expand All @@ -49,6 +51,21 @@ defmodule Absinthe.Phase.Validation.KnownTypeNames do
end
end

defp handle_node(%Blueprint.Document.VariableDefinition{} = node, schema) do
name = Blueprint.TypeReference.unwrap(node.type).name
inner_schema_type = schema.__absinthe_lookup__(name)

if inner_schema_type do
node
else
suggestions = suggested_type_names(schema, name)
error = error(node, name, suggestions)

Logger.warn("KnownTypeNames error: #{error.message}")
node
end
end

defp handle_node(node, _) do
node
end
Expand Down
23 changes: 21 additions & 2 deletions test/absinthe/phase/validation/known_type_names_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ defmodule Absinthe.Phase.Validation.KnownTypeNamesTest do
test "unknown type names are invalid" do
assert_fails_validation(
"""
query Foo($var: JumbledUpLetters, $foo: Boolen!, $bar: [Bar!]) {
query Foo($var: JumbledUpLetters, $foo: Boolen, $bar: [Bar!]) {
user(id: 4) {
name
pets { ... on Badger { name }, ...PetFields }
Expand All @@ -82,13 +82,32 @@ defmodule Absinthe.Phase.Validation.KnownTypeNamesTest do
1,
~s(Unknown type "Boolen". Did you mean "Alien" or "Boolean"?)
),
unknown_type(:variable_definition, "Bar", 1),
unknown_type(:inline_type_condition, "Badger", 4),
unknown_type(:named_type_condition, "Peettt", 7)
]
)
end

test "does not invalidate wrapped invalid type names" do
assert_fails_validation(
"""
query Foo($var: JumbledUpLetters, $foo: Boolen!, $bar: [Bar!]) {
user(id: 4) {
name
pets { ... on Badger { name }, ...PetFields }
}
}
fragment PetFields on Peettt {
name
}
""",
[],
[
unknown_type(:variable_definition, "JumbledUpLetters", 1)
]
)
end

test "ignores type definitions" do
assert_fails_validation(
"""
Expand Down

0 comments on commit 5afb370

Please sign in to comment.