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

Traverse deeply nested lists when searching for null violations #1275

Conversation

mattbaker
Copy link
Contributor

@mattbaker mattbaker commented Sep 5, 2023

Attempts to fix #1274 by traversing through layers of non-null/list wrappers when looking for non-null constraint violations.

@mattbaker mattbaker changed the title Add test demonstrating odd behavior Issue 1274 Test Case Sep 5, 2023
@mattbaker mattbaker changed the title Issue 1274 Test Case Traverse deeply nested lists when searching for null violations Sep 9, 2023
Absinthe.run(doc, Schema)
end

test "deeply nested non-nullable value inside non-nullable lists cannot be null" do
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

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

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 reason test "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.

@mattbaker
Copy link
Contributor Author

@benwilson512: Full transparency — this is a complex file and I don't know if what I'm doing is the right thing here, it could definitely benefit from your eyes!

It seems like, one way or another, this boils down to the fact that a sufficiently deep wrapping of non_null(list_of(non_null(list_of(...... will cause issues? I took a stab at making the "add errors" codes and the null propagation code more recursive and it seemed to do the trick. My only worry is I feel like I don't fully grok everything in this module and I may have done the wrong thing and just gotten lucky 😱

@mattbaker
Copy link
Contributor Author

@benwilson512 - Curious if you have any thoughts, but I'm also sure you're busy and I know this is probably more than a surface fix! I could try to set some time aside this month to dive deeper and build some more familiarity myself and maybe emerge with a bit more confidence too, if you think you won't have time to take a look. It's also not super urgent for us.

defp maybe_add_non_null_error([], [_ | _] = values, %Type.List{of_type: type}, path) do
Enum.with_index(values)
|> Enum.flat_map(fn {value, index} ->
maybe_add_non_null_error([], value, type, path ++ [index])
Copy link
Contributor

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.

Copy link
Contributor Author

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!

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.

Sorry this took me so long to get to, thanks Matt!

@benwilson512 benwilson512 merged commit a1a85b3 into absinthe-graphql:master Nov 18, 2023
7 checks passed
@mattbaker
Copy link
Contributor Author

Not a problem at all! It was an odd edge case that was on our "to do" list but wasn't urgent at all.

Thanks so much!

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.

Resolving field of type [[Value]!]!] seems to fail with valid values
2 participants