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

Account for nil schema_node in ArgumentsOfCorrectType suggestions #1000

Conversation

emeryotopalik
Copy link
Contributor

@emeryotopalik emeryotopalik commented Dec 8, 2020

When unstructured scalar input is sent in a list to a mutation argument (see example), the schema_node in the ArgumentsOfCorrectType.suggested_field_names/2 function is nil. I accounted for the case at the source of the error, but it is totally possible that the blueprint should account for this case and the schema_node should be something other than nil. I will defer to y'all's knowledge on that though.

Mutation example:

mutation($scalarInput: CustomScalar) {
    createDog(customScalarInput: $scalarInput)
}
variables: { "scalarInput": [ {"foo": "BAR"} ] }

Stacktrace:

** (exit) an exception was raised:
    ** (UndefinedFunctionError) function nil.fields/0 is undefined
        nil.fields()
        (absinthe 1.5.4) lib/absinthe/phase/document/validation/arguments_of_correct_type.ex:125: Absinthe.Phase.Document.Validation.ArgumentsOfCorrectType.suggested_field_names/2
        (absinthe 1.5.4) lib/absinthe/phase/document/validation/arguments_of_correct_type.ex:87: anonymous fn/3 in Absinthe.Phase.Document.Validation.ArgumentsOfCorrectType.collect_child_errors/2
        (elixir 1.10.4) lib/enum.ex:3343: Enum.flat_map_list/2
        (absinthe 1.5.4) lib/absinthe/phase/document/validation/arguments_of_correct_type.ex:33: Absinthe.Phase.Document.Validation.ArgumentsOfCorrectType.handle_node/2
        (absinthe 1.5.4) lib/absinthe/blueprint/transform.ex:16: anonymous fn/3 in Absinthe.Blueprint.Transform.prewalk/2
        (absinthe 1.5.4) lib/absinthe/blueprint/transform.ex:109: Absinthe.Blueprint.Transform.walk/4
        (elixir 1.10.4) lib/enum.ex:1520: Enum."-map_reduce/3-lists^mapfoldl/2-0-"/3
        (absinthe 1.5.4) lib/absinthe/blueprint/transform.ex:145: anonymous fn/4 in Absinthe.Blueprint.Transform.walk_children/5
        (elixir 1.10.4) lib/enum.ex:2111: Enum."-reduce/3-lists^foldl/2-0-"/3
        (absinthe 1.5.4) lib/absinthe/blueprint/transform.ex:114: Absinthe.Blueprint.Transform.walk/4
        (elixir 1.10.4) lib/enum.ex:1520: Enum."-map_reduce/3-lists^mapfoldl/2-0-"/3
        (absinthe 1.5.4) lib/absinthe/blueprint/transform.ex:145: anonymous fn/4 in Absinthe.Blueprint.Transform.walk_children/5
        (elixir 1.10.4) lib/enum.ex:2111: Enum."-reduce/3-lists^foldl/2-0-"/3
        (absinthe 1.5.4) lib/absinthe/blueprint/transform.ex:114: Absinthe.Blueprint.Transform.walk/4
        (elixir 1.10.4) lib/enum.ex:1520: Enum."-map_reduce/3-lists^mapfoldl/2-0-"/3
        (absinthe 1.5.4) lib/absinthe/blueprint/transform.ex:145: anonymous fn/4 in Absinthe.Blueprint.Transform.walk_children/5
        (elixir 1.10.4) lib/enum.ex:2111: Enum."-reduce/3-lists^foldl/2-0-"/3
        (absinthe 1.5.4) lib/absinthe/blueprint/transform.ex:114: Absinthe.Blueprint.Transform.walk/4
        (absinthe 1.5.4) lib/absinthe/blueprint/transform.ex:15: Absinthe.Blueprint.Transform.prewalk/2

@@ -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 ->
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this part necessary to recreate the bug?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably not! I'll verify.

Copy link
Contributor

@benwilson512 benwilson512 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes total sense, thanks!

@benwilson512
Copy link
Contributor

@binaryseed do you mind looking into these CI errors?

@binaryseed binaryseed changed the base branch from master to fix-nil December 8, 2020 22:36
@binaryseed binaryseed merged commit 07cbdb6 into absinthe-graphql:fix-nil Dec 8, 2020
@binaryseed
Copy link
Contributor

some dialyzer error, pulling into a working branch to try and fix

@binaryseed
Copy link
Contributor

Ok, fixed & merged via #1001

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants