Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve typechecks on nested args #1290

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## Unreleased
- POTENTIALLY BREAKING Bug Fix: [Validate variable usage in nested input arguments](https://github.com/absinthe-graphql/absinthe/pull/1290).This could break incoming documents previously considered valid. Skip the Absinthe.Phase.Document.Arguments.VariableTypesMatch phase to avoid this check. See Absinthe.Pipeline on adjusting the document pipeline.

## 1.7.6

- Bugfix: [Handle non_null(list_of(:thing)) with null list elements properly](https://github.com/absinthe-graphql/absinthe/pull/1259)
Expand Down
24 changes: 20 additions & 4 deletions lib/absinthe/phase/document/arguments/variable_types_match.ex
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,18 @@ defmodule Absinthe.Phase.Document.Arguments.VariableTypesMatch do
{:halt, node}
end

defp check_variable_type(
%Absinthe.Blueprint.Input.Field{
input_value: %Blueprint.Input.Value{
raw: %{content: %Blueprint.Input.Variable{} = variable}
}
} = node,
operation_name,
variable_defs
) do
compare_variable_with_definition(variable, node, operation_name, variable_defs)
end

defp check_variable_type(
%Absinthe.Blueprint.Input.Argument{
input_value: %Blueprint.Input.Value{
Expand All @@ -68,6 +80,14 @@ defmodule Absinthe.Phase.Document.Arguments.VariableTypesMatch do
operation_name,
variable_defs
) do
compare_variable_with_definition(variable, node, operation_name, variable_defs)
end

defp check_variable_type(node, _, _) do
node
end

defp compare_variable_with_definition(variable, node, operation_name, variable_defs) do
location_type = node.input_value.schema_node
location_definition = node.schema_node

Expand Down Expand Up @@ -95,10 +115,6 @@ defmodule Absinthe.Phase.Document.Arguments.VariableTypesMatch do
end
end

defp check_variable_type(node, _, _) do
node
end

def types_compatible?(type, type, _, _) do
true
end
Expand Down
4 changes: 2 additions & 2 deletions test/absinthe/execution/arguments/input_object_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ defmodule Absinthe.Execution.Arguments.InputObjectTest do
end

@graphql """
query ($email: String) {
query ($email: String!) {
contacts(contacts: [{email: $email}, {email: $email}])
}
"""
Expand Down Expand Up @@ -67,7 +67,7 @@ defmodule Absinthe.Execution.Arguments.InputObjectTest do
end

@graphql """
query ($email: String, $defaultWithString: String) {
query ($email: String!, $defaultWithString: String) {
user(contact: {email: $email, defaultWithString: $defaultWithString})
}
"""
Expand Down
25 changes: 25 additions & 0 deletions test/absinthe/integration/execution/input_object_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,29 @@ defmodule Elixir.Absinthe.Integration.Execution.InputObjectTest do
variables: %{"input" => true}
)
end

@query """
mutation ($input: String) {
updateThing(id: "foo", thing: {value: $input}) {
name
value
}
}
"""

test "errors if an invalid type is passed to nested arg" do
assert {:ok,
%{
errors: [
%{
locations: [%{column: 41, line: 2}],
message:
"Variable `$input` of type `String` found as input to argument of type `Int`."
}
]
}} ==
Absinthe.run(@query, Absinthe.Fixtures.Things.MacroSchema,
variables: %{"input" => 1}
)
end
end