-
Notifications
You must be signed in to change notification settings - Fork 528
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
Traverse deeply nested lists when searching for null violations #1275
Changes from 3 commits
28f26f6
3e5fafc
006b313
905ae4a
708375a
f69e0d0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -96,6 +96,29 @@ defmodule Absinthe.Phase.Document.Execution.NonNullTest do | |
resolve &things_resolver/3 | ||
end | ||
|
||
field :non_null_list_of_non_null_list_of_nullable, | ||
non_null(list_of(non_null(list_of(:string)))) do | ||
resolve fn _, _ -> | ||
{:ok, [["ok", nil]]} | ||
end | ||
end | ||
|
||
field :deeply_nested_non_nullable_list_of_nullable, | ||
non_null(list_of(non_null(list_of(non_null(list_of(non_null(list_of(:string)))))))) do | ||
resolve fn _, _ -> | ||
{:ok, [[[["ok", nil]]]]} | ||
end | ||
end | ||
|
||
field :deeply_nested_non_nullable_list_of_non_nullable, | ||
non_null( | ||
list_of(non_null(list_of(non_null(list_of(non_null(list_of(non_null(:string)))))))) | ||
) do | ||
resolve fn _, _ -> | ||
{:ok, [[[["1", nil, "3"], ["4", nil, "6"]]]]} | ||
end | ||
end | ||
|
||
@desc """ | ||
A field declared to be non null. | ||
|
||
|
@@ -217,6 +240,51 @@ defmodule Absinthe.Phase.Document.Execution.NonNullTest do | |
end | ||
|
||
describe "lists" do | ||
test "non-null list of non-null list of nullable value returns null value" do | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems like it should be redundant when So I ended up keeping this test just for my own sanity. |
||
doc = """ | ||
{ | ||
nonNullListOfNonNullListOfNullable | ||
} | ||
""" | ||
|
||
assert {:ok, %{data: %{"nonNullListOfNonNullListOfNullable" => [["ok", nil]]}}} == | ||
Absinthe.run(doc, Schema) | ||
end | ||
|
||
test "deeply nested nullable value inside non-nullable lists can be null" do | ||
doc = """ | ||
{ | ||
deeplyNestedNonNullableListOfNullable | ||
} | ||
""" | ||
|
||
assert {:ok, %{data: %{"deeplyNestedNonNullableListOfNullable" => [[[["ok", nil]]]]}}} == | ||
Absinthe.run(doc, Schema) | ||
end | ||
|
||
test "deeply nested non-nullable value inside non-nullable lists cannot be null" do | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This wasn't the issue I saw when I started digging into this, but this test also fails on master. I think it's in the same theme of needing to traverse through multiple layers of lists/non-nulls. |
||
doc = """ | ||
{ | ||
deeplyNestedNonNullableListOfNonNullable | ||
} | ||
""" | ||
|
||
errors = [ | ||
%{ | ||
locations: [%{column: 3, line: 2}], | ||
message: "Cannot return null for non-nullable field", | ||
path: ["deeplyNestedNonNullableListOfNonNullable", 0, 0, 0, 1] | ||
}, | ||
%{ | ||
locations: [%{column: 3, line: 2}], | ||
message: "Cannot return null for non-nullable field", | ||
path: ["deeplyNestedNonNullableListOfNonNullable", 0, 0, 1, 1] | ||
} | ||
] | ||
|
||
assert {:ok, %{data: nil, errors: errors}} == Absinthe.run(doc, Schema) | ||
end | ||
|
||
test "list of nullable things returns an error when child has a null violation" do | ||
doc = """ | ||
{ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Appending to this list here will be
O(n^2)
and the lists could potentially be quite large. I'm working to refactor this.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh very good catch, I breezed right past that!