-
Notifications
You must be signed in to change notification settings - Fork 530
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
Merged
benwilson512
merged 6 commits into
absinthe-graphql:master
from
mattbaker:non-null-list-non-null-list-nullable
Nov 18, 2023
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
28f26f6
Add test demonstrating odd behavior
mattbaker 3e5fafc
more tests
mattbaker 006b313
traverse deeply nested lists when searching for nullable violations
mattbaker 905ae4a
Merge branch 'master' into pr/mattbaker/1275
benwilson512 708375a
tweak index handling in the path
benwilson512 f69e0d0
changelog entry
benwilson512 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
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 = """ | ||
{ | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This seems like it should be redundant when
test "deeply nested nullable value inside non-nullable lists can be null"
exists below, but the latter actually passes in master for the same reasontest "deeply nested non-nullable value inside non-nullable lists cannot be null"
fails (I think).So I ended up keeping this test just for my own sanity.